diff options
author | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-21 12:00:42 +0000 |
---|---|---|
committer | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2008-11-21 12:00:42 +0000 |
commit | 6a9b9b7586fd7a377d57b5ce0117c664beebff25 (patch) | |
tree | 89b3ba1a641765113f5113501c3347511e58cfaf /branches/sca-java-1.x/modules/implementation-spring/src | |
parent | 985a434b60e0722ae583287e0cfecd359bbc517b (diff) |
Fixes for TUSCANY-2683 and TUSCANY-2685
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@719564 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/implementation-spring/src')
-rw-r--r-- | branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java index 34f46dacb9..214faf7198 100644 --- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java +++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java @@ -527,7 +527,7 @@ public class SpringXMLComponentTypeLoader { if (locationFile.isDirectory()) { try { - manifestFile = new File(locationFile, "META-INF"+ File.separator +"MANIFEST.MF"); + manifestFile = new File(locationFile, "META-INF"+ File.separator +"MANIFEST.MF"); if (manifestFile.exists()) { Manifest mf = new Manifest(new FileInputStream(manifestFile)); Attributes mainAttrs = mf.getMainAttributes(); @@ -548,11 +548,8 @@ public class SpringXMLComponentTypeLoader { } catch (IOException e) { throw new ContributionReadException("Error reading manifest " + manifestFile); } - } else { - if (locationFile.isFile() && locationFile.getName().indexOf(".jar") < 0) { - return new UrlResource(url); - } - else { + } else { + if (locationFile.isFile() && locationFile.getName().endsWith(".jar")) { try { JarFile jf = new JarFile(locationFile); JarEntry je; @@ -568,19 +565,46 @@ public class SpringXMLComponentTypeLoader { } } } - je = jf.getJarEntry("META-INF" + File.separator + "spring" - + File.separator + Constants.APPLICATION_CONTEXT); + je = jf.getJarEntry("META-INF" + "/" + "spring" + "/" + Constants.APPLICATION_CONTEXT); if (je != null) { return new UrlResource(new URL("jar:" + locationFile.toURI().toURL() + "!/" + Constants.APPLICATION_CONTEXT)); } } catch (IOException e) { // bad archive // TODO: create a more appropriate exception type - throw new ContributionReadException( - "SpringXMLLoader getApplicationContextResource: " + " IO exception reading context file.", - e); + throw new ContributionReadException("SpringXMLLoader getApplicationContextResource: " + + " IO exception reading context file.", e); } - } + } + else { + if (locationFile.getName().endsWith(".xml")) { + return new UrlResource(url); + } + else { + // Deal with the directory inside a jar file, in case the contribution itself is a JAR file. + try { + if (locationFile.getPath().indexOf(".jar") > 0) { + String jarEntry = url.getPath().substring(6, url.getPath().indexOf("!")); + JarFile jf = new JarFile(jarEntry); + JarEntry je = jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/")+2) + + "/" + "META-INF" + "/" + "MANIFEST.MF"); + if (je != null) { + Manifest mf = new Manifest(jf.getInputStream(je)); + Attributes mainAttrs = mf.getMainAttributes(); + String appCtxPath = mainAttrs.getValue("Spring-Context"); + if (appCtxPath != null) { + je = jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/")+2) + "/" + appCtxPath); + if (je != null) { + return new UrlResource(new URL("jar:" + url.getPath() + "/" + appCtxPath)); + } + } + } + } + } catch (IOException e) { + throw new ContributionReadException("Error reading manifest " + manifestFile); + } + } + } } throw new ContributionReadException("SpringXMLLoader getApplicationContextResource: " |