*/
package org.opendaylight.controller.md.sal.binding.impl;
+import java.util.Dictionary;
+import java.util.Hashtable;
import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
/**
* Factory class for creating and initializing the BindingToNormalizedNodeCodec instances.
SchemaService schemaService) {
return schemaService.registerSchemaContextListener(instance);
}
+
+ /**
+ * This method is called via blueprint to register a BindingToNormalizedNodeCodec instance with the OSGI
+ * service registry. This is done in code instead of directly via blueprint because the BindingToNormalizedNodeCodec
+ * instance must be advertised with the actual class for backwards compatibility with CSS modules and blueprint
+ * will try to create a proxy wrapper which is problematic with BindingToNormalizedNodeCodec because it's final
+ * and has final methods which can't be proxied.
+ *
+ * @param instance the BindingToNormalizedNodeCodec instance
+ * @param bundleContext the BundleContext
+ * @return ServiceRegistration instance
+ */
+ public static ServiceRegistration<BindingToNormalizedNodeCodec> registerOSGiService(BindingToNormalizedNodeCodec instance,
+ BundleContext bundleContext) {
+ Dictionary<String, String> props = new Hashtable<>();
+
+ // Set the appropriate service properties so the corresponding CSS module is restarted if this
+ // blueprint container is restarted
+ props.put("config-module-namespace", "urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding:impl");
+ props.put("config-module-name", "runtime-generated-mapping");
+ props.put("config-instance-name", "runtime-mapping-singleton");
+ return bundleContext.registerService(BindingToNormalizedNodeCodec.class, instance, props );
+ }
}
</bean>
<!-- Register the BindingToNormalizedNodeCodec with the SchemaService as a SchemaContextListener -->
- <bean id="mappingCodecReg" class="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodecFactory"
+ <bean id="mappingCodecListenerReg" class="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodecFactory"
factory-method="registerInstance" destroy-method="close">
<argument ref="mappingCodec"/>
<argument ref="schemaService"/>
<!-- We also register the BindingToNormalizedNodeCodec with its actual class name for
backwards compatibility for CSS users that inject the binding-dom-mapping-service -->
- <service ref="mappingCodec" interface="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec"
- odl:type="default">
- <!-- Set the appropriate service properties so the corresponding CSS module is restarted if this
- blueprint container is restarted -->
- <service-properties>
- <entry key="config-module-namespace" value="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding:impl"/>
- <entry key="config-module-name" value="runtime-generated-mapping"/>
- <entry key="config-instance-name" value="runtime-mapping-singleton"/>
- </service-properties>
- </service>
+ <bean id="mappingCodecServiceReg" class="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodecFactory"
+ factory-method="registerOSGiService" destroy-method="unregister">
+ <argument ref="mappingCodec"/>
+ <argument ref="blueprintBundleContext"/>
+ </bean>
<!-- Binding RPC Registry Service -->