You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by me...@apache.org on 2007/02/16 08:26:28 UTC

svn commit: r508330 - in /incubator/tuscany/java/sca: core-samples/standalone/calculator/src/main/java/calculator/ runtime/standalone/assembly/src/main/assembly/profiles/launcher/ runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runt...

Author: meerajk
Date: Thu Feb 15 23:26:27 2007
New Revision: 508330

URL: http://svn.apache.org/viewvc?view=rev&rev=508330
Log:
Added component type loader and builder for launched

Added:
    incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java   (with props)
    incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java   (with props)
    incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java   (with props)
Modified:
    incubator/tuscany/java/sca/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.java
    incubator/tuscany/java/sca/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl
    incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.java

Modified: incubator/tuscany/java/sca/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.java?view=diff&rev=508330&r1=508329&r2=508330
==============================================================================
--- incubator/tuscany/java/sca/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.java (original)
+++ incubator/tuscany/java/sca/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.java Thu Feb 15 23:26:27 2007
@@ -18,6 +18,8 @@
  */
 package calculator;
 
+import org.osoa.sca.annotations.Reference;
+
 /**
  * This client program shows how to create an SCA runtime, start it,
  * locate the Calculator service and invoke it.
@@ -26,6 +28,7 @@
     
     private CalculatorService calculatorService;
     
+    @Reference
     public void setCalculatorService(CalculatorService calculatorService) {
         this.calculatorService = calculatorService;
     }

Modified: incubator/tuscany/java/sca/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl?view=diff&rev=508330&r1=508329&r2=508330
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl (original)
+++ incubator/tuscany/java/sca/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl Thu Feb 15 23:26:27 2007
@@ -165,5 +165,13 @@
     <component name="launchedLoader">
         <system:implementation.system class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedLoader"/>
     </component>
+    
+    <component name="launchedComponentLoader">
+        <system:implementation.system class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentTypeLoader"/>
+    </component>
+    
+    <component name="launchedComponentBuilder">
+        <system:implementation.system class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentBuilder"/>
+    </component>
 
 </composite>

Modified: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.java?view=diff&rev=508330&r1=508329&r2=508330
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.java Thu Feb 15 23:26:27 2007
@@ -18,12 +18,13 @@
  */
 package org.apache.tuscany.runtime.standalone.host.implementation.launched;
 
-import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.AtomicImplementation;
 
 /**
  * @version $Rev$ $Date$
  */
-public class Launched extends ModelObject {
+public class Launched extends AtomicImplementation<PojoComponentType> {
     private String className;
     private String factoryName;
 

Added: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java?view=auto&rev=508330
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java (added)
+++ incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java Thu Feb 15 23:26:27 2007
@@ -0,0 +1,200 @@
+/*
+ * 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.runtime.standalone.host.implementation.launched;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.ResourceObjectFactory;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+/**
+ * @version $Revsion$ $Date$
+ * 
+ * TODO This is a straight copy from the JUnit component builder
+ *
+ */
+public class LaunchedComponentBuilder extends ComponentBuilderExtension<Launched>{
+
+    private ResourceHost host;
+
+    @Autowire
+    public void setHost(ResourceHost host) {
+        this.host = host;
+    }
+
+    @Override
+    protected Class<Launched> getImplementationType() {
+        return Launched.class;
+    }
+
+    public Component build(CompositeComponent parent,
+                           ComponentDefinition<Launched> definition,
+                           DeploymentContext deployment) throws BuilderConfigException {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+            definition.getImplementation().getComponentType();
+        Class<?> implClass = componentType.getImplClass();
+
+        PojoConfiguration configuration = new PojoConfiguration();
+        configuration.setParent(parent);
+        if (definition.getInitLevel() != null) {
+            configuration.setInitLevel(definition.getInitLevel());
+        } else {
+            configuration.setInitLevel(componentType.getInitLevel());
+        }
+        if (componentType.getMaxAge() > 0) {
+            configuration.setMaxAge(componentType.getMaxAge());
+        } else if (componentType.getMaxIdleTime() > 0) {
+            configuration.setMaxIdleTime(componentType.getMaxIdleTime());
+        }
+        Method initMethod = componentType.getInitMethod();
+        if (initMethod != null) {
+            configuration.setInitInvoker(new MethodEventInvoker(initMethod));
+        }
+        Method destroyMethod = componentType.getDestroyMethod();
+        if (destroyMethod != null) {
+            configuration.setDestroyInvoker(new MethodEventInvoker(destroyMethod));
+        }
+
+        configuration.setWireService(wireService);
+        configuration.setWorkContext(workContext);
+        configuration.setScheduler(workScheduler);
+        configuration.setImplementationClass(implClass);
+
+        // setup property injection sites
+        for (JavaMappedProperty<?> property : componentType.getProperties().values()) {
+            configuration.addPropertySite(property.getName(), property.getMember());
+        }
+
+        // setup reference injection sites
+        for (JavaMappedReference reference : componentType.getReferences().values()) {
+            Member member = reference.getMember();
+            if (member != null) {
+                // could be null if the reference is mapped to a constructor
+                configuration.addReferenceSite(reference.getUri().getFragment(), member);
+            }
+        }
+
+        for (Resource resource : componentType.getResources().values()) {
+            Member member = resource.getMember();
+            if (member != null) {
+                // could be null if the resource is mapped to a constructor
+                configuration.addResourceSite(resource.getName(), member);
+            }
+        }
+
+        // setup constructor injection
+        ConstructorDefinition<?> ctorDef = componentType.getConstructorDefinition();
+        Constructor<?> constr = ctorDef.getConstructor();
+        PojoObjectFactory<?> instanceFactory = new PojoObjectFactory(constr);
+        configuration.setInstanceFactory(instanceFactory);
+        configuration.getConstructorParamNames().addAll(ctorDef.getInjectionNames());
+        for (Class<?> clazz : constr.getParameterTypes()) {
+            configuration.addConstructorParamType(clazz);
+        }
+        configuration.setMonitor(monitor);
+        configuration.setName(definition.getUri());
+        JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+
+        // handle properties
+        handleProperties(definition, component);
+
+        // handle resources
+        handleResources(componentType, component, parent);
+
+        handleCallbackSites(componentType, configuration);
+
+        // FIXME JFM  this should be refactored to be by operation
+        component.setAllowsPassByReference(componentType.isAllowsPassByReference());
+
+        if (componentType.getConversationIDMember() != null) {
+            component.addConversationIDFactory(componentType.getConversationIDMember());
+        }
+
+        return component;
+    }
+
+    private void handleCallbackSites(
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+        PojoConfiguration configuration) {
+        for (JavaMappedService service : componentType.getServices().values()) {
+            // setup callback injection sites
+            if (service.getCallbackReferenceName() != null) {
+                // Only if there is a callback reference in the service
+                configuration.addCallbackSite(service.getCallbackReferenceName(), service.getCallbackMember());
+            }
+        }
+    }
+
+    @SuppressWarnings({"unchecked"})
+    private void handleResources(
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+        JavaAtomicComponent component,
+        CompositeComponent parent) {
+        for (Resource resource : componentType.getResources().values()) {
+            ObjectFactory<?> objectFactory = resource.getObjectFactory();
+            if (objectFactory != null) {
+                component.addResourceFactory(resource.getName(), objectFactory);
+            } else {
+                String name = resource.getName();
+                boolean optional = resource.isOptional();
+                Class<Object> type = (Class<Object>) resource.getType();
+                ResourceObjectFactory<Object> factory;
+                String mappedName = resource.getMappedName();
+                if (mappedName == null) {
+                    // by type
+                    factory = new ResourceObjectFactory<Object>(type, optional, host);
+                } else {
+                    factory = new ResourceObjectFactory<Object>(type, mappedName, optional, host);
+                }
+                component.addResourceFactory(name, factory);
+            }
+        }
+    }
+
+    private void handleProperties(ComponentDefinition<Launched> definition, JavaAtomicComponent component) {
+        for (PropertyValue<?> property : definition.getPropertyValues().values()) {
+            ObjectFactory<?> factory = property.getValueFactory();
+            if (factory != null) {
+                component.addPropertyFactory(property.getName(), factory);
+            }
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java?view=auto&rev=508330
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java (added)
+++ incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java Thu Feb 15 23:26:27 2007
@@ -0,0 +1,110 @@
+/*
+ * 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.runtime.standalone.host.implementation.launched;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * @version $Revision$ $Date$
+ *
+ */
+public class LaunchedComponentTypeLoader extends ComponentTypeLoaderExtension<Launched>{
+    private static final URI SERVICE_NAME = URI.create("#main");    
+    private Introspector introspector;
+    
+    public LaunchedComponentTypeLoader(@Autowire LoaderRegistry loaderRegistry,
+                                       @Autowire IntrospectionRegistry introspector) {
+        super(loaderRegistry);
+        this.introspector = introspector;
+    }
+
+    @Override
+    protected Class<Launched> getImplementationClass() {
+        return Launched.class;
+    }
+
+    public void load(CompositeComponent parent,
+                     Launched implementation,
+                     DeploymentContext deploymentContext) throws LoaderException {
+        String className = implementation.getClassName();
+        Class<?> implClass;
+        try {
+            implClass = deploymentContext.getClassLoader().loadClass(className);
+        } catch (ClassNotFoundException e) {
+            throw new MissingResourceException(className, e);
+        }
+        PojoComponentType componentType = loadByIntrospection(parent, implementation, deploymentContext, implClass);
+        implementation.setComponentType(componentType);
+    }
+
+    protected PojoComponentType loadByIntrospection(CompositeComponent parent,
+                                                    Launched implementation,
+                                                    DeploymentContext deploymentContext,
+                                                    Class<?> implClass) throws ProcessingException {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(implClass);
+        introspector.introspect(parent, implClass, componentType, deploymentContext);
+
+        ServiceContract launchedContract = generateContract(implClass);
+        JavaMappedService testService = new JavaMappedService(SERVICE_NAME, launchedContract, false);
+        componentType.add(testService);
+        return componentType;
+    }
+
+    private static final DataType<List<DataType<Type>>> INPUT_TYPE;
+    private static final DataType<Type> OUTPUT_TYPE;
+    private static final List<DataType<Type>> FAULT_TYPE;
+    static {
+        List<DataType<Type>> paramDataTypes = Collections.emptyList();
+        INPUT_TYPE = new DataType<List<DataType<Type>>>("idl:input", Object[].class, paramDataTypes);
+        OUTPUT_TYPE = new DataType<Type>(null, Object.class, Object.class);
+        FAULT_TYPE = Collections.emptyList();
+    }
+    
+    protected ServiceContract generateContract(Class<?> implClass) {
+        Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+        Operation<Type> operation = new Operation<Type>("main", INPUT_TYPE, OUTPUT_TYPE, FAULT_TYPE);
+        operations.put("main", operation);
+        return new LaunchedServiceContract(operations);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java?view=auto&rev=508330
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java (added)
+++ incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java Thu Feb 15 23:26:27 2007
@@ -0,0 +1,37 @@
+/*
+ * 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.runtime.standalone.host.implementation.launched;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * @version $Revison$ $Date$
+ *
+ */
+public class LaunchedServiceContract extends ServiceContract<Type> {
+
+    public LaunchedServiceContract(Map<String, Operation<Type>> operations) {
+        setOperations(operations);
+    }
+}
+

Propchange: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



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