Merge "Bug 3051: Fixed pattern checks in generated DTOs"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / UpgradableModificationApplyOperation.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 RootModificationApplyOperation}
12  *
13  * This implementation is associated with {@link LatestOperationHolder}
14  * which holds latest available implementation, which may be used for
15  * upgrade.
16  *
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.
20  *
21  */
22 final class UpgradableModificationApplyOperation extends RootModificationApplyOperation {
23     private final LatestOperationHolder holder;
24     private ModificationApplyOperation delegate;
25
26     UpgradableModificationApplyOperation(final LatestOperationHolder holder, final ModificationApplyOperation delegate) {
27         this.holder = holder;
28         this.delegate = delegate;
29     }
30
31     @Override
32     void upgradeIfPossible() {
33         ModificationApplyOperation holderCurrent = holder.getCurrent();
34         if (holderCurrent != delegate) {
35             // FIXME: Allow update only if there is addition of models, not
36             // removals.
37             delegate = holderCurrent;
38         }
39     }
40
41     @Override
42     ModificationApplyOperation getDelegate() {
43         return delegate;
44     }
45
46     @Override
47     RootModificationApplyOperation snapshot() {
48         return new UpgradableModificationApplyOperation(holder, getDelegate());
49     }
50
51 }