You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2007/03/11 00:01:28 UTC

svn commit: r516805 - in /incubator/tuscany/java/sca/kernel: core/src/main/java/org/apache/tuscany/core/implementation/java/ core/src/main/java/org/apache/tuscany/core/wire/ core/src/test/java/org/apache/tuscany/core/wire/ spi/src/main/java/org/apache/...

Author: jboynes
Date: Sat Mar 10 15:01:28 2007
New Revision: 516805

URL: http://svn.apache.org/viewvc?view=rev&rev=516805
Log:
convert all method lookups to using getMethod and remove deprecated findMethod

Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java
    incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java?view=diff&rev=516805&r1=516804&r2=516805
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java Sat Mar 10 15:01:28 2007
@@ -23,8 +23,8 @@
 import java.util.List;
 
 import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.idl.java.JavaIDLUtils;
 import org.apache.tuscany.spi.component.TargetInvokerCreationException;
-import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
 import org.apache.tuscany.spi.model.Operation;
 import org.apache.tuscany.spi.model.DataType;
 import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
@@ -49,35 +49,19 @@
     public TargetInvoker createTargetInvoker(String targetName, Operation operation)
         throws TargetInvokerCreationException {
 
-        String name = operation.getName();
-        Class<?>[] paramTypes = getPhysicalTypes(operation);
-        Method method;
+        Class<?> implClass;
+        if (operation.isCallback()) {
+            implClass = operation.getServiceContract().getCallbackClass();
+        } else {
+            implClass = implementationClass;
+        }
         try {
-            if (!operation.isCallback()) {
-                method = implementationClass.getMethod(name, paramTypes);
-            } else {
-                Class<?> callbackClass = operation.getServiceContract().getCallbackClass();
-                method = callbackClass.getMethod(name, paramTypes);
-            }
+            Method method = JavaIDLUtils.findMethod(implClass, operation);
+            return new JavaTargetInvoker(method, this, workContext);
         } catch (NoSuchMethodException e) {
             throw new TargetMethodNotFoundException(operation);
         }
-        return new JavaTargetInvoker(method, this, workContext);
-    }
 
-    private <T> Class<?>[] getPhysicalTypes(Operation<T> operation) {
-        DataType<List<DataType<T>>> inputType = operation.getInputType();
-        List<DataType<T>> types = inputType.getLogical();
-        Class<?>[] javaTypes = new Class<?>[types.size()];
-        for (int i = 0; i < javaTypes.length ; i++) {
-            Type physical = types.get(i).getPhysical();
-            if (physical instanceof Class<?>) {
-                javaTypes[i] = (Class<?>) physical;
-            } else {
-                throw new UnsupportedOperationException();
-            }
-        }
-        return javaTypes;
     }
 
     public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java?view=diff&rev=516805&r1=516804&r2=516805
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java Sat Mar 10 15:01:28 2007
@@ -39,29 +39,6 @@
     private WireUtils() {
     }
 
-    /**
-     * Maps invocation chains on a wire to corresponding methods
-     *
-     * @param wire    the wire containing the invocation chains to map
-     * @param methods the methods to map to
-     * @return a collection containing the method to invocation chain mapping
-     * @throws NoMethodForOperationException
-     */
-    public static Map<Method, InvocationChain> createInboundMapping(Wire wire, Method[] methods)
-        throws NoMethodForOperationException {
-        Map<Method, InvocationChain> chains = new HashMap<Method, InvocationChain>();
-        for (Map.Entry<Operation<?>, InvocationChain> entry : wire.getInvocationChains().entrySet()) {
-            Operation<?> operation = entry.getKey();
-            InvocationChain chain = entry.getValue();
-            Method method = findMethod(operation, methods);
-            if (method == null) {
-                throw new NoMethodForOperationException(operation.getName());
-            }
-            chains.put(method, chain);
-        }
-        return chains;
-    }
-
 
     /**
      * Maps methods on an interface to operations on a wire
@@ -75,14 +52,14 @@
         throws NoMethodForOperationException {
         Map<Operation<?>, InvocationChain> invocationChains = wire.getInvocationChains();
         Map<Method, ChainHolder> chains = new HashMap<Method, ChainHolder>(invocationChains.size());
-        Method[] methods = interfaze.getMethods();
         for (Map.Entry<Operation<?>, InvocationChain> entry : invocationChains.entrySet()) {
             Operation operation = entry.getKey();
-            Method method = findMethod(operation, methods);
-            if (method == null) {
+            try {
+                Method method = findMethod(interfaze, operation);
+                chains.put(method, new ChainHolder(entry.getValue()));
+            } catch (NoSuchMethodException e) {
                 throw new NoMethodForOperationException(operation.getName());
             }
-            chains.put(method, new ChainHolder(entry.getValue()));
         }
         return chains;
     }

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java?view=diff&rev=516805&r1=516804&r2=516805
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java Sat Mar 10 15:01:28 2007
@@ -113,8 +113,7 @@
         chain.addInterceptor(targetInterceptor);
         chain.addInterceptor(new InvokerInterceptor());
 
-        Method method = JavaIDLUtils.findMethod(operation, SimpleTarget.class.getMethods());
-        MockStaticInvoker invoker = new MockStaticInvoker(method, new SimpleTargetImpl());
+        MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
         chain.setTargetInvoker(invoker);
         return chain;
     }

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java?view=diff&rev=516805&r1=516804&r2=516805
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java Sat Mar 10 15:01:28 2007
@@ -58,29 +58,6 @@
         }
     }
 
-    public void testCreateMapping() throws Exception {
-        Wire wire = new WireImpl();
-        Operation<Type> op = new Operation<Type>("hello", null, null, null);
-        InvocationChain chain = new InvocationChainImpl(op);
-        wire.addInvocationChain(op, chain);
-        Map<Method, InvocationChain> chains = WireUtils.createInboundMapping(wire, new Method[]{m});
-        assertEquals(1, chains.size());
-        assertNotNull(chains.get(m));
-    }
-
-    public void testCreateMappingNoOperation() throws Exception {
-        Wire wire = new WireImpl();
-        Operation<Type> op = new Operation<Type>("goodbye", null, null, null);
-        InvocationChain chain = new InvocationChainImpl(op);
-        wire.addInvocationChain(op, chain);
-        try {
-            WireUtils.createInboundMapping(wire, new Method[]{m});
-            fail();
-        } catch (NoMethodForOperationException e) {
-            // expected
-        }
-    }
-
     protected void setUp() throws Exception {
         super.setUp();
         m = Foo.class.getMethod("hello");

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java?view=diff&rev=516805&r1=516804&r2=516805
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java Sat Mar 10 15:01:28 2007
@@ -19,6 +19,7 @@
 package org.apache.tuscany.spi.idl.java;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.Collection;
 import java.util.List;
 
@@ -37,20 +38,32 @@
     }
 
     /**
-     * Searches an array of methods for a match against the given operation
+     * Return the method on the implementation class that matches the operation.
      *
+     * @param implClass the implementation class or interface
      * @param operation the operation to match
-     * @param methods   the methods to match against
-     * @return a matching method or null
-     * @deprecated
+     * @return the method described by the operation
+     * @throws NoSuchMethodException if no such method exists
      */
-    public static Method findMethod(Operation<?> operation, Method[] methods) {
-        for (Method method : methods) {
-            if (match(operation, method)) {
-                return method;
+    public static <T> Method findMethod(Class<?> implClass, Operation<T> operation) throws NoSuchMethodException {
+        String name = operation.getName();
+        Class<?>[] paramTypes = getPhysicalTypes(operation);
+        return implClass.getMethod(name, paramTypes);
+    }
+
+    private static <T> Class<?>[] getPhysicalTypes(Operation<T> operation) {
+        DataType<List<DataType<T>>> inputType = operation.getInputType();
+        List<DataType<T>> types = inputType.getLogical();
+        Class<?>[] javaTypes = new Class<?>[types.size()];
+        for (int i = 0; i < javaTypes.length ; i++) {
+            Type physical = types.get(i).getPhysical();
+            if (physical instanceof Class<?>) {
+                javaTypes[i] = (Class<?>) physical;
+            } else {
+                throw new UnsupportedOperationException();
             }
         }
-        return null;
+        return javaTypes;
     }
 
     /**

Modified: incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java?view=diff&rev=516805&r1=516804&r2=516805
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java Sat Mar 10 15:01:28 2007
@@ -23,7 +23,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
 import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findOperation;
 import org.apache.tuscany.spi.model.DataType;
 import org.apache.tuscany.spi.model.Operation;
@@ -35,18 +34,8 @@
  * @version $Rev$ $Date$
  */
 public class JavaIDLUtilsTestCase extends TestCase {
-    private Method[] methods;
     private List<Operation<?>> operations;
 
-    public void testNoParamsFindMethod() {
-        List<DataType<Type>> types = new ArrayList<DataType<Type>>();
-        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
-        Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
-        Method method = findMethod(operation, methods);
-        assertEquals("foo", method.getName());
-        assertEquals(0, method.getParameterTypes().length);
-    }
-
     public void testNoParamsFindOperation() throws Exception {
         Method method = Foo.class.getMethod("foo");
         Operation ret = findOperation(method, operations);
@@ -54,17 +43,6 @@
         assertEquals(0, method.getParameterTypes().length);
     }
 
-    public void testParamsFindMethod() {
-        List<DataType<Type>> types = new ArrayList<DataType<Type>>();
-        DataType<Type> type = new DataType<Type>(String.class, Object.class);
-        types.add(type);
-        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
-        Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
-        Method method = findMethod(operation, methods);
-        assertEquals("foo", method.getName());
-        assertEquals(String.class, method.getParameterTypes()[0]);
-    }
-
     public void testParamsFindOperation() throws Exception {
         Method method = Foo.class.getMethod("foo", String.class);
         Operation ret = findOperation(method, operations);
@@ -72,65 +50,14 @@
         assertEquals(String.class, method.getParameterTypes()[0]);
     }
 
-
-    public void testTooManyParamsFindMethod() {
-        List<DataType<Type>> types = new ArrayList<DataType<Type>>();
-        DataType<Type> type = new DataType<Type>(String.class, Object.class);
-        DataType<Type> type2 = new DataType<Type>(String.class, Object.class);
-        types.add(type);
-        types.add(type2);
-        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
-        Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
-        Method method = findMethod(operation, methods);
-        assertNull(method);
-    }
-
-    public void testDifferentParamsFindMethod() {
-        List<DataType<Type>> types = new ArrayList<DataType<Type>>();
-        DataType<Type> type = new DataType<Type>(Integer.class, Object.class);
-        types.add(type);
-        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
-        Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
-        Method method = findMethod(operation, methods);
-        assertNull(method);
-    }
-
-    public void testPrimitiveParamNoFindMethod() {
-        List<DataType<Type>> types = new ArrayList<DataType<Type>>();
-        DataType<Type> type = new DataType<Type>(Integer.class, Object.class);
-        types.add(type);
-        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
-        Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
-        Method method = findMethod(operation, methods);
-        assertNull(method);
-    }
-
-    public void testPrimitiveParamFindMethod() {
-        List<DataType<Type>> types = new ArrayList<DataType<Type>>();
-        DataType<Type> type = new DataType<Type>(Integer.TYPE, Object.class);
-        types.add(type);
-        DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
-        Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
-        Method method = findMethod(operation, methods);
-        assertEquals("foo", method.getName());
-        assertEquals(Integer.TYPE, method.getParameterTypes()[0]);
-    }
-
     public void testPrimitiveParamFindOperation() throws NoSuchMethodException {
         Method method = Foo.class.getMethod("foo", Integer.TYPE);
         Operation<?> operation = findOperation(method, operations);
         assertEquals(Integer.TYPE, operation.getInputType().getLogical().get(0).getPhysical());
     }
 
-
-    public void testNotFoundMethod() {
-        Operation<Type> operation = new Operation<Type>("not there", null, null, null, false, null, NO_CONVERSATION);
-        assertNull(findMethod(operation, methods));
-    }
-
     protected void setUp() throws Exception {
         super.setUp();
-        methods = Foo.class.getMethods();
 
         Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION);
         operations = new ArrayList<Operation<?>>();



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