BUG-2873 : Remove dependency protocol-framework on BGP
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / controller / config / yang / bgp / rib / impl / RIBImplModule.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 /**
9  * Generated file
10
11  * Generated from: yang module name: bgp-rib-impl  yang module local name: rib-impl
12  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13  * Generated at: Wed Nov 06 13:02:32 CET 2013
14  *
15  * Do not modify this file unless it is present under src/main directory
16  */
17 package org.opendaylight.controller.config.yang.bgp.rib.impl;
18
19 import java.util.Hashtable;
20 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
22 import org.opendaylight.controller.sal.core.api.model.SchemaService;
23 import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
25 import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
27 import org.osgi.framework.BundleContext;
28
29 /**
30  *
31  */
32 public final class RIBImplModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractRIBImplModule {
33
34     private static final String IS_NOT_SET = "is not set.";
35     private BundleContext bundleContext;
36
37     public RIBImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
38             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
39         super(name, dependencyResolver);
40     }
41
42     public RIBImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
43             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final RIBImplModule oldModule,
44             final java.lang.AutoCloseable oldInstance) {
45         super(name, dependencyResolver, oldModule, oldInstance);
46     }
47
48     @Override
49     public void customValidation() {
50         JmxAttributeValidationException.checkNotNull(getExtensions(), IS_NOT_SET, extensionsJmxAttribute);
51         JmxAttributeValidationException.checkNotNull(getRibId(), IS_NOT_SET, ribIdJmxAttribute);
52         JmxAttributeValidationException.checkNotNull(getLocalAs(), IS_NOT_SET, localAsJmxAttribute);
53         JmxAttributeValidationException.checkNotNull(getBgpRibId(), IS_NOT_SET, bgpRibIdJmxAttribute);
54         JmxAttributeValidationException.checkNotNull(getTcpReconnectStrategy(), IS_NOT_SET, tcpReconnectStrategyJmxAttribute);
55         JmxAttributeValidationException.checkNotNull(getSessionReconnectStrategy(), IS_NOT_SET, sessionReconnectStrategyJmxAttribute);
56         JmxAttributeValidationException.checkNotNull(getLocalTable(), IS_NOT_SET, localTableJmxAttribute);
57     }
58
59     @Override
60     public java.lang.AutoCloseable createInstance() {
61         RIBImpl rib = new RIBImpl(getRibId(), new AsNumber(getLocalAs()), getBgpRibId(), getClusterId(), getExtensionsDependency(),
62             getBgpDispatcherDependency(), getTcpReconnectStrategyDependency(), getCodecTreeFactoryDependency(), getSessionReconnectStrategyDependency(),
63             getDataProviderDependency(), getDomDataProviderDependency(), getLocalTableDependency(), classLoadingStrategy());
64         registerSchemaContextListener(rib);
65         return rib;
66     }
67
68     private GeneratedClassLoadingStrategy classLoadingStrategy() {
69         return getExtensionsDependency().getClassLoadingStrategy();
70     }
71
72     private void registerSchemaContextListener(RIBImpl rib) {
73         DOMDataBroker domBroker = getDomDataProviderDependency();
74         if(domBroker instanceof SchemaService) {
75             ((SchemaService) domBroker).registerSchemaContextListener(rib);
76         } else {
77             // FIXME:Get bundle context and register global schema service from bundle
78             // context.
79             bundleContext.registerService(SchemaContextListener.class, rib, new Hashtable<String,String>());
80         }
81     }
82
83     public void setBundleContext(BundleContext bundleContext) {
84         this.bundleContext = bundleContext;
85     }
86 }