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.Map.Entry;
15 import javassist.ClassPool;
17 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
18 import org.opendaylight.yangtools.concepts.Delegator;
19 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
20 import org.opendaylight.yangtools.yang.binding.DataContainer;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.RpcService;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
25 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
27 import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
28 import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
29 import org.osgi.framework.BundleContext;
30 import org.osgi.framework.ServiceReference;
32 import com.google.common.base.Preconditions;
37 public final class RuntimeMappingModule extends
38 org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractRuntimeMappingModule {
40 private BundleContext bundleContext;
42 public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
43 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
44 super(identifier, dependencyResolver);
47 public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
48 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
49 RuntimeMappingModule oldModule, java.lang.AutoCloseable oldInstance) {
50 super(identifier, dependencyResolver, oldModule, oldInstance);
54 public void validate() {
56 Preconditions.checkNotNull(bundleContext);
57 // Add custom validation for module attributes here.
61 public boolean canReuseInstance(AbstractRuntimeMappingModule oldModule) {
66 public java.lang.AutoCloseable createInstance() {
68 RuntimeGeneratedMappingServiceProxy potential = tryToReuseGlobalInstance();
69 if(potential != null) {
72 RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl();
73 service.setPool(SingletonHolder.CLASS_POOL);
78 private RuntimeGeneratedMappingServiceProxy tryToReuseGlobalInstance() {
79 ServiceReference<BindingIndependentMappingService> serviceRef = getBundleContext().getServiceReference(BindingIndependentMappingService.class);
80 if(serviceRef == null) {
84 BindingIndependentMappingService delegate = bundleContext.getService(serviceRef);
85 if (delegate == null) {
88 return new RuntimeGeneratedMappingServiceProxy(getBundleContext(),serviceRef,delegate);
91 private BundleContext getBundleContext() {
95 public void setBundleContext(BundleContext bundleContext) {
96 this.bundleContext = bundleContext;
99 private static final class RuntimeGeneratedMappingServiceProxy implements //
100 BindingIndependentMappingService, //
101 Delegator<BindingIndependentMappingService>, //
104 private BindingIndependentMappingService delegate;
105 private ServiceReference<BindingIndependentMappingService> reference;
106 private BundleContext bundleContext;
108 public RuntimeGeneratedMappingServiceProxy(BundleContext bundleContext,
109 ServiceReference<BindingIndependentMappingService> serviceRef,
110 BindingIndependentMappingService delegate) {
111 this.bundleContext = Preconditions.checkNotNull(bundleContext);
112 this.reference = Preconditions.checkNotNull(serviceRef);
113 this.delegate = Preconditions.checkNotNull(delegate);
116 public CodecRegistry getCodecRegistry() {
117 return delegate.getCodecRegistry();
120 public CompositeNode toDataDom(DataObject data) {
121 return delegate.toDataDom(data);
124 public Entry<InstanceIdentifier, CompositeNode> toDataDom(
125 Entry<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject>, DataObject> entry) {
126 return delegate.toDataDom(entry);
129 public InstanceIdentifier toDataDom(
130 org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path) {
131 return delegate.toDataDom(path);
134 public DataObject dataObjectFromDataDom(
135 org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject> path,
136 CompositeNode result) throws DeserializationException {
137 return delegate.dataObjectFromDataDom(path, result);
140 public org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> fromDataDom(InstanceIdentifier entry)
141 throws DeserializationException {
142 return delegate.fromDataDom(entry);
145 public Set<QName> getRpcQNamesFor(Class<? extends RpcService> service) {
146 return delegate.getRpcQNamesFor(service);
149 public DataContainer dataObjectFromDataDom(Class<? extends DataContainer> inputClass, CompositeNode domInput) {
150 return delegate.dataObjectFromDataDom(inputClass, domInput);
154 public void close() throws Exception {
155 if(delegate != null) {
157 bundleContext.ungetService(reference);
164 public BindingIndependentMappingService getDelegate() {