2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia
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.
19 * ============LICENSE_END=========================================================
21 package org.onap.appc.dg.util.impl;
23 import com.att.eelf.configuration.EELFLogger;
24 import com.att.eelf.configuration.EELFManager;
25 import com.att.eelf.i18n.EELFResourceManager;
26 import org.onap.appc.i18n.Msg;
27 import org.onap.ccsdk.sli.adaptors.aai.AAIService;
28 import org.osgi.framework.Bundle;
29 import org.osgi.framework.BundleContext;
30 import org.osgi.framework.FrameworkUtil;
31 import org.osgi.framework.ServiceReference;
33 public class AAIServiceFactory {
35 private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIServiceFactory.class);
37 private FrameworkUtilWrapper frameworkUtilWrapper = new FrameworkUtilWrapper();
39 public AAIService getAAIService() {
40 BundleContext bctx = frameworkUtilWrapper.getBundle(AAIService.class).getBundleContext();
41 // Get AAIadapter reference
42 ServiceReference sref = bctx.getServiceReference(AAIService.class.getName());
44 logger.info("AAIService from bundlecontext");
45 return (AAIService) bctx.getService(sref);
48 logger.info("AAIService error from bundlecontext");
49 logger.error(EELFResourceManager.format(Msg.AAI_CONNECTION_FAILED, "AAIService"));
54 static class FrameworkUtilWrapper {
56 Bundle getBundle(Class<?> clazz) {
57 return FrameworkUtil.getBundle(clazz);