Fix RPC method name conflict with JLS
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / BindingToNormalizedNodeCodec.java
index 7f7a3c205daeaa24db02f6568840435a6c027792..55fde2cd655b19b5e47517d3ca0ec7895f84cf50 100644 (file)
@@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterators;
 import java.lang.reflect.Method;
+import java.time.Instant;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.Collection;
 import java.util.HashSet;
@@ -27,20 +28,21 @@ import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-import javassist.ClassPool;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingLazyContainerNode;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
-import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator;
 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
 import org.opendaylight.mdsal.binding.dom.codec.impl.MissingSchemaException;
 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
 import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
-import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
@@ -82,6 +84,7 @@ import org.slf4j.LoggerFactory;
  * <p>
  * NOTE: this class is non-final to allow controller adapter migration without duplicated code.
  */
+@Singleton
 public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
         BindingNormalizedNodeSerializer, SchemaContextListener, AutoCloseable {
 
@@ -100,6 +103,7 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
     private final FutureSchema futureSchema;
     private ListenerRegistration<?> listenerRegistration;
 
+    @Inject
     public BindingToNormalizedNodeCodec(final ClassLoadingStrategy classLoadingStrategy,
             final BindingNormalizedNodeCodecRegistry codecRegistry) {
         this(classLoadingStrategy, codecRegistry, false);
@@ -114,8 +118,7 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
 
     public static BindingToNormalizedNodeCodec newInstance(final ClassLoadingStrategy classLoadingStrategy,
             final DOMSchemaService schemaService) {
-        final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(
-                StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault())));
+        final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry();
         BindingToNormalizedNodeCodec instance = new BindingToNormalizedNodeCodec(
                 classLoadingStrategy, codecRegistry, true);
         instance.listenerRegistration = schemaService.registerSchemaContextListener(instance);
@@ -193,6 +196,12 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
         return codecRegistry.fromNormalizedNodeNotification(path, data);
     }
 
+    @Override
+    public final Notification fromNormalizedNodeNotification(final SchemaPath path, final ContainerNode data,
+            final Instant eventInstant) {
+        return codecRegistry.fromNormalizedNodeNotification(path, data, eventInstant);
+    }
+
     @Override
     public final DataObject fromNormalizedNodeRpcData(final SchemaPath path, final ContainerNode data) {
         return codecRegistry.fromNormalizedNodeRpcData(path, data);
@@ -316,6 +325,7 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
     }
 
     @Override
+    @PreDestroy
     public void close() {
         if (listenerRegistration != null) {
             listenerRegistration.close();
@@ -385,7 +395,7 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
 
     private Method findRpcMethod(final Class<? extends RpcService> key, final RpcDefinition rpcDef)
             throws NoSuchMethodException {
-        final String methodName = BindingMapping.getMethodName(rpcDef.getQName());
+        final String methodName = BindingMapping.getRpcMethodName(rpcDef.getQName());
         final Class<?> inputClz = runtimeContext().getClassForSchema(rpcDef.getInput());
         return key.getMethod(methodName, inputClz);
     }
@@ -400,7 +410,7 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
         return codecRegistry.create(context, bindingClasses);
     }
 
-    protected @NonNull Entry<InstanceIdentifier<?>, BindingCodecTreeNode<?>> getSubtreeCodec(
+    protected @NonNull Entry<InstanceIdentifier<?>, BindingDataObjectCodecTreeNode<?>> getSubtreeCodec(
             final YangInstanceIdentifier domIdentifier) {
 
         final BindingCodecTree currentCodecTree = codecRegistry.getCodecContext();
@@ -410,7 +420,7 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
          * If we are able to deserialize YANG instance identifier, getSubtreeCodec must
          * return non-null value.
          */
-        final BindingCodecTreeNode<?> codecContext = currentCodecTree.getSubtreeCodec(bindingPath);
+        final BindingDataObjectCodecTreeNode<?> codecContext = currentCodecTree.getSubtreeCodec(bindingPath);
         return new SimpleEntry<>(bindingPath, codecContext);
     }
 
@@ -449,8 +459,16 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
         return ImmutableNodes.fromInstanceId(runtimeContext().getSchemaContext(), parentPath);
     }
 
+    /**
+     * This method creates an empty list container of a particular type.
+     *
+     * @deprecated This method is not generally useful, as empty lists do not convey information in YANG (they are
+     *             equivalent to non-present lists). It also leaks implementation details to a broader scope and should
+     *             never have been public in the first place.
+     */
+    @Deprecated
     public NormalizedNode<?, ?> getDefaultNodeFor(final YangInstanceIdentifier parentMapPath) {
-        final BindingCodecTreeNode<?> mapCodec = requireNonNull(
+        final BindingCodecTreeNode mapCodec = requireNonNull(
                 codecRegistry.getCodecContext().getSubtreeCodec(parentMapPath),
                 "Codec not found for yang instance identifier: " + parentMapPath);
         final WithStatus schema = mapCodec.getSchema();