X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FSimpleNodeWrapper.java;h=4d22bfa73adce9106ff3ebc59a8a2f9227d4dda7;hb=c0b10c35abcdf8038546aa89bf29264720f12a75;hp=50b6ac77e6ee8b3c885efe87869231736ffce2d2;hpb=41af542c09b1bda7a1618d3d92be529c9573288f;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java index 50b6ac77e6..4d22bfa73a 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java @@ -1,3 +1,10 @@ +/* + * 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 java.net.URI; @@ -11,19 +18,36 @@ import org.opendaylight.yangtools.yang.data.impl.NodeFactory; import com.google.common.base.Preconditions; -public final class SimpleNodeWrapper implements NodeWrapper>, SimpleNode { +public final class SimpleNodeWrapper implements NodeWrapper>, SimpleNode { - private SimpleNode simpleNode; + private SimpleNode simpleNode; private String localName; - private String value; + private Object value; private URI namespace; + private QName name; - public SimpleNodeWrapper(String localName, String value) { + public SimpleNodeWrapper(String localName, Object value) { this.localName = Preconditions.checkNotNull(localName); this.value = value; } + public SimpleNodeWrapper(URI namespace, String localName, Object value) { + this(localName, value); + this.namespace = namespace; + } + + @Override + public void setQname(QName name) { + Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies."); + this.name = name; + } + + @Override + public QName getQname() { + return name; + } + @Override public String getLocalName() { if (simpleNode != null) { @@ -47,52 +71,62 @@ public final class SimpleNodeWrapper implements NodeWrapper>, Simp } @Override - public SimpleNode unwrap(CompositeNode parent) { + public boolean isChangeAllowed() { + return simpleNode == null ? true : false; + } + + @Override + public SimpleNode unwrap() { if (simpleNode == null) { - Preconditions.checkNotNull(namespace); - simpleNode = NodeFactory.createImmutableSimpleNode(new QName(namespace, localName), parent, value); + if (name == null) { + Preconditions.checkNotNull(namespace); + name = new QName(namespace, localName); + } + simpleNode = NodeFactory.createImmutableSimpleNode(name, null, value); value = null; namespace = null; localName = null; + name = null; } - return simpleNode; + return (SimpleNode) simpleNode; } @Override public QName getNodeType() { - return unwrap(null).getNodeType(); + return unwrap().getNodeType(); } @Override public CompositeNode getParent() { - return unwrap(null).getParent(); + return unwrap().getParent(); } @Override - public String getValue() { - return unwrap(null).getValue(); + public Object getValue() { + return unwrap().getValue(); } @Override public ModifyAction getModificationAction() { - return unwrap(null).getModificationAction(); + return unwrap().getModificationAction(); } @Override - public MutableSimpleNode asMutable() { - return unwrap(null).asMutable(); + public MutableSimpleNode asMutable() { + return unwrap().asMutable(); } @Override public QName getKey() { - return unwrap(null).getKey(); + return unwrap().getKey(); } @Override - public String setValue(String value) { - return unwrap(null).setValue(value); + public Object setValue(Object value) { + return unwrap().setValue(value); } + }