diff options
Diffstat (limited to 'java/sca/modules/implementation-spring/src/main')
3 files changed, 21 insertions, 20 deletions
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java index 3e12785353..b2a3f10483 100644 --- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java +++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.implementation.spring; import java.util.Hashtable;
import java.util.List;
+import java.net.URL;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.ComponentType;
@@ -31,19 +32,19 @@ import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.impl.ImplementationImpl;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.springframework.core.io.Resource;
+import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor;
/**
* Represents a Spring implementation.
*
* @version $Rev: 511195 $ $Date: 2007-02-24 02:29:46 +0000 (Sat, 24 Feb 2007) $
*/
-public class SpringImplementation extends ImplementationImpl implements Implementation, Extensible {
+public class SpringImplementation extends ImplementationImpl implements Implementation, ComponentPreProcessor, Extensible {
// The location attribute which points to the Spring application-context XML file
private String location;
// The application-context file as a Spring Resource
- private Resource resource;
+ private URL resource;
private ComponentType componentType;
// Mapping of Services to Beans
private Hashtable<String, SpringBeanElement> serviceMap;
@@ -75,11 +76,11 @@ public class SpringImplementation extends ImplementationImpl implements Implemen return;
}
- public void setResource(Resource resource) {
+ public void setResource(URL resource) {
this.resource = resource;
}
- public Resource getResource() {
+ public URL getResource() {
return resource;
}
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java index 2dfcd117ee..3fac12ac43 100644 --- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java +++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java @@ -65,8 +65,6 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.UrlResource;
/**
* Introspects a Spring XML application-context configuration file to create <implementation-spring../>
@@ -133,7 +131,7 @@ public class SpringXMLComponentTypeLoader { List<SpringSCAReferenceElement> references = new ArrayList<SpringSCAReferenceElement>();
List<SpringSCAPropertyElement> scaproperties = new ArrayList<SpringSCAPropertyElement>();
- Resource resource;
+ URL resource;
contextPath = implementation.getLocation();
@@ -144,10 +142,10 @@ public class SpringXMLComponentTypeLoader { resource = getApplicationContextResource(contextPath, cl);
implementation.setResource(resource);
// The URI is used to uniquely identify the Implementation
- implementation.setURI(resource.getURL().toString());
+ implementation.setURI(resource.toString());
// FIXME - need a better way to handle the XMLInputFactory than allocating a new one every time
XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
- reader = xmlFactory.createXMLStreamReader(resource.getInputStream());
+ reader = xmlFactory.createXMLStreamReader(new FileInputStream(resource.toString()));
// System.out.println("Spring TypeLoader - starting to read context file");
readContextDefinition(reader, beans, services, references, scaproperties);
@@ -175,10 +173,11 @@ public class SpringXMLComponentTypeLoader { try {
// FIXME - is the ContextClassLoader the right place to start the search?
cl = Thread.currentThread().getContextClassLoader();
- Resource resource = getApplicationContextResource(location, cl);
+ URL resource = getApplicationContextResource(location, cl);
// FIXME - need a better way to handle the XMLInputFactory than allocating a new one every time
XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
- XMLStreamReader reader = xmlFactory.createXMLStreamReader(resource.getInputStream());
+ XMLStreamReader reader =
+ xmlFactory.createXMLStreamReader(new FileInputStream(resource.toString()));
return reader;
} catch (IOException e) {
throw new ContributionReadException(e);
@@ -596,7 +595,7 @@ public class SpringXMLComponentTypeLoader { * @param locationAttr - the location attribute from the <implementation.spring../> element
* @param cl - the ClassLoader for the Spring implementation
*/
- protected Resource getApplicationContextResource(String locationAttr, ClassLoader cl)
+ protected URL getApplicationContextResource(String locationAttr, ClassLoader cl)
throws ContributionReadException {
File manifestFile = null;
File appXmlFile;
@@ -622,7 +621,7 @@ public class SpringXMLComponentTypeLoader { if (appCtxPath != null) {
appXmlFile = new File(locationFile, appCtxPath);
if (appXmlFile.exists()) {
- return new UrlResource(appXmlFile.toURL());
+ return appXmlFile.toURL();
}
}
}
@@ -630,7 +629,7 @@ public class SpringXMLComponentTypeLoader { appXmlFile = new File(locationFile, "META-INF" + File.separator + "spring"
+ File.separator + SpringImplementationConstants.APPLICATION_CONTEXT);
if (appXmlFile.exists()) {
- return new UrlResource(appXmlFile.toURL());
+ return appXmlFile.toURL();
}
} catch (IOException e) {
throw new ContributionReadException("Error reading manifest " + manifestFile);
@@ -648,13 +647,13 @@ public class SpringXMLComponentTypeLoader { je = jf.getJarEntry(appCtxPath);
if (je != null) {
// TODO return a Spring specific Resource type for jars
- return new UrlResource(new URL("jar:" + locationFile.toURI().toURL() + "!/" + appCtxPath));
+ return new URL("jar:" + locationFile.toURI().toURL() + "!/" + appCtxPath);
}
}
}
je = jf.getJarEntry("META-INF" + "/" + "spring" + "/" + SpringImplementationConstants.APPLICATION_CONTEXT);
if (je != null) {
- return new UrlResource(new URL("jar:" + locationFile.toURI().toURL() + "!/" + SpringImplementationConstants.APPLICATION_CONTEXT));
+ return new URL("jar:" + locationFile.toURI().toURL() + "!/" + SpringImplementationConstants.APPLICATION_CONTEXT);
}
} catch (IOException e) {
// bad archive
@@ -665,7 +664,7 @@ public class SpringXMLComponentTypeLoader { }
else {
if (locationFile.getName().endsWith(".xml")) {
- return new UrlResource(url);
+ return url;
}
else {
// Deal with the directory inside a jar file, in case the contribution itself is a JAR file.
@@ -682,7 +681,7 @@ public class SpringXMLComponentTypeLoader { 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));
+ return new URL("jar:" + url.getPath() + "/" + appCtxPath);
}
}
}
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java index 45e00a9c93..62682be532 100644 --- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java +++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java @@ -45,6 +45,7 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
+import org.springframework.core.io.UrlResource;
/**
* A provider class for runtime Spring implementation instances
@@ -79,7 +80,7 @@ public class SpringImplementationProvider implements ImplementationProvider { new SCAParentApplicationContext(component, implementation, proxyService, propertyValueObjectFactory);
//springContext = new SCAApplicationContext(scaParentContext, implementation.getResource());
- XmlBeanFactory beanFactory = new XmlBeanFactory(implementation.getResource());
+ XmlBeanFactory beanFactory = new XmlBeanFactory(new UrlResource(implementation.getResource()));
springContext = createApplicationContext(beanFactory, scaParentContext);
} // end constructor
|