You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ed...@apache.org on 2009/07/16 14:52:59 UTC

svn commit: r794657 - in /tuscany/java/sca/modules/assembly: ./ META-INF/ src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ src/main/java/org/apache/tuscany/sca/assembly/impl/

Author: edwardsmj
Date: Thu Jul 16 12:52:59 2009
New Revision: 794657

URL: http://svn.apache.org/viewvc?rev=794657&view=rev
Log:
Correct handling of component <property/> @source attribute when dealing with a target property that has a complex type - TUSCANY-3157

Modified:
    tuscany/java/sca/modules/assembly/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/assembly/pom.xml
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java
    tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java

Modified: tuscany/java/sca/modules/assembly/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/META-INF/MANIFEST.MF?rev=794657&r1=794656&r2=794657&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/assembly/META-INF/MANIFEST.MF Thu Jul 16 12:52:59 2009
@@ -36,11 +36,13 @@
  org.apache.tuscany.sca.assembly;version="2.0.0",
  org.apache.tuscany.sca.assembly.builder;version="2.0.0",
  org.apache.tuscany.sca.assembly.impl;version="2.0.0",
+ org.apache.tuscany.sca.assembly.xsd;version="2.0.0",
  org.apache.tuscany.sca.core;version="2.0.0",
  org.apache.tuscany.sca.definitions;version="2.0.0",
  org.apache.tuscany.sca.extensibility;version="2.0.0",
  org.apache.tuscany.sca.interfacedef;version="2.0.0",
- org.apache.tuscany.sca.interfacedef.impl;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.interfacedef.impl;version="2.0.0";
+ resolution:=optional,
  org.apache.tuscany.sca.monitor;version="2.0.0",
  org.apache.tuscany.sca.policy;version="2.0.0",
  org.apache.tuscany.sca.policy.util;version="2.0.0",

Modified: tuscany/java/sca/modules/assembly/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/pom.xml?rev=794657&r1=794656&r2=794657&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/pom.xml (original)
+++ tuscany/java/sca/modules/assembly/pom.xml Thu Jul 16 12:52:59 2009
@@ -29,6 +29,12 @@
     <name>Apache Tuscany SCA Assembly Model</name>
 
     <dependencies>
+    	<dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-assembly-xsd</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>
+        
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-policy</artifactId>

Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java?rev=794657&r1=794656&r2=794657&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java Thu Jul 16 12:52:59 2009
@@ -52,6 +52,10 @@
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 
+import static org.apache.tuscany.sca.assembly.xsd.Constants.PROPERTY;
+import static org.apache.tuscany.sca.assembly.xsd.Constants.SCA11_NS;
+import static org.apache.tuscany.sca.assembly.xsd.Constants.VALUE;
+
 /**
  * Utility class to deal with processing of component properties that are taking values from the parent 
  * composite's properties or an external file.
@@ -60,28 +64,51 @@
  */
 abstract class PropertyConfigurationUtil {
 
-    private static Document evaluate(Document node,
-                                     XPathExpression expression,
-                                     DocumentBuilderFactory documentBuilderFactory) throws XPathExpressionException,
-        ParserConfigurationException {
-
-        Node value = node.getDocumentElement();
+	/**
+	 * Evaluate an XPath expression against a Property value, returning the result as a Property value
+	 * @param node - the document root element of a Property value
+	 * @param expression - the XPath expression
+	 * @param documentBuilderFactory - a DOM document builder factory
+	 * @return - a DOM Document representing the result of the evaluation as a Property value
+	 * @throws XPathExpressionException
+	 * @throws ParserConfigurationException
+	 */
+    private static Document evaluate(Document node, 
+    		                         XPathExpression expression, 
+    		                         DocumentBuilderFactory documentBuilderFactory) throws XPathExpressionException, 
+    	ParserConfigurationException {
+
+    	// The document element is a <sca:property/> element
+        Node property = node.getDocumentElement();
+        // The first child of the <property/> element is a <value/> element
+        Node value = property.getFirstChild();
+        
         Node result = (Node)expression.evaluate(value, XPathConstants.NODE);
         if (result == null) {
             return null;
         }
 
-        // TODO: How to wrap the result into a Document?
-        Document document = documentBuilderFactory.newDocumentBuilder().newDocument();
         if (result instanceof Document) {
             return (Document)result;
         } else {
-            //Element root = document.createElementNS(null, "value");
-            //document.appendChild(root);
-            document.appendChild(document.importNode(result, true));
+        	Document document = documentBuilderFactory.newDocumentBuilder().newDocument();
+            Element newProperty = document.createElementNS(SCA11_NS, PROPERTY);
+            
+            if( VALUE.equals(result.getLocalName()) ) {
+            	// If the result is a <value/> element, use it directly in the result
+            	newProperty.appendChild(document.importNode(result, true));
+            } else {
+            	// If the result is not a <value/> element, create a <value/> element to contain the result
+            	Element newValue = document.createElementNS(SCA11_NS, VALUE);
+            	newValue.appendChild(document.importNode(result, true));
+            	newProperty.appendChild(newValue);
+            } // end if
+            document.appendChild(newProperty);
+            
             return document;
         }
-    }
+    } // end method evaluate
+
 
     private static Document loadFromFile(String file, TransformerFactory transformerFactory)
         throws MalformedURLException, IOException, TransformerException, ParserConfigurationException {

Modified: tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java?rev=794657&r1=794656&r2=794657&view=diff
==============================================================================
--- tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java (original)
+++ tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java Thu Jul 16 12:52:59 2009
@@ -89,5 +89,9 @@
     public void setSourceXPathExpression(XPathExpression sourceXPathExpression) {
         this.sourceXPathExpression = sourceXPathExpression;
     }
+    
+    public String toString() {
+    	return "Property: " + getName() + " Value: " + getValue();
+    } // end method toString
 
 }