tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r428519 - in /incubator/tuscany/java/sca: core/src/main/java/org/apache/tuscany/core/loader/ core/src/test/java/org/apache/tuscany/core/loader/ spi/src/main/java/org/apache/tuscany/spi/model/
Date Thu, 03 Aug 2006 20:45:01 GMT
Author: jboynes
Date: Thu Aug  3 13:45:00 2006
New Revision: 428519

URL: http://svn.apache.org/viewvc?rev=428519&view=rev
Log:
parse source attribute on property values

Modified:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java
    incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java?rev=428519&r1=428518&r2=428519&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
(original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
Thu Aug  3 13:45:00 2006
@@ -132,7 +132,8 @@
         return (Implementation<?>) o;
     }
 
-    protected void loadProperty(XMLStreamReader reader, DeploymentContext deploymentContext,
+    protected void loadProperty(XMLStreamReader reader,
+                                DeploymentContext deploymentContext,
                                 ComponentDefinition<?> componentDefinition)
         throws XMLStreamException, LoaderException {
         String name = reader.getAttributeValue(null, "name");
@@ -142,7 +143,14 @@
         if (property == null) {
             throw new UndefinedPropertyException(name);
         }
-        componentDefinition.add(createPropertyValue(reader, property, name));
+        PropertyValue<?> propertyValue;
+        String source = reader.getAttributeValue(null, "source");
+        if (source != null) {
+            propertyValue = new PropertyValue(name, source);
+        } else {
+            propertyValue = createPropertyValue(reader, property, name);
+        }
+        componentDefinition.add(propertyValue);
     }
 
     private <T> PropertyValue<T> createPropertyValue(XMLStreamReader reader,
@@ -177,31 +185,4 @@
         }
         componentDefinition.add(referenceTarget);
     }
-
-/*
-    protected StAXPropertyFactory<?> getPropertyFactory(String factoryName,
-        ResourceLoader resourceLoader) throws InvalidPropertyFactoryException {
-        Class<?> impl;
-        try {
-            // try to load factory from application classloader
-            impl = resourceLoader.loadClass(factoryName);
-        } catch (ClassNotFoundException e) {
-            try {
-                // try to load factory from container classloader
-                impl = Class.forName(factoryName);
-            } catch (ClassNotFoundException e1) {
-                throw new InvalidPropertyFactoryException(factoryName, e);
-            }
-        }
-        try {
-            return (StAXPropertyFactory<?>) impl.newInstance();
-        } catch (InstantiationException e) {
-            throw new InvalidPropertyFactoryException(factoryName, e);
-        } catch (IllegalAccessException e) {
-            throw new InvalidPropertyFactoryException(factoryName, e);
-        } catch (ClassCastException e) {
-            throw new InvalidPropertyFactoryException(factoryName, e);
-        }
-    }
-*/
 }

Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java?rev=428519&r1=428518&r2=428519&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java
(original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java
Thu Aug  3 13:45:00 2006
@@ -28,10 +28,17 @@
 import org.apache.tuscany.spi.loader.StAXPropertyFactory;
 import org.apache.tuscany.spi.model.ComponentDefinition;
 import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
 
 import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.apache.tuscany.core.implementation.PojoComponentType;
+
 import org.jmock.Mock;
 import org.jmock.MockObjectTestCase;
+import static org.easymock.EasyMock.*;
+import org.easymock.EasyMock;
 
 /**
  * @version $Rev$ $Date$
@@ -74,12 +81,30 @@
         assertEquals(Integer.valueOf(20), component.getInitLevel());
     }
 
+    public void testLoadPropertyWithSource() throws LoaderException, XMLStreamException {
+        PojoComponentType<?,?,Property<?>> type =
+            new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+        Property property = new Property();
+        property.setName("name");
+        type.add(property);
+        JavaImplementation impl = new JavaImplementation();
+        impl.setComponentType(type);
+        ComponentDefinition<?> defn = new ComponentDefinition<JavaImplementation>(impl);
+        XMLStreamReader reader = createMock(XMLStreamReader.class);
+        expect(reader.getAttributeValue(null, "name")).andReturn("name");
+        expect(reader.getAttributeValue(null, "source")).andReturn("$source");
+        replay(reader);
+        loader.loadProperty(reader, null, defn);
+        assertEquals("$source", defn.getPropertyValues().get("name").getSource());
+        EasyMock.verify(reader);
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         mockReader = mock(XMLStreamReader.class);
         mockRegistry = mock(LoaderRegistry.class);
         mockPropertyFactory = mock(StAXPropertyFactory.class);
         loader = new ComponentLoader((LoaderRegistry) mockRegistry.proxy(),
-            (StAXPropertyFactory) mockPropertyFactory.proxy());
+                                     (StAXPropertyFactory) mockPropertyFactory.proxy());
     }
 }

Modified: incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java?rev=428519&r1=428518&r2=428519&view=diff
==============================================================================
--- incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java
(original)
+++ incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java
Thu Aug  3 13:45:00 2006
@@ -25,22 +25,59 @@
  */
 public class PropertyValue<T> extends ModelObject {
     private String name;
+    private String source;
     private ObjectFactory<T> valueFactory;
 
     public PropertyValue() {
     }
 
+    /**
+     * Constructor specifying the name of a property and the XPath source expression.
+     *
+     * @param name the name of the property which this value is for
+     * @param source an XPath expression whose result will be the actual value
+     */
+    public PropertyValue(String name, String source) {
+        this.name = name;
+        this.source = source;
+    }
+
     public PropertyValue(String name, ObjectFactory<T> valueFactory) {
         this.name = name;
         this.valueFactory = valueFactory;
     }
 
+    /**
+     * Returns the name of the property that this value is for.
+     * @return the name of the property that this value is for
+     */
     public String getName() {
         return name;
     }
 
+    /**
+     * Sets the name of the property that this value is for.
+     * @param name the name of the property that this value is for
+     */
     public void setName(String name) {
         this.name = name;
+    }
+
+    /**
+     * Returns an XPath expression that should be evaluated to get the actual property value.
+     *
+     * @return an XPath expression that should be evaluated to get the actual property value
+     */
+    public String getSource() {
+        return source;
+    }
+
+    /**
+     * Sets an XPath expression that should be evaluated to get the actual property value.
+     * @param source an XPath expression that should be evaluated to get the actual property
value
+     */
+    public void setSource(String source) {
+        this.source = source;
     }
 
     public ObjectFactory<T> getValueFactory() {



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message