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