2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.restconf.impl;
10 import com.google.common.base.Preconditions;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.List;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
20 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
21 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
22 import org.opendaylight.yangtools.yang.data.api.Node;
23 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
24 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
27 * @deprecated class will be removed in Lithium release
30 public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, CompositeNode {
32 private MutableCompositeNode compositeNode;
34 private String localName;
35 private URI namespace;
37 private List<NodeWrapper<?>> values = new ArrayList<>();
39 public CompositeNodeWrapper(final String localName) {
40 this.localName = Preconditions.checkNotNull(localName);
43 public CompositeNodeWrapper(final URI namespace, final String localName) {
45 this.namespace = namespace;
49 public void setQname(final QName name) {
50 Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
55 public QName getQname() {
60 public String getLocalName() {
61 if (compositeNode != null) {
62 return compositeNode.getNodeType().getLocalName();
68 public URI getNamespace() {
69 if (compositeNode != null) {
70 return compositeNode.getNodeType().getNamespace();
76 public void setNamespace(final URI namespace) {
77 Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
78 this.namespace = namespace;
81 public void addValue(final NodeWrapper<?> value) {
82 Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
86 public void removeValue(final NodeWrapper<CompositeNode> value) {
87 Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
91 public List<NodeWrapper<?>> getValues() {
92 Preconditions.checkState(compositeNode == null, "Data can be inconsistent.");
93 return Collections.unmodifiableList(values);
97 public boolean isChangeAllowed() {
98 return compositeNode == null ? true : false;
102 public CompositeNode unwrap() {
103 if (compositeNode == null) {
105 Preconditions.checkNotNull(namespace);
106 name = new QName(namespace, localName);
109 final List<Node<?>> nodeValues = new ArrayList<>(values.size());
110 for (final NodeWrapper<?> nodeWrapper : values) {
111 nodeValues.add(nodeWrapper.unwrap());
113 compositeNode = NodeFactory.createMutableCompositeNode(name, null, nodeValues, null, null);
120 return compositeNode;
124 public QName getNodeType() {
125 return unwrap().getNodeType();
130 public CompositeNode getParent() {
131 return unwrap().getParent();
135 public List<Node<?>> getValue() {
136 return unwrap().getValue();
140 public ModifyAction getModificationAction() {
141 return unwrap().getModificationAction();
145 * @deprecated Use {@link #getValue()} instead.
149 public List<Node<?>> getChildren() {
150 return unwrap().getValue();
154 public List<CompositeNode> getCompositesByName(final QName children) {
155 return unwrap().getCompositesByName(children);
159 public List<CompositeNode> getCompositesByName(final String children) {
160 return unwrap().getCompositesByName(children);
164 public List<SimpleNode<?>> getSimpleNodesByName(final QName children) {
165 return unwrap().getSimpleNodesByName(children);
169 public List<SimpleNode<?>> getSimpleNodesByName(final String children) {
170 return unwrap().getSimpleNodesByName(children);
174 public CompositeNode getFirstCompositeByName(final QName container) {
175 return unwrap().getFirstCompositeByName(container);
179 public SimpleNode<?> getFirstSimpleByName(final QName leaf) {
180 return unwrap().getFirstSimpleByName(leaf);
184 public MutableCompositeNode asMutable() {
185 return unwrap().asMutable();
189 public QName getKey() {
190 return unwrap().getKey();
194 public List<Node<?>> setValue(final List<Node<?>> value) {
195 return unwrap().setValue(value);
200 return unwrap().size();
204 public boolean isEmpty() {
205 return unwrap().isEmpty();
209 public boolean containsKey(final Object key) {
210 return unwrap().containsKey(key);
214 public boolean containsValue(final Object value) {
215 return unwrap().containsValue(value);
219 public List<Node<?>> get(final Object key) {
220 return unwrap().get(key);
224 public List<Node<?>> put(final QName key, final List<Node<?>> value) {
225 return unwrap().put(key, value);
229 public List<Node<?>> remove(final Object key) {
230 return unwrap().remove(key);
234 public void putAll(final Map<? extends QName, ? extends List<Node<?>>> m) {
239 public void clear() {
244 public Set<QName> keySet() {
245 return unwrap().keySet();
249 public Collection<List<Node<?>>> values() {
250 return unwrap().values();
254 public Set<java.util.Map.Entry<QName, List<Node<?>>>> entrySet() {
255 return unwrap().entrySet();