+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.sal.restconf.impl;
+import com.google.common.base.Preconditions;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
-import com.google.common.base.Preconditions;
-
public final class CompositeNodeWrapper implements NodeWrapper<CompositeNode>, CompositeNode {
private MutableCompositeNode compositeNode;
private URI namespace;
private QName name;
private List<NodeWrapper<?>> values = new ArrayList<>();
-
- public CompositeNodeWrapper(String localName) {
+
+ public CompositeNodeWrapper(final String localName) {
this.localName = Preconditions.checkNotNull(localName);
}
-
- public CompositeNodeWrapper(URI namespace, String localName) {
+
+ public CompositeNodeWrapper(final URI namespace, final String localName) {
this(localName);
this.namespace = namespace;
}
-
+
@Override
- public void setQname(QName name) {
+ public void setQname(final QName name) {
Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
this.name = name;
}
+ @Override
+ public QName getQname() {
+ return name;
+ }
+
@Override
public String getLocalName() {
if (compositeNode != null) {
}
@Override
- public void setNamespace(URI namespace) {
+ public void setNamespace(final URI namespace) {
Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
this.namespace = namespace;
}
- public void addValue(NodeWrapper<?> value) {
+ public void addValue(final NodeWrapper<?> value) {
Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
values.add(value);
}
- public void removeValue(NodeWrapper<CompositeNode> value) {
+ public void removeValue(final NodeWrapper<CompositeNode> value) {
Preconditions.checkState(compositeNode == null, "Cannot change the object, due to data inconsistencies.");
values.remove(value);
}
-
+
public List<NodeWrapper<?>> getValues() {
Preconditions.checkState(compositeNode == null, "Data can be inconsistent.");
return Collections.unmodifiableList(values);
}
@Override
- public CompositeNode unwrap(CompositeNode parent) {
+ public boolean isChangeAllowed() {
+ return compositeNode == null ? true : false;
+ }
+
+ @Override
+ public CompositeNode unwrap() {
if (compositeNode == null) {
if (name == null) {
Preconditions.checkNotNull(namespace);
name = new QName(namespace, localName);
}
- compositeNode = NodeFactory.createMutableCompositeNode(name, parent, new ArrayList<Node<?>>(), null, null);
-
- List<Node<?>> nodeValues = new ArrayList<>();
+
+ List<Node<?>> nodeValues = new ArrayList<>(values.size());
for (NodeWrapper<?> nodeWrapper : values) {
- nodeValues.add(nodeWrapper.unwrap(compositeNode));
+ nodeValues.add(nodeWrapper.unwrap());
}
- compositeNode.setValue(nodeValues);
-
+ compositeNode = NodeFactory.createMutableCompositeNode(name, null, nodeValues, null, null);
+
values = null;
namespace = null;
localName = null;
@Override
public QName getNodeType() {
- return unwrap(null).getNodeType();
+ return unwrap().getNodeType();
}
+ @Deprecated
@Override
public CompositeNode getParent() {
- return unwrap(null).getParent();
+ return unwrap().getParent();
}
@Override
public List<Node<?>> getValue() {
- return unwrap(null).getValue();
+ return unwrap().getValue();
}
@Override
public ModifyAction getModificationAction() {
- return unwrap(null).getModificationAction();
+ return unwrap().getModificationAction();
}
+ /**
+ * @deprecated Use {@link #getValue()} instead.
+ */
+ @Deprecated
@Override
public List<Node<?>> getChildren() {
- return unwrap(null).getChildren();
+ return unwrap().getValue();
}
@Override
- public List<CompositeNode> getCompositesByName(QName children) {
- return unwrap(null).getCompositesByName(children);
+ public List<CompositeNode> getCompositesByName(final QName children) {
+ return unwrap().getCompositesByName(children);
}
@Override
- public List<CompositeNode> getCompositesByName(String children) {
- return unwrap(null).getCompositesByName(children);
+ public List<CompositeNode> getCompositesByName(final String children) {
+ return unwrap().getCompositesByName(children);
}
@Override
- public List<SimpleNode<?>> getSimpleNodesByName(QName children) {
- return unwrap(null).getSimpleNodesByName(children);
+ public List<SimpleNode<?>> getSimpleNodesByName(final QName children) {
+ return unwrap().getSimpleNodesByName(children);
}
@Override
- public List<SimpleNode<?>> getSimpleNodesByName(String children) {
- return unwrap(null).getSimpleNodesByName(children);
+ public List<SimpleNode<?>> getSimpleNodesByName(final String children) {
+ return unwrap().getSimpleNodesByName(children);
}
@Override
- public CompositeNode getFirstCompositeByName(QName container) {
- return unwrap(null).getFirstCompositeByName(container);
+ public CompositeNode getFirstCompositeByName(final QName container) {
+ return unwrap().getFirstCompositeByName(container);
}
@Override
- public SimpleNode<?> getFirstSimpleByName(QName leaf) {
- return unwrap(null).getFirstSimpleByName(leaf);
+ public SimpleNode<?> getFirstSimpleByName(final QName leaf) {
+ return unwrap().getFirstSimpleByName(leaf);
}
@Override
public MutableCompositeNode asMutable() {
- return unwrap(null).asMutable();
+ return unwrap().asMutable();
}
@Override
public QName getKey() {
- return unwrap(null).getKey();
+ return unwrap().getKey();
}
@Override
- public List<Node<?>> setValue(List<Node<?>> value) {
- return unwrap(null).setValue(value);
+ public List<Node<?>> setValue(final List<Node<?>> value) {
+ return unwrap().setValue(value);
}
@Override
public int size() {
- return unwrap(null).size();
+ return unwrap().size();
}
@Override
public boolean isEmpty() {
- return unwrap(null).isEmpty();
+ return unwrap().isEmpty();
}
@Override
- public boolean containsKey(Object key) {
- return unwrap(null).containsKey(key);
+ public boolean containsKey(final Object key) {
+ return unwrap().containsKey(key);
}
@Override
- public boolean containsValue(Object value) {
- return unwrap(null).containsValue(value);
+ public boolean containsValue(final Object value) {
+ return unwrap().containsValue(value);
}
@Override
- public List<Node<?>> get(Object key) {
- return unwrap(null).get(key);
+ public List<Node<?>> get(final Object key) {
+ return unwrap().get(key);
}
@Override
- public List<Node<?>> put(QName key, List<Node<?>> value) {
- return unwrap(null).put(key, value);
+ public List<Node<?>> put(final QName key, final List<Node<?>> value) {
+ return unwrap().put(key, value);
}
@Override
- public List<Node<?>> remove(Object key) {
- return unwrap(null).remove(key);
+ public List<Node<?>> remove(final Object key) {
+ return unwrap().remove(key);
}
@Override
- public void putAll(Map<? extends QName, ? extends List<Node<?>>> m) {
- unwrap(null).putAll(m);
+ public void putAll(final Map<? extends QName, ? extends List<Node<?>>> m) {
+ unwrap().putAll(m);
}
@Override
public void clear() {
- unwrap(null).clear();
+ unwrap().clear();
}
@Override
public Set<QName> keySet() {
- return unwrap(null).keySet();
+ return unwrap().keySet();
}
@Override
public Collection<List<Node<?>>> values() {
- return unwrap(null).values();
+ return unwrap().values();
}
@Override
public Set<java.util.Map.Entry<QName, List<Node<?>>>> entrySet() {
- return unwrap(null).entrySet();
+ return unwrap().entrySet();
}
}