1 package org
.argeo
.slc
.osgi
;
4 import java
.io
.IOException
;
6 import org
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.argeo
.slc
.SlcException
;
9 import org
.argeo
.slc
.core
.execution
.FileExecutionResources
;
10 import org
.osgi
.framework
.BundleContext
;
11 import org
.springframework
.core
.io
.Resource
;
12 import org
.springframework
.osgi
.context
.BundleContextAware
;
13 import org
.springframework
.osgi
.io
.OsgiBundleResource
;
15 public class OsgiExecutionResources
extends FileExecutionResources
implements
17 private final static Log log
= LogFactory
18 .getLog(OsgiExecutionResources
.class);
20 private BundleContext bundleContext
;
23 protected File
fileFromResource(Resource resource
) {
24 File file
= super.fileFromResource(resource
);
28 if (!(resource
instanceof OsgiBundleResource
))
31 OsgiBundleResource osgiBundleResource
= (OsgiBundleResource
) resource
;
33 return osgiBundleResource
.getFile();
34 } catch (IOException e
) {
35 if (log
.isTraceEnabled())
36 log
.trace("Resource " + resource
37 + " is not available on the file system: " + e
);
40 // TODO: ability to access resources in other bundles
41 String location
= bundleContext
.getBundle().getLocation();
43 if (location
.startsWith("reference:file:"))
44 base
= location
.substring("reference:file:".length());
45 else if (location
.startsWith("initial@reference:file:")) {
46 // TODO: Equinox specific?
47 String relPath
= location
.substring("initial@reference:file:"
49 if (relPath
.startsWith("../"))// relative to the framework jar
50 relPath
= relPath
.substring("../".length());
51 String framework
= System
.getProperty("osgi.framework").substring(
53 int sepIndex
= framework
.lastIndexOf(File
.separatorChar
);
54 framework
= framework
.substring(0, sepIndex
);
55 base
= framework
+ '/' + relPath
;
60 String path
= base
+ '/' + osgiBundleResource
.getPathWithinContext();
62 file
= new File(path
).getCanonicalFile();
63 } catch (IOException e
) {
64 throw new SlcException("Cannot determine canonical path for "
67 if (log
.isDebugEnabled())
68 log
.debug("OSGi local resource: " + file
+ " from " + resource
);
72 public void setBundleContext(BundleContext bundleContext
) {
73 this.bundleContext
= bundleContext
;