diff options
author | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-16 12:52:59 +0000 |
---|---|---|
committer | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-16 12:52:59 +0000 |
commit | c1ff0d7657686a89edc9e70a0b4c514cbb36ef20 (patch) | |
tree | c8cf46f781ca2b99eeba2497bfa84a89b6214a32 /java/sca/modules/assembly/src | |
parent | 3ce45cf08490efd5a3ab8bab1f8eae9dbd375851 (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/sca/modules/assembly/src')
2 files changed, 43 insertions, 12 deletions
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 } |