4 * Generated from: yang module name: opendaylight-sal-binding-broker-impl yang module local name: runtime-generated-mapping
5 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6 * Generated at: Wed Nov 20 18:20:19 CET 2013
8 * Do not modify this file unless it is present under src/main directory
10 package org.opendaylight.controller.config.yang.md.sal.binding.impl;
12 import java.util.Hashtable;
13 import java.util.Map.Entry;
16 import javassist.ClassPool;
18 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
19 import org.opendaylight.yangtools.concepts.Delegator;
20 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
21 import org.opendaylight.yangtools.yang.binding.DataContainer;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.RpcService;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
26 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
28 import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
29 import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
30 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
31 import org.osgi.framework.BundleContext;
32 import org.osgi.framework.ServiceReference;
34 import com.google.common.base.Preconditions;
39 public final class RuntimeMappingModule extends
40 org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractRuntimeMappingModule {
42 private BundleContext bundleContext;
44 public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
45 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
46 super(identifier, dependencyResolver);
49 public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
50 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
51 RuntimeMappingModule oldModule, java.lang.AutoCloseable oldInstance) {
52 super(identifier, dependencyResolver, oldModule, oldInstance);
56 public void validate() {
58 Preconditions.checkNotNull(bundleContext);
59 // Add custom validation for module attributes here.
63 public boolean canReuseInstance(AbstractRuntimeMappingModule oldModule) {
68 public java.lang.AutoCloseable createInstance() {
70 RuntimeGeneratedMappingServiceProxy potential = tryToReuseGlobalInstance();
71 if(potential != null) {
74 RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl();
75 service.setPool(SingletonHolder.CLASS_POOL);
77 bundleContext.registerService(SchemaServiceListener.class, service, new Hashtable<String,String>());
81 private RuntimeGeneratedMappingServiceProxy tryToReuseGlobalInstance() {
82 ServiceReference<BindingIndependentMappingService> serviceRef = getBundleContext().getServiceReference(BindingIndependentMappingService.class);
83 if(serviceRef == null) {
87 BindingIndependentMappingService delegate = bundleContext.getService(serviceRef);
88 if (delegate == null) {
91 return new RuntimeGeneratedMappingServiceProxy(getBundleContext(),serviceRef,delegate);
94 private BundleContext getBundleContext() {
98 public void setBundleContext(BundleContext bundleContext) {
99 this.bundleContext = bundleContext;
102 private static final class RuntimeGeneratedMappingServiceProxy implements //
103 BindingIndependentMappingService, //
104 Delegator<BindingIndependentMappingService>, //
107 private BindingIndependentMappingService delegate;
108 private ServiceReference<BindingIndependentMappingService> reference;
109 private BundleContext bundleContext;
111 public RuntimeGeneratedMappingServiceProxy(BundleContext bundleContext,
112 ServiceReference<BindingIndependentMappingService> serviceRef,
113 BindingIndependentMappingService delegate) {
114 this.bundleContext = Preconditions.checkNotNull(bundleContext);
115 this.reference = Preconditions.checkNotNull(serviceRef);
116 this.delegate = Preconditions.checkNotNull(delegate);
119 public CodecRegistry getCodecRegistry() {
120 return delegate.getCodecRegistry();
123 public CompositeNode toDataDom(DataObject data) {
124 return delegate.toDataDom(data);
127 public Entry<InstanceIdentifier, CompositeNode> toDataDom(
128 Entry<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject>, DataObject> entry) {
129 return delegate.toDataDom(entry);
132 public InstanceIdentifier toDataDom(
133 org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path) {
134 return delegate.toDataDom(path);
137 public DataObject dataObjectFromDataDom(
138 org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path,
139 CompositeNode result) throws DeserializationException {
140 return delegate.dataObjectFromDataDom(path, result);
143 public org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> fromDataDom(InstanceIdentifier entry)
144 throws DeserializationException {
145 return delegate.fromDataDom(entry);
148 public Set<QName> getRpcQNamesFor(Class<? extends RpcService> service) {
149 return delegate.getRpcQNamesFor(service);
152 public DataContainer dataObjectFromDataDom(Class<? extends DataContainer> inputClass, CompositeNode domInput) {
153 return delegate.dataObjectFromDataDom(inputClass, domInput);
157 public void close() throws Exception {
158 if(delegate != null) {
160 bundleContext.ungetService(reference);
167 public BindingIndependentMappingService getDelegate() {