summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authoredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2009-07-16 12:52:59 +0000
committeredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2009-07-16 12:52:59 +0000
commitc1ff0d7657686a89edc9e70a0b4c514cbb36ef20 (patch)
treec8cf46f781ca2b99eeba2497bfa84a89b6214a32 /java
parent3ce45cf08490efd5a3ab8bab1f8eae9dbd375851 (diff)
Correct handling of component <property/> @source attribute when dealing with a target property that has a complex type - TUSCANY-3157
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@794657 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/assembly/META-INF/MANIFEST.MF4
-rw-r--r--java/sca/modules/assembly/pom.xml6
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java51
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java4
4 files changed, 52 insertions, 13 deletions
diff --git a/java/sca/modules/assembly/META-INF/MANIFEST.MF b/java/sca/modules/assembly/META-INF/MANIFEST.MF
index 544337cd89..51a858cda1 100644
--- a/java/sca/modules/assembly/META-INF/MANIFEST.MF
+++ b/java/sca/modules/assembly/META-INF/MANIFEST.MF
@@ -36,11 +36,13 @@ Import-Package: javax.xml.namespace,
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",
diff --git a/java/sca/modules/assembly/pom.xml b/java/sca/modules/assembly/pom.xml
index f5b8657ef5..c351aa698d 100644
--- a/java/sca/modules/assembly/pom.xml
+++ b/java/sca/modules/assembly/pom.xml
@@ -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>
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java
index 283843498e..abbcf5591d 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java
@@ -52,6 +52,10 @@ import org.w3c.dom.Element;
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 @@ import org.xml.sax.InputSource;
*/
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 {
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java
index 5cb1693799..9db522930f 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java
@@ -89,5 +89,9 @@ public class ComponentPropertyImpl extends PropertyImpl implements ComponentProp
public void setSourceXPathExpression(XPathExpression sourceXPathExpression) {
this.sourceXPathExpression = sourceXPathExpression;
}
+
+ public String toString() {
+ return "Property: " + getName() + " Value: " + getValue();
+ } // end method toString
}