tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r495872 - in /incubator/tuscany/java/sca/services/containers/container.groovy/src: main/java/org/apache/tuscany/container/groovy/ test/java/org/apache/tuscany/container/groovy/
Date Sat, 13 Jan 2007 11:31:16 GMT
Author: antelder
Date: Sat Jan 13 03:31:14 2007
New Revision: 495872

URL: http://svn.apache.org/viewvc?view=rev&rev=495872
Log:
TUSCANY-1051,Commit fixes from Lee Zhenghui to get Groovy with helloworld sample

Modified:
    incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentBuilder.java
    incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentType.java
    incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoader.java
    incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyConfiguration.java
    incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyImplementation.java
    incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/ImplementationLoader.java
    incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java
    incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java

Modified: incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentBuilder.java?view=diff&rev=495872&r1=495871&r2=495872
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentBuilder.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentBuilder.java
Sat Jan 13 03:31:14 2007
@@ -18,6 +18,9 @@
  */
 package org.apache.tuscany.container.groovy;
 
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyObject;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -31,9 +34,6 @@
 import org.apache.tuscany.spi.model.ComponentDefinition;
 import org.apache.tuscany.spi.model.Property;
 import org.apache.tuscany.spi.model.ServiceDefinition;
-
-import groovy.lang.GroovyClassLoader;
-import groovy.lang.GroovyObject;
 import org.codehaus.groovy.control.CompilationFailedException;
 
 /**
@@ -47,6 +47,7 @@
         return GroovyImplementation.class;
     }
 
+    @SuppressWarnings("unchecked")
     public Component build(CompositeComponent parent,
                            ComponentDefinition<GroovyImplementation> componentDefinition,
                            DeploymentContext deploymentContext)
@@ -68,7 +69,7 @@
         // get the Groovy classloader for this deployment component
         GroovyClassLoader groovyClassLoader = (GroovyClassLoader) deploymentContext.getExtension("groovy.classloader");
         if (groovyClassLoader == null) {
-            groovyClassLoader = new GroovyClassLoader(deploymentContext.getClassLoader());
+            groovyClassLoader = new GroovyClassLoader(implementation.getApplicationLoader());
             deploymentContext.putExtension("groovy.classloader", groovyClassLoader);
         }
 

Modified: incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentType.java?view=diff&rev=495872&r1=495871&r2=495872
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentType.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentType.java
Sat Jan 13 03:31:14 2007
@@ -39,5 +39,9 @@
     public void setLifecycleScope(Scope lifecycleScope) {
         this.lifecycleScope = lifecycleScope;
     }
+    
+    public GroovyComponentType() {
+        implementationScope = Scope.COMPOSITE;
+    }
 
 }

Modified: incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoader.java?view=diff&rev=495872&r1=495871&r2=495872
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoader.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoader.java
Sat Jan 13 03:31:14 2007
@@ -18,6 +18,8 @@
  */
 package org.apache.tuscany.container.groovy;
 
+import java.net.URL;
+
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
 import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
@@ -28,16 +30,44 @@
  * @version $Rev$ $Date$
  */
 public class GroovyComponentTypeLoader extends ComponentTypeLoaderExtension<GroovyImplementation>
{
+    
+    @Override
     protected Class<GroovyImplementation> getImplementationClass() {
         return GroovyImplementation.class;
     }
 
     public void load(CompositeComponent parent, GroovyImplementation implementation, DeploymentContext
context)
         throws LoaderException {
-        GroovyComponentType componentType = new GroovyComponentType();
+        URL resource = implementation.getApplicationLoader().getResource(getSideFileName(implementation));
+        GroovyComponentType componentType;
+        if (resource == null) {
+            //TODO this should be replaced by loadFromIntrospection,
+            componentType = new GroovyComponentType();
+        } else {
+            componentType = loadFromSidefile(resource, context);
+        }
+        
         // for now, default to composite
         componentType.setLifecycleScope(Scope.COMPOSITE);
         implementation.setComponentType(componentType);
     }
+    
+    protected GroovyComponentType loadFromSidefile(URL url, DeploymentContext deploymentContext)
+        throws LoaderException {
+        GroovyComponentType ct = new GroovyComponentType();
+        return (GroovyComponentType)loaderRegistry.load(null,ct, url, GroovyComponentType.class,
deploymentContext);
+    }
 
+    private String getSideFileName(GroovyImplementation implementation) {
+        String baseName = getResourceName(implementation);
+        int lastDot = baseName.lastIndexOf('.');
+        if (lastDot != -1) {
+            baseName = baseName.substring(0, lastDot);
+        }
+        return baseName + ".componentType";
+    }
+    
+    protected String getResourceName(GroovyImplementation implementation) {
+        return implementation.getScriptResourceName();
+    }
 }

Modified: incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyConfiguration.java?view=diff&rev=495872&r1=495871&r2=495872
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyConfiguration.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyConfiguration.java
Sat Jan 13 03:31:14 2007
@@ -18,6 +18,8 @@
  */
 package org.apache.tuscany.container.groovy;
 
+import groovy.lang.GroovyObject;
+
 import java.lang.reflect.Member;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -25,12 +27,9 @@
 import java.util.Map;
 
 import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.ScopeContainer;
 import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.wire.WireService;
 import org.apache.tuscany.spi.extension.ExecutionMonitor;
-
-import groovy.lang.GroovyObject;
+import org.apache.tuscany.spi.wire.WireService;
 
 /**
  * Encapsulates confuration for a Groovy-based atomic component
@@ -40,7 +39,6 @@
 public class GroovyConfiguration {
 
     private CompositeComponent parent;
-    private ScopeContainer scopeContainer;
     private int initLevel;
     private Map<String, Member> referenceSites = new HashMap<String, Member>();
     private Map<String, Member> propertySites = new HashMap<String, Member>();

Modified: incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyImplementation.java?view=diff&rev=495872&r1=495871&r2=495872
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyImplementation.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/GroovyImplementation.java
Sat Jan 13 03:31:14 2007
@@ -27,6 +27,34 @@
 
     //the Groovy source to be executed
     private String script;
+    
+    // the application class loader, we need this to construct a GroovyClassLoader in GroovyComponentBuilder
+    private ClassLoader applicationLoader;
+    
+    // TODO , Suggest to change the current script to scriptContent, acutally, we need script
file name to get component side file name.
+    private String scriptResourceName;
+    
+    public String getScriptResourceName() {
+        return scriptResourceName;
+    }
+
+    public void setScriptResourceName(String scriptResourceName) {
+        this.scriptResourceName = scriptResourceName;
+    }
+
+    /**
+     * Return Application class loader to be executed.
+     */
+    public ClassLoader getApplicationLoader() {
+        return applicationLoader;
+    }
+
+    /**
+     * Sets the Application class loader to be executed.
+     */
+    public void setApplicationLoader(ClassLoader applicationLoader) {
+        this.applicationLoader = applicationLoader;
+    }
 
     /**
      * Returns the Groovy source to be executed.

Modified: incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/ImplementationLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/ImplementationLoader.java?view=diff&rev=495872&r1=495871&r2=495872
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/ImplementationLoader.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.groovy/src/main/java/org/apache/tuscany/container/groovy/ImplementationLoader.java
Sat Jan 13 03:31:14 2007
@@ -69,8 +69,9 @@
 
         GroovyImplementation implementation = new GroovyImplementation();
         implementation.setScript(source);
-        // no component type support
-        //registry.loadComponentType(parent, implementation, deploymentContext);
+        implementation.setApplicationLoader(deploymentContext.getClassLoader());
+        implementation.setScriptResourceName(script);
+        
         return implementation;
     }
 

Modified: incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java?view=diff&rev=495872&r1=495871&r2=495872
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/AsyncInvokerTestCase.java
Sat Jan 13 03:31:14 2007
@@ -45,6 +45,7 @@
  */
 public class AsyncInvokerTestCase extends TestCase {
 
+    @SuppressWarnings("unchecked")
     public void testInvoke() throws Exception {
         GroovyObject instance = createMock(GroovyObject.class);
         expect(instance.invokeMethod("invoke", null)).andReturn(null).once();

Modified: incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java?view=diff&rev=495872&r1=495871&r2=495872
==============================================================================
--- incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java
(original)
+++ incubator/tuscany/java/sca/services/containers/container.groovy/src/test/java/org/apache/tuscany/container/groovy/GroovyComponentTypeLoaderTestCase.java
Sat Jan 13 03:31:14 2007
@@ -30,6 +30,8 @@
     public void testLoad() throws Exception {
         GroovyComponentTypeLoader loader = new GroovyComponentTypeLoader();
         GroovyImplementation impl = new GroovyImplementation();
+        impl.setScriptResourceName("Foo.groovy");
+        impl.setApplicationLoader(Thread.currentThread().getContextClassLoader());
         loader.load(null, impl, null);
         GroovyComponentType type = impl.getComponentType();
         assertEquals(Scope.COMPOSITE, type.getLifecycleScope());



---------------------------------------------------------------------
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