From c1ff0d7657686a89edc9e70a0b4c514cbb36ef20 Mon Sep 17 00:00:00 2001 From: edwardsmj Date: Thu, 16 Jul 2009 12:52:59 +0000 Subject: Correct handling of component @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 --- java/sca/modules/assembly/META-INF/MANIFEST.MF | 4 +- java/sca/modules/assembly/pom.xml | 6 +++ .../builder/impl/PropertyConfigurationUtil.java | 51 +++++++++++++++++----- .../sca/assembly/impl/ComponentPropertyImpl.java | 4 ++ 4 files changed, 52 insertions(+), 13 deletions(-) (limited to 'java/sca') 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 @@ Apache Tuscany SCA Assembly Model + + org.apache.tuscany.sca + tuscany-assembly-xsd + 2.0-SNAPSHOT + + org.apache.tuscany.sca tuscany-policy 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 element + Node property = node.getDocumentElement(); + // The first child of the element is a 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 element, use it directly in the result + newProperty.appendChild(document.importNode(result, true)); + } else { + // If the result is not a element, create a 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 } -- cgit v1.2.3