Extract dom-serializer-api|impl from binding-broker-impl
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / BindingIndependentMappingServiceTracker.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 package org.opendaylight.controller.config.manager.impl.osgi;
9
10 import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService;
11 import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
12 import org.osgi.framework.BundleContext;
13 import org.osgi.framework.ServiceReference;
14 import org.osgi.util.tracker.ServiceTrackerCustomizer;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Every time factory is added or removed, blank transaction is triggered to handle
20  * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory, org.osgi.framework.BundleContext)}
21  * functionality.
22  */
23 public class BindingIndependentMappingServiceTracker implements ServiceTrackerCustomizer<BindingIndependentMappingService, BindingIndependentMappingService> {
24     private static final Logger logger = LoggerFactory.getLogger(BindingIndependentMappingServiceTracker.class);
25
26     private final ConfigManagerActivator activator;
27     private final BundleContext ctx;
28     private BindingIndependentMappingService service;
29
30     public BindingIndependentMappingServiceTracker(BundleContext context, ConfigManagerActivator activator) {
31         this.ctx = context;
32         this.activator = activator;
33     }
34
35     @Override
36     public synchronized BindingIndependentMappingService addingService(
37             ServiceReference<BindingIndependentMappingService> moduleFactoryServiceReference) {
38
39         if (service != null) {
40             // FIXME
41             // Second registration appears from
42             // org.opendaylight.controller.config.yang.md.sal.binding.impl.RuntimeMappingModule
43             logger.debug("BindingIndependentMappingService was already added as {}" + " now added as {}",
44                     service, ctx.getService(moduleFactoryServiceReference));
45             return null;
46         }
47
48         BindingIndependentMappingService service = ctx.getService(moduleFactoryServiceReference);
49         this.service = service;
50         CodecRegistry codecRegistry = service.getCodecRegistry();
51         logger.warn("Codec registry acquired {}", codecRegistry);
52         activator.initConfigManager(ctx, codecRegistry);
53         return service;
54     }
55
56     @Override
57     public void modifiedService(ServiceReference <BindingIndependentMappingService> moduleFactoryServiceReference, BindingIndependentMappingService o) {
58         // TODO crash
59     }
60
61     @Override
62     public void removedService(ServiceReference<BindingIndependentMappingService> moduleFactoryServiceReference, BindingIndependentMappingService    o) {
63         // TODO crash
64     }
65 }