Split off DefaultBindingCodecTreeFactory 38/88038/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Feb 2020 11:07:34 +0000 (12:07 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Feb 2020 11:12:21 +0000 (12:12 +0100)
BindingCodecTreeFactory is a simple interface which should be backed
by a simple implementation, rather than munging it with the codec
itself. Split it out of BindingNormalizedNodeCodecRegistry and back
it by the corresponding context.

JIRA: MDSAL-392
Change-Id: I1c35d39ab1b7d3b40a6cc3eacd69d3677306c081
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingToNormalizedNodeCodec.java
binding/mdsal-binding-dom-adapter/src/main/resources/org/opendaylight/blueprint/binding-adapter.xml
binding/mdsal-binding-dom-codec/pom.xml
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingNormalizedNodeCodecRegistry.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DefaultBindingCodecTreeFactory.java [new file with mode: 0644]

index 666214537a86459a1a41952804c12bd406594bb6..bdca5389b398b25dc52adb1e8857230c6d5c6446 100644 (file)
@@ -88,8 +88,8 @@ import org.slf4j.LoggerFactory;
  * NOTE: this class is non-final to allow controller adapter migration without duplicated code.
  */
 @Singleton
-public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
-        BindingNormalizedNodeSerializer, SchemaContextListener, AutoCloseable {
+public class BindingToNormalizedNodeCodec implements BindingNormalizedNodeSerializer, SchemaContextListener,
+        AutoCloseable {
 
     private static final long WAIT_DURATION_SEC = 5;
     private static final Logger LOG = LoggerFactory.getLogger(BindingToNormalizedNodeCodec.class);
@@ -420,11 +420,6 @@ public class BindingToNormalizedNodeCodec implements BindingCodecTreeFactory,
         return key.getMethod(methodName, inputClz);
     }
 
-    @Override
-    public final BindingCodecTree create(final BindingRuntimeContext context) {
-        return codecRegistry.create(context);
-    }
-
     protected @NonNull Entry<InstanceIdentifier<?>, BindingDataObjectCodecTreeNode<?>> getSubtreeCodec(
             final YangInstanceIdentifier domIdentifier) {
 
index c212e017e2f707c866a19a04b8e3d6132585752a..b6a0d46fb6924d1ddaeb597dd3de478c2ecc0659 100644 (file)
@@ -15,7 +15,6 @@
   <service ref="mappingCodec" odl:type="default">
     <interfaces>
       <value>org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer</value>
-      <value>org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory</value>
     </interfaces>
   </service>
 
index efd677f1f74b8e430aec6e317ccec884e102a7cc..667b635bdf8cb67485bc0f8983b7fd6e9cd63bfa 100644 (file)
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>mdsal-binding-dom-codec-spi</artifactId>
         </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.kohsuke.metainf-services</groupId>
+            <artifactId>metainf-services</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
index 480eff6db0d3f4880ba3df68117bcaed459efe79..6a7f94b8135adc4d4243cd09543f04b0475a7456 100644 (file)
@@ -25,7 +25,6 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.binding.runtime.api.BindingRuntimeContext;
 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.BindingDataObjectCodecTreeNode;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingLazyContainerNode;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
@@ -57,7 +56,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class BindingNormalizedNodeCodecRegistry implements DataObjectSerializerRegistry,
-        BindingCodecTreeFactory, BindingNormalizedNodeWriterFactory, BindingNormalizedNodeSerializer {
+        BindingNormalizedNodeWriterFactory, BindingNormalizedNodeSerializer {
     private static final Logger LOG = LoggerFactory.getLogger(BindingNormalizedNodeCodecRegistry.class);
 
     private static final AtomicReferenceFieldUpdater<BindingNormalizedNodeCodecRegistry, BindingCodecContext> UPDATER =
@@ -300,11 +299,6 @@ public class BindingNormalizedNodeCodecRegistry implements DataObjectSerializerR
         return new DeserializeFunction<>(ctx);
     }
 
-    @Override
-    public BindingCodecTree create(final BindingRuntimeContext context) {
-        return new BindingCodecContext(context, this);
-    }
-
     private static final class DeserializeFunction<T> implements Function<Optional<NormalizedNode<?, ?>>, Optional<T>> {
         private final DataObjectCodecContext<?,?> ctx;
 
diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DefaultBindingCodecTreeFactory.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DefaultBindingCodecTreeFactory.java
new file mode 100644 (file)
index 0000000..50da721
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.mdsal.binding.dom.codec.impl;
+
+import com.google.common.annotations.Beta;
+import javax.inject.Singleton;
+import org.kohsuke.MetaInfServices;
+import org.opendaylight.binding.runtime.api.BindingRuntimeContext;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Beta
+@MetaInfServices
+@Singleton
+@Component(immediate = true)
+public final class DefaultBindingCodecTreeFactory implements BindingCodecTreeFactory {
+    private static final Logger LOG = LoggerFactory.getLogger(DefaultBindingCodecTreeFactory.class);
+
+    @Override
+    public BindingCodecTree create(final BindingRuntimeContext context) {
+        return new BindingCodecContext(context, new BindingNormalizedNodeCodecRegistry(context));
+    }
+
+    @Activate
+    @SuppressWarnings("static-method")
+    void activate() {
+        LOG.info("Binding-DOM Codec enabled");
+    }
+
+
+    @Deactivate
+    @SuppressWarnings("static-method")
+    void deactivate() {
+        LOG.info("Binding-DOM Codec disabled");
+    }
+}