2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
11 * Implementation of Upgradable {@link RootModificationApplyOperation}
14 * This implementation is associated with {@link LatestOperationHolder}
15 * which holds latest available implementation, which may be used for
19 * Upgrading {@link LatestOperationHolder} will not affect any instance,
20 * unless client invoked {@link #upgradeIfPossible()} which will result in
21 * changing delegate to the latest one.
23 final class UpgradableModificationApplyOperation extends RootModificationApplyOperation {
24 private final LatestOperationHolder holder;
25 private ModificationApplyOperation delegate;
27 UpgradableModificationApplyOperation(final LatestOperationHolder holder,
28 final ModificationApplyOperation delegate) {
30 this.delegate = delegate;
34 void upgradeIfPossible() {
35 ModificationApplyOperation holderCurrent = holder.getCurrent();
36 if (holderCurrent != delegate) {
37 // FIXME: Allow update only if there is addition of models, not
39 delegate = holderCurrent;
44 ModificationApplyOperation delegate() {
49 RootModificationApplyOperation snapshot() {
50 return new UpgradableModificationApplyOperation(holder, delegate);