1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.odlux;
20 import java.util.ArrayList;
21 import java.util.Comparator;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.concurrent.ConcurrentSkipListSet;
25 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundle;
26 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleLoader;
27 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleResourceAccess;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class OdluxBundleLoaderImpl implements OdluxBundleLoader {
33 private final static Logger LOG = LoggerFactory.getLogger(OdluxBundleLoaderImpl.class);
35 private static OdluxBundleLoaderImpl singleton = null;
38 // private List<OdluxBundle> bundles;
39 private ConcurrentSkipListSet<OdluxBundle> bundles2;
40 private Comparator<OdluxBundle> sortorderbundlecomparator;
42 public OdluxBundleLoaderImpl() {
43 if (singleton != null) {
44 LOG.error("Multiple intializations of singleton");
47 sortorderbundlecomparator = (arg0, arg1) -> {
48 int diff = arg0.getIndex() - arg1.getIndex();
49 return diff > 0 ? 1 : diff < 0 ? -1 : 0;
51 bundles2 = new ConcurrentSkipListSet<>(sortorderbundlecomparator);
57 public static OdluxBundleLoaderImpl getInstance() {
58 if (singleton == null) {
59 LOG.warn("Test initialization order");
60 new OdluxBundleLoaderImpl();
66 public int getNumberOfBundles() {
68 return this.bundles2.size();
73 public void addBundle(OdluxBundle bundle) {
74 LOG.debug("odlux bundle " + bundle.getBundleName() + " added");
75 this.bundles2.add(bundle);
81 public void removeBundle(OdluxBundle bundle) {
82 this.bundles2.remove(bundle);
83 LOG.debug("odlux bundle " + bundle.getBundleName() + " removed");
87 public List<String> getLoadedBundles(String myBundleName) {
88 List<String> list = new ArrayList<>();
89 for (OdluxBundle b : bundles2) {
90 list.add(b.getBundleName());
92 list.add(myBundleName);
96 private List<String> getBundleNames(String myBundleName) {
97 final List<String> names = new ArrayList<>();
98 for (OdluxBundle b : bundles2) {
99 names.add(b.getBundleName());
101 names.add(myBundleName);
105 public String getResourceContent(String fn, OdluxBundleResourceAccess indexBundle) {
106 String fileContent = null;
108 if (indexBundle.hasResource(fn)) {
109 fileContent = indexBundle.getResourceFileContent(fn, getBundleNames(indexBundle.getBundleName()));
111 LOG.debug("not found in framework res. try to find in applications");
112 final Iterator<OdluxBundle> it = bundles2.iterator();
113 while (it.hasNext()) {
114 OdluxBundle b = it.next();
115 if (b.hasResource(fn)) {
116 LOG.debug("found res in " + b.getBundleName());
117 fileContent = b.getResourceFileContent(fn);