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;
11 import java.util.Collections;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
15 import org.opendaylight.yangtools.yang.data.api.Node;
16 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
18 import com.google.common.base.Preconditions;
20 public final class EmptyNodeWrapper implements NodeWrapper<Node<?>>, Node<Void> {
22 private Node<?> unwrapped;
24 private String localName;
25 private URI namespace;
28 private boolean composite;
30 public boolean isComposite() {
34 public void setComposite(boolean composite) {
35 this.composite = composite;
38 public EmptyNodeWrapper(URI namespace, String localName) {
39 this.localName = Preconditions.checkNotNull(localName);
40 this.namespace = namespace;
44 public void setQname(QName name) {
45 Preconditions.checkState(unwrapped == null, "Cannot change the object, due to data inconsistencies.");
50 public QName getQname() {
55 public String getLocalName() {
56 if (unwrapped != null) {
57 return unwrapped.getNodeType().getLocalName();
63 public URI getNamespace() {
64 if (unwrapped != null) {
65 return unwrapped.getNodeType().getNamespace();
71 public void setNamespace(URI namespace) {
72 Preconditions.checkState(unwrapped == null, "Cannot change the object, due to data inconsistencies.");
73 this.namespace = namespace;
77 public boolean isChangeAllowed() {
78 return unwrapped == null ? true : false;
82 public Node<?> unwrap() {
83 if (unwrapped == null) {
85 Preconditions.checkNotNull(namespace);
86 name = new QName(namespace, localName);
89 unwrapped = NodeFactory.createImmutableCompositeNode(name, null, Collections.<Node<?>>emptyList(),null);
91 unwrapped = NodeFactory.createImmutableSimpleNode(name, null, null);
101 public QName getNodeType() {
102 return unwrap().getNodeType();
106 public CompositeNode getParent() {
107 return unwrap().getParent();
111 public Void getValue() {
116 public QName getKey() {
117 return unwrap().getKey();
121 public Void setValue(Void value) {