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;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
17 import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
18 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
19 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
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(final String localName, final Object value) {
31 this.localName = Preconditions.checkNotNull(localName);
35 public SimpleNodeWrapper(final URI namespace, final String localName, final Object value) {
36 this(localName, value);
37 this.namespace = namespace;
41 public void setQname(final 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(final 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);
96 public QName getNodeType() {
97 return unwrap().getNodeType();
102 public CompositeNode getParent() {
103 return unwrap().getParent();
107 public Object getValue() {
108 return unwrap().getValue();
113 public ModifyAction getModificationAction() {
114 return unwrap().getModificationAction();
118 public MutableSimpleNode<Object> asMutable() {
119 return unwrap().asMutable();
123 public QName getKey() {
124 return unwrap().getKey();
128 public Object setValue(final Object value) {
129 return unwrap().setValue(value);