X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fmd%2Fsal%2Fbinding%2Fimpl%2FRuntimeMappingModule.java;h=14006a3fce2ff3eea04e4fcae84bf0e412ea850b;hb=b17a51ecb983331f0e521e40f9dd2474f268de13;hp=aadf2fcc8dfdeb730877e40392bc04ae6505ce0e;hpb=e2ae7bd2fc1f56cbb1b7a242e061dfb25b5fda63;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/RuntimeMappingModule.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/RuntimeMappingModule.java index aadf2fcc8d..0ad0434892 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/RuntimeMappingModule.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/RuntimeMappingModule.java @@ -1,54 +1,41 @@ -/** - * Generated file - - * Generated from: yang module name: opendaylight-sal-binding-broker-impl yang module local name: runtime-generated-mapping - * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - * Generated at: Wed Nov 20 18:20:19 CET 2013 +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * - * Do not modify this file unless it is present under src/main directory + * 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.controller.config.yang.md.sal.binding.impl; +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.concepts.Delegator; +import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator; +import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry; +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.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService; -import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry; -import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException; -import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener; +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -import com.google.common.base.Preconditions; - /** * */ -public final class RuntimeMappingModule extends - org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractRuntimeMappingModule { +public final class RuntimeMappingModule extends AbstractRuntimeMappingModule { private BundleContext bundleContext; - public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, - org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } - public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, - org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, - RuntimeMappingModule oldModule, java.lang.AutoCloseable oldInstance) { + 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) { super(identifier, dependencyResolver, oldModule, oldInstance); } @@ -60,112 +47,48 @@ public final class RuntimeMappingModule extends } @Override - public boolean canReuseInstance(AbstractRuntimeMappingModule oldModule) { + public boolean canReuseInstance(final AbstractRuntimeMappingModule oldModule) { return true; } @Override public java.lang.AutoCloseable createInstance() { - - RuntimeGeneratedMappingServiceProxy potential = tryToReuseGlobalInstance(); - if(potential != null) { - return potential; + final GeneratedClassLoadingStrategy classLoading = getGlobalClassLoadingStrategy(); + final BindingIndependentMappingService legacyMapping = getGlobalLegacyMappingService(classLoading); + BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(SingletonHolder.JAVASSIST)); + BindingToNormalizedNodeCodec instance = new BindingToNormalizedNodeCodec(classLoading, legacyMapping, codecRegistry); + bundleContext.registerService(SchemaContextListener.class, instance, new Hashtable()); + 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()); } - RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl(); - service.setPool(SingletonHolder.CLASS_POOL); - service.init(); - bundleContext.registerService(SchemaServiceListener.class, service, new Hashtable()); - return service; + return potential; } - private RuntimeGeneratedMappingServiceProxy tryToReuseGlobalInstance() { + private GeneratedClassLoadingStrategy getGlobalClassLoadingStrategy() { + ServiceReference ref = bundleContext.getServiceReference(GeneratedClassLoadingStrategy.class); + return bundleContext.getService(ref); + } + + private BindingIndependentMappingService tryToReuseGlobalMappingServiceInstance() { ServiceReference 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(BundleContext bundleContext) { + public void setBundleContext(final BundleContext bundleContext) { this.bundleContext = bundleContext; } - - private static final class RuntimeGeneratedMappingServiceProxy implements // - BindingIndependentMappingService, // - Delegator, // - AutoCloseable { - - private BindingIndependentMappingService delegate; - private ServiceReference reference; - private BundleContext bundleContext; - - public RuntimeGeneratedMappingServiceProxy(BundleContext bundleContext, - ServiceReference serviceRef, - BindingIndependentMappingService delegate) { - this.bundleContext = Preconditions.checkNotNull(bundleContext); - this.reference = Preconditions.checkNotNull(serviceRef); - this.delegate = Preconditions.checkNotNull(delegate); - } - - public CodecRegistry getCodecRegistry() { - return delegate.getCodecRegistry(); - } - - public CompositeNode toDataDom(DataObject data) { - return delegate.toDataDom(data); - } - - public Entry toDataDom( - Entry, DataObject> entry) { - return delegate.toDataDom(entry); - } - - public InstanceIdentifier toDataDom( - org.opendaylight.yangtools.yang.binding.InstanceIdentifier path) { - return delegate.toDataDom(path); - } - - public DataObject dataObjectFromDataDom( - org.opendaylight.yangtools.yang.binding.InstanceIdentifier path, - CompositeNode result) throws DeserializationException { - return delegate.dataObjectFromDataDom(path, result); - } - - public org.opendaylight.yangtools.yang.binding.InstanceIdentifier fromDataDom(InstanceIdentifier entry) - throws DeserializationException { - return delegate.fromDataDom(entry); - } - - public Set getRpcQNamesFor(Class service) { - return delegate.getRpcQNamesFor(service); - } - - public DataContainer dataObjectFromDataDom(Class inputClass, CompositeNode domInput) { - return delegate.dataObjectFromDataDom(inputClass, domInput); - } - - @Override - public void close() throws Exception { - if(delegate != null) { - delegate = null; - bundleContext.ungetService(reference); - bundleContext= null; - reference = null; - } - } - - @Override - public BindingIndependentMappingService getDelegate() { - return delegate; - } - } }