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 {
24 private final LatestOperationHolder holder;
25 private ModificationApplyOperation delegate;
27 public UpgradableModificationApplyOperation(final LatestOperationHolder holder, final ModificationApplyOperation delegate) {
29 this.delegate = delegate;
34 public 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 getDelegate() {
49 public RootModificationApplyOperation snapshot() {
50 return new UpgradableModificationApplyOperation(holder, getDelegate());