1 package org.opendaylight.controller.sal.restconf.impl;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.Collections;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
13 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
14 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
15 import org.opendaylight.yangtools.yang.data.api.Node;
16 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
17 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
19 import com.google.common.base.Preconditions;
21 public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, CompositeNode {
23 private MutableCompositeNode compositeNode;
25 private String localName;
26 private URI namespace;
27 private List<NodeWrapper<?>> values = new ArrayList<>();
29 public CompositeNodeWrapper(String localName) {
30 this.localName = Preconditions.checkNotNull(localName);
33 public CompositeNodeWrapper(URI namespace, String localName) {
35 this.namespace = namespace;
39 public String getLocalName() {
40 if (compositeNode != null) {
41 return compositeNode.getNodeType().getLocalName();
47 public URI getNamespace() {
48 if (compositeNode != null) {
49 return compositeNode.getNodeType().getNamespace();
55 public void setNamespace(URI namespace) {
56 Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
57 this.namespace = namespace;
60 public void addValue(NodeWrapper<?> value) {
61 Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
65 public void removeValue(NodeWrapper<CompositeNode> value) {
66 Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
70 public List<NodeWrapper<?>> getValues() {
71 Preconditions.checkState(compositeNode == null, "Data can be inconsistent.");
72 return Collections.unmodifiableList(values);
76 public CompositeNode unwrap(CompositeNode parent) {
77 if (compositeNode == null) {
78 Preconditions.checkNotNull(namespace);
79 compositeNode = NodeFactory.createMutableCompositeNode(new QName(namespace, localName),
80 parent, new ArrayList<Node<?>>(), ModifyAction.CREATE, null);
82 List<Node<?>> nodeValues = new ArrayList<>();
83 for (NodeWrapper<?> nodeWrapper : values) {
84 nodeValues.add(nodeWrapper.unwrap(compositeNode));
86 compositeNode.setValue(nodeValues);
96 public QName getNodeType() {
97 return unwrap(null).getNodeType();
101 public CompositeNode getParent() {
102 return unwrap(null).getParent();
106 public List<Node<?>> getValue() {
107 return unwrap(null).getValue();
111 public ModifyAction getModificationAction() {
112 return unwrap(null).getModificationAction();
116 public List<Node<?>> getChildren() {
117 return unwrap(null).getChildren();
121 public List<CompositeNode> getCompositesByName(QName children) {
122 return unwrap(null).getCompositesByName(children);
126 public List<CompositeNode> getCompositesByName(String children) {
127 return unwrap(null).getCompositesByName(children);
131 public List<SimpleNode<?>> getSimpleNodesByName(QName children) {
132 return unwrap(null).getSimpleNodesByName(children);
136 public List<SimpleNode<?>> getSimpleNodesByName(String children) {
137 return unwrap(null).getSimpleNodesByName(children);
141 public CompositeNode getFirstCompositeByName(QName container) {
142 return unwrap(null).getFirstCompositeByName(container);
146 public SimpleNode<?> getFirstSimpleByName(QName leaf) {
147 return unwrap(null).getFirstSimpleByName(leaf);
151 public MutableCompositeNode asMutable() {
152 return unwrap(null).asMutable();
156 public QName getKey() {
157 return unwrap(null).getKey();
161 public List<Node<?>> setValue(List<Node<?>> value) {
162 return unwrap(null).setValue(value);
167 return unwrap(null).size();
171 public boolean isEmpty() {
172 return unwrap(null).isEmpty();
176 public boolean containsKey(Object key) {
177 return unwrap(null).containsKey(key);
181 public boolean containsValue(Object value) {
182 return unwrap(null).containsValue(value);
186 public List<Node<?>> get(Object key) {
187 return unwrap(null).get(key);
191 public List<Node<?>> put(QName key, List<Node<?>> value) {
192 return unwrap(null).put(key, value);
196 public List<Node<?>> remove(Object key) {
197 return unwrap(null).remove(key);
201 public void putAll(Map<? extends QName, ? extends List<Node<?>>> m) {
202 unwrap(null).putAll(m);
206 public void clear() {
207 unwrap(null).clear();
211 public Set<QName> keySet() {
212 return unwrap(null).keySet();
216 public Collection<List<Node<?>>> values() {
217 return unwrap(null).values();
221 public Set<java.util.Map.Entry<QName, List<Node<?>>>> entrySet() {
222 return unwrap(null).entrySet();