08d2436666621aec20b4bdf3f81917ae6c32226a
[ccsdk/features.git] /
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
9  * 
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * 
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles;
19
20 import java.io.IOException;
21 import java.net.URL;
22 import java.util.Iterator;
23 import org.osgi.framework.Bundle;
24 import org.osgi.framework.FrameworkUtil;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import com.opensymphony.xwork2.util.ClassLoaderUtil;
28
29 public class ClassLoaderUtilExt {
30
31     final static Logger LOG = LoggerFactory.getLogger(ClassLoaderUtilExt.class);
32
33     public static URL getResource(String resourceName, Class callingClass) {
34
35         Iterator<URL> urls = null;
36         URL url = null;
37         try {
38             urls = getResources(resourceName, callingClass, true);
39         } catch (IOException e) {
40             // TODO Auto-generated catch block
41             e.printStackTrace();
42         }
43         if (urls != null) {
44             while (urls.hasNext()) {
45                 URL u = urls.next();
46                 LOG.debug("found " + u.toString());
47                 url = u;
48                 break;
49             }
50         }
51         if (url == null) {
52             LOG.debug("res currently not found. try to find with bundle");
53             Bundle b = FrameworkUtil.getBundle(callingClass);
54             url = b.getEntry(resourceName);
55         }
56         return url;
57     }
58
59     public static Iterator<URL> getResources(String resourceName, Class callingClass, boolean aggregate)
60             throws IOException {
61         return ClassLoaderUtil.getResources(resourceName, callingClass, aggregate);
62     }
63
64 }