Convert mdsal-binding-dom-codec to a JPMS module
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / NodeCodecContext.java
index 9e40fdad373d3df5725a61074883e5a2820578a9..f4ac5d8c63d4fffcb7cabe30055fa6f658f553a1 100644 (file)
@@ -8,55 +8,51 @@
 package org.opendaylight.mdsal.binding.dom.codec.impl;
 
 import com.google.common.collect.ImmutableMap;
+import java.lang.reflect.Method;
 import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
-import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
-import org.opendaylight.yangtools.concepts.Codec;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.DataObjectSerializer;
+import org.opendaylight.mdsal.binding.dom.codec.impl.loader.CodecClassLoader;
+import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
+import org.opendaylight.mdsal.binding.runtime.api.ListRuntimeType;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
 /**
- * Location specific context for schema nodes, which contains codec specific
- * information to properly serialize / deserialize from Java YANG Binding data
- * to NormalizedNode data.
+ * Location specific context for schema nodes, which contains codec specific information to properly serialize
+ * and deserialize from Java YANG Binding data to NormalizedNode data.
  *
+ * <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>
- * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain
- * nested YANG modeled substructures. This context nodes contains context
- * for children nodes.</li>
+ * <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>
  * </ul>
  */
-abstract class NodeCodecContext<D extends DataObject> implements BindingCodecTreeNode<D> {
-
+abstract class NodeCodecContext implements BindingCodecTreeNode {
     /**
-     * Returns Yang Instance Identifier Path Argument of current node
+     * Returns Yang Instance Identifier Path Argument of current node.
      *
      * @return DOM Path Argument of node
      */
     protected abstract YangInstanceIdentifier.PathArgument getDomPathArgument();
 
     /**
+     * Immutable factory, which provides access to runtime context, create leaf nodes and provides path argument codecs.
      *
-     * Immutable factory, which provides access to runtime context,
-     * create leaf nodes and provides path argument codecs.
      * <p>
-     * During lifetime of factory all calls for same arguments to method must return
-     * equal result (not necessary same instance of result).
-     *
+     * During lifetime of factory all calls for same arguments to method must return equal result (not necessary same
+     * instance of result).
      */
     protected interface CodecContextFactory {
         /**
          * Returns immutable runtime context associated with this factory.
+         *
          * @return runtime context
          */
         BindingRuntimeContext getRuntimeContext();
@@ -68,25 +64,31 @@ abstract class NodeCodecContext<D extends DataObject> implements BindingCodecTre
          * @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<Method, ValueNodeCodecContext> getLeafNodes(Class<?> type, EffectiveStatement<?, ?> schema);
 
         /**
-         * Returns Path argument codec for list item
+         * Returns Path argument codec for list item.
          *
-         * @param type Type of list item
-         * @param schema Schema of list item
+         * @param listClz Type of list item
+         * @param type Schema of list item
          * @return Path argument codec for supplied list item.
          */
-        Codec<NodeIdentifierWithPredicates, IdentifiableItem<?, ?>> getPathArgumentCodec(Class<?> type,
-                ListSchemaNode schema);
+        IdentifiableItemCodec getPathArgumentCodec(Class<?> listClz, ListRuntimeType type);
+
+        /**
+         * Return the codec loader associated with this factory.
+         *
+         * @return A codec loader instance
+         */
+        @NonNull CodecClassLoader getLoader();
+
+        @NonNull DataObjectStreamer<?> getDataObjectSerializer(Class<?> type);
 
         DataObjectSerializer getEventStreamSerializer(Class<?> type);
     }
 
     /**
-     *
-     * Serializes supplied Binding Path Argument
-     * and adds all necessary YANG instance identifiers to supplied list.
+     * Serializes supplied Binding Path Argument and adds all necessary YANG instance identifiers to supplied list.
      *
      * @param arg Binding Path Argument
      * @param builder DOM Path argument.
@@ -98,5 +100,15 @@ abstract class NodeCodecContext<D extends DataObject> implements BindingCodecTre
         }
     }
 
-    protected abstract Object deserializeObject(NormalizedNode<?, ?> normalizedNode);
+    /**
+     * Return the default value object. Implementations of this method are explicitly allowed to throw unchecked
+     * exceptions, which are propagated as-is upwards the stack.
+     *
+     * @return The default value object, or null if the default value is not defined.
+     */
+    @Nullable Object defaultObject() {
+        return null;
+    }
+
+    protected abstract Object deserializeObject(NormalizedNode normalizedNode);
 }