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.base.Optional;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
18 * Represents a {@link ModificationApplyOperation} which is rooted at conceptual
22 * This implementation differs from other implementations in this package that
23 * is not immutable, but may be upgraded to newer state if available by
24 * explicitly invoking {@link #upgradeIfPossible()} and also serves as factory
25 * for deriving snapshot {@link RootModificationApplyOperation} which will not
26 * be affected by upgrade of original one.
29 * There are two variations of this {@link ModificationApplyOperation}:
32 * <b>Upgradable</b> - operation may be upgraded to different backing
33 * implementation by invoking {@link #upgradeIfPossible()}.</li>
34 * <li><b>Not Upgradable</b> - operation is immutable, invocation of
35 * {@link #upgradeIfPossible()} is no-op and method {@link #snapshot()} returns
36 * pointer on same object.
38 * <h3>Upgradable Root Modification Operation</h3>
40 * Upgradable Root Modification Operation may be created using:
42 * <li> {@link #from(ModificationApplyOperation)} with other upgradable root
43 * modification as an argument
44 * <li>using factory {@link LatestOperationHolder} which instantiates Upgradable
45 * Root Modification Operations and provides an option to set latest
49 * Upgradable root operation is never upgraded to latest operation
50 * automatically, but client code must explicitly invoke
51 * {@link #upgradeIfPossible()} to get latest implementation.
53 * Note: This is helpful for implementing
54 * {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification}
55 * which may be derived from
56 * {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree} before
57 * update of schema and user actually writes data after schema update. During
58 * update user did not invoked any operation.
61 abstract class RootModificationApplyOperation extends ModificationApplyOperation {
64 public final Optional<ModificationApplyOperation> getChild(final PathArgument child) {
65 return getDelegate().getChild(child);
69 final void checkApplicable(final YangInstanceIdentifier path, final NodeModification modification, final Optional<TreeNode> current)
70 throws DataValidationFailedException {
71 getDelegate().checkApplicable(path, modification, current);
75 final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
76 final Version version) {
77 return getDelegate().apply(modification, currentMeta, version);
81 public final boolean equals(final Object obj) {
82 return getDelegate().equals(obj);
86 public final int hashCode() {
87 return getDelegate().hashCode();
91 public final String toString() {
92 return getDelegate().toString();
96 final void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
97 getDelegate().verifyStructure(modification);
101 final ChildTrackingPolicy getChildPolicy() {
102 return getDelegate().getChildPolicy();
106 * Return the underlying delegate.
108 * @return Underlying delegate.
110 abstract ModificationApplyOperation getDelegate();
113 * Creates a snapshot from this modification, which may have separate
114 * upgrade lifecycle and is not affected by upgrades
116 * Newly created snapshot uses backing implementation of this modi
118 * @return Derived {@link RootModificationApplyOperation} with separate
121 abstract RootModificationApplyOperation snapshot();
124 * Upgrades backing implementation to latest available, if possible.
126 * Latest implementation of {@link RootModificationApplyOperation} is
127 * managed by {@link LatestOperationHolder} which was used to construct this
128 * operation and latest operation is updated by
129 * {@link LatestOperationHolder#setCurrent(ModificationApplyOperation)}.
131 abstract void upgradeIfPossible();
133 static RootModificationApplyOperation from(final ModificationApplyOperation resolver) {
134 if (resolver instanceof RootModificationApplyOperation) {
135 return ((RootModificationApplyOperation) resolver).snapshot();
137 return new NotUpgradableModificationApplyOperation(resolver);