From e16b71858955a18e5e82b23eb9c1f920834a2b8f Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 20 Aug 2009 02:58:09 +0000 Subject: Fix for ASM_5026 related property processing git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@806026 13f79535-47bb-0310-9956-ffa450edef68 --- .../builder/impl/PropertyConfigurationUtil.java | 53 +++++++++++----------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'java/sca/modules/assembly') 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 b9da3301ea..7a91e4da18 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 @@ -62,25 +62,25 @@ import org.xml.sax.InputSource; */ abstract class PropertyConfigurationUtil { - /** - * 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 + /** + * 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; @@ -89,25 +89,24 @@ abstract class PropertyConfigurationUtil { if (result instanceof Document) { return (Document)result; } else { - Document document = documentBuilderFactory.newDocumentBuilder().newDocument(); + 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)); + + if (result.getNodeType() == Node.ELEMENT_NODE) { + // 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); + // 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 { URI uri = URI.create(file); -- cgit v1.2.3