Author: ramkumar
Date: Wed Jan 28 10:45:52 2009
New Revision: 738433

URL: http://svn.apache.org/viewvc?rev=738433&view=rev
Log:
Fixes for TUSCANY-2771

Modified:
    
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java
    
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
    
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml

Modified: 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java?rev=738433&r1=738432&r2=738433&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java
 Wed Jan 28 10:45:52 2009
@@ -50,12 +50,12 @@
         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

Modified: 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java?rev=738433&r1=738432&r2=738433&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java
 Wed Jan 28 10:45:52 2009
@@ -139,7 +139,7 @@
             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 @@
     }    
     
     /**
-     * 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 @@
                             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 @@
                         } 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 @@
                             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 @@
                                     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

Modified: 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml
URL: 
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml?rev=738433&r1=738432&r2=738433&view=diff
==============================================================================
--- 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml
 (original)
+++ 
tuscany/branches/sca-java-1.x/modules/implementation-spring/src/test/resources/spring/META-INF/spring/SpringSCAProperty-context.xml
 Wed Jan 28 10:45:52 2009
@@ -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


Reply via email to