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