2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.osgi
.deploy
;
18 import org
.argeo
.slc
.core
.deploy
.DefaultResourceSet
;
19 import org
.osgi
.framework
.Bundle
;
20 import org
.osgi
.framework
.BundleContext
;
21 import org
.springframework
.core
.io
.ResourceLoader
;
22 import org
.springframework
.osgi
.context
.BundleContextAware
;
23 import org
.springframework
.osgi
.io
.OsgiBundleResourceLoader
;
24 import org
.springframework
.osgi
.io
.OsgiBundleResourcePatternResolver
;
25 import org
.springframework
.osgi
.util
.OsgiBundleUtils
;
28 * Retrieves ressources from an OSGi bundle either the active one or another one
29 * referenced by its symbolic name.
31 public class OsgiResourceSet
extends DefaultResourceSet
implements
33 private BundleContext bundleContext
;
34 private Bundle bundle
= null;
35 private String bundleSymbolicName
= null;
37 private OsgiBundleResourceLoader osgiBundleResourceLoader
= null;
40 public void afterPropertiesSet() throws Exception
{
41 osgiBundleResourceLoader
= new OsgiBundleResourceLoader(getBundle());
42 if (getResourcePatternResolver() == null)
43 setResourcePatternResolver(new OsgiBundleResourcePatternResolver(
44 osgiBundleResourceLoader
));
45 super.afterPropertiesSet();
48 public Bundle
getBundle() {
51 else if (bundleSymbolicName
!= null)// do not cache
52 return OsgiBundleUtils
.findBundleBySymbolicName(bundleContext
,
56 return bundleContext
.getBundle();
59 public void setBundleContext(BundleContext bundleContext
) {
60 this.bundleContext
= bundleContext
;
64 public ResourceLoader
getResourceLoaderToUse() {
65 return osgiBundleResourceLoader
;
68 public void setBundle(Bundle bundle
) {
72 public void setBundleSymbolicName(String bundleSymbolicName
) {
73 this.bundleSymbolicName
= bundleSymbolicName
;