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 org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
14 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
15 import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
16 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
17 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
19 public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, SimpleNode<Object> {
21 private SimpleNode<Object> simpleNode;
23 private String localName;
25 private URI namespace;
28 public SimpleNodeWrapper(final String localName, final Object value) {
29 this.localName = Preconditions.checkNotNull(localName);
33 public SimpleNodeWrapper(final URI namespace, final String localName, final Object value) {
34 this(localName, value);
35 this.namespace = namespace;
39 public void setQname(final QName name) {
40 Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies.");
45 public QName getQname() {
50 public String getLocalName() {
51 if (simpleNode != null) {
52 return simpleNode.getNodeType().getLocalName();
58 public URI getNamespace() {
59 if (simpleNode != null) {
60 return simpleNode.getNodeType().getNamespace();
66 public void setNamespace(final URI namespace) {
67 Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies.");
68 this.namespace = namespace;
72 public boolean isChangeAllowed() {
73 return simpleNode == null ? true : false;
77 public SimpleNode<Object> unwrap() {
78 if (simpleNode == null) {
80 Preconditions.checkNotNull(namespace);
81 name = new QName(namespace, localName);
83 simpleNode = NodeFactory.createImmutableSimpleNode(name, null, value);
94 public QName getNodeType() {
95 return unwrap().getNodeType();
100 public CompositeNode getParent() {
101 return unwrap().getParent();
105 public Object getValue() {
106 return unwrap().getValue();
111 public ModifyAction getModificationAction() {
112 return unwrap().getModificationAction();
116 public MutableSimpleNode<Object> asMutable() {
117 return unwrap().asMutable();
121 public QName getKey() {
122 return unwrap().getKey();
126 public Object setValue(final Object value) {
127 return unwrap().setValue(value);