Merge "Bug 992 - Fix broken netconf xml serialization."
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / BrokerConfigActivator.xtend
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 package org.opendaylight.controller.sal.dom.broker
9
10 import java.util.Hashtable
11 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker
12 import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker
13 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry
14 import org.opendaylight.controller.sal.core.api.data.DataBrokerService
15 import org.opendaylight.controller.sal.core.api.data.DataProviderService
16 import org.opendaylight.controller.sal.core.api.data.DataStore
17 import org.opendaylight.controller.sal.core.api.model.SchemaService
18 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService
19 import org.opendaylight.controller.sal.core.api.mount.MountService
20 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter
21 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker
22 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProviders
23 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
24 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener
25 import org.osgi.framework.BundleContext
26 import org.osgi.framework.ServiceRegistration
27
28 class BrokerConfigActivator implements AutoCloseable {
29
30     private static val ROOT = InstanceIdentifier.builder().toInstance();
31
32     @Property
33     private var DataProviderService dataService;
34
35     private var ServiceRegistration<DataBrokerService> dataReg;
36     private var ServiceRegistration<DataProviderService> dataProviderReg;
37     private var ServiceRegistration<MountService> mountReg;
38     private var ServiceRegistration<MountProvisionService> mountProviderReg;
39     private var SchemaService schemaService;
40     private var ServiceRegistration<RpcProvisionRegistry> rpcProvisionRegistryReg;
41     private var MountPointManagerImpl mountService;
42
43     SchemaAwareDataStoreAdapter wrappedStore
44
45     public def void start(BrokerImpl broker, DataStore store, DOMDataBroker asyncBroker,BundleContext context) {
46         val emptyProperties = new Hashtable<String, String>();
47         broker.setBundleContext(context);
48
49         val serviceRef = context.getServiceReference(SchemaService);
50         schemaService = context.getService(serviceRef);
51
52         broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders.fromSchemaService(schemaService)));
53         
54
55         if(asyncBroker == null) {
56             dataService = new DataBrokerImpl();
57             dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties);
58     
59             wrappedStore = new SchemaAwareDataStoreAdapter();
60             wrappedStore.changeDelegate(store);
61             wrappedStore.setValidationEnabled(false);
62             context.registerService(SchemaServiceListener, wrappedStore, emptyProperties)
63             
64             dataService.registerConfigurationReader(ROOT, wrappedStore);
65             dataService.registerCommitHandler(ROOT, wrappedStore);
66             dataService.registerOperationalReader(ROOT, wrappedStore);
67         } else {
68             val compatibleDataBroker = new BackwardsCompatibleDataBroker(asyncBroker);
69             context.registerService(SchemaServiceListener,compatibleDataBroker,emptyProperties);
70             dataService = compatibleDataBroker;
71         }
72         
73
74 //        
75
76         mountService = new MountPointManagerImpl();
77         dataReg = context.registerService(DataBrokerService, dataService, emptyProperties);
78             mountReg = context.registerService(MountService, mountService, emptyProperties);
79         mountProviderReg = context.registerService(MountProvisionService, mountService, emptyProperties);
80
81         rpcProvisionRegistryReg = context.registerService(RpcProvisionRegistry, broker.getRouter(), emptyProperties);
82     }
83
84     override def close() {
85         dataReg?.unregister();
86         dataProviderReg?.unregister();
87         mountReg?.unregister();
88         mountProviderReg?.unregister();
89         rpcProvisionRegistryReg?.unregister();
90     }
91
92 }