Author: antelder
Date: Fri May  1 14:36:14 2009
New Revision: 770692

URL: http://svn.apache.org/viewvc?rev=770692&view=rev
Log:
Start bringing up the spring annotation support

Added:
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java
Modified:
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
    
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java

Modified: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java?rev=770692&r1=770691&r2=770692&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentNameAnnotationProcessor.java
 Fri May  1 14:36:14 2009
@@ -25,6 +25,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
+import org.oasisopen.sca.annotation.ComponentName;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.FatalBeanException;
@@ -34,13 +35,11 @@
 
 public class ComponentNameAnnotationProcessor implements BeanPostProcessor {
 
-//    private Class<? extends Annotation> componentNameAnnotationType = 
ComponentName.class;
-    private Class<? extends Annotation> componentNameAnnotationType;
+    private Class<? extends Annotation> componentNameAnnotationType = 
ComponentName.class;
     
     private String componentName;
     
-    public ComponentNameAnnotationProcessor (Class<? extends Annotation> 
componentNameAnnotationType,String componentName) {
-        this.componentNameAnnotationType = componentNameAnnotationType;
+    public ComponentNameAnnotationProcessor (String componentName) {
         this.componentName = componentName;
     }
     

Added: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java?rev=770692&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java
 (added)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ComponentStub.java
 Fri May  1 14:36:14 2009
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.implementation.spring.processor;
+
+import java.lang.reflect.Method;
+
+public class ComponentStub {
+
+    private Object tie;
+    private Method getService;
+    private Method getReference;
+    
+    public ComponentStub(Object tie) {
+        this.tie = tie;
+        Class<?> tieClass = tie.getClass();
+        try {
+            getService = tieClass.getMethod("getService", new 
Class<?>[]{Class.class, String.class});
+            getReference = tieClass.getMethod("getReference", new 
Class<?>[]{Class.class, String.class});
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+    public Object getService(Class<?> type, String name) {
+        try {
+
+            return getService.invoke(tie, type, name);
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public Object getReference(Class<?> type, String name) {
+        try {
+
+            return getReference.invoke(tie, type, name);
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

Modified: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java?rev=770692&r1=770691&r2=770692&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ConstructorAnnotationProcessor.java
 Fri May  1 14:36:14 2009
@@ -28,14 +28,13 @@
 
 public class ConstructorAnnotationProcessor extends 
InstantiationAwareBeanPostProcessorAdapter {
 
-//    private Class<? extends Annotation> constructorAnnotationType 
-//    = org.oasisopen.sca.annotation.Constructor.class;
-    private Class<? extends Annotation> constructorAnnotationType;
+    private Class<? extends Annotation> constructorAnnotationType 
+    = org.oasisopen.sca.annotation.Constructor.class;
     
     private Class<? extends Annotation> autowiredAnnotationType = 
Autowired.class;
     
-    public ConstructorAnnotationProcessor (Class<? extends Annotation> 
annotation) {
-        this.constructorAnnotationType = annotation;
+    public ConstructorAnnotationProcessor () {
+        // Default constructor.
     }
     
     /**

Modified: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java?rev=770692&r1=770691&r2=770692&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/InitDestroyAnnotationProcessor.java
 Fri May  1 14:36:14 2009
@@ -20,22 +20,17 @@
 
 import java.lang.annotation.Annotation;
 
+import org.oasisopen.sca.annotation.Destroy;
+import org.oasisopen.sca.annotation.Init;
 import 
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor;
 
-public class InitDestroyAnnotationProcessor extends 
InitDestroyAnnotationBeanPostProcessor {    
-    
+public class InitDestroyAnnotationProcessor extends 
InitDestroyAnnotationBeanPostProcessor {
+
     private static final long serialVersionUID = 0;
-    
-//    private Class<? extends Annotation> initAnnotationType = Init.class;
-//    private Class<? extends Annotation> destroyAnnotationType = 
Destroy.class;
-    private Class<? extends Annotation> initAnnotationType;
-    private Class<? extends Annotation> destroyAnnotationType;
-    
-    public InitDestroyAnnotationProcessor(Class<? extends Annotation> 
initAnnotationType, Class<? extends Annotation> destroyAnnotationType) {
-        this.initAnnotationType = initAnnotationType;
-        this.destroyAnnotationType = destroyAnnotationType;
-    }
-    
+
+    private Class<? extends Annotation> initAnnotationType = Init.class;
+    private Class<? extends Annotation> destroyAnnotationType = Destroy.class;
+
     /**
      * Gets init annotation type.
      */
@@ -46,11 +41,13 @@
     /**
      * Sets init annotation type.
      */
-    /*public void setInitAnnotationType(Class<? extends Annotation> 
initAnnotationType) {
-        Assert.notNull(initAnnotationType, "Init annotation type must not be 
null.");
-        this.initAnnotationType = initAnnotationType;
-    }*/
-    
+    /*
+     * public void setInitAnnotationType(Class<? extends Annotation>
+     * initAnnotationType) { Assert.notNull(initAnnotationType,
+     * "Init annotation type must not be null."); this.initAnnotationType =
+     * initAnnotationType; }
+     */
+
     /**
      * Gets destroy annotation type.
      */
@@ -61,15 +58,17 @@
     /**
      * Sets destroy annotation type.
      */
-    /*public void setDestroyAnnotationType(Class<? extends Annotation> 
destroyAnnotationType) {
-        Assert.notNull(destroyAnnotationType, "Destroy annotation type must 
not be null.");
-        this.destroyAnnotationType = destroyAnnotationType;
-    }*/
+    /*
+     * public void setDestroyAnnotationType(Class<? extends Annotation>
+     * destroyAnnotationType) { Assert.notNull(destroyAnnotationType,
+     * "Destroy annotation type must not be null."); this.destroyAnnotationType
+     * = destroyAnnotationType; }
+     */
 
-    public InitDestroyAnnotationProcessor () {
+    public InitDestroyAnnotationProcessor() {
         // Set the @Init annotation type
         setInitAnnotationType(initAnnotationType);
-        
+
         // Set the @Destroy annotation type
         setDestroyAnnotationType(destroyAnnotationType);
     }

Modified: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java?rev=770692&r1=770691&r2=770692&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyAnnotationProcessor.java
 Fri May  1 14:36:14 2009
@@ -22,28 +22,24 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 
+import org.oasisopen.sca.annotation.Property;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.FatalBeanException;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.util.Assert;
 import org.springframework.util.ReflectionUtils;
 
-import com.sun.xml.internal.bind.v2.runtime.property.Property;
-
 public class PropertyAnnotationProcessor implements BeanPostProcessor {
 
-//    private Class<? extends Annotation> propertyAnnotationType = 
Property.class;
-    private Class<? extends Annotation> propertyAnnotationType;
+    private Class<? extends Annotation> propertyAnnotationType = 
Property.class;
     
-//    private RuntimeComponent component;
-//    
-//    private JavaPropertyValueObjectFactory propertyFactory;
+    private PropertyValueStub propertyValue;
     
-    public PropertyAnnotationProcessor (Class<? extends Annotation> 
propertyAnnotationType) {
-        this.propertyAnnotationType = propertyAnnotationType;
-//        this.propertyFactory = propertyFactory;
-//        this.component = component;
+    public PropertyAnnotationProcessor (PropertyValueStub propertyValue) {
+        this.propertyValue = propertyValue;
     }
 
     /**
@@ -91,87 +87,66 @@
 
         ReflectionUtils.doWithMethods(clazz, new 
ReflectionUtils.MethodCallback() {
             public void doWith(Method method) {
-//                //Annotation annotation = 
method.getAnnotation(getPropertyAnnotationType());                
-//                Property annotation = (Property) 
method.getAnnotation(getPropertyAnnotationType());
-//                
-//                if (annotation != null) {
-//                    if (Modifier.isStatic(method.getModifiers())) {
-//                        throw new IllegalStateException("Property annotation 
is not supported on static methods");
-//                    }
-//                    
-//                    if (Modifier.isPrivate(method.getModifiers())) {
-//                        throw new IllegalStateException("Property annotation 
is not supported on private methods");
-//                    }
-//
-//                    if (method.getParameterTypes().length == 0) {
-//                        throw new IllegalStateException("Property annotation 
requires at least one argument: " + method);
-//                    }
-//                    
-//                    PropertyDescriptor pd = 
BeanUtils.findPropertyForMethod(method);
-//                    if (pd != null) {
-//                        String propName = annotation.name();
-//                        if ("".equals(propName)) {
-//                            injectProperty(bean, pd, 
getPropertyObj(pd.getPropertyType(), pd.getName()));
-//                        } else {
-//                            injectProperty(bean, pd, 
getPropertyObj(pd.getPropertyType(), propName));
-//                        }
-//                    }
-//                }
+
+                Property annotation = (Property) 
method.getAnnotation(getPropertyAnnotationType());
+                
+                if (annotation != null) {
+                    if (Modifier.isStatic(method.getModifiers())) {
+                        throw new IllegalStateException("Property annotation 
is not supported on static methods");
+                    }
+                    
+                    if (Modifier.isPrivate(method.getModifiers())) {
+                        throw new IllegalStateException("Property annotation 
is not supported on private methods");
+                    }
+
+                    if (method.getParameterTypes().length == 0) {
+                        throw new IllegalStateException("Property annotation 
requires at least one argument: " + method);
+                    }
+                    
+                    PropertyDescriptor pd = 
BeanUtils.findPropertyForMethod(method);
+                    if (pd != null) {
+                        String propName = annotation.name();
+                        if ("".equals(propName)) {
+                            injectProperty(bean, pd, 
propertyValue.getPropertyObj(pd.getPropertyType(), pd.getName()));
+                        } else {
+                            injectProperty(bean, pd, 
propertyValue.getPropertyObj(pd.getPropertyType(), propName));
+                        }
+                    }
+                }
             }
         });
         
         ReflectionUtils.doWithFields(clazz, new 
ReflectionUtils.FieldCallback() {
             public void doWith(Field field) {
-                //Annotation annotation = 
field.getAnnotation(getPropertyAnnotationType());
-//                Property annotation = (Property) 
field.getAnnotation(getPropertyAnnotationType());
-//                
-//                if (annotation != null) {
-//                    if (Modifier.isStatic(field.getModifiers())) {
-//                        throw new IllegalStateException("Property annotation 
is not supported on static fields");
-//                    }
-//                    
-//                    if (Modifier.isPrivate(field.getModifiers())) {
-//                        throw new IllegalStateException("Property annotation 
is not supported on private fields");
-//                    }
-//
-//                    ReflectionUtils.makeAccessible(field);
-//                    
-//                    Object propertyObj = null;
-//                    String propName = annotation.name();
-//                    if ("".equals(propName)) {
-//                        propertyObj = getPropertyObj(field.getType(), 
field.getName());                        
-//                    } else {
-//                        propertyObj = getPropertyObj(field.getType(), 
propName);
-//                    }
-//                    
-//                    if (propertyObj != null)
-//                        ReflectionUtils.setField(field, bean, propertyObj);
-//                }
+
+                Property annotation = (Property) 
field.getAnnotation(getPropertyAnnotationType());
+                
+                if (annotation != null) {
+                    if (Modifier.isStatic(field.getModifiers())) {
+                        throw new IllegalStateException("Property annotation 
is not supported on static fields");
+                    }
+                    
+                    if (Modifier.isPrivate(field.getModifiers())) {
+                        throw new IllegalStateException("Property annotation 
is not supported on private fields");
+                    }
+
+                    ReflectionUtils.makeAccessible(field);
+                    
+                    Object propertyObj = null;
+                    String propName = annotation.name();
+                    if ("".equals(propName)) {
+                        propertyObj = 
propertyValue.getPropertyObj(field.getType(), field.getName());                 
       
+                    } else {
+                        propertyObj = 
propertyValue.getPropertyObj(field.getType(), propName);
+                    }
+                    
+                    if (propertyObj != null)
+                        ReflectionUtils.setField(field, bean, propertyObj);
+                }
             }
         });
     }
     
-    /**
-     * Processes a property descriptor to inject a service.
-     */
-    public Object getPropertyObj(Class requiredType, String name) {
-        
-        Object propertyObj = null;
-        
-//        List<ComponentProperty> props = component.getProperties();
-//        for (ComponentProperty prop : props) {
-//            if (prop.getName().equals(name)) {
-//                // On finding the property, create a factory for it and 
create a Bean using
-//                // the factory
-//                ObjectFactory factory = 
propertyFactory.createValueFactory(prop, prop.getValue(), requiredType);
-//                propertyObj = factory.getInstance();
-//            } // end if
-//        } // end for        
-        
-        return propertyObj;
-    }
-    
-    
     public void injectProperty(Object bean, PropertyDescriptor pd, Object 
propertyObj) {
         
         if (propertyObj != null) {
@@ -183,32 +158,4 @@
         }
     }
     
-    /**
-     * Processes a property descriptor to inject a service.
-     */
-    /*public void injectMethod(Object bean, Method method) {
-        PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);       
 
-
-        if (pd != null) {
-            Object propertyObj = null;
-            
-            List<ComponentProperty> props = component.getProperties();
-            for (ComponentProperty prop : props) {
-                if (prop.getName().equals(pd.getName())) {
-                    // On finding the property, create a factory for it and 
create a Bean using
-                    // the factory
-                    ObjectFactory factory = 
propertyFactory.createValueFactory(prop, prop.getValue(), pd.getPropertyType());
-                    propertyObj = factory.getInstance();
-                } // end if
-            } // end for
-
-            if (propertyObj != null) {
-                try {                                                       
-                    pd.getWriteMethod().invoke(bean, new Object[] { 
propertyObj });
-                } catch (Throwable e) {
-                    throw new FatalBeanException("Problem injecting property:  
" + e.getMessage(), e);
-                }
-            }
-        }
-    }*/
 }

Added: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java?rev=770692&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java
 (added)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/PropertyValueStub.java
 Fri May  1 14:36:14 2009
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.implementation.spring.processor;
+
+import java.lang.reflect.Method;
+
+public class PropertyValueStub {
+
+    private Object tie;
+    private Method getPropertyObj;
+    
+    public PropertyValueStub(Object tie) {
+        this.tie = tie;
+        Class<?> tieClass = tie.getClass();
+        try {
+            getPropertyObj = tieClass.getMethod("getPropertyObj", new 
Class<?>[]{Class.class, String.class});
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public Object getPropertyObj(Class<?> propertyType, String name) {
+        try {
+
+            return getPropertyObj.invoke(tie, propertyType, name);
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

Modified: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java?rev=770692&r1=770691&r2=770692&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/ReferenceAnnotationProcessor.java
 Fri May  1 14:36:14 2009
@@ -22,9 +22,10 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 
-import javax.naming.Reference;
-
+import org.oasisopen.sca.annotation.Reference;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.FatalBeanException;
 import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -33,13 +34,11 @@
 
 public class ReferenceAnnotationProcessor implements BeanPostProcessor {
 
-//    private Class<? extends Annotation> referenceAnnotationType = 
Reference.class;
-    private Class<? extends Annotation> referenceAnnotationType;
-    
-//    private RuntimeComponent component;
+    private Class<? extends Annotation> referenceAnnotationType = 
Reference.class;
+    private ComponentStub component;
     
-    public ReferenceAnnotationProcessor (Class<? extends Annotation> 
referenceAnnotationType, Object component) {
-        this.referenceAnnotationType = referenceAnnotationType;
+    public ReferenceAnnotationProcessor (ComponentStub component) {
+        this.component = component;
     }
     
     /**
@@ -87,98 +86,79 @@
 
         ReflectionUtils.doWithMethods(clazz, new 
ReflectionUtils.MethodCallback() {
             public void doWith(Method method) {
-                //Annotation annotation = 
method.getAnnotation(getReferenceAnnotationType());                
-//                Reference annotation = (Reference) 
method.getAnnotation(getReferenceAnnotationType());
-//                
-//                if (annotation != null) {
-//                    if (Modifier.isStatic(method.getModifiers())) {
-//                        throw new IllegalStateException("Reference 
annotation is not supported on static methods");
-//                    }
-//                    
-//                    if (Modifier.isPrivate(method.getModifiers())) {
-//                        throw new IllegalStateException("Reference 
annotation is not supported on private methods");
-//                    }
-//
-//                    if (method.getParameterTypes().length == 0) {
-//                        throw new IllegalStateException("Reference 
annotation requires at least one argument: " + method);
-//                    }
-//                    
-//                    PropertyDescriptor pd = 
BeanUtils.findPropertyForMethod(method);
-//                    if (pd != null) {
-//                        String refName = annotation.name();
-//                        if ("".equals(refName)) {
-//                            injectReference(bean, pd, pd.getName());
-//                        } else {
-//                            injectReference(bean, pd, refName);
-//                        }
-//                    }
-//                }
+
+                Reference annotation = (Reference) 
method.getAnnotation(getReferenceAnnotationType());
+                
+                if (annotation != null) {
+                    if (Modifier.isStatic(method.getModifiers())) {
+                        throw new IllegalStateException("Reference annotation 
is not supported on static methods");
+                    }
+                    
+                    if (Modifier.isPrivate(method.getModifiers())) {
+                        throw new IllegalStateException("Reference annotation 
is not supported on private methods");
+                    }
+
+                    if (method.getParameterTypes().length == 0) {
+                        throw new IllegalStateException("Reference annotation 
requires at least one argument: " + method);
+                    }
+                    
+                    PropertyDescriptor pd = 
BeanUtils.findPropertyForMethod(method);
+                    if (pd != null) {
+                        String refName = annotation.name();
+                        if ("".equals(refName)) {
+                            injectReference(bean, pd, pd.getName());
+                        } else {
+                            injectReference(bean, pd, refName);
+                        }
+                    }
+                }
             }
         });
         
         ReflectionUtils.doWithFields(clazz, new 
ReflectionUtils.FieldCallback() {
             public void doWith(Field field) {
-                //Annotation annotation = 
field.getAnnotation(getReferenceAnnotationType());                
-//                Reference annotation = (Reference) 
field.getAnnotation(getReferenceAnnotationType());
-//                
-//                if (annotation != null) {
-//                    if (Modifier.isStatic(field.getModifiers())) {
-//                        throw new IllegalStateException("Reference 
annotation is not supported on static fields");
-//                    }
-//                    
-//                    if (Modifier.isPrivate(field.getModifiers())) {
-//                        throw new IllegalStateException("Reference 
annotation is not supported on private fields");
-//                    }
-//
-//                    ReflectionUtils.makeAccessible(field);
-//                    
-//                    Object referenceObj = null;
-//                    String refName = annotation.name();
-//                    if ("".equals(refName)) {
-//                        referenceObj = 
component.getComponentContext().getService(field.getType(), field.getName());
-//                    } else {
-//                        referenceObj = 
component.getComponentContext().getService(field.getType(), refName);
-//                    }                        
-//                    
-//                    if (referenceObj != null)
-//                        ReflectionUtils.setField(field, bean, referenceObj);
-//                }
+
+                Reference annotation = (Reference) 
field.getAnnotation(getReferenceAnnotationType());
+                
+                if (annotation != null) {
+                    if (Modifier.isStatic(field.getModifiers())) {
+                        throw new IllegalStateException("Reference annotation 
is not supported on static fields");
+                    }
+                    
+                    if (Modifier.isPrivate(field.getModifiers())) {
+                        throw new IllegalStateException("Reference annotation 
is not supported on private fields");
+                    }
+
+                    ReflectionUtils.makeAccessible(field);
+                    
+                    Object referenceObj = null;
+                    String refName = annotation.name();
+                    if ("".equals(refName)) {
+                        referenceObj = component.getService(field.getType(), 
field.getName());
+                    } else {
+                        referenceObj = component.getService(field.getType(), 
refName);
+                    }                        
+                    
+                    if (referenceObj != null)
+                        ReflectionUtils.setField(field, bean, referenceObj);
+                }
             }
         });
     }
-    
+
     /**
      * Processes a property descriptor to inject a service.
      */
     public void injectReference(Object bean, PropertyDescriptor pd, String 
name) {
                
-//        Object referenceObj = 
component.getComponentContext().getService(pd.getPropertyType(), name);
-//        
-//        if (referenceObj != null) {
-//            try {                                                       
-//                pd.getWriteMethod().invoke(bean, new Object[] { referenceObj 
});
-//            } catch (Throwable e) {
-//                throw new FatalBeanException("Problem injecting reference:  
" + e.getMessage(), e);
-//            }
-//        }
-    }
-    
-    /**
-     * Processes a property descriptor to inject a service.
-     */
-    /*public void injectMethod(Object bean, Method method) {
-        PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);       
 
-
-        if (pd != null) {            
-            Object referenceObj = 
component.getComponentContext().getService(pd.getPropertyType(), pd.getName());
-
-            if (referenceObj != null) {
-                try {                                                       
-                    pd.getWriteMethod().invoke(bean, new Object[] { 
referenceObj });
-                } catch (Throwable e) {
-                    throw new FatalBeanException("Problem injecting reference: 
 " + e.getMessage(), e);
-                }
+        Object referenceObj = component.getReference(pd.getPropertyType(), 
name);
+        
+        if (referenceObj != null) {
+            try {                                                       
+                pd.getWriteMethod().invoke(bean, new Object[] { referenceObj 
});
+            } catch (Throwable e) {
+                throw new FatalBeanException("Problem injecting reference:  " 
+ e.getMessage(), e);
             }
         }
-    }*/
+    }
 }

Modified: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java?rev=770692&r1=770691&r2=770692&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringContextTie.java
 Fri May  1 14:36:14 2009
@@ -23,8 +23,13 @@
 import java.util.Iterator;
 import java.util.List;
 
+import 
org.apache.tuscany.sca.implementation.spring.processor.ComponentNameAnnotationProcessor;
+import org.apache.tuscany.sca.implementation.spring.processor.ComponentStub;
 import 
org.apache.tuscany.sca.implementation.spring.processor.ConstructorAnnotationProcessor;
 import 
org.apache.tuscany.sca.implementation.spring.processor.InitDestroyAnnotationProcessor;
+import 
org.apache.tuscany.sca.implementation.spring.processor.PropertyAnnotationProcessor;
+import 
org.apache.tuscany.sca.implementation.spring.processor.PropertyValueStub;
+import 
org.apache.tuscany.sca.implementation.spring.processor.ReferenceAnnotationProcessor;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -47,10 +52,12 @@
 public class SpringContextTie {
 
     private AbstractApplicationContext springContext;
+    private SpringImplementationStub implementation;
     
     public SpringContextTie(SpringImplementationStub implementation, URL 
resource) {
         SCAParentApplicationContext scaParentContext = new 
SCAParentApplicationContext(implementation);
-        springContext = createApplicationContext(scaParentContext, resource);  
      
+        springContext = createApplicationContext(scaParentContext, resource);  
+        this.implementation = implementation;
     }
 
     public void start() {
@@ -107,11 +114,11 @@
                         
                         if 
(beanClassName.indexOf(".ClassPathXmlApplicationContext") != -1) {              
                                                     
                                 appContext = new 
ClassPathXmlApplicationContext(listValues, false, scaParentContext);            
                       
-                                
//includeAnnotationProcessors(appContext.getBeanFactory());
+                                
includeAnnotationProcessors(appContext.getBeanFactory());
                                         return appContext;
                         } else {
                                 appContext = new 
FileSystemXmlApplicationContext(listValues, false, scaParentContext);           
                       
-                                
//includeAnnotationProcessors(appContext.getBeanFactory());
+                                
includeAnnotationProcessors(appContext.getBeanFactory());
                                         return appContext;
                         }
                 }               
@@ -136,25 +143,26 @@
     private void includeAnnotationProcessors(ConfigurableListableBeanFactory 
beanFactory) {
         
         // Processor to deal with @Init and @Destroy SCA Annotations
-//        BeanPostProcessor initDestroyProcessor = new 
InitDestroyAnnotationProcessor();
-//        beanFactory.addBeanPostProcessor(initDestroyProcessor);
+        BeanPostProcessor initDestroyProcessor = new 
InitDestroyAnnotationProcessor();
+        beanFactory.addBeanPostProcessor(initDestroyProcessor);
 
-// TODO: implement passing the component and property factory        
-//        // Processor to deal with @Reference SCA Annotations
+        ComponentStub component = null; //TODO
+        // Processor to deal with @Reference SCA Annotations
 //        BeanPostProcessor referenceProcessor = new 
ReferenceAnnotationProcessor(component);
 //        beanFactory.addBeanPostProcessor(referenceProcessor);
-//        
-//        // Processor to deal with @Property SCA Annotations
-//        BeanPostProcessor propertyProcessor = new 
PropertyAnnotationProcessor(propertyValueObjectFactory, component);
+        
+        PropertyValueStub pvs = null; //TODO
+        // Processor to deal with @Property SCA Annotations
+//        BeanPostProcessor propertyProcessor = new 
PropertyAnnotationProcessor(pvs);
 //        beanFactory.addBeanPostProcessor(propertyProcessor);
-//        
-//        // Processor to deal with @ComponentName SCA Annotations
-//        BeanPostProcessor componentNameProcessor = new 
ComponentNameAnnotationProcessor(component);
-//        beanFactory.addBeanPostProcessor(componentNameProcessor);
+        
+        // Processor to deal with @ComponentName SCA Annotations
+        BeanPostProcessor componentNameProcessor = new 
ComponentNameAnnotationProcessor(implementation.getComponentName());
+        beanFactory.addBeanPostProcessor(componentNameProcessor);
         
         // Processor to deal with @Constructor SCA Annotations
-//        BeanPostProcessor constructorProcessor = new 
ConstructorAnnotationProcessor();
-//        beanFactory.addBeanPostProcessor(constructorProcessor);         
+        BeanPostProcessor constructorProcessor = new 
ConstructorAnnotationProcessor();
+        beanFactory.addBeanPostProcessor(constructorProcessor);         
     }
 
 }

Modified: 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java?rev=770692&r1=770691&r2=770692&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java
 (original)
+++ 
tuscany/java/sca/modules/implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/runtime/context/SpringImplementationStub.java
 Fri May  1 14:36:14 2009
@@ -36,6 +36,7 @@
     Object tie;
     Method getURI;
     Method getBean;
+    Method getComponentName;
     
     public SpringImplementationStub(Object tie) {
         this.tie = tie;
@@ -43,6 +44,7 @@
         try {
             getURI = tieClass.getMethod("getURI", new Class<?>[]{});
             getBean = tieClass.getMethod("getBean", new 
Class<?>[]{String.class, Class.class});
+            getComponentName = tieClass.getMethod("getComponentName");
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
@@ -77,6 +79,16 @@
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
+    }
+
+    public String getComponentName() {
+        try {
+
+            return (String)getComponentName.invoke(tie);
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
 
     }
 }


Reply via email to