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==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import java.io.BufferedReader;
23 import java.io.IOException;
24 import java.io.InputStreamReader;
28 * At startup of each karaf bundle, each UI module creates an instance of this class via blueprint. Initialize method
29 * gets called at loading of bundle.
32 public class OdluxBundle {
34 final static Logger LOG = LoggerFactory.getLogger(OdluxBundle.class);
35 private static final String LR = "\n";
37 private String bundleName;
38 private OdluxBundleLoader loader;
44 public int getIndex() {
49 * @param index the index to set
51 public void setIndex(int index) {
55 public OdluxBundleLoader getLoader() {
59 public void setLoader(OdluxBundleLoader loader) {
63 public void setBundleName(String bundleName) {
64 this.bundleName = bundleName;
67 public String getBundleName() {
68 return this.bundleName;
71 public OdluxBundle() {}
73 protected OdluxBundle(final OdluxBundleLoader loader, final String bundleName) {
75 this.bundleName = bundleName;
78 public void initialize() {
80 LOG.info("Registering resources");
81 if (this.loader != null) {
82 if (this.bundleName == null)
83 LOG.error("bundle name is missing. Bundle can not be registered with odlux");
85 LOG.info("Registering bunlde {}", this.bundleName);
86 this.loader.addBundle(this);
92 LOG.info("Unregistering resources");
94 if (this.loader != null) {
95 this.loader.removeBundle(this);
99 public boolean hasResource(String filename) {
100 return this.getResource(filename) != null;
103 public String getResourceFileContent(String filename) {
104 return this.loadFileContent(this.getResource(filename));
107 protected URL getResource(String filename) {
108 return ClassLoaderUtilExt.getResource(filename, this.getClass());
111 protected String loadFileContent(final URL url) {
114 LOG.debug("try to load res " + url.toString());
115 StringBuilder sb = new StringBuilder();
116 BufferedReader in = null;
118 in = new BufferedReader(new InputStreamReader(url.openStream()));
121 while ((inputLine = in.readLine()) != null) {
122 sb.append(inputLine + LR);
124 } catch (IOException e) {
125 LOG.warn("could not load resfile " + url.toString() + ": " + e.getMessage());
131 } catch (IOException e) {
137 return sb.toString();