diff options
author | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-28 10:45:52 +0000 |
---|---|---|
committer | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-28 10:45:52 +0000 |
commit | 107201a98e9cd4ef8ebf7e785d5d3d8e7792d187 (patch) | |
tree | 2c15295ccdbc2698e339946697dd3f42949e2697 /branches/sca-java-1.x/modules | |
parent | ab830bb318a95f46748f45afcc5706c15f1f9f3c (diff) |
Fixes for TUSCANY-2771
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@738433 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules')
3 files changed, 68 insertions, 25 deletions
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java index 39e1286f32..c60fdb86a9 100644 --- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java +++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java @@ -50,12 +50,12 @@ public class SpringPropertyElement { this.ref = ref; } - public List<String> getProperties() { - return values; + public List<String> getValues() { + return this.values; } - public void addProperty(String value) { - values.add(value); + public void addValue(String value) { + this.values.add(value); } } // end class SpringPropertyElement 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 214faf7198..9738cf22ef 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 @@ -139,7 +139,7 @@ public class SpringXMLComponentTypeLoader { reader = xmlFactory.createXMLStreamReader(resource.getInputStream()); // System.out.println("Spring TypeLoader - starting to read context file"); - readBeanDefinition(reader, beans, services, references, scaproperties); + readContextDefinition(reader, beans, services, references, scaproperties); } catch (IOException e) { throw new ContributionReadException(e); @@ -177,18 +177,16 @@ public class SpringXMLComponentTypeLoader { } /** - * Method which reads the bean definitions from Spring application-context.xml file and identifies - * the defined beans, properties, services and references + * Method which reads the spring context definitions from Spring application-context.xml + * file and identifies the defined beans, properties, services and references */ - private void readBeanDefinition(XMLStreamReader reader, + private void readContextDefinition(XMLStreamReader reader, List<SpringBeanElement> beans, List<SpringSCAServiceElement> services, List<SpringSCAReferenceElement> references, List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException { SpringBeanElement bean = null; - SpringPropertyElement property = null; - SpringConstructorArgElement constructorArg = null; try { boolean completed = false; @@ -202,8 +200,8 @@ public class SpringXMLComponentTypeLoader { String location = reader.getAttributeValue(null, "resource"); if (location != null) { XMLStreamReader ireader = getApplicationContextReader(location); - // Read the bean definition for the identified imported resource - readBeanDefinition(ireader, beans, services, references, scaproperties); + // Read the context definition for the identified imported resource + readContextDefinition(ireader, beans, services, references, scaproperties); } } else if (Constants.SERVICE_ELEMENT.equals(qname)) { SpringSCAServiceElement service = @@ -223,14 +221,59 @@ public class SpringXMLComponentTypeLoader { } else if (Constants.BEAN_ELEMENT.equals(qname)) { bean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader .getAttributeValue(null, "class")); - //beans.add(bean); + beans.add(bean); + // Read the <bean> element and its child elements + readBeanDefinition(reader, bean, beans, services, references, scaproperties); + } // end if*/ + break; + case END_ELEMENT: + if (Constants.BEANS_ELEMENT.equals(reader.getName())) { + //System.out.println("Spring TypeLoader - finished read of context file"); + completed = true; + break; + } // end if + } // end switch + } // end while + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + } + + + /** + * 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, + SpringBeanElement bean, + List<SpringBeanElement> beans, + List<SpringSCAServiceElement> services, + List<SpringSCAReferenceElement> references, + List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException { + + SpringBeanElement innerbean = null; + SpringPropertyElement property = null; + SpringConstructorArgElement constructorArg = null; + + try { + boolean completed = false; + while (!completed) { + switch (reader.next()) { + case START_ELEMENT: + QName qname = reader.getName(); + if (Constants.BEAN_ELEMENT.equals(qname)) { + innerbean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader + .getAttributeValue(null, "class")); + beans.add(innerbean); + readBeanDefinition(reader, innerbean, beans, services, references, scaproperties); } else if (Constants.PROPERTY_ELEMENT.equals(qname)) { property = new SpringPropertyElement(reader.getAttributeValue(null, "name"), reader .getAttributeValue(null, "ref")); - //bean.addProperty(property); + bean.addProperty(property); } else if (Constants.CONSTRUCTORARG_ELEMENT.equals(qname)) { constructorArg = new SpringConstructorArgElement(reader.getAttributeValue(null, "ref"), - reader.getAttributeValue(null, "type")); + reader.getAttributeValue(null, "type")); + bean.addCustructorArgs(constructorArg); } else if (Constants.REF_ELEMENT.equals(qname)) { String ref = reader.getAttributeValue(null, "bean"); // Check if the parent element is a property @@ -239,6 +282,8 @@ public class SpringXMLComponentTypeLoader { if (constructorArg != null) constructorArg.setRef(ref); } else if (Constants.VALUE_ELEMENT.equals(qname)) { String value = reader.getElementText(); + // Check if the parent element is a property + if (property != null) property.addValue(value); // Check if the parent element is a constructor-arg if (constructorArg != null) { constructorArg.addValue(value); @@ -247,26 +292,20 @@ public class SpringXMLComponentTypeLoader { if ((bean.getClassName().indexOf(".ClassPathXmlApplicationContext") != -1) || (bean.getClassName().indexOf(".FileSystemXmlApplicationContext") != -1)) { XMLStreamReader creader = getApplicationContextReader(value); - // Read the bean definition for the constructor-arg resources - readBeanDefinition(creader, beans, services, references, scaproperties); + // Read the context definition for the constructor-arg resources + readContextDefinition(creader, beans, services, references, scaproperties); } } } } // end if break; case END_ELEMENT: - if (Constants.BEANS_ELEMENT.equals(reader.getName())) { - //System.out.println("Spring TypeLoader - finished read of context file"); + if (Constants.BEAN_ELEMENT.equals(reader.getName())) { completed = true; break; - } else if (Constants.BEAN_ELEMENT.equals(reader.getName())) { - beans.add(bean); - bean = null; } else if (Constants.PROPERTY_ELEMENT.equals(reader.getName())) { - bean.addProperty(property); property = null; } else if (Constants.CONSTRUCTORARG_ELEMENT.equals(reader.getName())) { - bean.addCustructorArgs(constructorArg); constructorArg = null; } // end if } // end switch diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml b/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml index f1ee21686d..6950f3e26a 100644 --- a/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml +++ b/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml @@ -25,10 +25,14 @@ 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.TestSCAPropertyBean" lazy-init="true"> + <bean id="testBean1" class="org.apache.tuscany.sca.implementation.spring.itests.mock.TestSCAPropertyBean" lazy-init="true"> <property name="hello" ref="TestProperty"/> </bean> + <bean id="testBean2" class="org.apache.tuscany.sca.implementation.spring.itests.mock.TestSCAPropertyBean" lazy-init="true"> + <property name="hello"><ref bean="TestProperty"/></property> + </bean> + <sca:property id="foo" name="TestProperty" type="java.lang.String"/> </beans>
\ No newline at end of file |