You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2010/07/29 02:14:46 UTC

svn commit: r980272 - in /tuscany/sca-java-2.x/trunk: modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/ modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/sp...

Author: rfeng
Date: Thu Jul 29 00:14:45 2010
New Revision: 980272

URL: http://svn.apache.org/viewvc?rev=980272&view=rev
Log:
Add the parent delegation for the SCA spring application context
Improve the sample to demonstrate the child bean wired to a bean in the parent context (WebApplicationContext)

Modified:
    tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java
    tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java
    tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java
    tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/DateServiceImpl.java
    tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java
    tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml
    tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite
    tuscany/sca-java-2.x/trunk/samples/webapps/helloworld-spring/pom.xml

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java?rev=980272&r1=980271&r2=980272&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SCAParentApplicationContext.java Thu Jul 29 00:14:45 2010
@@ -69,7 +69,15 @@ class SCAParentApplicationContext implem
      * @return Object - a Bean which matches the requested bean
      */
     public Object getBean(String name, Class requiredType) throws BeansException {
-        return implementation.getBean(name, requiredType);
+        Object bean = implementation.getBean(name, requiredType);
+        if (bean == null && getParent() != null) {
+            bean = getParent().getBean(name, requiredType);
+        }
+        if (bean == null) {
+            throw new NoSuchBeanDefinitionException("Unable to find Bean with name " + name);
+        } else {
+            return bean;
+        }
     } // end method getBean( String, Class )
 
     public Object getBean(String name, Object[] args) throws BeansException {
@@ -77,7 +85,7 @@ class SCAParentApplicationContext implem
     }
 
     public <T> T getBean(Class<T> clazz) throws BeansException {
-        return clazz.cast(implementation.getBean(clazz.getName(), clazz));
+        return clazz.cast(getBean(clazz.getName(), clazz));
     }
 
     public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> clazz) throws BeansException {

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java?rev=980272&r1=980271&r2=980272&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java Thu Jul 29 00:14:45 2010
@@ -22,7 +22,6 @@ package org.apache.tuscany.sca.implement
 import java.lang.reflect.Method;
 
 import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 import org.springframework.context.ApplicationContext;
 
 /**
@@ -80,9 +79,9 @@ public class SpringImplementationStub {
         try {
 
             Object bean = getBean.invoke(tie, new Object[] {name, requiredType});
-            if (bean == null) {
-                throw new NoSuchBeanDefinitionException("Unable to find Bean with name " + name);
-            }
+//            if (bean == null) {
+//                throw new NoSuchBeanDefinitionException("Unable to find Bean with name " + name);
+//            }
             return bean;
 
         } catch (Exception e) {

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java?rev=980272&r1=980271&r2=980272&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationTie.java Thu Jul 29 00:14:45 2010
@@ -132,7 +132,8 @@ public class SpringImplementationTie {
             } // end if
         } // end for
           // TODO: NoSuchBeanException
-        throw new RuntimeException("Unable to find Bean with name " + name);
+        // throw new RuntimeException("Unable to find Bean with name " + name);
+        return null;
 
     } // end method getBean( String, Class )
 

Modified: tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/DateServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/DateServiceImpl.java?rev=980272&r1=980271&r2=980272&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/DateServiceImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/DateServiceImpl.java Thu Jul 29 00:14:45 2010
@@ -30,6 +30,7 @@ import org.oasisopen.sca.annotation.Serv
 public class DateServiceImpl implements DateService {
 
     public Date getDate() {
+        System.out.println("DateServiceImpl.getDate()");
         return new Date();
     }
 

Modified: tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java?rev=980272&r1=980271&r2=980272&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java (original)
+++ tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/java/sample/HelloworldImpl.java Thu Jul 29 00:14:45 2010
@@ -18,17 +18,17 @@
  */
 package sample;
 
-import org.oasisopen.sca.annotation.Reference;
 
 public class HelloworldImpl implements Helloworld {
-    @Reference(required = false)
-    private DateService dateService;
+
+    public HelloworldImpl() {
+        super();
+        System.out.println("HelloworldImpl()");
+    }
 
     public String sayHello(String name) {
-        if (dateService == null) {
-            return "Hello " + name;
-        }
-        return "[" + dateService.getDate() + "] Hello " + name;
+        System.out.println("HelloworldImpl.sayHello(" + name + ")");
+        return "Hello " + name;
     }
 
 }

Modified: tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml?rev=980272&r1=980271&r2=980272&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml (original)
+++ tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld-context.xml Thu Jul 29 00:14:45 2010
@@ -24,9 +24,7 @@
        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="sample.HelloworldImpl">
+    <bean id="HelloworldBean" class="sample.HelloworldImpl">
     </bean>
-    
-    <sca:reference name="dateService" type="sample.DateService"/>
 
 </beans>
\ No newline at end of file

Modified: tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite?rev=980272&r1=980271&r2=980272&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite (original)
+++ tuscany/sca-java-2.x/trunk/samples/helloworld-spring/src/main/resources/helloworld.composite Thu Jul 29 00:14:45 2010
@@ -19,10 +19,14 @@
 -->
 <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
       targetNamespace="http://sample"
+      xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
       name="helloworld">
     
-    <component name="HelloworldComponent">
-        <implementation.spring location="helloworld-context.xml"/>
+    <component name="HelloworldClientComponent">
+        <implementation.spring location="helloworld-client-context.xml"/>
+        <service name="HelloworldClientBean">
+            <tuscany:binding.jsonrpc/>
+        </service>
         <reference name="dateService" target="DateServiceComponent"/>
     </component>
     

Modified: tuscany/sca-java-2.x/trunk/samples/webapps/helloworld-spring/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/webapps/helloworld-spring/pom.xml?rev=980272&r1=980271&r2=980272&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/webapps/helloworld-spring/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/samples/webapps/helloworld-spring/pom.xml Thu Jul 29 00:14:45 2010
@@ -69,7 +69,12 @@
             <version>4.8.1</version>
             <scope>test</scope>
         </dependency>
-
+        <dependency>
+            <groupId>httpunit</groupId>
+            <artifactId>httpunit</artifactId>
+            <version>1.6.1</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>