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;
10 import com.google.common.collect.ForwardingObject;
13 * Represents a {@link ModificationApplyOperation} which is rooted at conceptual
17 * This implementation differs from other implementations in this package that
18 * is not immutable, but may be upgraded to newer state if available by
19 * explicitly invoking {@link #upgradeIfPossible()} and also serves as factory
20 * for deriving snapshot {@link RootApplyStrategy} which will not
21 * be affected by upgrade of original one.
24 * There are two variations of this {@link ModificationApplyOperation}:
27 * <b>Upgradable</b> - operation may be upgraded to different backing
28 * implementation by invoking {@link #upgradeIfPossible()}.</li>
29 * <li><b>Not Upgradable</b> - operation is immutable, invocation of
30 * {@link #upgradeIfPossible()} is no-op and method {@link #snapshot()} returns
31 * pointer on same object.
33 * <h3>Upgradable Root Modification Operation</h3>
34 * Upgradable Root Modification Operation may be created using:
36 * <li> {@link #from(ModificationApplyOperation)} with other upgradable root
37 * modification as an argument
38 * <li>using factory {@link LatestOperationHolder} which instantiates Upgradable
39 * Root Modification Operations and provides an option to set latest
44 * Upgradable root operation is never upgraded to latest operation
45 * automatically, but client code must explicitly invoke
46 * {@link #upgradeIfPossible()} to get latest implementation.
49 * Note: This is helpful for implementing
50 * {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification}
51 * which may be derived from
52 * {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree} before
53 * update of schema and user actually writes data after schema update. During
54 * update user did not invoked any operation.
56 abstract class RootApplyStrategy extends ForwardingObject {
58 static RootApplyStrategy from(final ModificationApplyOperation resolver) {
59 return new NotUpgradableRootApplyStrategy(resolver);
63 protected abstract ModificationApplyOperation delegate();
66 public final boolean equals(final Object obj) {
67 return delegate().equals(obj);
71 public final int hashCode() {
72 return delegate().hashCode();
76 public final String toString() {
77 return delegate().toString();
81 * Creates a snapshot from this modification, which may have separate
82 * upgrade lifecycle and is not affected by upgrades.
85 * Newly created snapshot uses backing implementation of this modification.
87 * @return Derived {@link RootApplyStrategy} with separate
90 abstract RootApplyStrategy snapshot();
93 * Upgrades backing implementation to latest available, if possible.
96 * Latest implementation of {@link RootApplyStrategy} is
97 * managed by {@link LatestOperationHolder} which was used to construct this
98 * operation and latest operation is updated by
99 * {@link LatestOperationHolder#setCurrent(ModificationApplyOperation)}.
101 abstract void upgradeIfPossible();