tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edward...@apache.org
Subject svn commit: r546086 - in /incubator/tuscany/java/sca/modules/implementation-spring/src: main/java/org/apache/tuscany/implementation/spring/xml/ test/java/org/apache/tuscany/implementation/spring/itests/helloworld/ test/resources/META-INF/sca/ test/reso...
Date Mon, 11 Jun 2007 11:05:46 GMT
Author: edwardsmj
Date: Mon Jun 11 04:05:45 2007
New Revision: 546086

URL: http://svn.apache.org/viewvc?view=rev&rev=546086
Log:
Spring implementation supports implicit references within Spring application context

Added:
    incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java
  (with props)
    incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml
  (with props)
    incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReference.composite
Modified:
    incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringXMLComponentTypeLoader.java
    incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/HelloWorld.java
    incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitReferenceTestCase.java

Modified: incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringXMLComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringXMLComponentTypeLoader.java?view=diff&rev=546086&r1=546085&r2=546086
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringXMLComponentTypeLoader.java
(original)
+++ incubator/tuscany/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringXMLComponentTypeLoader.java
Mon Jun 11 04:05:45 2007
@@ -277,23 +277,50 @@
 	    			}
 	    		} // end while
 	    	} // end if
-	    	// Now check to see if there are any more references
+	    	// Now check to see if there are any more references from beans that are not satisfied
 	    	itb = beans.iterator();
 	    	while( itb.hasNext() ) {
 	    		SpringBeanElement beanElement = itb.next();
+	    		boolean unresolvedProperties = false;
 	    		if( !beanElement.getProperties().isEmpty() ) {
+	    			// Scan through the properties
 	    			Iterator<SpringPropertyElement> itp = beanElement.getProperties().iterator();
 	    			while( itp.hasNext() ) {
 	    				SpringPropertyElement propertyElement = itp.next();
 	    				if( propertyRefUnresolved( propertyElement.getRef(), beans, references ) ) {
 	    					// This means an unresolved reference from the spring bean...
-	    					// TODO
+	    					unresolvedProperties = true;
 	    				} // end if
 	    			} // end while 
+	    			// If there are unresolved properties, then find which ones are references
+	    			if( unresolvedProperties ) {
+		    			Class<?> beanClass = cl.loadClass( beanElement.getClassName() );
+		    			// Introspect the bean 
+		    			ComponentType beanComponentType = assemblyFactory.createComponentType();
+		    			beanIntrospector.introspectBean( beanClass, beanComponentType );
+		    			// Get the references by this Spring Bean and add the unresolved ones to
+		    			// the component type of the Spring Assembly
+		    			List<Reference> beanReferences = beanComponentType.getReferences();
+		    			itp = beanElement.getProperties().iterator();
+		    			while( itp.hasNext() ) {
+		    				SpringPropertyElement propertyElement = itp.next();
+		    				if( propertyRefUnresolved( propertyElement.getRef(), beans, references ) ) {
+		    					// This means an unresolved reference from the spring bean...add it to
+		    					// the references for the Spring application context
+		    					for ( Reference reference : beanReferences ) {
+		    						if( propertyElement.getName().equals(reference.getName()) ) {
+		    							// The name of the reference in this case is the string in
+		    							// the @ref attribute of the Spring property element, NOT the
+		    							// name of the field in the Spring bean....
+		    							reference.setName(propertyElement.getRef());
+		    							componentType.getReferences().add( reference );
+		    						} // end if
+		    					} // end for
+		    				} // end if
+		    			} // end while 
+	    			} // end if
 	    		} // end if
 	    		
-	    		//Reference theReference = createReference( interfaze, referenceElement.getName()
);
-	    		//componentType.getReferences().add( theReference );
 	    	} // end while
 		
     	} catch ( ClassNotFoundException e ) {
@@ -335,7 +362,7 @@
     				break;
     			} // end if
     		} // end while
-	    	// Scan over the references looking for a match
+	    	// Scan over the SCA reference elements looking for a match
     		if( unresolved ) {
     			Iterator<SpringSCAReferenceElement> itr = references.iterator();
     			while( itr.hasNext() ) {
@@ -346,6 +373,10 @@
     				} // end if
     			} // end while
     		} // end if
+    	} else {
+    		// In the case where ref = null, the property is not going to be a reference of any
+    		// kind and can be ignored
+    		unresolved = false;
     	} // end if
     	
     	return unresolved;

Modified: incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/HelloWorld.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/HelloWorld.java?view=diff&rev=546086&r1=546085&r2=546086
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/HelloWorld.java
(original)
+++ incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/HelloWorld.java
Mon Jun 11 04:05:45 2007
@@ -19,12 +19,15 @@
 
 package org.apache.tuscany.implementation.spring.itests.helloworld;
 
+import org.osoa.sca.annotations.Remotable;
+
 /**
  * Interface for the "hello world" service - predictably simple with a single operation
  * "sayHello"
  * @author MikeEdwards
  *
  */
+@Remotable
 public interface HelloWorld {
     
     public String sayHello(String s);

Modified: incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitReferenceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitReferenceTestCase.java?view=diff&rev=546086&r1=546085&r2=546086
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitReferenceTestCase.java
(original)
+++ incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitReferenceTestCase.java
Mon Jun 11 04:05:45 2007
@@ -20,7 +20,12 @@
 package org.apache.tuscany.implementation.spring.itests.helloworld;
 
 /**
- * A test case of:
+ * A test case designed to test the implementation of References from a Spring application
+ * context, where the references are explicit, through the presence of an sca:reference
+ * element within the Spring application context
+ * 
+ * The artifacts involved in this test are:
+ * 
  * 1) A composite containing a component with a Spring implementation which makes
  * a reference to a second component
  * 2) The composite has a component with a Java POJO implementation which satisfies the reference

Added: incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java?view=auto&rev=546086
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java
(added)
+++ incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java
Mon Jun 11 04:05:45 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.implementation.spring.itests.helloworld;
+
+/**
+ * A test case designed to test the implementation of References from a Spring application
+ * context, where the references are implicit, through the presence of Bean properties with
a 
+ * ref attribute which is not satisfied by a Bean within the application context.
+ * 
+ * The artifacts involved in this test are:
+ * 
+ * 1) A composite containing a component with a Spring implementation which makes
+ * a reference to a second component
+ * 2) The composite has a component with a Java POJO implementation which satisfies the reference
+ * 3) The <implementation.spring.../> element references an application context that
+ * does not use an explicit sca:reference element to identify the reference made by the 
+ * Spring application, but relies on an unsatisfied Bean property with a ref attribute.
+ * 
+ * @author MikeEdwards
+ */
+public class SpringImplicitReferenceTestCase extends AbstractHelloWorldTestCase {
+    // super class does it all getting composite based on this class name
+}
+
+

Propchange: incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml?view=auto&rev=546086
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml
(added)
+++ incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml
Mon Jun 11 04:05:45 2007
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.springframework.org/schema/sca/spring-sca.xsd">
+
+    <bean id="testBean" class="org.apache.tuscany.implementation.spring.itests.mock.TestReferenceBean">
+        <!-- Here is the implicit reference - a property with a ref not satisifed within
the
+         * Spring application context.
+         -->
+        <property name="bean" ref="testReference"/>
+    </bean>
+
+</beans>

Propchange: incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReference.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReference.composite?view=auto&rev=546086
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReference.composite
(added)
+++ incubator/tuscany/java/sca/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReference.composite
Mon Jun 11 04:05:45 2007
@@ -0,0 +1,39 @@
+<?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 for the SpringImplicitReferenceTestCase         
+ * This composite has a ClientComponent implemented with a Spring implementation where
+ * Spring application context uses an implicit reference definition through a Bean with
+ * a property with an unsatisfied ref attribute, which forms the reference.
+ * The reference is satisified by a wire to a ReferenceComponent which is implemented
+ * by a plain Java POJO.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+           name="SpringImplicitReference">
+
+    <component name="ClientComponent">
+        <implementation.spring location="META-INF/sca/SpringImplicitReference-context.xml"/>
+        <reference name="testReference" target="ReferenceComponent"></reference>
+    </component>
+
+    <component name="ReferenceComponent">
+		<implementation.java class="org.apache.tuscany.implementation.spring.itests.helloworld.HelloWorldImpl"/>
+    </component>
+
+</composite>



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message