You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/10/09 18:35:30 UTC
svn commit: r583217 - in /incubator/tuscany/java/sca:
itest/properties/src/main/java/org/apache/tuscany/sca/itest/
itest/properties/src/main/resources/
itest/properties/src/test/java/org/apache/tuscany/sca/itest/
modules/assembly/src/main/java/org/apac...
Author: rfeng
Date: Tue Oct 9 09:35:27 2007
New Revision: 583217
URL: http://svn.apache.org/viewvc?rev=583217&view=rev
Log:
Apply the patch from Mark Combellack for TUSCANY-1823, TUSCANY-1839
Added:
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java (with props)
Modified:
incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/PropertyComponentImpl.java
incubator/tuscany/java/sca/itest/properties/src/main/resources/PropertyTest.composite
incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/PropertyTestCase.java
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
Modified: incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/PropertyComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/PropertyComponentImpl.java?rev=583217&r1=583216&r2=583217&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/PropertyComponentImpl.java (original)
+++ incubator/tuscany/java/sca/itest/properties/src/main/java/org/apache/tuscany/sca/itest/PropertyComponentImpl.java Tue Oct 9 09:35:27 2007
@@ -52,10 +52,10 @@
protected Collection<ComplexPropertyBean> complexPropertyFour;
@Property(name = "location")
- protected String location = "RTP";
+ protected String location;
@Property(name = "year")
- protected String year = "2006";
+ protected String year;
public String getLocation(){
return location;
Modified: incubator/tuscany/java/sca/itest/properties/src/main/resources/PropertyTest.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/main/resources/PropertyTest.composite?rev=583217&r1=583216&r2=583217&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/properties/src/main/resources/PropertyTest.composite (original)
+++ incubator/tuscany/java/sca/itest/properties/src/main/resources/PropertyTest.composite Tue Oct 9 09:35:27 2007
@@ -209,6 +209,9 @@
<cust:lastName>Sdo Lasting Name</cust:lastName>
</cust:customer>
</property>
+ <property name="location" type="xsd:string">RTP</property>
+ <property name="year" type="xsd:string">2006</property>
</component>
</composite>
+
Modified: incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/PropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/PropertyTestCase.java?rev=583217&r1=583216&r2=583217&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/PropertyTestCase.java (original)
+++ incubator/tuscany/java/sca/itest/properties/src/test/java/org/apache/tuscany/sca/itest/PropertyTestCase.java Tue Oct 9 09:35:27 2007
@@ -189,8 +189,7 @@
assertEquals("Sdo Lasting Name", dataObject.getString("lastName"));
}
- // FIXME: Uncomment the @Test to enable this test case (TUSCANY-1832)
- // @Test
+ @Test
public void testGetLocationFromComponentContext() {
String location = propertyService.getLocation();
assertNotNull(location);
Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java?rev=583217&r1=583216&r2=583217&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java Tue Oct 9 09:35:27 2007
@@ -47,14 +47,14 @@
/**
* Returns the default value of the property.
*
- * @return the default value of ths property
+ * @return the default value of this property
*/
Object getValue();
/**
* Sets the default value of the property.
*
- * @param defaultValue the default value of ths property
+ * @param defaultValue the default value of this property
*/
void setValue(Object defaultValue);
@@ -115,7 +115,7 @@
* Sets the element defining the data type of this property. This is the
* qualified name of an XML schema element.
*
- * @param type the element defining the type of this property
+ * @param element the element defining the type of this property
*/
void setXSDElement(QName element);
Added: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java?rev=583217&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java (added)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java Tue Oct 9 09:35:27 2007
@@ -0,0 +1,38 @@
+/*
+ * 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.context;
+
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+
+/**
+ * Interface implemented by the provider of the property values
+ */
+public interface PropertyValueFactory {
+
+ /**
+ * This method will create an instance of the value for the specified Property.
+ *
+ * @param property The Property from which to retrieve the property value
+ * @param type The type of the property value being retrieved from the Property
+ * @param <B> Type type of the property value being looked up
+ *
+ * @return the value for the Property
+ */
+ <B> B createPropertyValue(ComponentProperty property, Class<B> type);
+}
Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java?rev=583217&r1=583216&r2=583217&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java Tue Oct 9 09:35:27 2007
@@ -32,6 +32,7 @@
import org.apache.tuscany.sca.assembly.OptimizableBinding;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.context.PropertyValueFactory;
import org.apache.tuscany.sca.context.RequestContextFactory;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
@@ -64,6 +65,15 @@
private final AssemblyFactory assemblyFactory;
private final JavaInterfaceFactory javaInterfaceFactory;
+ /**
+ * This is a reference to the PropertyValueFactory that is provided by the Implementation
+ * that can be used to get the value from a Property Object.
+ *
+ * @see #setPropertyValueFactory(PropertyValueFactory)
+ * @see #getProperty(Class, String)
+ */
+ private PropertyValueFactory propertyFactory;
+
public ComponentContextImpl(CompositeActivator compositeActivator,
AssemblyFactory assemblyFactory,
ProxyFactory proxyFactory,
@@ -108,10 +118,36 @@
}
}
+ /**
+ * The Implementation is responsible for calling this method to set the
+ * PropertyValueFactory that is used to get the Property Value from
+ * a Tuscany Property object.
+ *
+ * @param factory The PropertyValueFactory to use
+ *
+ * @see #getProperty(Class, String)
+ */
+ public void setPropertyValueFactory(PropertyValueFactory factory)
+ {
+ propertyFactory = factory;
+ }
+
+ /**
+ * Gets the value for the specified property with the specified type.
+ *
+ * @param type The type of the property value we are getting
+ * @param propertyName The name of the property we are getting
+ * @param B The class of the property value we are getting
+ *
+ * @throws ServiceRuntimeException If a Property for the specified propertyName
+ * is not found
+ *
+ * @see #setPropertyValueFactory(PropertyValueFactory)
+ */
public <B> B getProperty(Class<B> type, String propertyName) {
for (ComponentProperty p : component.getProperties()) {
if (propertyName.equals(p.getName())) {
- return type.cast(p.getValue());
+ return propertyFactory.createPropertyValue(p, type);
}
}
throw new ServiceRuntimeException("Property not found: " + propertyName);
Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java?rev=583217&r1=583216&r2=583217&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java Tue Oct 9 09:35:27 2007
@@ -22,7 +22,9 @@
import java.util.List;
import java.util.StringTokenizer;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.context.PropertyValueFactory;
import org.apache.tuscany.sca.core.factory.ObjectCreationException;
import org.apache.tuscany.sca.core.factory.ObjectFactory;
import org.apache.tuscany.sca.databinding.Mediator;
@@ -37,7 +39,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-public class JavaPropertyValueObjectFactory {
+public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
private Mediator mediator = null;
private boolean isSimpleType;
@@ -198,5 +200,20 @@
return instances;
}
}
+ }
+
+ /**
+ * This method will create an instance of the value for the specified Property.
+ *
+ * @param property The Property from which to retrieve the property value
+ * @param type The type of the property value being retrieved from the Property
+ * @param <B> Type type of the property value being looked up
+ *
+ * @return the value for the Property
+ */
+ public <B> B createPropertyValue(ComponentProperty property, Class<B> type)
+ {
+ ObjectFactory<B> factory = this.createValueFactory(property, property.getValue(), type);
+ return factory.getInstance();
}
}
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=583217&r1=583216&r2=583217&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 Tue Oct 9 09:35:27 2007
@@ -35,6 +35,7 @@
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.context.ComponentContextFactory;
import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.context.ComponentContextImpl;
import org.apache.tuscany.sca.core.context.InstanceWrapper;
import org.apache.tuscany.sca.core.factory.ObjectCreationException;
import org.apache.tuscany.sca.core.factory.ObjectFactory;
@@ -221,6 +222,13 @@
}
}
}
+
+ // 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();
+ ccImpl.setPropertyValueFactory(propertyValueFactory);
+
setUpPolicyHandlers();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org