BUG 2854 : Do not add empty read write transactions to the replicable journal
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / restconf / impl / EmptyNodeWrapper.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.controller.sal.restconf.impl;
9
10 import com.google.common.base.Preconditions;
11 import java.net.URI;
12 import java.util.Collections;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
15 import org.opendaylight.yangtools.yang.data.api.Node;
16 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
17
18 /**
19  * @deprecated class will be removed in Lithium release
20  */
21 @Deprecated
22 public final class EmptyNodeWrapper implements NodeWrapper<Node<?>>, Node<Void> {
23
24     private Node<?> unwrapped;
25
26     private String localName;
27     private URI namespace;
28     private QName name;
29
30     private boolean composite;
31
32     public boolean isComposite() {
33         return composite;
34     }
35
36     public void setComposite(final boolean composite) {
37         this.composite = composite;
38     }
39
40     public EmptyNodeWrapper(final URI namespace, final String localName) {
41         this.localName = Preconditions.checkNotNull(localName);
42         this.namespace = namespace;
43     }
44
45     @Override
46     public void setQname(final QName name) {
47         Preconditions.checkState(unwrapped == null, "Cannot change the object, due to data inconsistencies.");
48         this.name = name;
49     }
50
51     @Override
52     public QName getQname() {
53         return name;
54     }
55
56     @Override
57     public String getLocalName() {
58         if (unwrapped != null) {
59             return unwrapped.getNodeType().getLocalName();
60         }
61         return localName;
62     }
63
64     @Override
65     public URI getNamespace() {
66         if (unwrapped != null) {
67             return unwrapped.getNodeType().getNamespace();
68         }
69         return namespace;
70     }
71
72     @Override
73     public void setNamespace(final URI namespace) {
74         Preconditions.checkState(unwrapped == null, "Cannot change the object, due to data inconsistencies.");
75         this.namespace = namespace;
76     }
77
78     @Override
79     public boolean isChangeAllowed() {
80         return unwrapped == null ? true : false;
81     }
82
83     @Override
84     public Node<?> unwrap() {
85         if (unwrapped == null) {
86             if (name == null) {
87                 Preconditions.checkNotNull(namespace);
88                 name = new QName(namespace, localName);
89             }
90             if (composite) {
91                 unwrapped = NodeFactory.createImmutableCompositeNode(name, null, Collections.<Node<?>> emptyList(),
92                         null);
93             } else {
94                 unwrapped = NodeFactory.createImmutableSimpleNode(name, null, null);
95             }
96             namespace = null;
97             localName = null;
98             name = null;
99         }
100         return unwrapped;
101     }
102
103     @Override
104     public QName getNodeType() {
105         return unwrap().getNodeType();
106     }
107
108     @Override
109     @Deprecated
110     public CompositeNode getParent() {
111         return unwrap().getParent();
112     }
113
114     @Override
115     public Void getValue() {
116         return null;
117     }
118
119     @Override
120     public QName getKey() {
121         return unwrap().getKey();
122     }
123
124     @Override
125     public Void setValue(final Void value) {
126         return null;
127     }
128
129 }