*/
package org.opendaylight.controller.config.yang.md.sal.binding.impl;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
import java.util.Hashtable;
import java.util.Map.Entry;
import java.util.Set;
-import javassist.ClassPool;
-import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
+
import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
-import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
-import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
import org.opendaylight.yangtools.concepts.Delegator;
-import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
/**
*
*/
private BundleContext bundleContext;
- public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
- public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
- final RuntimeMappingModule oldModule, final java.lang.AutoCloseable oldInstance) {
+ public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ RuntimeMappingModule oldModule, java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
}
@Override
- public boolean canReuseInstance(final AbstractRuntimeMappingModule oldModule) {
+ public boolean canReuseInstance(AbstractRuntimeMappingModule oldModule) {
return true;
}
@Override
public java.lang.AutoCloseable createInstance() {
- final GeneratedClassLoadingStrategy classLoading = getGlobalClassLoadingStrategy();
- final BindingIndependentMappingService legacyMapping = getGlobalLegacyMappingService(classLoading);
- BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(new StreamWriterGenerator(SingletonHolder.JAVASSIST));
- BindingToNormalizedNodeCodec instance = new BindingToNormalizedNodeCodec(classLoading, legacyMapping, codecRegistry);
- bundleContext.registerService(SchemaContextListener.class, instance, new Hashtable<String,String>());
- return instance;
- }
- private BindingIndependentMappingService getGlobalLegacyMappingService(final GeneratedClassLoadingStrategy classLoading) {
- BindingIndependentMappingService potential = tryToReuseGlobalMappingServiceInstance();
- if(potential == null) {
- potential = new RuntimeGeneratedMappingServiceImpl(ClassPool.getDefault(),classLoading);
- bundleContext.registerService(SchemaContextListener.class, (SchemaContextListener) potential, new Hashtable<String,String>());
+ RuntimeGeneratedMappingServiceProxy potential = tryToReuseGlobalInstance();
+ if(potential != null) {
+ return potential;
}
- return potential;
- }
- private GeneratedClassLoadingStrategy getGlobalClassLoadingStrategy() {
- ServiceReference<GeneratedClassLoadingStrategy> ref = bundleContext.getServiceReference(GeneratedClassLoadingStrategy.class);
- return bundleContext.getService(ref);
+ final RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl(SingletonHolder.CLASS_POOL);
+ bundleContext.registerService(SchemaContextListener.class, service, new Hashtable<String,String>());
+ return service;
}
- private BindingIndependentMappingService tryToReuseGlobalMappingServiceInstance() {
+ private RuntimeGeneratedMappingServiceProxy tryToReuseGlobalInstance() {
ServiceReference<BindingIndependentMappingService> serviceRef = getBundleContext().getServiceReference(BindingIndependentMappingService.class);
if(serviceRef == null) {
return null;
}
- return bundleContext.getService(serviceRef);
+ BindingIndependentMappingService delegate = bundleContext.getService(serviceRef);
+ if (delegate == null) {
+ return null;
+ }
+ return new RuntimeGeneratedMappingServiceProxy(getBundleContext(),serviceRef,delegate);
}
private BundleContext getBundleContext() {
return bundleContext;
}
- public void setBundleContext(final BundleContext bundleContext) {
+ public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
private ServiceReference<BindingIndependentMappingService> reference;
private BundleContext bundleContext;
- public RuntimeGeneratedMappingServiceProxy(final BundleContext bundleContext,
- final ServiceReference<BindingIndependentMappingService> serviceRef,
- final BindingIndependentMappingService delegate) {
+ public RuntimeGeneratedMappingServiceProxy(BundleContext bundleContext,
+ ServiceReference<BindingIndependentMappingService> serviceRef,
+ BindingIndependentMappingService delegate) {
this.bundleContext = Preconditions.checkNotNull(bundleContext);
this.reference = Preconditions.checkNotNull(serviceRef);
this.delegate = Preconditions.checkNotNull(delegate);
}
@Override
- public CompositeNode toDataDom(final DataObject data) {
+ public CompositeNode toDataDom(DataObject data) {
return delegate.toDataDom(data);
}
@Override
public Entry<YangInstanceIdentifier, CompositeNode> toDataDom(
- final Entry<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject>, DataObject> entry) {
+ Entry<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject>, DataObject> entry) {
return delegate.toDataDom(entry);
}
@Override
public YangInstanceIdentifier toDataDom(
- final org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path) {
+ org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path) {
return delegate.toDataDom(path);
}
@Override
public DataObject dataObjectFromDataDom(
- final org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path,
- final CompositeNode result) throws DeserializationException {
+ org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path,
+ CompositeNode result) throws DeserializationException {
return delegate.dataObjectFromDataDom(path, result);
}
@Override
- public org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> fromDataDom(final YangInstanceIdentifier entry)
+ public org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> fromDataDom(YangInstanceIdentifier entry)
throws DeserializationException {
return delegate.fromDataDom(entry);
}
@Override
- public Set<QName> getRpcQNamesFor(final Class<? extends RpcService> service) {
+ public Set<QName> getRpcQNamesFor(Class<? extends RpcService> service) {
return delegate.getRpcQNamesFor(service);
}
@Override
- public Optional<Class<? extends RpcService>> getRpcServiceClassFor(final String namespace, final String revision) {
+ public Optional<Class<? extends RpcService>> getRpcServiceClassFor(String namespace, String revision) {
return delegate.getRpcServiceClassFor(namespace,revision);
}
@Override
- public DataContainer dataObjectFromDataDom(final Class<? extends DataContainer> inputClass, final CompositeNode domInput) {
+ public DataContainer dataObjectFromDataDom(Class<? extends DataContainer> inputClass, CompositeNode domInput) {
return delegate.dataObjectFromDataDom(inputClass, domInput);
}