2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.core.sli.provider;
23 import java.util.HashMap;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
26 import org.osgi.framework.BundleContext;
27 import org.osgi.framework.FrameworkUtil;
28 import org.osgi.framework.ServiceReference;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class SvcLogicAdaptorFactory {
34 private static final Logger LOG = LoggerFactory
35 .getLogger(SvcLogicAdaptorFactory.class);
37 private static HashMap<String, SvcLogicAdaptor> adaptorMap = new HashMap<String, SvcLogicAdaptor>();
39 public static void registerAdaptor(SvcLogicAdaptor adaptor) {
40 String name = adaptor.getClass().getName();
41 LOG.info("Registering adaptor " + name);
42 adaptorMap.put(name, adaptor);
46 public static void unregisterAdaptor(String name) {
47 if (adaptorMap.containsKey(name)) {
48 LOG.info("Unregistering " + name);
49 adaptorMap.remove(name);
53 public static SvcLogicAdaptor getInstance(String name) {
54 if (adaptorMap.containsKey(name)) {
55 return (adaptorMap.get(name));
57 BundleContext bctx = null;
60 bctx = FrameworkUtil.getBundle(SvcLogicAdaptorFactory.class)
65 LOG.debug("Caught exception trying to locate device adaptor "+name, e);
69 ServiceReference sref = bctx.getServiceReference(name);
72 SvcLogicAdaptor adaptor = (SvcLogicAdaptor) bctx
75 if (adaptor != null) {
76 registerAdaptor(adaptor);