/*
 * 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;
import java.util.Collections;

import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;

import com.google.common.base.Preconditions;

public final class EmptyNodeWrapper implements NodeWrapper<Node<?>>, Node<Void> {

    private Node<?> unwrapped;

    private String localName;
    private URI namespace;
    private QName name;

    private boolean composite;

    public boolean isComposite() {
        return composite;
    }

    public void setComposite(boolean composite) {
        this.composite = composite;
    }

    public EmptyNodeWrapper(URI namespace, String localName) {
        this.localName = Preconditions.checkNotNull(localName);
        this.namespace = namespace;
    }

    @Override
    public void setQname(QName name) {
        Preconditions.checkState(unwrapped == null, "Cannot change the object, due to data inconsistencies.");
        this.name = name;
    }

    @Override
    public QName getQname() {
        return name;
    }

    @Override
    public String getLocalName() {
        if (unwrapped != null) {
            return unwrapped.getNodeType().getLocalName();
        }
        return localName;
    }

    @Override
    public URI getNamespace() {
        if (unwrapped != null) {
            return unwrapped.getNodeType().getNamespace();
        }
        return namespace;
    }

    @Override
    public void setNamespace(URI namespace) {
        Preconditions.checkState(unwrapped == null, "Cannot change the object, due to data inconsistencies.");
        this.namespace = namespace;
    }

    @Override
    public boolean isChangeAllowed() {
        return unwrapped == null ? true : false;
    }

    @Override
    public Node<?> unwrap() {
        if (unwrapped == null) {
            if (name == null) {
                Preconditions.checkNotNull(namespace);
                name = new QName(namespace, localName);
            }
            if(composite) {
                unwrapped = NodeFactory.createImmutableCompositeNode(name, null, Collections.<Node<?>>emptyList(),null);
            } else {
                unwrapped = NodeFactory.createImmutableSimpleNode(name, null, null);
            }
            namespace = null;
            localName = null;
            name = null;
        }
        return unwrapped;
    }

    @Override
    public QName getNodeType() {
        return unwrap().getNodeType();
    }

    @Override
    public CompositeNode getParent() {
        return unwrap().getParent();
    }

    @Override
    public Void getValue() {
        return null;
    }

    @Override
    public QName getKey() {
        return unwrap().getKey();
    }

    @Override
    public Void setValue(Void value) {
        return null;
    }

}

@@ -357,16 +357,62 @@
 .impl;%0A%0A
+import com.google.common.base.Preconditions;%0A%0A
 import j
@@ -692,54 +692,8 @@
 y;%0A%0A
-import com.google.common.base.Preconditions;%0A%0A
 publ
@@ -1014,16 +1014,22 @@
 mposite(
+final 
 boolean 
@@ -1112,16 +1112,22 @@
 Wrapper(
+final 
 URI name
@@ -1132,16 +1132,22 @@
 mespace,
+ final
  String 
@@ -1305,16 +1305,22 @@
 etQname(
+final 
 QName na
@@ -1949,16 +1949,22 @@
 mespace(
+final 
 URI name
@@ -2965,32 +2965,48 @@
 %0A%0A    @Override%0A
+    @Deprecated%0A
     public Compo
@@ -3265,16 +3265,22 @@
 etValue(
+final 
 Void val

Fix a warning in EmptyNodeWrapper