Rename LeafNodeCodecContext to ValueNodeCodecContext 69/81569/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 11 Apr 2019 13:36:58 +0000 (15:36 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 11 Apr 2019 13:42:42 +0000 (15:42 +0200)
'LeafNode' prefix has wrong implications, as it is reminiscent
of nodes from 'leaf' statement, when in fact it covers all nodes
considered 'leaf' values in the Binding Object tree. This covers leaf,
leaf-list, anyxml, anydata -- where leaf-list and leaf have actually
differnent handling.

This renames the class to ValueNodeCodecContext, to make a clear
distinction between the two groups.

JIRA: MDSAL-436
Change-Id: I02d60afc1650319efe6cbd90b12eeb47e5152a8f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingToNormalizedStreamWriter.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/NodeCodecContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/TypeObjectNormalizedNodeCache.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueNodeCodecContext.java [moved from binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LeafNodeCodecContext.java with 94% similarity]

index ea35425667392a804097808ab721812a7be7d002..e19831657fa71cdaca09f217b0eeb39cab460924 100644 (file)
@@ -189,7 +189,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
                     bindingArguments.add(((DataContainerCodecContext<?, ?>) nextNode).getBindingPathArgument(domArg));
                 }
                 currentNode = nextNode;
-            } else if (nextNode instanceof LeafNodeCodecContext) {
+            } else if (nextNode instanceof ValueNodeCodecContext) {
                 LOG.debug("Instance identifier referencing a leaf is not representable ({})", dom);
                 return null;
             }
@@ -233,7 +233,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
     }
 
     @Override
-    public ImmutableMap<String, LeafNodeCodecContext> getLeafNodes(final Class<?> parentClass,
+    public ImmutableMap<String, ValueNodeCodecContext> getLeafNodes(final Class<?> parentClass,
             final DataNodeContainer childSchema) {
         final Map<String, DataSchemaNode> getterToLeafSchema = new HashMap<>();
         for (final DataSchemaNode leaf : childSchema.getChildNodes()) {
@@ -244,9 +244,9 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
         return getLeafNodesUsingReflection(parentClass, getterToLeafSchema);
     }
 
-    private ImmutableMap<String, LeafNodeCodecContext> getLeafNodesUsingReflection(final Class<?> parentClass,
+    private ImmutableMap<String, ValueNodeCodecContext> getLeafNodesUsingReflection(final Class<?> parentClass,
             final Map<String, DataSchemaNode> getterToLeafSchema) {
-        final Map<String, LeafNodeCodecContext> leaves = new HashMap<>();
+        final Map<String, ValueNodeCodecContext> leaves = new HashMap<>();
         for (final Method method : parentClass.getMethods()) {
             if (method.getParameterCount() == 0) {
                 final DataSchemaNode schema = getterToLeafSchema.get(method.getName());
@@ -276,7 +276,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
                 }
 
                 final Codec<Object, Object> codec = getCodec(valueType, typedSchema.getType());
-                final LeafNodeCodecContext leafNode = new LeafNodeCodecContext(typedSchema, codec, method,
+                final ValueNodeCodecContext leafNode = new ValueNodeCodecContext(typedSchema, codec, method,
                         context.getSchemaContext());
                 leaves.put(schema.getQName().getLocalName(), leafNode);
             }
@@ -330,7 +330,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
 
         final Class<Identifier<?>> identifier = optIdentifier.get();
         final Map<QName, ValueContext> valueCtx = new HashMap<>();
-        for (final LeafNodeCodecContext leaf : getLeafNodes(identifier, schema).values()) {
+        for (final ValueNodeCodecContext leaf : getLeafNodes(identifier, schema).values()) {
             final QName name = leaf.getDomPathArgument().getNodeType();
             valueCtx.put(name, new ValueContext(identifier, leaf));
         }
index bf8edd9d2a8952d058c92a266287a124fe4c8ac8..35791ccf5e64a7419f3b04b92992102d03392573 100644 (file)
@@ -111,7 +111,7 @@ final class BindingToNormalizedStreamWriter implements BindingStreamEventWriter,
         Preconditions.checkArgument(current() instanceof DataObjectCodecContext);
 
         DataObjectCodecContext<?,?> currentCasted = (DataObjectCodecContext<?,?>) current();
-        LeafNodeCodecContext leafContext = currentCasted.getLeafChild(localName);
+        ValueNodeCodecContext leafContext = currentCasted.getLeafChild(localName);
 
         NodeIdentifier domArg = (NodeIdentifier) leafContext.getDomPathArgument();
         Object domValue = leafContext.getValueCodec().serialize(value);
@@ -137,7 +137,7 @@ final class BindingToNormalizedStreamWriter implements BindingStreamEventWriter,
 
     @Override
     public void leafSetEntryNode(final Object value) throws IOException {
-        final LeafNodeCodecContext ctx = (LeafNodeCodecContext) current();
+        final ValueNodeCodecContext ctx = (ValueNodeCodecContext) current();
         final Object domValue = ctx.getValueCodec().serialize(value);
         delegate.startLeafSetEntryNode(new NodeWithValue<>(ctx.getSchema().getQName(), domValue));
         delegate.scalarValue(domValue);
index 4c105af43319bcf22e84657ad408bc32878dcac5..6e3c7ee08796aab36f0188d6b79e61c4c44ee601 100644 (file)
@@ -82,7 +82,7 @@ abstract class DataObjectCodecContext<D extends DataObject, T extends DataNodeCo
     private static final Augmentations EMPTY_AUGMENTATIONS = new Augmentations(ImmutableMap.of(), ImmutableMap.of());
     private static final Method[] EMPTY_METHODS = new Method[0];
 
-    private final ImmutableMap<String, LeafNodeCodecContext> leafChild;
+    private final ImmutableMap<String, ValueNodeCodecContext> leafChild;
     private final ImmutableMap<YangInstanceIdentifier.PathArgument, NodeContextSupplier> byYang;
     private final ImmutableMap<String, NodeContextSupplier> byMethod;
     private final ImmutableMap<String, String> nonnullToGetter;
@@ -114,7 +114,7 @@ abstract class DataObjectCodecContext<D extends DataObject, T extends DataNodeCo
         final Map<Class<?>, DataContainerCodecPrototype<?>> byBindingArgClassBuilder = new HashMap<>();
 
         // Adds leaves to mapping
-        for (final LeafNodeCodecContext leaf : leafChild.values()) {
+        for (final ValueNodeCodecContext leaf : leafChild.values()) {
             tmpMethodToSupplier.put(leaf.getGetter(), leaf);
             byYangBuilder.put(leaf.getDomPathArgument(), leaf);
         }
@@ -343,8 +343,8 @@ abstract class DataObjectCodecContext<D extends DataObject, T extends DataNodeCo
         return childNonNull(childSupplier, arg, "Argument %s is not valid child of %s", arg, getSchema()).get();
     }
 
-    protected final LeafNodeCodecContext getLeafChild(final String name) {
-        final LeafNodeCodecContext value = leafChild.get(name);
+    protected final ValueNodeCodecContext getLeafChild(final String name) {
+        final ValueNodeCodecContext value = leafChild.get(name);
         return IncorrectNestingException.checkNonNull(value, "Leaf %s is not valid for %s", name, getBindingClass());
     }
 
index c89fdf72b5de9bfa4d90190aeaa237d210217984..12c9d85201c5d86ba1132a6187b86d6164db1b71 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
  * <p>
  * Two core subtypes of codec context are available:
  * <ul>
- * <li>{@link LeafNodeCodecContext} - Context for nodes, which does not contain any nested YANG modeled substructures.
+ * <li>{@link ValueNodeCodecContext} - Context for nodes, which does not contain any nested YANG modeled substructures.
  * </li>
  * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain nested YANG modeled substructures. This
  * context nodes contains context for children nodes.</li>
@@ -63,7 +63,7 @@ abstract class NodeCodecContext implements BindingCodecTreeNode {
          * @param schema  Instantiated schema of binding type.
          * @return Map of local name to leaf node context.
          */
-        ImmutableMap<String, LeafNodeCodecContext> getLeafNodes(Class<?> type, DataNodeContainer schema);
+        ImmutableMap<String, ValueNodeCodecContext> getLeafNodes(Class<?> type, DataNodeContainer schema);
 
         /**
          * Returns Path argument codec for list item.
index 3201e14e899859f98ee3dd583ee415f7a16fdd69..75cf553f8e638166e1483449969488fc6193f306 100644 (file)
@@ -15,8 +15,8 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
  * A cache of NormalizedNodes corresponding to a particular TypeObject instantiation.
  */
 final class TypeObjectNormalizedNodeCache
-        extends AbstractBindingNormalizedNodeCache<TypeObject, LeafNodeCodecContext> {
-    TypeObjectNormalizedNodeCache(final LeafNodeCodecContext rootContext) {
+        extends AbstractBindingNormalizedNodeCache<TypeObject, ValueNodeCodecContext> {
+    TypeObjectNormalizedNodeCache(final ValueNodeCodecContext rootContext) {
         super(rootContext);
     }
 
index b52eab538935a0612cc5c97c960bdf09488e54ee..f18133e4837d74b727a0ca27c3a4057ca4190464 100644 (file)
@@ -21,7 +21,7 @@ final class ValueContext {
     private final Class<?> identifier;
     private final String getterName;
 
-    ValueContext(final Class<?> identifier, final LeafNodeCodecContext leaf) {
+    ValueContext(final Class<?> identifier, final ValueNodeCodecContext leaf) {
         getterName = leaf.getGetter().getName();
         try {
             getter = MethodHandles.publicLookup().unreflect(identifier.getMethod(getterName)).asType(OBJECT_METHOD);
@@ -32,16 +32,20 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 
+/**
+ * Abstract base class for atomic nodes. These are nodes which are not decomposed in the Binding Specification, such
+ * as LeafNodes and LeafSetNodes.
+ */
 // FIXME: MDSAL-436: this class should be specialized for Leaf and LeafSet
-final class LeafNodeCodecContext extends NodeCodecContext implements NodeContextSupplier {
+final class ValueNodeCodecContext extends NodeCodecContext implements NodeContextSupplier {
     private final NodeIdentifier yangIdentifier;
     private final Codec<Object, Object> valueCodec;
     private final Method getter;
     private final TypedDataSchemaNode schema;
     private final Object defaultObject;
 
-    LeafNodeCodecContext(final TypedDataSchemaNode schema, final Codec<Object, Object> codec, final Method getter,
-                final SchemaContext schemaContext) {
+    ValueNodeCodecContext(final TypedDataSchemaNode schema, final Codec<Object, Object> codec,
+            final Method getter, final SchemaContext schemaContext) {
         this.yangIdentifier = NodeIdentifier.create(schema.getQName());
         this.valueCodec = requireNonNull(codec);
         this.getter = getter;