Author: rfeng
Date: Mon Oct 29 14:49:08 2007
New Revision: 589874

URL: http://svn.apache.org/viewvc?rev=589874&view=rev
Log:
Fix for TUSCANY-1875

Added:
    
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/
    
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Bar.java
   (with props)
    
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo1.java
   (with props)
    
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo2.java
   (with props)
    
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo3.java
   (with props)
    
incubator/tuscany/java/sca/itest/properties/src/main/resources/ConstructorPropertyInjection.composite
    
incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/cdi/
    
incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/cdi/ConstructorPropertyInjectionTestCase.java
   (with props)
Modified:
    
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java

Added: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Bar.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Bar.java?rev=589874&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Bar.java
 (added)
+++ 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Bar.java
 Mon Oct 29 14:49:08 2007
@@ -0,0 +1,23 @@
+/*
+ * 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.itest.cdi;
+
+public interface Bar {
+    public String getBar();
+}

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Bar.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Bar.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo1.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo1.java?rev=589874&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo1.java
 (added)
+++ 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo1.java
 Mon Oct 29 14:49:08 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.itest.cdi;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Service;
+
[EMAIL PROTECTED](Bar.class)
+public class Foo1 implements Bar {
+
+    @Property
+    protected String bar;
+
+    @Constructor( {"bar"})
+    public Foo1(String b) {
+        this.bar = b;
+    }
+
+    public String getBar() {
+        return this.bar;
+    }
+}

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo1.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo2.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo2.java?rev=589874&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo2.java
 (added)
+++ 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo2.java
 Mon Oct 29 14:49:08 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.itest.cdi;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Service;
+
[EMAIL PROTECTED](Bar.class)
+public class Foo2 implements Bar {
+
+    protected String bar;
+
+    @Constructor
+    public Foo2(@Property(name = "bar") String b) {
+        this.bar = b;
+    }
+
+    public String getBar() {
+        return this.bar;
+    }
+
+}

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo2.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo3.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo3.java?rev=589874&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo3.java
 (added)
+++ 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo3.java
 Mon Oct 29 14:49:08 2007
@@ -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.sca.itest.cdi;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Service;
+
[EMAIL PROTECTED](Bar.class)
+public class Foo3 implements Bar {
+
+    protected String bar;
+
+    @Constructor
+    public Foo3() {
+        this.bar = "bar";
+    }
+
+    public String getBar() {
+        return this.bar;
+    }
+
+    @Property(name = "bar")
+    public void setBar(String b) {
+        this.bar = b;
+    }
+
+}

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo3.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/cdi/Foo3.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/java/sca/itest/properties/src/main/resources/ConstructorPropertyInjection.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/main/resources/ConstructorPropertyInjection.composite?rev=589874&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/properties/src/main/resources/ConstructorPropertyInjection.composite
 (added)
+++ 
incubator/tuscany/java/sca/itest/properties/src/main/resources/ConstructorPropertyInjection.composite
 Mon Oct 29 14:49:08 2007
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+       * 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.    
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0";
+       name="ConstructorPropertyInjection">
+
+       <component name="Foo1Component">
+               <implementation.java
+                       class="org.apache.tuscany.sca.itest.cdi.Foo1" />
+               <property name="bar">fubar</property>
+       </component>
+
+       <component name="Foo2Component">
+               <implementation.java
+                       class="org.apache.tuscany.sca.itest.cdi.Foo2" />
+               <property name="bar">fubar</property>
+       </component>
+
+       <component name="Foo3Component">
+               <implementation.java
+                       class="org.apache.tuscany.sca.itest.cdi.Foo3" />
+               <property name="bar">fubar</property>
+       </component>
+
+</composite>
\ No newline at end of file

Added: 
incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/cdi/ConstructorPropertyInjectionTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/cdi/ConstructorPropertyInjectionTestCase.java?rev=589874&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/cdi/ConstructorPropertyInjectionTestCase.java
 (added)
+++ 
incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/cdi/ConstructorPropertyInjectionTestCase.java
 Mon Oct 29 14:49:08 2007
@@ -0,0 +1,26 @@
+package org.apache.tuscany.sca.itest.cdi;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+public class ConstructorPropertyInjectionTestCase extends TestCase {
+
+    public void testFoo1() throws Exception {
+        SCADomain sca = 
SCADomain.newInstance("ConstructorPropertyInjection.composite");
+        Bar foo = sca.getService(Bar.class, "Foo1Component");
+        assertEquals("fubar", foo.getBar());
+    }
+
+    public void testFoo2() throws Exception {
+        SCADomain sca = 
SCADomain.newInstance("ConstructorPropertyInjection.composite");
+        Bar foo = sca.getService(Bar.class, "Foo2Component");
+        assertEquals("fubar", foo.getBar());
+    }
+
+    public void testFoo3() throws Exception {
+        SCADomain sca = 
SCADomain.newInstance("ConstructorPropertyInjection.composite");
+        Bar foo = sca.getService(Bar.class, "Foo3Component");
+        assertEquals("fubar", foo.getBar());
+    }
+}

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/cdi/ConstructorPropertyInjectionTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/cdi/ConstructorPropertyInjectionTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java?rev=589874&r1=589873&r2=589874&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
 Mon Oct 29 14:49:08 2007
@@ -46,6 +46,7 @@
 import org.apache.tuscany.sca.core.scope.ScopeContainer;
 import org.apache.tuscany.sca.core.scope.TargetResolutionException;
 import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
 import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
 import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
 import 
org.apache.tuscany.sca.implementation.java.injection.ConversationIDObjectFactory;
@@ -56,7 +57,6 @@
 import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.policy.PolicySet;
-import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 import org.apache.tuscany.sca.policy.util.PolicyHandler;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
@@ -112,13 +112,22 @@
         JavaElementImpl element =
             
instanceFactoryProvider.getImplementation().getPropertyMembers().get(configuredProperty.getName());
 
-        if (element != null && !(element.getAnchor() instanceof Constructor) 
&& configuredProperty.getValue() != null) {
-            instanceFactoryProvider.getInjectionSites().add(element);
+        if (element != null && configuredProperty.getValue() != null) {
+            if (!(element.getAnchor() instanceof Constructor)) {
+                instanceFactoryProvider.getInjectionSites().add(element);
+            }
 
             //Class propertyJavaType = 
JavaIntrospectionHelper.getBaseType(element.getType(), 
element.getGenericType());
             ObjectFactory<?> propertyObjectFactory =
                 createPropertyValueFactory(configuredProperty, 
configuredProperty.getValue(), element);
             instanceFactoryProvider.setObjectFactory(element, 
propertyObjectFactory);
+            
+            JavaConstructorImpl constructor = 
instanceFactoryProvider.getImplementation().getConstructor();
+            for(JavaElementImpl p: constructor.getParameters()){
+                if(element.getName().equals(p.getName())) {
+                    instanceFactoryProvider.setObjectFactory(p, 
propertyObjectFactory);
+                }
+            }
         }
     }
 
@@ -201,6 +210,12 @@
                         factories.add(factory);
                     }
                     instanceFactoryProvider.setObjectFactories(element, 
factories);
+                    JavaConstructorImpl constructor = 
instanceFactoryProvider.getImplementation().getConstructor();
+                    for(JavaElementImpl p: constructor.getParameters()){
+                        if(element.getName().equals(p.getName())) {
+                            instanceFactoryProvider.setObjectFactories(p, 
factories);
+                        }
+                    }
                 } else {
                     if (wireList == null && ref.getMultiplicity() == 
Multiplicity.ONE_ONE) {
                         throw new IllegalStateException("Required reference is 
missing: " + ref.getName());
@@ -218,17 +233,23 @@
                             factory = createObjectFactory(element.getType(), 
wireList.get(0));
                         }
                         instanceFactoryProvider.setObjectFactory(element, 
factory);
+                        JavaConstructorImpl constructor = 
instanceFactoryProvider.getImplementation().getConstructor();
+                        for(JavaElementImpl p: constructor.getParameters()){
+                            if(element.getName().equals(p.getName())) {
+                                instanceFactoryProvider.setObjectFactory(p, 
factory);
+                            }
+                        }
                     }
                 }
             }
         }
-        
+
         // We need to set the PropertyValueFactory on the ComponentContextImpl
         // so the ComponentContext can "de-marshal" the property type to a 
value 
         // when the getProperty() method is called
-        ComponentContextImpl ccImpl = (ComponentContextImpl) 
component.getComponentContext();
+        ComponentContextImpl ccImpl = 
(ComponentContextImpl)component.getComponentContext();
         ccImpl.setPropertyValueFactory(propertyValueFactory);
-        
+
         setUpPolicyHandlers();
     }
 
@@ -276,12 +297,12 @@
         Class<?> implClass = instanceFactoryProvider.getImplementationClass();
 
         Method method = JavaInterfaceUtil.findMethod(implClass, operation);
-        
+
         /*if ( component.getImplementation() instanceof PolicySetAttachPoint  
&&
               
!((PolicySetAttachPoint)component.getImplementation()).getPolicySets().isEmpty()
 ) {
             return new PoliciedJavaImplementationInvoker(operation, method, 
component, policyHandlers);
         } else {*/
-            return new JavaImplementationInvoker(operation, method, component);
+        return new JavaImplementationInvoker(operation, method, component);
         //}
     }
 
@@ -341,9 +362,11 @@
         return new WireObjectFactory<B>(interfaze, wire, proxyFactory);
     }
 
-    private ObjectFactory<?> createPropertyValueFactory(ComponentProperty 
property, Object propertyValue, JavaElementImpl javaElement) {
+    private ObjectFactory<?> createPropertyValueFactory(ComponentProperty 
property,
+                                                        Object propertyValue,
+                                                        JavaElementImpl 
javaElement) {
         return propertyValueFactory.createValueFactory(property, 
propertyValue, javaElement);
-    } 
+    }
 
     /**
      * @return the component
@@ -351,15 +374,15 @@
     RuntimeComponent getComponent() {
         return component;
     }
-    
+
     private void setUpPolicyHandlers() {
-        for ( PolicyHandler policyHandler : policyHandlers.values() ) {
+        for (PolicyHandler policyHandler : policyHandlers.values()) {
             policyHandler.setUp(component.getImplementation());
         }
     }
-    
+
     private void cleanUpPolicyHandlers() {
-        for ( PolicyHandler policyHandler : policyHandlers.values() ) {
+        for (PolicyHandler policyHandler : policyHandlers.values()) {
             policyHandler.cleanUp(this);
         }
     }



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

Reply via email to