Move case statement implementations
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / tree / spi / ValueNode.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
9
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 /**
17  * Concretization of AbstractTreeNode for leaf nodes which only contain data.
18  * Instances of this class report all children as absent, subtree version
19  * equal to this node's version and do not support mutable view.
20  */
21 final class ValueNode extends AbstractTreeNode {
22     private static final Logger LOG = LoggerFactory.getLogger(ValueNode.class);
23
24     protected ValueNode(final NormalizedNode data, final Version version) {
25         super(data, version);
26     }
27
28     @Override
29     public TreeNode childByArg(final PathArgument arg) {
30         LOG.warn("Attempted to access child {} of value-node {}", arg, this);
31         return null;
32     }
33
34     @Override
35     public Version getSubtreeVersion() {
36         return getVersion();
37     }
38
39     @Override
40     public MutableTreeNode mutable() {
41         /**
42          * Value nodes can only we read/written/delete, which does a straight
43          * replace. That means they don't haver need to be made mutable.
44          */
45         throw new UnsupportedOperationException(String.format("Attempted to mutate value-node %s", this));
46     }
47
48     @Override
49     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
50         return helper.add("value", getData());
51     }
52 }