summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-spring/src/main
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-09-10 16:25:59 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-09-10 16:25:59 +0000
commita3e32f58df8108d7ddb4728e13d3a4829b4a698d (patch)
treeb9979e8286494c3de11e3f0836faec0fc2a311e1 /java/sca/modules/implementation-spring/src/main
parent8473ddb216243b3c4e1d653263f22ce2ed0818be (diff)
TUSCANY-2585- support includes in spring contexts in component implementations
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@693884 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-spring/src/main')
-rw-r--r--java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java8
-rw-r--r--java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java.orig44
-rw-r--r--java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAReferenceElement.java8
-rw-r--r--java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAServiceElement.java12
-rw-r--r--java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java64
5 files changed, 118 insertions, 18 deletions
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java
index b3f0b8bbf9..2f37ab6504 100644
--- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java
+++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java
@@ -32,10 +32,18 @@ public class SpringSCAPropertyElement {
this.name = name;
this.type = type;
}
+
+ public void setName(String name) {
+ this.name = name;
+ }
public String getName() {
return name;
}
+
+ public void setType(String type) {
+ this.type = type;
+ }
public String getType() {
return type;
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java.orig b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java.orig
new file mode 100644
index 0000000000..19874ad35d
--- /dev/null
+++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java.orig
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.spring.xml;
+
+/**
+ * Represents an <sca:property> element in a Spring application-context
+ * - this has name and type attributes
+ * @version $Rev: 511195 $ $Date: 2007-02-24 02:29:46 +0000 (Sat, 24 Feb 2007) $
+ */
+public class SpringSCAPropertyElement {
+
+ private String name;
+ private String type;
+
+ public SpringSCAPropertyElement(String name, String type) {
+ this.name = name;
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+} // end class SpringPropertyElement
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAReferenceElement.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAReferenceElement.java
index 9e55f30b46..b3f45415fd 100644
--- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAReferenceElement.java
+++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAReferenceElement.java
@@ -34,10 +34,18 @@ public class SpringSCAReferenceElement {
this.name = name;
this.type = type;
}
+
+ public void setName(String name) {
+ this.name = name;
+ }
public String getName() {
return name;
}
+
+ public void setType(String type) {
+ this.type = type;
+ }
public String getType() {
return type;
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAServiceElement.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAServiceElement.java
index 85b29e5684..2eb5686270 100644
--- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAServiceElement.java
+++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAServiceElement.java
@@ -36,14 +36,26 @@ public class SpringSCAServiceElement {
this.type = type;
this.target = target;
}
+
+ public void setName(String name) {
+ this.name = name;
+ }
public String getName() {
return name;
}
+
+ public void setType(String type) {
+ this.type = type;
+ }
public String getType() {
return type;
}
+
+ public void setTarget(String target) {
+ this.target = target;
+ }
public String getTarget() {
return target;
diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
index 50c7bfa9f3..f8cc9ead80 100644
--- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
+++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
@@ -42,9 +42,11 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.ComponentType;
import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.xml.Constants;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
@@ -71,6 +73,7 @@ public class SpringXMLComponentTypeLoader {
private static final QName SERVICE_ELEMENT = new QName(SCA_NS, "service");
private static final QName REFERENCE_ELEMENT = new QName(SCA_NS, "reference");
private static final QName SCAPROPERTY_ELEMENT = new QName(SCA_NS, "property");
+ private static final QName IMPORT_ELEMENT = new QName(SPRING_NS, "import");
private static final QName BEANS_ELEMENT = new QName(SPRING_NS, "beans");
private static final QName BEAN_ELEMENT = new QName(SPRING_NS, "bean");
private static final QName PROPERTY_ELEMENT = new QName(SPRING_NS, "property");
@@ -129,8 +132,7 @@ public class SpringXMLComponentTypeLoader {
List<SpringBeanElement> beans = new ArrayList<SpringBeanElement>();
List<SpringSCAServiceElement> services = new ArrayList<SpringSCAServiceElement>();
List<SpringSCAReferenceElement> references = new ArrayList<SpringSCAReferenceElement>();
- List<SpringSCAPropertyElement> scaproperties = new ArrayList<SpringSCAPropertyElement>();
- SpringBeanElement bean = null;
+ List<SpringSCAPropertyElement> scaproperties = new ArrayList<SpringSCAPropertyElement>();
Resource resource;
@@ -148,15 +150,53 @@ public class SpringXMLComponentTypeLoader {
XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
reader = xmlFactory.createXMLStreamReader(resource.getInputStream());
- // System.out.println("Spring TypeLoader - starting to read context file");
+ // System.out.println("Spring TypeLoader - starting to read context file");
+ readBeanDefinition(reader, beans, services, references, scaproperties);
+
+ } catch (IOException e) {
+ throw new ContributionReadException(e);
+ } catch (XMLStreamException e) {
+ throw new ContributionReadException(e);
+ }
+ /* At this point, the complete application-context.xml file has been read and its contents */
+ /* stored in the lists of beans, services, references. These are now used to generate */
+ /* the implied componentType for the application context */
+ generateComponentType(implementation, beans, services, references, scaproperties);
+
+ return;
+ } // end method loadFromXML
+
+
+ /**
+ * Method which reads the bean definitions from Spring application-context.xml file and identifies
+ * the defined beans, properties, services and references
+ */
+ private void readBeanDefinition(XMLStreamReader reader,
+ List<SpringBeanElement> beans,
+ List<SpringSCAServiceElement> services,
+ List<SpringSCAReferenceElement> references,
+ List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException {
+
+ SpringBeanElement bean = null;
+
+ try {
boolean completed = false;
while (!completed) {
switch (reader.next()) {
case START_ELEMENT:
QName qname = reader.getName();
//System.out.println("Spring TypeLoader - found element with name: " + qname.toString());
- if (SERVICE_ELEMENT.equals(qname)) {
+ if (IMPORT_ELEMENT.equals(qname)) {
+ String location = reader.getAttributeValue(null, "resource");
+ // Create an input stream for the imported resource file
+ cl = Thread.currentThread().getContextClassLoader();
+ Resource resource = getApplicationContextResource(location, cl);
+ XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
+ XMLStreamReader ireader = xmlFactory.createXMLStreamReader(resource.getInputStream());
+ // Call this method to read the bean definition for the imported resource
+ readBeanDefinition(ireader, beans, services, references, scaproperties);
+ } else if (SERVICE_ELEMENT.equals(qname)) {
SpringSCAServiceElement service =
new SpringSCAServiceElement(reader.getAttributeValue(null, "name"), reader
.getAttributeValue(null, "type"), reader.getAttributeValue(null, "target"));
@@ -172,11 +212,7 @@ public class SpringXMLComponentTypeLoader {
.getAttributeValue(null, "type"));
scaproperties.add(scaproperty);
} else if (BEAN_ELEMENT.equals(qname)) {
- // TODO FIX THIS !!
- //FIXME count is never used
- //int count = reader.getAttributeCount();
- bean =
- new SpringBeanElement(reader.getAttributeValue(null, "id"), reader
+ bean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader
.getAttributeValue(null, "class"));
beans.add(bean);
} else if (PROPERTY_ELEMENT.equals(qname)) {
@@ -194,20 +230,12 @@ public class SpringXMLComponentTypeLoader {
} // end if
} // end switch
} // end while
-
} catch (IOException e) {
throw new ContributionReadException(e);
} catch (XMLStreamException e) {
throw new ContributionReadException(e);
}
-
- /* At this point, the complete application-context.xml file has been read and its contents */
- /* stored in the lists of beans, services, references. These are now used to generate */
- /* the implied componentType for the application context */
- generateComponentType(implementation, beans, services, references, scaproperties);
-
- return;
- } // end method loadFromXML
+ }
/**
* Generates the Spring implementation component type from the configuration contained in the