Do not pretty-print body class
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / UpgradableRootApplyStrategy.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
9
10 /**
11  * Implementation of Upgradable {@link RootApplyStrategy}
12  *
13  * <p>
14  * This implementation is associated with {@link LatestOperationHolder}
15  * which holds latest available implementation, which may be used for
16  * upgrade.
17  *
18  * <p>
19  * Upgrading {@link LatestOperationHolder} will not affect any instance,
20  * unless client invoked {@link #upgradeIfPossible()} which will result in
21  * changing delegate to the latest one.
22  */
23 final class UpgradableRootApplyStrategy extends RootApplyStrategy {
24     private final LatestOperationHolder holder;
25     private ModificationApplyOperation delegate;
26
27     UpgradableRootApplyStrategy(final LatestOperationHolder holder,
28         final ModificationApplyOperation delegate) {
29         this.holder = holder;
30         this.delegate = delegate;
31     }
32
33     @Override
34     void upgradeIfPossible() {
35         ModificationApplyOperation holderCurrent = holder.getCurrent();
36         if (holderCurrent != null && holderCurrent != delegate) {
37             // FIXME: Allow update only if there is addition of models, not
38             // removals.
39             delegate = holderCurrent;
40         }
41     }
42
43     @Override
44     protected ModificationApplyOperation delegate() {
45         return delegate;
46     }
47
48     @Override
49     RootApplyStrategy snapshot() {
50         return new UpgradableRootApplyStrategy(holder, delegate);
51     }
52 }