From fbec6122ef4823cf488981d22f9e567034cb1953 Mon Sep 17 00:00:00 2001 From: Andreas Veithen Date: Sat, 20 May 2017 18:27:25 +0100 Subject: [PATCH] SWS-1004 - Use Axiom's getSAXResult method instead of the custom AxiomResult class --- .../ws/soap/axiom/AxiomHandler.java | 244 ------------------ .../ws/soap/axiom/AxiomResult.java | 61 ----- .../ws/soap/axiom/AxiomSoapFaultDetail.java | 2 +- .../axiom/AxiomSoapFaultDetailElement.java | 2 +- .../ws/soap/axiom/AxiomSoapHeader.java | 2 +- .../ws/soap/axiom/AxiomSoapHeaderElement.java | 2 +- .../ws/soap/axiom/CachingPayload.java | 2 +- .../ws/soap/axiom/AxiomHandlerTest.java | 244 ------------------ 8 files changed, 5 insertions(+), 554 deletions(-) delete mode 100644 spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java delete mode 100644 spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomResult.java delete mode 100644 spring-ws-core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java deleted file mode 100644 index 47b30ac7..00000000 --- a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright 2005-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ws.soap.axiom; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.xml.XMLConstants; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamConstants; - -import org.apache.axiom.om.OMAttribute; -import org.apache.axiom.om.OMContainer; -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMFactory; -import org.apache.axiom.om.OMNamespace; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.ext.LexicalHandler; - -import org.springframework.util.Assert; -import org.springframework.xml.namespace.QNameUtils; - -/** - * Specific SAX {@link ContentHandler} and {@link LexicalHandler} that adds the resulting - * AXIOM OMElement to a specified parent element when {@code endDocument} is called. - * Used for returing {@code SAXResult}s from Axiom elements. - * @author Arjen Poutsma - * @author Tommy Winther - * @since 1.0.0 - */ -class AxiomHandler implements ContentHandler, LexicalHandler { - - private final OMFactory factory; - - private final List elements = new ArrayList(); - - private final OMContainer container; - - private int charactersType = XMLStreamConstants.CHARACTERS; - - private List> namespaceMappings = - new ArrayList>(); - - AxiomHandler(OMContainer container, OMFactory factory) { - Assert.notNull(container, "'container' must not be null"); - Assert.notNull(factory, "'factory' must not be null"); - this.factory = factory; - this.container = container; - } - - private OMContainer getParent() { - if (!elements.isEmpty()) { - return elements.get(elements.size() - 1); - } - else { - return container; - } - } - - @Override - public void startDocument() throws SAXException { - removeAllNamespaceMappings(); - newNamespaceMapping(); - } - - @Override - public void endDocument() throws SAXException { - removeAllNamespaceMappings(); - } - - @Override - public void startPrefixMapping(String prefix, String uri) throws SAXException { - currentNamespaceMapping().put(prefix, uri); - } - - @Override - public void endPrefixMapping(String prefix) throws SAXException { - currentNamespaceMapping().remove(prefix); - } - - @Override - public void startElement(String uri, String localName, String qName, - Attributes attributes) throws SAXException { - OMContainer parent = getParent(); - OMNamespace ns = factory.createOMNamespace(uri, - QNameUtils.toQName(uri, qName).getPrefix()); - OMElement element = factory.createOMElement(localName, ns, parent); - - // declare namespaces - Map namespaceMappings = currentNamespaceMapping(); - for (Map.Entry entry : namespaceMappings.entrySet()) { - String prefix = entry.getKey(); - String namespaceUri = entry.getValue(); - - if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { - element.declareDefaultNamespace(namespaceUri); - } else { - element.declareNamespace(namespaceUri, prefix); - } - } - // declare attributes - for (int i = 0; i < attributes.getLength(); i++) { - QName attrName = - QNameUtils.toQName(attributes.getURI(i), attributes.getQName(i)); - if (!isNamespaceDeclaration(attrName)) { - OMNamespace namespace = - factory.createOMNamespace(attrName.getNamespaceURI(), - attrName.getPrefix()); - OMAttribute attribute = - factory.createOMAttribute(attrName.getLocalPart(), namespace, - attributes.getValue(i)); - element.addAttribute(attribute); - } - } - elements.add(element); - newNamespaceMapping(); - } - - private boolean isNamespaceDeclaration(QName qName) { - String prefix = qName.getPrefix(); - String localPart = qName.getLocalPart(); - return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.length() == 0) || - (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && localPart.length() != 0); - } - - @Override - public void endElement(String uri, String localName, String qName) - throws SAXException { - elements.remove(elements.size() - 1); - removeNamespaceMapping(); - } - - @Override - public void characters(char ch[], int start, int length) throws SAXException { - String data = new String(ch, start, length); - OMContainer parent = getParent(); - factory.createOMText(parent, data, charactersType); - } - - @Override - public void ignorableWhitespace(char ch[], int start, int length) - throws SAXException { - charactersType = XMLStreamConstants.SPACE; - characters(ch, start, length); - charactersType = XMLStreamConstants.CHARACTERS; - } - - @Override - public void processingInstruction(String target, String data) throws SAXException { - OMContainer parent = getParent(); - factory.createOMProcessingInstruction(parent, target, data); - } - - @Override - public void comment(char ch[], int start, int length) throws SAXException { - String content = new String(ch, start, length); - OMContainer parent = getParent(); - factory.createOMComment(parent, content); - } - - @Override - public void startCDATA() throws SAXException { - charactersType = XMLStreamConstants.CDATA; - } - - @Override - public void endCDATA() throws SAXException { - charactersType = XMLStreamConstants.CHARACTERS; - } - - @Override - public void startEntity(String name) throws SAXException { - if (!isPredefinedEntityReference(name)) { - charactersType = XMLStreamConstants.ENTITY_REFERENCE; - } - } - - @Override - public void endEntity(String name) throws SAXException { - charactersType = XMLStreamConstants.CHARACTERS; - } - - private boolean isPredefinedEntityReference(String name) { - return "lt".equals(name) || "gt".equals(name) || "amp".equals(name) || - "quot".equals(name) || - "apos".equals(name); - } - - /* - * Unsupported - */ - - @Override - public void setDocumentLocator(Locator locator) { - } - - @Override - public void skippedEntity(String name) throws SAXException { - } - - @Override - public void startDTD(String name, String publicId, String systemId) - throws SAXException { - } - - @Override - public void endDTD() throws SAXException { - } - - private Map currentNamespaceMapping() { - return namespaceMappings.get(namespaceMappings.size() - 1); - } - - private void newNamespaceMapping() { - namespaceMappings.add(new HashMap()); - } - - private void removeNamespaceMapping() { - namespaceMappings.remove(namespaceMappings.size() - 1); - } - - private void removeAllNamespaceMappings() { - namespaceMappings.clear(); - } - -} diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomResult.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomResult.java deleted file mode 100644 index 6e9dcd94..00000000 --- a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomResult.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ws.soap.axiom; - -import javax.xml.transform.sax.SAXResult; - -import org.apache.axiom.om.OMContainer; -import org.apache.axiom.om.OMFactory; -import org.xml.sax.ContentHandler; -import org.xml.sax.ext.LexicalHandler; - -/** - * Specific TrAX {@link javax.xml.transform.Result} that adds the resulting AXIOM OMElement to a specified parent - * element when {@code endDocument} is called. - * - * @author Arjen Poutsma - * @see AxiomHandler - * @since 1.5.0 - */ -class AxiomResult extends SAXResult { - - AxiomResult(OMContainer container, OMFactory factory) { - AxiomHandler handler = new AxiomHandler(container, factory); - super.setHandler(handler); - super.setLexicalHandler(handler); - } - - /** - * Throws a {@code UnsupportedOperationException}. - * - * @throws UnsupportedOperationException always - */ - @Override - public void setHandler(ContentHandler handler) { - throw new UnsupportedOperationException("setHandler is not supported"); - } - - /** - * Throws a {@code UnsupportedOperationException}. - * - * @throws UnsupportedOperationException always - */ - @Override - public void setLexicalHandler(LexicalHandler handler) { - throw new UnsupportedOperationException("setLexicalHandler is not supported"); - } -} diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetail.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetail.java index aee020e0..699d8a61 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetail.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetail.java @@ -60,7 +60,7 @@ class AxiomSoapFaultDetail extends AxiomSoapElement implements SoapFaultDetail { @Override public Result getResult() { - return new AxiomResult(getAxiomFaultDetail(), getAxiomFactory()); + return getAxiomFaultDetail().getSAXResult(); } protected SOAPFaultDetail getAxiomFaultDetail() { diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetailElement.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetailElement.java index b506e466..5978f813 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetailElement.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetailElement.java @@ -39,7 +39,7 @@ class AxiomSoapFaultDetailElement extends AxiomSoapElement implements SoapFaultD @Override public Result getResult() { try { - return new AxiomResult(getAxiomElement(), getAxiomFactory()); + return getAxiomElement().getSAXResult(); } catch (OMException ex) { throw new AxiomSoapFaultException(ex); diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java index f88c902a..8eadc40b 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java @@ -45,7 +45,7 @@ abstract class AxiomSoapHeader extends AxiomSoapElement implements SoapHeader { @Override public Result getResult() { - return new AxiomResult(getAxiomHeader(), getAxiomFactory()); + return getAxiomHeader().getSAXResult(); } @Override diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeaderElement.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeaderElement.java index 84d404c4..1ff1e202 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeaderElement.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeaderElement.java @@ -54,7 +54,7 @@ class AxiomSoapHeaderElement extends AxiomSoapElement implements SoapHeaderEleme @Override public Result getResult() { try { - return new AxiomResult(getAxiomHeaderBlock(), getAxiomFactory()); + return getAxiomHeaderBlock().getSAXResult(); } catch (OMException ex) { throw new AxiomSoapHeaderException(ex); diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/CachingPayload.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/CachingPayload.java index 36c157cb..b8453362 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/CachingPayload.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/CachingPayload.java @@ -46,7 +46,7 @@ class CachingPayload extends AbstractPayload { @Override public Result getResultInternal() { - return new AxiomResult(getAxiomBody(), getAxiomFactory()); + return getAxiomBody().getSAXResult(); } } diff --git a/spring-ws-core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java b/spring-ws-core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java deleted file mode 100644 index 21156b83..00000000 --- a/spring-ws-core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright 2005-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ws.soap.axiom; - -import static org.custommonkey.xmlunit.XMLAssert.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.StringReader; -import java.util.Iterator; -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXResult; - -import org.apache.axiom.om.OMAbstractFactory; -import org.apache.axiom.om.OMDocument; -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMFactory; -import org.apache.axiom.om.OMNamespace; -import org.junit.Before; -import org.junit.Test; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -public class AxiomHandlerTest { - - private static final String XML_1 = - "" + "" + "" + - "content" + - ""; - - private static final String XML_2_EXPECTED = - "" + "" + "" + - ""; - - private static final String XML_2_SNIPPET = - "" + ""; - - private static final String XML_3_ENTITY = - "<>&"'"; - - private static final String XML_4_SNIPPET = "" + ""; - - private static final String XML_5_SNIPPET = "" + ""; - - private static final String XML_6_SNIPPET = "" + ""; - - private AxiomHandler handler; - - private OMDocument result; - - private XMLReader xmlReader; - - private OMFactory factory; - - @Before - public void setUp() throws Exception { - factory = OMAbstractFactory.getOMFactory(); - result = factory.createOMDocument(); - xmlReader = XMLReaderFactory.createXMLReader(); - } - - @Test - public void testContentHandlerDocumentNamespacePrefixes() throws Exception { - xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); - handler = new AxiomHandler(result, factory); - xmlReader.setContentHandler(handler); - xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); - xmlReader.parse(new InputSource(new StringReader(XML_1))); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - result.serialize(bos); - assertXMLEqual("Invalid result", XML_1, bos.toString("UTF-8")); - } - - @Test - public void testContentHandlerDocumentNoNamespacePrefixes() throws Exception { - xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); - handler = new AxiomHandler(result, factory); - xmlReader.setContentHandler(handler); - xmlReader.parse(new InputSource(new StringReader(XML_1))); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - result.serialize(bos); - assertXMLEqual("Invalid result", XML_1, bos.toString("UTF-8")); - } - - @Test - public void testContentHandlerElement() throws Exception { - OMNamespace namespace = factory.createOMNamespace("namespace", ""); - OMElement rootElement = factory.createOMElement("root", namespace, result); - handler = new AxiomHandler(rootElement, factory); - xmlReader.setContentHandler(handler); - xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET))); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - result.serialize(bos); - assertXMLEqual("Invalid result", XML_2_EXPECTED, bos.toString("UTF-8")); - } - - @Test - public void testContentHandlerElementWithSamePrefixAndDifferentNamespace() throws Exception { - OMNamespace namespace = factory.createOMNamespace("namespace1", ""); - OMElement rootElement = factory.createOMElement("root", namespace, result); - handler = new AxiomHandler(rootElement, factory); - xmlReader.setContentHandler(handler); - xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET))); - Iterator it = result.getOMDocumentElement().getChildrenWithLocalName("child"); - assertTrue(it.hasNext()); - OMElement child = (OMElement) it.next(); - assertEquals("", child.getQName().getPrefix()); - assertEquals("namespace2", child.getQName().getNamespaceURI()); - } - - @Test - public void testContentHandlerElementWithSameNamespacesAndPrefix() throws Exception { - OMNamespace namespace = factory.createOMNamespace("namespace1", ""); - OMElement rootElement = factory.createOMElement("root", namespace, result); - handler = new AxiomHandler(rootElement, factory); - xmlReader.setContentHandler(handler); - xmlReader.parse(new InputSource(new StringReader(XML_4_SNIPPET))); - Iterator it = result.getOMDocumentElement().getChildrenWithLocalName("child"); - assertTrue(it.hasNext()); - OMElement child = (OMElement) it.next(); - assertEquals("", child.getQName().getPrefix()); - assertEquals("namespace1", child.getQName().getNamespaceURI()); - } - - @Test - public void testContentHandlerElementWithSameNamespacesAndDifferentPrefix() throws Exception { - OMNamespace namespace = factory.createOMNamespace("namespace1", ""); - OMElement rootElement = factory.createOMElement("root", namespace, result); - handler = new AxiomHandler(rootElement, factory); - xmlReader.setContentHandler(handler); - xmlReader.parse(new InputSource(new StringReader(XML_5_SNIPPET))); - Iterator it = result.getOMDocumentElement().getChildrenWithLocalName("child"); - assertTrue(it.hasNext()); - OMElement child = (OMElement) it.next(); - assertEquals("x", child.getQName().getPrefix()); - assertEquals("namespace1", child.getQName().getNamespaceURI()); - } - - @Test - public void testContentHandlerSiblingPrefixMapping() throws Exception { - handler = new AxiomHandler(result, factory); - xmlReader.setContentHandler(handler); - xmlReader.parse(new InputSource(new StringReader(XML_6_SNIPPET))); - - Iterator it = result.getOMDocumentElement().getChildren(); - assertTrue(it.hasNext()); - OMElement firstSibling = (OMElement) it.next(); - assertEquals("first-sibling", firstSibling.getLocalName()); - Iterator firstSiblingNsIt = firstSibling.getAllDeclaredNamespaces(); - // Verify first sibling has a single namespace declaration (with child-namespace URI) - assertTrue(firstSiblingNsIt.hasNext()); - assertEquals("child-namespace", ((OMNamespace) firstSiblingNsIt.next()).getNamespaceURI()); - assertFalse(firstSiblingNsIt.hasNext()); - - assertTrue(it.hasNext()); - OMElement secondSibling = (OMElement) it.next(); - // Verify second sibling has no namespace declarations as it's covered by - // This also verifies the child-namespace from the element isn't copied to second-sibling - assertEquals("second-sibling", secondSibling.getLocalName()); - Iterator secondSiblingNsIt = secondSibling.getAllDeclaredNamespaces(); - assertFalse(secondSiblingNsIt.hasNext()); - - } - - @Test - public void testContentHandlerPredefinedEntityReference() throws Exception { - handler = new AxiomHandler(result, factory); - xmlReader.setContentHandler(handler); - xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); - xmlReader.parse(new InputSource(new StringReader(XML_3_ENTITY))); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - result.serialize(bos); - assertXMLEqual("Invalid result", XML_3_ENTITY, bos.toString("UTF-8")); - } - - @Test - public void testTransformDom() throws Exception { - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setNamespaceAware(true); - DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); - String XML = "" + - "" + - ""; - - Document document = - documentBuilder.parse(new ByteArrayInputStream(XML.getBytes("UTF-8"))); - - DOMSource domSource = new DOMSource(document); - handler = new AxiomHandler(result, factory); - - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - SAXResult saxResult = new SAXResult(handler); - transformer.transform(domSource, saxResult); - - OMElement root = result.getOMDocumentElement(); - assertEquals(2, getNamespaceCount(root)); - NamespaceContext namespaceContext = root.getNamespaceContext(false); - assertEquals("http://www.springframework.org/spring-ws", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX)); - assertEquals("http://www.springframework.org/spring-ws/attr", - namespaceContext.getNamespaceURI("attr")); - - OMElement child = root.getFirstElement(); - assertEquals(1, getNamespaceCount(child)); - namespaceContext = child.getNamespaceContext(false); - assertEquals("http://www.springframework.org/spring-ws", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX)); - assertEquals("http://www.springframework.org/spring-ws/child", namespaceContext.getNamespaceURI("prefix")); - } - - private int getNamespaceCount(OMElement element) { - int i = 0; - Iterator namespaces = element.getAllDeclaredNamespaces(); - while (namespaces.hasNext()) { - namespaces.next(); - i++; - } - return i; - } - -}