tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r416228 - in /incubator/tuscany/sandbox/jboynes/sca: core2/src/main/java/org/apache/tuscany/core/system/loader/ core2/src/test/java/org/apache/tuscany/core/deployer/ core2/src/test/resources/org/apache/tuscany/core/deployer/ spi/src/main/ja...
Date Thu, 22 Jun 2006 02:53:17 GMT
Author: jboynes
Date: Wed Jun 21 19:53:17 2006
New Revision: 416228

URL: http://svn.apache.org/viewvc?rev=416228&view=rev
Log:
Add rudimentary introspection for system implementation type.
This is a temporary hack to allow us to bootstrap the primordial deployer
so that we can make progress on running a simple sample without needing
the full blown, annotation/sidefile aware introspector.


Modified:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/loader/SystemComponentTypeLoader.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl
    incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedProperty.java
    incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedReference.java
    incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/loader/SystemComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/loader/SystemComponentTypeLoader.java?rev=416228&r1=416227&r2=416228&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/loader/SystemComponentTypeLoader.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/loader/SystemComponentTypeLoader.java
Wed Jun 21 19:53:17 2006
@@ -16,15 +16,21 @@
  */
 package org.apache.tuscany.core.system.loader;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.net.URL;
 
+import org.apache.tuscany.core.system.model.SystemImplementation;
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
 import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
 import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.JavaMappedProperty;
+import org.apache.tuscany.spi.model.JavaMappedReference;
+import org.apache.tuscany.spi.model.JavaServiceContract;
 import org.apache.tuscany.spi.model.PojoComponentType;
-
-import org.apache.tuscany.core.system.model.SystemImplementation;
-import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+import org.apache.tuscany.spi.model.ServiceDefinition;
 
 /**
  * Loads a system component type
@@ -49,7 +55,51 @@
     }
 
     protected PojoComponentType loadByIntrospection(SystemImplementation implementation)
{
-        return new PojoComponentType();
+        PojoComponentType componentType = new PojoComponentType();
+
+        // FIXME: replace this rudimentary introspection mechanism
+        Class<?> implClass = implementation.getImplementationClass();
+        for (Class<?> serviceIntf : implClass.getInterfaces()) {
+            JavaServiceContract serviceContract = new JavaServiceContract(serviceIntf);
+            ServiceDefinition service = new ServiceDefinition(serviceIntf.getName(), serviceContract);
+            componentType.add(service);
+        }
+        for (Field field : implClass.getFields()) {
+            if (Modifier.isStatic(field.getModifiers())) {
+                continue;
+            }
+            String name = field.getName();
+            Class<?> javaType = field.getType();
+            if (javaType.isInterface()) {
+                JavaMappedReference reference = new JavaMappedReference(name, new JavaServiceContract(javaType),
field);
+                componentType.add(reference);
+            } else {
+                JavaMappedProperty<?> property = new JavaMappedProperty(name, null,
javaType, field);
+                componentType.add(property);
+            }
+        }
+        for (Method method : implClass.getMethods()) {
+            if (Modifier.isStatic(method.getModifiers())
+                || !(Void.TYPE == method.getReturnType())
+                || method.getParameterTypes().length != 1
+                || !method.getName().startsWith("set")
+                || !(method.getName().length() > 3)
+                ) {
+                continue;
+            }
+            String name = method.getName();
+            name = Character.toLowerCase(name.charAt(3)) + name.substring(4);
+            Class<?> javaType = method.getParameterTypes()[0];
+            if (javaType.isInterface()) {
+                JavaMappedReference reference = new JavaMappedReference(name, new JavaServiceContract(javaType),
method);
+                componentType.add(reference);
+            } else {
+                JavaMappedProperty<?> property = new JavaMappedProperty(name, null,
javaType, method);
+                componentType.add(property);
+            }
+        }
+
+        return componentType;
     }
 
 

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java?rev=416228&r1=416227&r2=416228&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java
Wed Jun 21 19:53:17 2006
@@ -26,6 +26,11 @@
 import org.apache.tuscany.spi.model.ComponentDefinition;
 import org.apache.tuscany.spi.model.CompositeComponentType;
 import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
 
 import junit.framework.TestCase;
 import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
@@ -45,20 +50,39 @@
     private ComponentDefinition<SystemCompositeImplementation> componentDefinition;
     private SystemCompositeImplementation implementation;
 
-    public void testBoot1() throws LoaderException {
+    public void testBoot1Load() throws LoaderException {
         URL scdl = BootstrapDeployerTestCase.class.getResource("boot1.scdl");
         implementation.setScdlLocation(scdl);
         deployer.load(componentDefinition, deploymentContext);
-        CompositeComponentType componentType = implementation.getComponentType();
-        assertNotNull(componentType);
-        assertEquals("simple", componentType.getName());
-        Map<String, ServiceDefinition> services = componentType.getServices();
+        CompositeComponentType composite = implementation.getComponentType();
+        assertNotNull(composite);
+        assertEquals("simple", composite.getName());
+
+        // check parse of <service>
+        Map<String, ServiceDefinition> services = composite.getServices();
         assertEquals(1, services.size());
         BoundServiceDefinition serviceDefinition = (BoundServiceDefinition) services.get("service");
         assertNotNull(serviceDefinition);
         assertEquals("service", serviceDefinition.getName());
         assertEquals(BasicInterface.class, serviceDefinition.getServiceContract().getInterfaceClass());
         assertTrue(serviceDefinition.getBinding() instanceof SystemBinding);
+
+        // check parse of <component>
+        Map<String, ComponentDefinition<? extends Implementation<?>>> components
= composite.getComponents();
+        assertEquals(1, components.size());
+        ComponentDefinition<? extends Implementation<?>> component = components.get("component");
+        assertNotNull(component);
+        PropertyValue<?> propVal = component.getPropertyValues().get("publicProperty");
+        assertEquals("propval", propVal.getValueFactory().getInstance());
+
+        // check introspection of implementation
+        ComponentType<?,?,?> componentType = component.getImplementation().getComponentType();
+        ServiceDefinition service = componentType.getServices().get(BasicInterface.class.getName());
+        assertEquals(BasicInterface.class, service.getServiceContract().getInterfaceClass());
+        Property<?> property = componentType.getProperties().get("publicProperty");
+        assertEquals(String.class, property.getJavaType());
+        ReferenceDefinition referenceDefinition = componentType.getReferences().get("publicReference");
+        assertEquals(BasicInterface.class, referenceDefinition.getServiceContract().getInterfaceClass());
     }
 
     protected void setUp() throws Exception {

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl?rev=416228&r1=416227&r2=416228&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl
Wed Jun 21 19:53:17 2006
@@ -24,9 +24,7 @@
 
     <component name="component">
         <system:implementation.system class="org.apache.tuscany.core.mock.component.BasicInterfaceImpl"/>
-<!--
         <property name="publicProperty">propval</property>
         <reference name="publicReference" target="target"/>
--->
     </component>
 </composite>

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedProperty.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedProperty.java?rev=416228&r1=416227&r2=416228&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedProperty.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedProperty.java
Wed Jun 21 19:53:17 2006
@@ -31,10 +31,6 @@
     public JavaMappedProperty() {
     }
 
-    public JavaMappedProperty(Member member) {
-        this.member = member;
-    }
-
     public JavaMappedProperty(String name, QName xmlType, Class<T> javaType) {
         super(name, xmlType, javaType);
     }

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedReference.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedReference.java?rev=416228&r1=416227&r2=416228&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedReference.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/JavaMappedReference.java
Wed Jun 21 19:53:17 2006
@@ -27,6 +27,14 @@
 public class JavaMappedReference extends ReferenceDefinition {
     private Member member;
 
+    public JavaMappedReference() {
+    }
+
+    public JavaMappedReference(String name, ServiceContract serviceContract, Member member)
{
+        super(name, serviceContract);
+        this.member = member;
+    }
+
     /**
      * Returns the Member that this reference is mapped to.
      *

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java?rev=416228&r1=416227&r2=416228&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java
Wed Jun 21 19:53:17 2006
@@ -27,6 +27,14 @@
     private Multiplicity multiplicity;
     private boolean autowire;
 
+    public ReferenceDefinition() {
+    }
+
+    public ReferenceDefinition(String name, ServiceContract serviceContract) {
+        this.name = name;
+        this.serviceContract = serviceContract;
+    }
+
     public String getName() {
         return name;
     }



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