diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-10 16:25:59 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-10 16:25:59 +0000 |
commit | a3e32f58df8108d7ddb4728e13d3a4829b4a698d (patch) | |
tree | b9979e8286494c3de11e3f0836faec0fc2a311e1 /java/sca/modules/implementation-spring | |
parent | 8473ddb216243b3c4e1d653263f22ce2ed0818be (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')
10 files changed, 273 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 diff --git a/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImportHelloWorldTestCase.java b/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImportHelloWorldTestCase.java new file mode 100644 index 0000000000..bfe3d64cf3 --- /dev/null +++ b/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImportHelloWorldTestCase.java @@ -0,0 +1,32 @@ +/* + * 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.itests.helloworld; + +/** + * A basic test case of: + * 1) A composite containing a component with a Spring implementation + * 2) The composite has a component with a Java POJO implementation which uses the + * Spring implementation to satisfy a reference + * + * @version $Rev$ $Date$ + */ +public class SpringImportHelloWorldTestCase extends AbstractHelloWorldTestCase { + // super class does it all getting composite based on this class name +} diff --git a/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringHelloWorld-Imported-context.xml b/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringHelloWorld-Imported-context.xml new file mode 100644 index 0000000000..18ce21805c --- /dev/null +++ b/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringHelloWorld-Imported-context.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<!-- Application context for the SpringHelloWorld testcase --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd"> + + <bean id="testBean" class="org.apache.tuscany.sca.implementation.spring.itests.mock.TestHelloWorldBean" lazy-init="true"> + </bean> + +</beans>
\ No newline at end of file diff --git a/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImportHelloWorld-context.xml b/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImportHelloWorld-context.xml new file mode 100644 index 0000000000..8e18a56cca --- /dev/null +++ b/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImportHelloWorld-context.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd"> + + <import resource="SpringHelloWorld-Imported-context.xml"/> + +</beans> diff --git a/java/sca/modules/implementation-spring/src/test/resources/SpringHelloWorld-Imported-context.xml b/java/sca/modules/implementation-spring/src/test/resources/SpringHelloWorld-Imported-context.xml new file mode 100644 index 0000000000..18ce21805c --- /dev/null +++ b/java/sca/modules/implementation-spring/src/test/resources/SpringHelloWorld-Imported-context.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<!-- Application context for the SpringHelloWorld testcase --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:sca="http://www.springframework.org/schema/sca" + xsi:schemaLocation=" +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd"> + + <bean id="testBean" class="org.apache.tuscany.sca.implementation.spring.itests.mock.TestHelloWorldBean" lazy-init="true"> + </bean> + +</beans>
\ No newline at end of file diff --git a/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImportHelloWorld.composite b/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImportHelloWorld.composite new file mode 100644 index 0000000000..95dd9131eb --- /dev/null +++ b/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImportHelloWorld.composite @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + name="SpringHelloWorld"> + + <component name="ClientComponent"> + <implementation.java class="org.apache.tuscany.sca.implementation.spring.itests.helloworld.HelloWorldProxy"/> + <reference name="delegate" target="HelloWorldComponent"/> + </component> + + <component name="HelloWorldComponent"> + <implementation.spring location="META-INF/sca/SpringImportHelloWorld-context.xml"/> + </component> + +</composite> |