Author: jmarino
Date: Fri Jul 21 16:25:39 2006
New Revision: 424490

URL: http://svn.apache.org/viewvc?rev=424490&view=rev
Log:
CDI refactoring to allow for injection of properties defined by custom 
annotations; some cleanup still needed

Added:
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
   (with props)
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
   (with props)
Modified:
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/ConstructorDefinition.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java
    
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ProcessorUtils.java
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
    
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/ConstructorDefinition.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/ConstructorDefinition.java?rev=424490&r1=424489&r2=424490&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/ConstructorDefinition.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/ConstructorDefinition.java
 Fri Jul 21 16:25:39 2006
@@ -18,6 +18,8 @@
 import java.util.List;
 
 /**
+ * Hold injection information for the constructor used to instantiate a 
component implementation instance
+ *
  * @version $Rev$ $Date$
  */
 public class ConstructorDefinition<T> {

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java?rev=424490&r1=424489&r2=424490&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
 Fri Jul 21 16:25:39 2006
@@ -15,7 +15,6 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.tuscany.spi.component.CompositeComponent;
@@ -28,6 +27,7 @@
 import org.apache.tuscany.core.implementation.JavaMappedService;
 import org.apache.tuscany.core.implementation.PojoComponentType;
 import org.apache.tuscany.core.implementation.ProcessingException;
+import static 
org.apache.tuscany.core.implementation.processor.ProcessorUtils.addName;
 import static 
org.apache.tuscany.core.implementation.processor.ProcessorUtils.processParam;
 
 /**
@@ -65,41 +65,40 @@
             return;
         }
         ConstructorDefinition<?> definition = type.getConstructorDefinition();
-        if (definition != null) {
+        if (definition != null && 
!definition.getConstructor().equals(constructor)) {
             DuplicateConstructorException e =
                 new DuplicateConstructorException("More than one constructor 
marked with @Constructor");
             e.setIdentifier(constructor.getDeclaringClass().getName());
             throw e;
+        } else if (definition == null) {
+            definition = new ConstructorDefinition(constructor);
         }
-        definition = new ConstructorDefinition(constructor);
         Class<?>[] params = constructor.getParameterTypes();
         String[] names = annotation.value();
         Annotation[][] annotations = constructor.getParameterAnnotations();
-        List<String> explicitNames = new ArrayList<String>();
-        boolean annotationsDeclared = false;
+        List<String> injectionNames = definition.getInjectionNames();
+        boolean validateNames = true;
         for (int i = 0; i < params.length; i++) {
             Class<?> param = params[i];
             Annotation[] paramAnnotations = annotations[i];
             try {
-                if (processParam(param, paramAnnotations, names, i, type, 
explicitNames)) {
-                    annotationsDeclared = true;
+                if (!processParam(param, paramAnnotations, names, i, type, 
injectionNames)) {
+                    String name = (i < names.length) ? names[i] : "";
+                    addName(injectionNames, i, name);
+                    if (validateNames) {
+                        validateNames = false;
+                    }
                 }
-            } catch (ProcessingException e) {
+            } catch (ProcessingException
+                e) {
                 e.setIdentifier(constructor.toString());
                 throw e;
             }
         }
-        if (!annotationsDeclared) {
-            if (names.length != params.length) {
-                throw new InvalidConstructorException("Names in @Constructor 
do not match number of parameters");
-            }
-            for (String name : names) {
-                definition.getInjectionNames().add(name);
-            }
-        } else {
-            for (String name : explicitNames) {
-                definition.getInjectionNames().add(name);
-            }
+        if (validateNames && names.length != 0 && names[0].length() != 0 && 
names.length != params.length) {
+            throw new InvalidConstructorException("Names in @Constructor do 
not match number of parameters");
+        } else if (names.length != 0 && names[0].length() != 0 && names.length 
!= params.length) {
+            throw new InvalidConstructorException("Names in @Constructor do 
not match number of parameters");
         }
         type.setConstructorDefinition(definition);
     }

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java?rev=424490&r1=424489&r2=424490&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java
 Fri Jul 21 16:25:39 2006
@@ -27,12 +27,9 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.osoa.sca.annotations.Property;
-import org.osoa.sca.annotations.Reference;
 import org.osoa.sca.annotations.Remotable;
 import org.osoa.sca.annotations.Service;
 
-import org.apache.tuscany.spi.annotation.Autowire;
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
 
@@ -44,6 +41,7 @@
 import org.apache.tuscany.core.implementation.JavaServiceContract;
 import org.apache.tuscany.core.implementation.PojoComponentType;
 import org.apache.tuscany.core.implementation.ProcessingException;
+import static 
org.apache.tuscany.core.implementation.processor.ProcessorUtils.annotationsDefined;
 import static 
org.apache.tuscany.core.implementation.processor.ProcessorUtils.areUnique;
 import static 
org.apache.tuscany.core.implementation.processor.ProcessorUtils.createService;
 import static 
org.apache.tuscany.core.implementation.processor.ProcessorUtils.processParam;
@@ -155,51 +153,80 @@
     private void calcConstructor(PojoComponentType<JavaMappedService, 
JavaMappedReference, JavaMappedProperty<?>> type,
                                  Class<?> clazz) throws ProcessingException {
         // determine constructor if one is not annotated
-        if (type.getConstructorDefinition() != null) {
+        ConstructorDefinition<?> definition = type.getConstructorDefinition();
+        Constructor constructor;
+        boolean explictConstructor = false;
+        if (definition != null
+            && 
definition.getConstructor().getAnnotation(org.osoa.sca.annotations.Constructor.class)
 != null) {
+            // the constructor was already defined explicitly
             return;
-        }
-        Constructor[] constructors = clazz.getConstructors();
-        if (constructors.length == 0) {
-            NoConstructorException e = new NoConstructorException("No public 
constructor for class");
-            e.setIdentifier(clazz.getName());
-            throw e;
-        } else if (constructors.length == 1) {
-            boolean explictAnnotations;
-            Constructor constructor = constructors[0];
-            Class[] params = constructor.getParameterTypes();
-            if (params.length == 0) {
-                ConstructorDefinition<?> definition = new 
ConstructorDefinition(constructor);
-                type.setConstructorDefinition(definition);
-                return;
+        } else if (definition != null) {
+            explictConstructor = true;
+            constructor = definition.getConstructor();
+        } else {
+            // no definition, heuristically determine constructor
+            Constructor[] constructors = clazz.getConstructors();
+            if (constructors.length == 0) {
+                NoConstructorException e = new NoConstructorException("No 
public constructor for class");
+                e.setIdentifier(clazz.getName());
+                throw e;
+            } else if (constructors.length == 1) {
+                constructor = constructors[0];
             } else {
-                Annotation[][] annotations = 
constructor.getParameterAnnotations();
-                List<String> paramNames = new ArrayList<String>();
-                explictAnnotations = annotationsDefined(annotations);
-                if (explictAnnotations) {
-                    for (int i = 0; i < params.length; i++) {
-                        Class param = params[i];
-                        processParam(param, annotations[i], new String[0], i, 
type, paramNames);
+                // FIXME multiple constructors, none yet done
+                Constructor selected = null;
+                int sites = type.getProperties().size() + 
type.getReferences().size();
+                for (Constructor ctor : constructors) {
+                    if (ctor.getParameterTypes().length == 0) {
+                        selected = ctor;
                     }
-                    ConstructorDefinition<?> definition = new 
ConstructorDefinition(constructor);
-                    definition.setInjectionNames(paramNames);
-                    type.setConstructorDefinition(definition);
-                    return;
+                    if (ctor.getParameterTypes().length == sites) {
+                        //TODO finish
+                        //selected = constructor;
+                        // select constructor
+                        //break;
+                    }
+                }
+                if (selected == null) {
+                    throw new NoConstructorException();
                 }
+                constructor = selected;
+                definition = new ConstructorDefinition(selected);
+                type.setConstructorDefinition(definition);
+                //return;
             }
-
-            Map<String, JavaMappedProperty<?>> props = type.getProperties();
-            Map<String, JavaMappedReference> refs = type.getReferences();
-            if (!explictAnnotations && !areUnique(params)) {
+            definition = new ConstructorDefinition(constructor);
+            type.setConstructorDefinition(definition);
+        }
+        Class[] params = constructor.getParameterTypes();
+        if (params.length == 0) {
+            return;
+        }
+        List<String> paramNames = definition.getInjectionNames();
+        Map<String, JavaMappedProperty<?>> props = type.getProperties();
+        Map<String, JavaMappedReference> refs = type.getReferences();
+        Annotation[][] annotations = constructor.getParameterAnnotations();
+        if (!explictConstructor) {
+            // the constructor wasn't defined by an annotation, so check to 
see if any of the params have an annotation
+            // which we can impute as explicitly defining the constructor, 
e.g. @Property, @Reference, or @Autowire
+            explictConstructor = annotationsDefined(annotations);
+        }
+        if (explictConstructor) {
+            for (int i = 0; i < params.length; i++) {
+                Class param = params[i];
+                processParam(param, annotations[i], new String[0], i, type, 
paramNames);
+            }
+        } else {
+            if (!areUnique(params)) {
                 throw new AmbiguousConstructorException(
                     "Unable to resolve parameter types as they are not unique, 
use @Constructor");
             }
-            if (!explictAnnotations && !calcPropRefUniqueness(props.values(), 
refs.values())) {
+            if (!calcPropRefUniqueness(props.values(), refs.values())) {
                 throw new AmbiguousConstructorException(
                     "Unable to resolve parameter types as reference and 
property types are not unique, "
                         + "use @Constructor");
             }
             boolean empty = props.size() + refs.size() == 0;
-            List<String> paramNames = new ArrayList<String>();
             if (!empty) {
                 // the constructor param types must unambiguously match 
defined reference or property types
                 for (Class param : params) {
@@ -221,43 +248,11 @@
                     paramNames.add(name);
                 }
             }
-            ConstructorDefinition<?> definition = new 
ConstructorDefinition(constructor);
-            definition.setInjectionNames(paramNames);
-            type.setConstructorDefinition(definition);
-        } else {
-            Constructor selected = null;
-            int sites = type.getProperties().size() + 
type.getReferences().size();
-            for (Constructor constructor : constructors) {
-                if (constructor.getParameterTypes().length == 0) {
-                    selected = constructor;
-                }
-                if (constructor.getParameterTypes().length == sites) {
-                    //TODO finish
-                    //selected = constructor;
-                    // select constructor
-                    //break;
-                }
-            }
-            ConstructorDefinition<?> definition = new 
ConstructorDefinition(selected);
-            type.setConstructorDefinition(definition);
-        }
-    }
 
-    private boolean annotationsDefined(Annotation[][] annots) {
-        // since all parameters must be annotated or not, just check the first 
one
-        if (annots.length > 0 && annots[0].length > 0) {
-            Annotation[] annotations = annots[0];
-            for (Annotation annotation : annotations) {
-                Class<? extends Annotation> annotType = 
annotation.annotationType();
-                if (annotType.equals(Autowire.class)
-                    || annotType.equals(Property.class)
-                    || annotType.equals(Reference.class)) {
-                    return true;
-                }
-            }
         }
-        return false;
+        //definition.setInjectionNames(paramNames);
     }
+
 
     /**
      * Returns true if the union of the given collections of properties and 
references have unique Java types

Modified: 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ProcessorUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ProcessorUtils.java?rev=424490&r1=424489&r2=424490&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ProcessorUtils.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/implementation/processor/ProcessorUtils.java
 Fri Jul 21 16:25:39 2006
@@ -87,23 +87,19 @@
     }
 
     /**
-     * Determines if all the members of a collection have unique types
-     *
-     * @param collection the collection to analyze
-     * @param start      the position in the collection to start
-     * @return true if the types are unique
+     * Inserts a name at the specified position, paddiling the list if its 
size is less than the position
      */
-    private static boolean areUnique(Class[] collection, int start) {
-        Object compare = collection[start];
-        for (int i = start + 1; i < collection.length; i++) {
-            if (compare.equals(collection[i])) {
-                return false;
+    public static void addName(List<String> names, int pos, String name) {
+        if (names.size() < pos) {
+            for (int i = 0; i < pos; i++) {
+                names.add(i, "");
             }
-        }
-        if (start + 1 < collection.length) {
-            return areUnique(collection, start + 1);
+            names.add(name);
+        } else if (names.size() > pos) {
+            names.remove(pos);
+            names.add(pos, name);
         } else {
-            return true;
+            names.add(pos, name);
         }
     }
 
@@ -115,8 +111,7 @@
      * @param constructorNames the array of constructorNames specified by 
@Constructor
      * @param pos              the declaration position of the constructor 
parameter
      * @param type             the component type associated with 
implementation being reflected
-     * @param explicitNames    the list of parameter constructorNames 
specified on parameter annotations
-     * @return true if the parameters have explicit annotation declarations
+     * @param injectionNames   the list of parameter constructorNames 
specified on parameter annotations
      * @throws org.apache.tuscany.core.implementation.ProcessingException
      *
      */
@@ -126,22 +121,57 @@
                                        int pos,
                                        PojoComponentType<JavaMappedService, 
JavaMappedReference,
                                            JavaMappedProperty<?>> type,
-                                       List<String> explicitNames)
+                                       List<String> injectionNames)
         throws ProcessingException {
-        boolean annotationsDeclared = false;
+        boolean processed = false;
         for (Annotation annot : paramAnnotations) {
             if (Autowire.class.equals(annot.annotationType())) {
-                processAutowire(annot, constructorNames, pos, param, type, 
explicitNames);
-                annotationsDeclared = true;
+                processed = true;
+                processAutowire(annot, constructorNames, pos, param, type, 
injectionNames);
             } else if (Property.class.equals(annot.annotationType())) {
-                processProperty(annot, constructorNames, pos, type, param, 
explicitNames);
-                annotationsDeclared = true;
+                processed = true;
+                processProperty(annot, constructorNames, pos, type, param, 
injectionNames);
             } else if (Reference.class.equals(annot.annotationType())) {
-                processReference(annot, constructorNames, pos, type, param, 
explicitNames);
-                annotationsDeclared = true;
+                processed = true;
+                processReference(annot, constructorNames, pos, type, param, 
injectionNames);
+            }
+        }
+        return processed;
+    }
+
+    /**
+     * Determines if all the members of a collection have unique types
+     *
+     * @param collection the collection to analyze
+     * @param start      the position in the collection to start
+     * @return true if the types are unique
+     */
+    private static boolean areUnique(Class[] collection, int start) {
+        Object compare = collection[start];
+        for (int i = start + 1; i < collection.length; i++) {
+            if (compare.equals(collection[i])) {
+                return false;
             }
         }
-        return annotationsDeclared;
+        if (start + 1 < collection.length) {
+            return areUnique(collection, start + 1);
+        } else {
+            return true;
+        }
+    }
+
+    public static boolean annotationsDefined(Annotation[][] annots) {
+        for (Annotation[] annotations : annots) {
+            for (Annotation annotation : annotations) {
+                Class<? extends Annotation> annotType = 
annotation.annotationType();
+                if (annotType.equals(Autowire.class)
+                    || annotType.equals(Property.class)
+                    || annotType.equals(Reference.class)) {
+                    return true;
+                }
+            }
+        }
+        return false;
     }
 
     private static void processAutowire(Annotation annot, String[] 
constructorNames,
@@ -149,8 +179,8 @@
                                         Class<?> param,
                                         PojoComponentType<JavaMappedService, 
JavaMappedReference,
                                             JavaMappedProperty<?>> type,
-                                        List<String> explicitNames) throws 
InvalidAutowireException,
-                                                                           
InvalidConstructorException {
+                                        List<String> injectionNames) throws 
InvalidAutowireException,
+                                                                            
InvalidConstructorException {
         // the param is marked as an autowire
         Autowire autowireAnnot = (Autowire) annot;
         JavaMappedReference reference = new JavaMappedReference();
@@ -177,7 +207,7 @@
         contract.setInterfaceClass(param);
         reference.setServiceContract(contract);
         type.getReferences().put(name, reference);
-        explicitNames.add(name);
+        addName(injectionNames, pos, name);
     }
 
     private static void processProperty(Annotation annot,
@@ -213,7 +243,7 @@
         property.setRequired(propAnnot.required());
         property.setJavaType(param);
         type.getProperties().put(name, property);
-        explicitNames.add(name);
+        addName(explicitNames, pos, name);
     }
 
     private static void processReference(Annotation annot, String[] 
constructorNames,
@@ -251,6 +281,7 @@
         contract.setInterfaceClass(param);
         reference.setServiceContract(contract);
         type.getReferences().put(name, reference);
-        explicitNames.add(name);
+        addName(explicitNames, pos, name);
     }
+
 }

Modified: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java?rev=424490&r1=424489&r2=424490&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java
 Fri Jul 21 16:25:39 2006
@@ -46,6 +46,7 @@
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
         Constructor ctor = Foo.class.getConstructor(Bar.class, Bar.class);
         processor.visitConstructor(null, ctor, type, null);
+        assertEquals(2, 
type.getConstructorDefinition().getInjectionNames().size());
         assertNotNull(type.getReferences().get("myRef1"));
         assertNotNull(type.getReferences().get("myRef2"));
     }
@@ -135,8 +136,8 @@
 
     public static class Foo3 {
 
-        @org.osoa.sca.annotations.Constructor({"prop1"})
-        public Foo3(@Property String prop, @Baz String baz) {
+        @org.osoa.sca.annotations.Constructor
+        public Foo3(@Property(name = "prop1") String prop, @Baz String baz) {
         }
     }
 

Added: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java?rev=424490&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
 (added)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
 Fri Jul 21 16:25:39 2006
@@ -0,0 +1,61 @@
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import org.osoa.sca.annotations.Property;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.JavaMappedProperty;
+import org.apache.tuscany.core.implementation.JavaMappedReference;
+import org.apache.tuscany.core.implementation.JavaMappedService;
+import org.apache.tuscany.core.implementation.PojoComponentType;
+import org.apache.tuscany.core.implementation.ConstructorDefinition;
+
+/**
+ * Verifies the constructor processor works when parameters are marked with 
extension annotations
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorExtensibilityTestCase extends TestCase {
+    private ConstructorProcessor processor = new ConstructorProcessor();
+
+    public void testProcessFirst() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        Constructor ctor1 = Foo.class.getConstructor(String.class, 
String.class);
+        processor.visitConstructor(null, ctor1, type, null);
+        assertEquals("foo", 
type.getConstructorDefinition().getInjectionNames().get(0));
+    }
+
+    /**
+     * Verifies the constructor processor can be called after another 
processor has evaluated the constructor and found
+     * an annotation
+     *
+     * @throws Exception
+     */
+    public void testProcessLast() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        Constructor ctor1 = Foo.class.getConstructor(String.class, 
String.class);
+        ConstructorDefinition<Foo> definition = new 
ConstructorDefinition<Foo>(ctor1);
+        definition.getInjectionNames().add("");
+        definition.getInjectionNames().add("mybar");
+        type.setConstructorDefinition(definition);
+        processor.visitConstructor(null, ctor1, type, null);
+        assertEquals("foo", 
type.getConstructorDefinition().getInjectionNames().get(0));
+    }
+
+
+    private @interface Bar {
+
+    }
+
+    private static class Foo {
+        @org.osoa.sca.annotations.Constructor
+        public Foo(@Property(name = "foo") String foo, @Bar String bar) {
+
+        }
+    }
+
+
+}

Propchange: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Modified: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java?rev=424490&r1=424489&r2=424490&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
 Fri Jul 21 16:25:39 2006
@@ -28,10 +28,10 @@
         assertEquals("myRef", reference.getName());
     }
 
-    public void testTwoPropertiesSameType() throws Exception {
+    public void testTwoReferencesSameType() throws Exception {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        Constructor ctor = 
ConstructorReferenceTestCase.Foo.class.getConstructor(String.class, 
String.class);
+        Constructor ctor = Foo.class.getConstructor(String.class, 
String.class);
         processor.visitConstructor(null, ctor, type, null);
         assertNotNull(type.getReferences().get("myRef1"));
         assertNotNull(type.getReferences().get("myRef2"));

Modified: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java?rev=424490&r1=424489&r2=424490&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
 Fri Jul 21 16:25:39 2006
@@ -180,10 +180,23 @@
         assertNotNull(type.getReferences().get(String.class.getName()));
     }
 
+    public void testPrivateConstructor() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        try {
+            processor.visitEnd(null, Foo14.class, type, null);
+            fail();
+        } catch (NoConstructorException e) {
+            // expected
+        }
+    }
+
+
     public void testMultipleConstructors() throws Exception {
         //    throw new UnsupportedOperationException("Finish heuristic 
multiple constructors - Foo10");
     }
 
+
     public static class Foo1 {
         public Foo1(String val) {
         }
@@ -269,6 +282,11 @@
 
     public static class Foo13 {
         public Foo13(@Autowire String foo) {
+        }
+    }
+
+    public final static class Foo14 {
+        private Foo14() {
         }
     }
 

Modified: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java?rev=424490&r1=424489&r2=424490&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
 (original)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
 Fri Jul 21 16:25:39 2006
@@ -2,6 +2,7 @@
 
 import java.util.Collection;
 import java.util.List;
+import java.lang.reflect.Constructor;
 
 import org.osoa.sca.annotations.Property;
 import org.osoa.sca.annotations.Reference;
@@ -9,12 +10,12 @@
 import org.osoa.sca.annotations.Service;
 
 import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.ConstructorDefinition;
 import org.apache.tuscany.core.implementation.JavaMappedProperty;
 import org.apache.tuscany.core.implementation.JavaMappedReference;
 import org.apache.tuscany.core.implementation.JavaMappedService;
 import org.apache.tuscany.core.implementation.PojoComponentType;
 import org.apache.tuscany.core.implementation.ProcessingException;
-import org.apache.tuscany.core.implementation.ConstructorDefinition;
 
 /**
  * Verfies component type information is properly introspected from an 
unadorned POJO according to the SCA Java Client
@@ -33,7 +34,8 @@
     public void testSingleInterface() throws Exception {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        type.setConstructorDefinition(new ConstructorDefinition(null));
+        Constructor ctor =  SingleInterfaceImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
         processor.visitEnd(null, SingleInterfaceImpl.class, type, null);
         assertEquals(1, type.getServices().size());
         assertEquals(PropertyInterface.class,
@@ -50,7 +52,8 @@
     public void testPropertyReference() throws Exception {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        type.setConstructorDefinition(new ConstructorDefinition(null));
+        Constructor ctor =  
SingleInterfaceWithPropertyReferenceImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
         processor.visitEnd(null, 
SingleInterfaceWithPropertyReferenceImpl.class, type, null);
         assertEquals(1, type.getServices().size());
         assertEquals(Interface1.class,
@@ -69,7 +72,8 @@
     public void testPropertySetterInInterface() throws Exception {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        type.setConstructorDefinition(new ConstructorDefinition(null));
+        Constructor ctor =  SingleInterfaceImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
         processor.visitEnd(null, SingleInterfaceImpl.class, type, null);
         assertEquals(0, type.getProperties().size());
     }
@@ -81,7 +85,8 @@
     public void testReferenceSetterInInterface() throws Exception {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        type.setConstructorDefinition(new ConstructorDefinition(null));
+        Constructor ctor =  RefInterfaceImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
         processor.visitEnd(null, RefInterfaceImpl.class, type, null);
         assertEquals(0, type.getReferences().size());
     }
@@ -93,7 +98,8 @@
     public void testReferenceCollectionType() throws Exception {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        type.setConstructorDefinition(new ConstructorDefinition(null));
+        Constructor ctor =  ReferenceCollectionImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
         processor.visitEnd(null, ReferenceCollectionImpl.class, type, null);
         assertEquals(0, type.getProperties().size());
         assertEquals(4, type.getReferences().size());
@@ -106,7 +112,8 @@
     public void testPropertyCollectionType() throws Exception {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        type.setConstructorDefinition(new ConstructorDefinition(null));
+        Constructor ctor =  PropertyCollectionImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
         processor.visitEnd(null, PropertyCollectionImpl.class, type, null);
         assertEquals(0, type.getReferences().size());
         assertEquals(4, type.getProperties().size());
@@ -119,21 +126,65 @@
     public void testRemotableRef() throws Exception {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        type.setConstructorDefinition(new ConstructorDefinition(null));
+        Constructor ctor =  RemotableRefImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
         processor.visitEnd(null, RemotableRefImpl.class, type, null);
         assertEquals(2, type.getReferences().size());
         assertEquals(0, type.getProperties().size());
     }
 
     @SuppressWarnings("unchecked")
-    public void testParentInterface() throws ProcessingException {
+    public void testParentInterface() throws ProcessingException, 
NoSuchMethodException {
         PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
             new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        type.setConstructorDefinition(new ConstructorDefinition(null));
+        Constructor ctor =  Child.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
         processor.visitEnd(null, Child.class, type, null);
         
assertTrue(type.getServices().containsKey("HeuristicPojoProcessorTestCase$Interface1"));
     }
 
+    /**
+     * Verifies a service inteface is calculated when only props and refs are 
given
+     */
+    public void testExcludedPropertyAndReference() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        JavaMappedReference ref = new JavaMappedReference();
+        ref.setName("reference");
+        type.add(ref);
+        JavaMappedReference ref2 = new JavaMappedReference();
+        ref2.setName("reference2");
+        type.add(ref2);
+        JavaMappedProperty<?> prop1 = new JavaMappedProperty();
+        prop1.setName("string1");
+        type.add(prop1);
+        JavaMappedProperty<?> prop2 = new JavaMappedProperty();
+        prop2.setName("string2");
+        type.add(prop2);
+        processor.visitEnd(null, ServiceImpl.class, type, null);
+        assertEquals(1, type.getServices().size());
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testProtectedRemotableRefField() throws ProcessingException, 
NoSuchMethodException {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        Constructor ctor =  
ProtectedRemotableRefFieldImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
+        processor.visitEnd(null, ProtectedRemotableRefFieldImpl.class, type, 
null);
+        assertNotNull(type.getReferences().get("otherRef"));
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testProtectedRemotableRefMethod() throws ProcessingException, 
NoSuchMethodException {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        Constructor ctor =  
ProtectedRemotableRefMethodImpl.class.getConstructor();
+        type.setConstructorDefinition(new ConstructorDefinition(ctor));
+        processor.visitEnd(null, ProtectedRemotableRefMethodImpl.class, type, 
null);
+        assertNotNull(type.getReferences().get("otherRef"));
+    }
+
     private interface PropertyInterface {
         void setString1(String val);
     }
@@ -141,15 +192,20 @@
     private interface Interface1 {
     }
 
-    private class Parent implements Interface1 {
+    private static class Parent implements Interface1 {
 
     }
 
-    private class Child extends Parent {
+    private static class Child extends Parent {
+        public Child() {
+        }
 
     }
 
-    private class SingleInterfaceImpl implements PropertyInterface {
+    private static class SingleInterfaceImpl implements PropertyInterface {
+        public SingleInterfaceImpl() {
+        }
+
         public void setString1(String val) {
         }
     }
@@ -182,28 +238,6 @@
 
     }
 
-    /**
-     * Verifies a service inteface is calculated when only props and refs are 
given
-     */
-    public void testExcludedPropertyAndReference() throws Exception {
-        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
-            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
-        JavaMappedReference ref = new JavaMappedReference();
-        ref.setName("reference");
-        type.add(ref);
-        JavaMappedReference ref2 = new JavaMappedReference();
-        ref2.setName("reference2");
-        type.add(ref2);
-        JavaMappedProperty<?> prop1 = new JavaMappedProperty();
-        prop1.setName("string1");
-        type.add(prop1);
-        JavaMappedProperty<?> prop2 = new JavaMappedProperty();
-        prop2.setName("string2");
-        type.add(prop2);
-        processor.visitEnd(null, ServiceImpl.class, type, null);
-        assertEquals(1, type.getServices().size());
-    }
-
     @Service
     private interface Ref {
     }
@@ -215,12 +249,18 @@
         void setReference(Ref ref);
     }
 
-    private class RefInterfaceImpl implements RefInterface {
+    private static class RefInterfaceImpl implements RefInterface {
+        public RefInterfaceImpl() {
+        }
+
         public void setReference(Ref ref) {
         }
     }
 
-    private class SingleInterfaceWithPropertyReferenceImpl implements 
Interface1 {
+    private static class SingleInterfaceWithPropertyReferenceImpl implements 
Interface1 {
+        public SingleInterfaceWithPropertyReferenceImpl() {
+        }
+
         public void setReference(Ref ref) {
         }
 
@@ -228,7 +268,10 @@
         }
     }
 
-    private class ReferenceCollectionImpl implements Interface1 {
+    private static class ReferenceCollectionImpl implements Interface1 {
+        public ReferenceCollectionImpl() {
+        }
+
         public void setCollectionReference(Collection<Ref> ref) {
         }
 
@@ -242,7 +285,10 @@
         }
     }
 
-    private class PropertyCollectionImpl implements Interface1 {
+    private static class PropertyCollectionImpl implements Interface1 {
+        public PropertyCollectionImpl() {
+        }
+
         public void setCollectionProperty(Collection<ComplexProperty> prop) {
         }
 
@@ -260,13 +306,37 @@
     private interface RemotableRef {
     }
 
-    private class RemotableRefImpl implements Interface1 {
-
+    private static class RemotableRefImpl implements Interface1 {
         protected RemotableRef otherRef;
 
+        public RemotableRefImpl() {
+        }
+
         public void setRef(RemotableRef ref) {
 
         }
     }
+
+    private static class ProtectedRemotableRefFieldImpl implements Interface1 {
+        protected RemotableRef otherRef;
+
+        public ProtectedRemotableRefFieldImpl() {
+        }
+
+        public ProtectedRemotableRefFieldImpl(RemotableRef otherRef) {
+            this.otherRef = otherRef;
+        }
+
+    }
+
+    private static class ProtectedRemotableRefMethodImpl implements Interface1 
{
+        public ProtectedRemotableRefMethodImpl() {
+        }
+
+        protected void setOtherRef(RemotableRef otherRef) {
+        }
+
+    }
+
 
 }

Added: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java?rev=424490&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
 (added)
+++ 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
 Fri Jul 21 16:25:39 2006
@@ -0,0 +1,123 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors, as 
applicable.
+ *
+ * Licensed 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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.ConstructorDefinition;
+import org.apache.tuscany.core.implementation.JavaMappedProperty;
+import org.apache.tuscany.core.implementation.JavaMappedReference;
+import org.apache.tuscany.core.implementation.JavaMappedService;
+import org.apache.tuscany.core.implementation.PojoComponentType;
+
+/**
+ * Verifies constructors that have extensible annotation types, i.e. that have 
parameters marked by annotations which
+ * are themselves processed by some other implementation processor
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeutisticExtensibleConstructorTestCase extends TestCase {
+
+    private HeuristicPojoProcessor processor = new HeuristicPojoProcessor();
+
+    /**
+     * Verifies heuristic processing can be called priot to an extension 
annotation processors being called.
+     */
+    @SuppressWarnings("unchecked")
+    public void testBarAnnotationProcessedFirst() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        Constructor ctor = Foo.class.getConstructor(String.class, 
String.class);
+        ConstructorDefinition definition = new ConstructorDefinition(ctor);
+        type.setConstructorDefinition(definition);
+        JavaMappedProperty property = new JavaMappedProperty();
+        property.setName("myBar");
+        definition.getInjectionNames().add("myBar");
+        type.getProperties().put("myBar", property);
+        processor.visitEnd(null, Foo.class, type, null);
+        assertEquals(2, type.getProperties().size());
+    }
+
+    /**
+     * Verifies heuristic processing can be called before an extension 
annotation processors is called.
+     * <p/>
+     * For example, given:
+     * <pre> Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = 
"foo") String prop2)</pre>
+     * <p/>
+     * Heuristic evaluation of @Property can occur prior to another 
implementation processor evaluating @Bar
+     *
+     * @throws Exception
+     */
+    public void testBarAnnotationProcessedLast() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        processor.visitEnd(null, Foo.class, type, null);
+
+        // now simulate process the bar impl
+        ConstructorDefinition<?> definition = type.getConstructorDefinition();
+        List<String> injectionNames = definition.getInjectionNames();
+        injectionNames.remove(0);
+        injectionNames.add(0, "mybar");
+        type.getProperties().put("mybar", new JavaMappedProperty<String>());
+
+        assertEquals(2, type.getProperties().size());
+        assertEquals("foo", definition.getInjectionNames().get(1));
+    }
+
+    /**
+     * Verifies heuristic processing can be called before an extension 
annotation processors is called with the
+     * extension parameter in a middle position. Specifically, verifies that 
the heuristic processor updates injection
+     * names and preserves their ordering.
+     */
+    @SuppressWarnings("unchecked")
+    public void testBarAnnotationProcessedFirstInMiddle() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, 
JavaMappedProperty<?>>();
+        Constructor ctor = Foo2.class.getConstructor(String.class, 
String.class, String.class);
+        ConstructorDefinition definition = new ConstructorDefinition(ctor);
+        type.setConstructorDefinition(definition);
+        // insert placeholder for first param, which would be done by a 
processor
+        definition.getInjectionNames().add("");
+        JavaMappedProperty property = new JavaMappedProperty();
+        property.setName("myBar");
+        definition.getInjectionNames().add("myBar");
+        type.getProperties().put("myBar", property);
+        processor.visitEnd(null, Foo2.class, type, null);
+        assertEquals("baz", definition.getInjectionNames().get(0));
+        assertEquals(2, type.getProperties().size());
+        assertEquals(1, type.getReferences().size());
+    }
+
+    public @interface Bar {
+
+    }
+
+    public static class Foo {
+        public Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = 
"foo") String prop2) {
+        }
+    }
+
+    public static class Foo2 {
+        public Foo2(@org.osoa.sca.annotations.Reference(name = "baz") String 
prop1,
+                    @Bar String prop2,
+                    @org.osoa.sca.annotations.Property(name = "foo") String 
prop3) {
+        }
+    }
+
+
+}
+
+

Propchange: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to