Moved Schema Aware logic from DataStore to SchemaAwareDataStore adapter
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / BrokerConfigActivator.xtend
1 package org.opendaylight.controller.sal.dom.broker
2
3 import org.osgi.framework.ServiceRegistration
4 import org.opendaylight.controller.sal.core.api.model.SchemaService
5 import org.opendaylight.controller.sal.core.api.data.DataBrokerService
6 import org.opendaylight.controller.sal.core.api.data.DataProviderService
7 import org.opendaylight.controller.sal.dom.broker.impl.HashMapDataStore
8 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService
9 import org.opendaylight.controller.sal.core.api.mount.MountService
10 import org.osgi.framework.BundleContext
11 import java.util.Hashtable
12 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
14 import org.opendaylight.controller.sal.core.api.data.DataStore
15 import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter
16
17 class BrokerConfigActivator implements AutoCloseable {
18     
19     
20     private static val ROOT = InstanceIdentifier.builder().toInstance();
21     
22     private var ServiceRegistration<SchemaService> schemaReg;
23     private var ServiceRegistration<DataBrokerService> dataReg;
24     private var ServiceRegistration<DataProviderService> dataProviderReg;
25     private var ServiceRegistration<MountService> mountReg;
26     private var ServiceRegistration<MountProvisionService> mountProviderReg;
27     
28     private var SchemaServiceImpl schemaService;
29     private var DataBrokerImpl dataService;
30     private var MountPointManagerImpl mountService;
31     
32     SchemaAwareDataStoreAdapter wrappedStore
33
34     public def void start(BrokerImpl broker,DataStore store,BundleContext context) {
35         val emptyProperties = new Hashtable<String, String>();
36         broker.setBundleContext(context);
37         
38
39         schemaService = new SchemaServiceImpl();
40         schemaService.setContext(context);
41         schemaService.setParser(new YangParserImpl());
42         schemaService.start();
43         schemaReg = context.registerService(SchemaService, schemaService, emptyProperties);
44         
45         dataService = new DataBrokerImpl();
46         dataService.setExecutor(broker.getExecutor());
47         
48         dataReg = context.registerService(DataBrokerService, dataService, emptyProperties);
49         dataProviderReg = context.registerService(DataProviderService, dataService, emptyProperties);
50
51         wrappedStore = new SchemaAwareDataStoreAdapter();
52         wrappedStore.changeDelegate(store);
53         wrappedStore.setValidationEnabled(false);
54         
55         dataService.registerConfigurationReader(ROOT, wrappedStore);
56         dataService.registerCommitHandler(ROOT, wrappedStore);
57         dataService.registerOperationalReader(ROOT, wrappedStore);
58         
59         mountService = new MountPointManagerImpl();
60         mountService.setDataBroker(dataService);
61         
62         mountReg = context.registerService(MountService, mountService, emptyProperties);
63         mountProviderReg =  context.registerService(MountProvisionService, mountService, emptyProperties);
64     }
65
66     override def close() {
67         schemaReg?.unregister();
68         dataReg?.unregister();
69         dataProviderReg?.unregister();
70         mountReg?.unregister();
71         mountProviderReg?.unregister();
72     }
73     
74 }