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;
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 import com.google.common.base.Preconditions;
21 public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, SimpleNode<Object> {
23 private SimpleNode<Object> simpleNode;
25 private String localName;
27 private URI namespace;
30 public SimpleNodeWrapper(String localName, Object value) {
31 this.localName = Preconditions.checkNotNull(localName);
35 public SimpleNodeWrapper(URI namespace, String localName, Object value) {
36 this(localName, value);
37 this.namespace = namespace;
41 public void setQname(QName name) {
42 Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies.");
47 public QName getQname() {
52 public String getLocalName() {
53 if (simpleNode != null) {
54 return simpleNode.getNodeType().getLocalName();
60 public URI getNamespace() {
61 if (simpleNode != null) {
62 return simpleNode.getNodeType().getNamespace();
68 public void setNamespace(URI namespace) {
69 Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies.");
70 this.namespace = namespace;
74 public boolean isChangeAllowed() {
75 return simpleNode == null ? true : false;
79 public SimpleNode<Object> unwrap() {
80 if (simpleNode == null) {
82 Preconditions.checkNotNull(namespace);
83 name = new QName(namespace, localName);
85 simpleNode = NodeFactory.createImmutableSimpleNode(name, null, value);
92 return (SimpleNode<Object>) simpleNode;
96 public QName getNodeType() {
97 return unwrap().getNodeType();
101 public CompositeNode getParent() {
102 return unwrap().getParent();
106 public Object getValue() {
107 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(Object value) {
127 return unwrap().setValue(value);