33fc91a08b160dc443ecfe6dc0de9bc071611e90
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / LatestOperationHolder.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  * Holder and factory for upgradable root modifications.
12  *
13  * <p>
14  * This class is factory for upgradable root modifications and provides an access to set latest backing implementation.
15  */
16 final class LatestOperationHolder {
17
18     private ModificationApplyOperation current = AlwaysFailOperation.INSTANCE;
19
20     /**
21      * Return latest backing implementation.
22      *
23      * @return latest backing implementation
24      */
25     ModificationApplyOperation getCurrent() {
26         return current;
27     }
28
29     /**
30      * Sets latest backing implementation of associated {@link RootModificationApplyOperation}.
31      *
32      * <p>
33      * Note: This does not result in upgrading implementation of already existing
34      * {@link RootModificationApplyOperation}. Users, who obtained instances using {@link #newSnapshot()}, deriving
35      * {@link RootModificationApplyOperation} from this modification must explicitly invoke
36      * {@link RootModificationApplyOperation#upgradeIfPossible()} on their instance to be updated to latest backing
37      * implementation.
38      *
39      * @param newApplyOper New backing implementation
40      */
41     void setCurrent(final ModificationApplyOperation newApplyOper) {
42         current = newApplyOper;
43     }
44
45     /**
46      * Creates new upgradable {@link RootModificationApplyOperation} associated with holder.
47      *
48      * @return New upgradable {@link RootModificationApplyOperation} with {@link #getCurrent()} used
49      *         as the backing implementation.
50      */
51     RootModificationApplyOperation newSnapshot() {
52         return new UpgradableModificationApplyOperation(this, current);
53     }
54
55 }