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}
13 * This implementation is associated with {@link LatestOperationHolder}
14 * which holds latest available implementation, which may be used for
17 * Upgrading {@link LatestOperationHolder} will not affect any instance,
18 * unless client invoked {@link #upgradeIfPossible()} which will result in
19 * changing delegate to the latest one.
22 final class UpgradableModificationApplyOperation extends RootModificationApplyOperation {
23 private final LatestOperationHolder holder;
24 private ModificationApplyOperation delegate;
26 UpgradableModificationApplyOperation(final LatestOperationHolder holder, final ModificationApplyOperation delegate) {
28 this.delegate = delegate;
32 void upgradeIfPossible() {
33 ModificationApplyOperation holderCurrent = holder.getCurrent();
34 if (holderCurrent != delegate) {
35 // FIXME: Allow update only if there is addition of models, not
37 delegate = holderCurrent;
42 ModificationApplyOperation getDelegate() {
47 RootModificationApplyOperation snapshot() {
48 return new UpgradableModificationApplyOperation(holder, getDelegate());