tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r557394 - in /incubator/tuscany/java/sca: itest/conversations/src/main/java/org/apache/tuscany/sca/test/ modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/ modules/implementation-java-ru...
Date Wed, 18 Jul 2007 20:47:47 GMT
Author: antelder
Date: Wed Jul 18 13:47:46 2007
New Revision: 557394

URL: http://svn.apache.org/viewvc?view=rev&rev=557394
Log:
Start getting conversationid injection working

Added:
    incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java
  (with props)
    incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java
  (with props)
Modified:
    incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClientImpl.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java

Modified: incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClientImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClientImpl.java?view=diff&rev=557394&r1=557393&r2=557394
==============================================================================
--- incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClientImpl.java
(original)
+++ incubator/tuscany/java/sca/itest/conversations/src/main/java/org/apache/tuscany/sca/test/ConversationsClientImpl.java
Wed Jul 18 13:47:46 2007
@@ -112,7 +112,7 @@
 	{
 		
 	  // Verify that conversationID was injected. 	
-//	  Assert.assertNotNull("test0 - conversationID injected", conversationID);
+	  Assert.assertNotNull("test0 - conversationID injected", conversationID);
 	  System.out.println("ConversationID: " + conversationID);
 	  
 	  //

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java?view=diff&rev=557394&r1=557393&r2=557394
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java
(original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java
Wed Jul 18 13:47:46 2007
@@ -104,15 +104,17 @@
 
             ObjectFactory<?> objectFactory = (ObjectFactory<?>)component.getConfiguration().getFactories().get(resource
                 .getElement());
-            Class<?> type = resource.getElement().getType();
-            if (ComponentContext.class.equals(type)) {
-                objectFactory = new PojoComponentContextFactory(component);
-            } else if (String.class.equals(type)) {
-                objectFactory = new PojoComponentNameFactory(component);
-            } else {
-                boolean optional = resource.isOptional();
-                String mappedName = resource.getMappedName();
-                objectFactory = createResourceObjectFactory(type, mappedName, optional, null);
+            if (objectFactory == null) {
+                Class<?> type = resource.getElement().getType();
+                if (ComponentContext.class.equals(type)) {
+                    objectFactory = new PojoComponentContextFactory(component);
+                } else if (String.class.equals(type)) {
+                    objectFactory = new PojoComponentNameFactory(component);
+                } else {
+                    boolean optional = resource.isOptional();
+                    String mappedName = resource.getMappedName();
+                    objectFactory = createResourceObjectFactory(type, mappedName, optional,
null);
+                }
             }
             component.addResourceFactory(name, objectFactory);
         }

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java?view=diff&rev=557394&r1=557393&r2=557394
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
(original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
Wed Jul 18 13:47:46 2007
@@ -42,6 +42,7 @@
 import org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor;
 import org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor;
 import org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ConversationIDProcessor;
 import org.apache.tuscany.sca.implementation.java.introspect.impl.ConversationProcessor;
 import org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor;
 import org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor;
@@ -96,6 +97,7 @@
             new AllowsPassByReferenceProcessor(assemblyFactory),
             new ComponentNameProcessor(assemblyFactory),
             new ContextProcessor(assemblyFactory),
+            new ConversationIDProcessor(assemblyFactory),
             new ConversationProcessor(assemblyFactory),
             new DestroyProcessor(assemblyFactory),
             new EagerInitProcessor(assemblyFactory),

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java?view=auto&rev=557394
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java
(added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java
Wed Jul 18 13:47:46 2007
@@ -0,0 +1,76 @@
+/*
+ * 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.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException;
+import org.osoa.sca.annotations.ConversationID;
+
+/**
+ * Processes {@link @ConversationID} annotations on a component implementation and adds
+ * a {@link JavaMappedProperty} to the component type which will be used to
+ * inject the appropriate conversationId
+ */
+public class ConversationIDProcessor extends BaseJavaClassVisitor {
+    
+    public ConversationIDProcessor(AssemblyFactory factory) {
+        super(factory);
+    }
+
+    public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException
{
+        if (method.getAnnotation(ConversationID.class) == null) {
+            return;
+        }
+        if (method.getParameterTypes().length != 1) {
+            throw new IllegalContextException("ConversationID setter must have one parameter",
method);
+        }
+        Class<?> paramType = method.getParameterTypes()[0];
+        String name = JavaIntrospectionHelper.toPropertyName(method.getName());
+        if (String.class.equals(paramType)) {
+            JavaElementImpl element = new JavaElementImpl(method, 0);
+            element.setName(name);
+            element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+            JavaResourceImpl resource = new JavaResourceImpl(element);
+            type.getResources().put(resource.getName(), resource);
+        } else {
+            throw new UnknownContextTypeException(paramType.getName());
+        }
+    }
+
+    public void visitField(Field field, JavaImplementation type) throws IntrospectionException
{
+        if (field.getAnnotation(ConversationID.class) == null) {
+            return;
+        }
+        Class<?> paramType = field.getType();
+        if (String.class.equals(paramType)) {
+            JavaElementImpl element = new JavaElementImpl(field);
+            element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+            JavaResourceImpl resource = new JavaResourceImpl(element);
+            type.getResources().put(resource.getName(), resource);
+        } else {
+            throw new UnknownContextTypeException(paramType.getName());
+        }
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java?view=auto&rev=557394
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java
(added)
+++ incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java
Wed Jul 18 13:47:46 2007
@@ -0,0 +1,70 @@
+/*
+ * 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.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.ConversationID;
+
+/**
+ * Test the ConversationIDProcessor
+ */
+public class ConversationIDProcessorTestCase extends TestCase {
+    private ConversationIDProcessor processor;
+    private JavaImplementationFactory javaImplementationFactory;
+
+    public void testConversationIDMethod() throws Exception {
+        Method method = Foo.class.getMethod("setConversationID", String.class);
+        JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+        processor.visitMethod(method, type);
+        assertNotNull(type.getResources().get("conversationID"));
+    }
+
+    public void testConversationIDField() throws Exception {
+        Field field = Foo.class.getDeclaredField("cid");
+        JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+        processor.visitField(field, type);
+        assertNotNull(type.getResources().get("cid"));
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        javaImplementationFactory = new DefaultJavaImplementationFactory();
+        processor = new ConversationIDProcessor(new DefaultAssemblyFactory());
+    }
+
+    private class Foo {
+
+        @ConversationID
+        protected String cid;
+
+        @ConversationID
+        public void setConversationID(String cid) {
+
+        }
+
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.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


Mime
View raw message