You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/10/27 19:36:43 UTC

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

Author: jmarino
Date: Fri Oct 27 10:36:42 2006
New Revision: 468471

URL: http://svn.apache.org/viewvc?view=rev&rev=468471
Log:
initial annotation processing and metadata support for @Resource; not enabled yet

Added:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java   (with props)
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java   (with props)
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java?view=diff&rev=468471&r1=468470&r2=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java Fri Oct 27 10:36:42 2006
@@ -69,7 +69,7 @@
 
     public <T> void visitConstructor(CompositeComponent parent, Constructor<T> constructor,
                                      PojoComponentType<JavaMappedService, JavaMappedReference,
-                                     JavaMappedProperty<?>> type,
+                                         JavaMappedProperty<?>> type,
                                      DeploymentContext context) throws ProcessingException {
         org.osoa.sca.annotations.Constructor annotation =
             constructor.getAnnotation(org.osoa.sca.annotations.Constructor.class);
@@ -97,8 +97,7 @@
                     String name = (i < names.length) ? names[i] : "";
                     service.addName(injectionNames, i, name);
                 }
-            } catch (ProcessingException
-                e) {
+            } catch (ProcessingException e) {
                 e.setIdentifier(constructor.toString());
                 throw e;
             }

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java?view=auto&rev=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java Fri Oct 27 10:36:42 2006
@@ -0,0 +1,43 @@
+/*
+ * 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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when an implementation has more than one resource injection site with the same name
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateResourceException extends ProcessingException {
+    public DuplicateResourceException() {
+    }
+
+    public DuplicateResourceException(String message) {
+        super(message);
+    }
+
+    public DuplicateResourceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public DuplicateResourceException(Throwable cause) {
+        super(cause);
+    }
+}

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

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java?view=auto&rev=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java Fri Oct 27 10:36:42 2006
@@ -0,0 +1,43 @@
+/*
+ * 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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an illegal resource definition in a component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalResourceException extends ProcessingException {
+    public IllegalResourceException() {
+    }
+
+    public IllegalResourceException(String message) {
+        super(message);
+    }
+
+    public IllegalResourceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public IllegalResourceException(Throwable cause) {
+        super(cause);
+    }
+}

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

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java?view=diff&rev=468471&r1=468470&r2=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java Fri Oct 27 10:36:42 2006
@@ -27,6 +27,7 @@
 import org.osoa.sca.annotations.Property;
 import org.osoa.sca.annotations.Reference;
 import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Resource;
 
 import org.apache.tuscany.spi.annotation.Autowire;
 import org.apache.tuscany.spi.idl.InvalidServiceContractException;
@@ -119,6 +120,9 @@
             } else if (Reference.class.equals(annot.annotationType())) {
                 processed = true;
                 processReference(annot, constructorNames, pos, type, param, injectionNames);
+            } else if (Resource.class.equals(annot.annotationType())) {
+                processed = true;
+                processResource((Resource) annot, constructorNames, pos, type, param, injectionNames);
             }
         }
         return processed;
@@ -129,7 +133,8 @@
             for (Annotation annotation : annotations) {
                 Class<? extends Annotation> annotType = annotation.annotationType();
                 if (annotType.equals(Autowire.class) || annotType.equals(Property.class)
-                    || annotType.equals(Reference.class)) {
+                    || annotType.equals(Reference.class)
+                    || annotType.equals(Resource.class)) {
                     return true;
                 }
             }
@@ -137,6 +142,27 @@
         return false;
     }
 
+    public JavaMappedReference createReference(String name, Member member, Class<?> paramType)
+        throws ProcessingException {
+        JavaMappedReference reference = new JavaMappedReference();
+        reference.setName(name);
+        reference.setMember(member);
+        reference.setRequired(false);
+        ServiceContract contract;
+        try {
+            contract = registry.introspect(paramType);
+        } catch (InvalidServiceContractException e1) {
+            throw new ProcessingException(e1);
+        }
+        try {
+            processCallback(paramType, contract);
+        } catch (IllegalCallbackException e) {
+            throw new ProcessingException(e);
+        }
+        reference.setServiceContract(contract);
+        return reference;
+    }
+
     /**
      * Determines if all the members of a collection have unique types
      *
@@ -315,25 +341,52 @@
         addName(explicitNames, pos, name);
     }
 
-    public JavaMappedReference createReference(String name, Member member, Class<?> paramType)
-        throws ProcessingException {
-        JavaMappedReference reference = new JavaMappedReference();
-        reference.setName(name);
-        reference.setMember(member);
-        reference.setRequired(false);
-        ServiceContract contract = null;
-        try {
-            contract = registry.introspect(paramType);
-        } catch (InvalidServiceContractException e1) {
-            throw new ProcessingException(e1);
+    /**
+     * Processes resource metadata for a constructor parameter
+     *
+     * @param resourceAnnot    the resource annotation
+     * @param constructorNames the parameter names as specified in an {@link org.osoa.sca.annotations.Constructor}
+     *                         annotation
+     * @param pos              the position of the parameter in the constructor's parameter list
+     * @param type             the component type associated with the implementation being processed
+     * @param param            the parameter type
+     * @param explicitNames    the collection of injection names to update
+     * @throws ProcessingException
+     */
+    private <T> void processResource(
+        Resource resourceAnnot,
+        String[] constructorNames,
+        int pos,
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+        Class<T> param,
+        List<String> explicitNames) throws ProcessingException {
+
+        org.apache.tuscany.spi.implementation.java.Resource resource =
+            new org.apache.tuscany.spi.implementation.java.Resource();
+        String name = resourceAnnot.name();
+        if (name == null || name.length() == 0) {
+            if (constructorNames.length < pos + 1 || constructorNames[pos] == null
+                || constructorNames[pos].length() == 0) {
+                throw new InvalidResourceException("No name specified for resource parameter " + (pos + 1));
+            }
+            name = constructorNames[pos];
+        } else if (pos < constructorNames.length && constructorNames[pos] != null
+            && constructorNames[pos].length() != 0 && !name.equals(constructorNames[pos])) {
+            throw new InvalidConstructorException("Name specified by @Constructor does not match resource name at "
+                + (pos + 1));
         }
-        try {
-            processCallback(paramType, contract);
-        } catch (IllegalCallbackException e) {
-            throw new ProcessingException(e);
+        if (type.getResources().get(name) != null) {
+            throw new DuplicateResourceException(name);
         }
-        reference.setServiceContract(contract);
-        return reference;
+        resource.setName(name);
+        resource.setOptional(resourceAnnot.optional());
+        resource.setType(param);
+        String mappedName = resourceAnnot.mappedName();
+        if (mappedName.length() > 0) {
+            resource.setMappedName(mappedName);
+        }
+        type.add(resource);
+        addName(explicitNames, pos, name);
     }
 
 }

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java?view=auto&rev=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java Fri Oct 27 10:36:42 2006
@@ -0,0 +1,44 @@
+/*
+ * 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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an invalid usage of {@link @org.osoa.sca.annotations.Resource}
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidResourceException extends ProcessingException {
+
+    public InvalidResourceException() {
+    }
+
+    public InvalidResourceException(String message) {
+        super(message);
+    }
+
+    public InvalidResourceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public InvalidResourceException(Throwable cause) {
+        super(cause);
+    }
+}

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

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java?view=auto&rev=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java Fri Oct 27 10:36:42 2006
@@ -0,0 +1,120 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+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.implementation.java.Resource;
+
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.toPropertyName;
+
+/**
+ * Processes an {@link @Resource} annotation, updating the component type with corresponding {@link
+ * org.apache.tuscany.spi.implementation.java.Resource}
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessor extends ImplementationProcessorExtension {
+
+    public ResourceProcessor() {
+    }
+
+    public void visitMethod(CompositeComponent parent, Method method,
+                            PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+                            DeploymentContext context)
+        throws ProcessingException {
+        org.osoa.sca.annotations.Resource annotation = method.getAnnotation(org.osoa.sca.annotations.Resource.class);
+        if (annotation == null) {
+            return;
+        }
+        if (method.getParameterTypes().length != 1) {
+            IllegalResourceException e = new IllegalResourceException("Resource setter must have one parameter");
+            e.setIdentifier(method.toString());
+            throw e;
+        }
+        String name = annotation.name();
+        if (name.length() < 1) {
+            name = method.getName();
+            if (method.getName().startsWith("set")) {
+                name = toPropertyName(method.getName());
+            }
+        }
+        if (type.getResources().get(name) != null) {
+            throw new DuplicateResourceException(name);
+        }
+
+        String mappedName = annotation.mappedName();
+        Resource resource = new Resource();
+        resource.setMember(method);
+        resource.setType(method.getParameterTypes()[0]);
+        resource.setOptional(annotation.optional());
+        resource.setName(name);
+        if (mappedName.length() > 0) {
+            resource.setMappedName(mappedName);
+        }
+        type.add(resource);
+    }
+
+    public void visitField(CompositeComponent parent, Field field,
+                           PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+                           DeploymentContext context) throws ProcessingException {
+
+        org.osoa.sca.annotations.Resource annotation = field.getAnnotation(org.osoa.sca.annotations.Resource.class);
+        if (annotation == null) {
+            return;
+        }
+        String name = annotation.name();
+        if (name.length() < 1) {
+            name = field.getName();
+        }
+        if (type.getResources().get(name) != null) {
+            throw new DuplicateResourceException(name);
+        }
+
+        String mappedName = annotation.mappedName();
+        Resource resource = new Resource();
+        resource.setMember(field);
+        resource.setType(field.getType());
+        resource.setOptional(annotation.optional());
+        resource.setName(name);
+        if (mappedName.length() > 0) {
+            resource.setMappedName(mappedName);
+        }
+        type.add(resource);
+    }
+
+    public <T> void visitConstructor(CompositeComponent parent, Constructor<T> constructor,
+                                     PojoComponentType<JavaMappedService, JavaMappedReference,
+                                         JavaMappedProperty<?>> type,
+                                     DeploymentContext context) throws ProcessingException {
+
+    }
+
+
+}

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

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java?view=auto&rev=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java Fri Oct 27 10:36:42 2006
@@ -0,0 +1,166 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.osoa.sca.annotations.Resource;
+
+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 junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorResourceTestCase extends TestCase {
+
+    ConstructorProcessor processor =
+        new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+    public void testResource() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+        processor.visitConstructor(null, ctor, type, null);
+        org.apache.tuscany.spi.implementation.java.Resource resource = type.getResources().get("myResource");
+        assertFalse(resource.isOptional());
+    }
+
+    public void testTwoResourcesSameType() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+        processor.visitConstructor(null, ctor, type, null);
+        assertNotNull(type.getResources().get("myResource1"));
+        assertNotNull(type.getResources().get("myResource2"));
+    }
+
+    public void testDuplicateResource() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+        try {
+            processor.visitConstructor(null, ctor, type, null);
+            fail();
+        } catch (DuplicateResourceException e) {
+            // expected
+        }
+    }
+
+    public void testNoName() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+            ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class);
+        try {
+            processor.visitConstructor(null, ctor, type, null);
+            fail();
+        } catch (InvalidResourceException e) {
+            // expected
+        }
+    }
+
+    public void testNamesOnConstructor() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+        processor.visitConstructor(null, ctor, type, null);
+        assertNotNull(type.getResources().get("myResource"));
+    }
+
+    public void testInvalidNumberOfNames() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+            ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class);
+        try {
+            processor.visitConstructor(null, ctor, type, null);
+            fail();
+        } catch (InvalidResourceException e) {
+            // expected
+        }
+    }
+
+    public void testNoMatchingNames() throws Exception {
+        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+        Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+            ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class);
+        try {
+            processor.visitConstructor(null, ctor, type, null);
+            fail();
+        } catch (InvalidConstructorException e) {
+            // expected
+        }
+    }
+
+    private static class Foo {
+
+        @org.osoa.sca.annotations.Constructor
+        public Foo(@Resource(name = "myResource") String resource) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor("myResource")
+        public Foo(@Resource Integer resource) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor
+        public Foo(@Resource(name = "myResource1") String res1, @Resource(name = "myResource2") String res2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor
+        public Foo(@Resource List res) {
+
+        }
+    }
+
+    private static class BadFoo {
+
+        @org.osoa.sca.annotations.Constructor
+        public BadFoo(@Resource(name = "myResource") String res1, @Resource(name = "myResource") String res2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor
+        public BadFoo(@Resource String res) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor("myProp")
+        public BadFoo(@Resource Integer res, @Resource Integer res2) {
+
+        }
+
+        @org.osoa.sca.annotations.Constructor({"myRes", "myRes2"})
+        public BadFoo(@Resource List res, @Resource(name = "myOtherRes") List res2) {
+
+        }
+
+    }
+
+}

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

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

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java?view=auto&rev=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java Fri Oct 27 10:36:42 2006
@@ -0,0 +1,99 @@
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+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 junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessorTestCase extends TestCase {
+
+    PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+    ResourceProcessor processor = new ResourceProcessor();
+
+    public void testVisitField() throws Exception {
+        Field field = Foo.class.getDeclaredField("bar");
+        processor.visitField(null, field, type, null);
+        Resource resource = type.getResources().get("bar");
+        assertFalse(resource.isOptional());
+        assertNull(resource.getMappedName());
+        assertEquals(field.getType(), resource.getType());
+    }
+
+    public void testVisitMethod() throws Exception {
+        Method method = Foo.class.getMethod("setBar", Bar.class);
+        processor.visitMethod(null, method, type, null);
+        Resource resource = type.getResources().get("bar");
+        assertFalse(resource.isOptional());
+        assertNull(resource.getMappedName());
+        assertEquals(method.getParameterTypes()[0], resource.getType());
+    }
+
+    public void testVisitNamedMethod() throws Exception {
+        Method method = Foo.class.getMethod("setBar2", Bar.class);
+        processor.visitMethod(null, method, type, null);
+        Resource resource = type.getResources().get("someName");
+        assertFalse(resource.isOptional());
+        assertEquals("mapped", resource.getMappedName());
+    }
+
+    public void testVisitBadMethod() throws Exception {
+        Method method = Foo.class.getMethod("setBad");
+        try {
+            processor.visitMethod(null, method, type, null);
+            fail();
+        } catch (IllegalResourceException e) {
+            // expected
+        }
+    }
+
+    public void testDuplicateResources() throws Exception {
+        Field field = Foo.class.getDeclaredField("bar");
+        processor.visitField(null, field, type, null);
+        try {
+            processor.visitField(null, field, type, null);
+            fail();
+        } catch (DuplicateResourceException e) {
+            //expected
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+    }
+
+    private class Foo {
+
+        @org.osoa.sca.annotations.Resource
+        protected Bar bar;
+
+        @org.osoa.sca.annotations.Resource(optional = true)
+        protected Bar barNotRequired;
+
+        @org.osoa.sca.annotations.Resource
+        public void setBar(Bar bar) {
+        }
+
+        @org.osoa.sca.annotations.Resource(name = "someName", mappedName = "mapped")
+        public void setBar2(Bar bar) {
+        }
+
+        @org.osoa.sca.annotations.Resource
+        public void setBad() {
+        }
+
+    }
+
+    private interface Bar {
+
+    }
+}

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

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

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java?view=diff&rev=468471&r1=468470&r2=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java Fri Oct 27 10:36:42 2006
@@ -19,6 +19,8 @@
 package org.apache.tuscany.spi.implementation.java;
 
 import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.tuscany.spi.model.ComponentType;
 import org.apache.tuscany.spi.model.Property;
@@ -38,6 +40,7 @@
     private ConstructorDefinition<?> constructorDefinition;
     private Method initMethod;
     private Method destroyMethod;
+    private final Map<String, Resource> resources = new HashMap<String, Resource>();
 
     /**
      * Returns the component implementation scope
@@ -93,6 +96,14 @@
      */
     public void setDestroyMethod(Method destroyMethod) {
         this.destroyMethod = destroyMethod;
+    }
+
+    public Map<String, Resource> getResources() {
+        return resources;
+    }
+
+    public void add(Resource resource) {
+        resources.put(resource.getName(), resource);
     }
 
 }

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java?view=auto&rev=468471
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java Fri Oct 27 10:36:42 2006
@@ -0,0 +1,85 @@
+/*
+ * 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.spi.implementation.java;
+
+import java.lang.reflect.Member;
+
+/**
+ * A resource dependency declared by a Java component implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class Resource {
+
+    private String name;
+    private String mappedName;
+    private boolean optional;
+    private Member member;
+    private Class<?> type;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getMappedName() {
+        return mappedName;
+    }
+
+    public void setMappedName(String mappedName) {
+        this.mappedName = mappedName;
+    }
+
+    public boolean isOptional() {
+        return optional;
+    }
+
+    public void setOptional(boolean optional) {
+        this.optional = optional;
+    }
+
+    /**
+     * Returns the Member that this resource is mapped to.
+     *
+     * @return the Member that this resource is mapped to
+     */
+    public Member getMember() {
+        return member;
+    }
+
+    /**
+     * Sets the Member that this resource is mapped to
+     *
+     * @param member the Member that this resource is mapped to
+     */
+    public void setMember(Member member) {
+        this.member = member;
+    }
+
+    public Class<?> getType() {
+        return type;
+    }
+
+    public void setType(Class<?> type) {
+        this.type = type;
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.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