You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/08/04 14:25:17 UTC
svn commit: r1369301 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/main/java/org/apache/axiom/util/stax/
axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/
axiom-common-impl/src/main/java/org/apache/axiom/om/impl/co...
Author: veithen
Date: Sat Aug 4 12:25:16 2012
New Revision: 1369301
URL: http://svn.apache.org/viewvc?rev=1369301&view=rev
Log:
AXIOM-401: Increased the test coverage and compliance of DOMXMLStreamReader.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMNamespaceContext.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMUtils.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/BuilderFactory.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/Normalizer.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java Sat Aug 4 12:25:16 2012
@@ -83,6 +83,28 @@ public abstract class AbstractXMLStreamR
return getEventType() == CHARACTERS;
}
+ public boolean isWhiteSpace() {
+ switch (getEventType()) {
+ case SPACE:
+ return true;
+ case CHARACTERS:
+ // XMLStreamReader Javadoc says that isWhiteSpace "returns true if the cursor
+ // points to a character data event that consists of all whitespace". This
+ // means that this method may return true for a CHARACTER event and we need
+ // to scan the text of the node.
+ String text = getText();
+ for (int i=0; i<text.length(); i++) {
+ char c = text.charAt(i);
+ if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
+ return false;
+ }
+ }
+ return true;
+ default:
+ return false;
+ }
+ }
+
public boolean hasName() {
int event = getEventType();
return event == START_ELEMENT || event == END_ELEMENT;
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java Sat Aug 4 12:25:16 2012
@@ -797,25 +797,7 @@ class SwitchingWrapper extends AbstractX
if (parser != null) {
return parser.isWhiteSpace();
} else {
- switch (currentEvent) {
- case SPACE:
- return true;
- case CHARACTERS:
- // XMLStreamReader Javadoc says that isWhiteSpace "returns true if the cursor
- // points to a character data event that consists of all whitespace". This
- // means that this method may return true for a CHARACTER event and we need
- // to scan the text of the node.
- String text = getTextFromNode();
- for (int i=0; i<text.length(); i++) {
- char c = text.charAt(i);
- if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
- return false;
- }
- }
- return true;
- default:
- return false;
- }
+ return super.isWhiteSpace();
}
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMNamespaceContext.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMNamespaceContext.java?rev=1369301&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMNamespaceContext.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMNamespaceContext.java Sat Aug 4 12:25:16 2012
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.axiom.om.impl.common.factory;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.axiom.util.namespace.AbstractNamespaceContext;
+import org.w3c.dom.Attr;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+class DOMNamespaceContext extends AbstractNamespaceContext {
+ private final DOMXMLStreamReader reader;
+
+ DOMNamespaceContext(DOMXMLStreamReader reader) {
+ this.reader = reader;
+ }
+
+ protected String doGetNamespaceURI(String prefix) {
+ String namespaceURI = reader.getNamespaceURI(prefix);
+ return namespaceURI == null ? "" : namespaceURI;
+ }
+
+ protected String doGetPrefix(String namespaceURI) {
+ Set seenPrefixes = new HashSet();
+ Node current = reader.currentNode();
+ do {
+ NamedNodeMap attributes = current.getAttributes();
+ if (attributes != null) {
+ for (int i=0, l=attributes.getLength(); i<l; i++) {
+ Attr attr = (Attr)attributes.item(i);
+ if (DOMUtils.isNSDecl(attr)) {
+ String prefix = DOMUtils.getNSDeclPrefix(attr);
+ if (prefix == null) {
+ prefix = "";
+ }
+ if (seenPrefixes.add(prefix) && attr.getValue().equals(namespaceURI)) {
+ return prefix;
+ }
+ }
+ }
+ }
+ current = current.getParentNode();
+ } while (current != null);
+ return null;
+ }
+
+ protected Iterator doGetPrefixes(String namespaceURI) {
+ // seenPrefixes tracks all prefixes we have encountered; this is important to
+ // handle prefixes that are overridden by descendant elements
+ Set seenPrefixes = new HashSet();
+ Set matchingPrefixes = new HashSet();
+ Node current = reader.currentNode();
+ do {
+ NamedNodeMap attributes = current.getAttributes();
+ if (attributes != null) {
+ for (int i=0, l=attributes.getLength(); i<l; i++) {
+ Attr attr = (Attr)attributes.item(i);
+ if (DOMUtils.isNSDecl(attr)) {
+ String prefix = DOMUtils.getNSDeclPrefix(attr);
+ if (prefix == null) {
+ prefix = "";
+ }
+ if (seenPrefixes.add(prefix) && attr.getValue().equals(namespaceURI)) {
+ matchingPrefixes.add(prefix);
+ }
+ }
+ }
+ }
+ current = current.getParentNode();
+ } while (current != null);
+ return matchingPrefixes.iterator();
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMNamespaceContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMUtils.java?rev=1369301&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMUtils.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMUtils.java Sat Aug 4 12:25:16 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.axiom.om.impl.common.factory;
+
+import javax.xml.XMLConstants;
+
+import org.w3c.dom.Attr;
+
+final class DOMUtils {
+ private DOMUtils() {}
+
+ static boolean isNSDecl(Attr attr) {
+ return XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI());
+ }
+
+ static String getNSDeclPrefix(Attr attr) {
+ String prefix = attr.getPrefix();
+ return prefix == null ? null : attr.getLocalName();
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java Sat Aug 4 12:25:16 2012
@@ -18,7 +18,6 @@
*/
package org.apache.axiom.om.impl.common.factory;
-import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
@@ -28,9 +27,11 @@ import org.apache.axiom.util.stax.Abstra
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
class DOMXMLStreamReader extends AbstractXMLStreamReader implements DTDReader {
private final Node root;
@@ -42,14 +43,19 @@ class DOMXMLStreamReader extends Abstrac
private Attr[] attributes = new Attr[8];
private int namespaceCount;
private Attr[] namespaces = new Attr[8];
+ private NamespaceContext nsContext;
- public DOMXMLStreamReader(Node node, boolean expandEntityReferences) {
+ DOMXMLStreamReader(Node node, boolean expandEntityReferences) {
root = node;
this.node = node;
this.expandEntityReferences = expandEntityReferences;
event = START_DOCUMENT;
}
+ Node currentNode() {
+ return node;
+ }
+
public Object getProperty(String name) throws IllegalArgumentException {
if (DTDReader.PROPERTY.equals(name)) {
return this;
@@ -58,6 +64,10 @@ class DOMXMLStreamReader extends Abstrac
}
}
+ public boolean hasNext() throws XMLStreamException {
+ return event != END_DOCUMENT;
+ }
+
public int next() throws XMLStreamException {
boolean forceTraverse = false;
while (true) {
@@ -89,15 +99,13 @@ class DOMXMLStreamReader extends Abstrac
event = DTD;
break;
case Node.ELEMENT_NODE:
- if (visited) {
- event = END_ELEMENT;
- } else {
- event = START_ELEMENT;
- attributesLoaded = false;
- }
+ event = visited? END_ELEMENT : START_ELEMENT;
+ // Namespace declarations can be queried on an END_ELEMENT event; always reset the
+ // attributesLoaded flag
+ attributesLoaded = false;
break;
case Node.TEXT_NODE:
- event = CHARACTERS;
+ event = ((Text)node).isElementContentWhitespace() ? SPACE : CHARACTERS;
break;
case Node.CDATA_SECTION_NODE:
event = CDATA;
@@ -130,7 +138,11 @@ class DOMXMLStreamReader extends Abstrac
}
public String getEncoding() {
- return ((Document)node).getInputEncoding();
+ if (event == START_DOCUMENT) {
+ return ((Document)node).getInputEncoding();
+ } else {
+ throw new IllegalStateException();
+ }
}
public String getVersion() {
@@ -138,7 +150,11 @@ class DOMXMLStreamReader extends Abstrac
}
public String getCharacterEncodingScheme() {
- return ((Document)node).getXmlEncoding();
+ if (event == START_DOCUMENT) {
+ return ((Document)node).getXmlEncoding();
+ } else {
+ throw new IllegalStateException();
+ }
}
public boolean isStandalone() {
@@ -170,11 +186,33 @@ class DOMXMLStreamReader extends Abstrac
}
public String getNamespaceURI() {
- return node.getNamespaceURI();
+ switch (event) {
+ case START_ELEMENT:
+ case END_ELEMENT:
+ return node.getNamespaceURI();
+ default:
+ throw new IllegalStateException();
+ }
}
public String getPrefix() {
- return node.getPrefix();
+ switch (event) {
+ case START_ELEMENT:
+ case END_ELEMENT:
+ return node.getPrefix();
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ public QName getName() {
+ switch (event) {
+ case START_ELEMENT:
+ case END_ELEMENT:
+ return getQName(node);
+ default:
+ throw new IllegalStateException();
+ }
}
private Attr[] grow(Attr[] array) {
@@ -190,7 +228,7 @@ class DOMXMLStreamReader extends Abstrac
NamedNodeMap attrs = node.getAttributes();
for (int i=0, l=attrs.getLength(); i<l; i++) {
Attr attr = (Attr)attrs.item(i);
- if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())) {
+ if (DOMUtils.isNSDecl(attr)) {
if (namespaceCount == namespaces.length) {
namespaces = grow(namespaces);
}
@@ -207,103 +245,177 @@ class DOMXMLStreamReader extends Abstrac
}
public int getAttributeCount() {
- loadAttributes();
- return attributeCount;
+ if (event == START_ELEMENT) {
+ loadAttributes();
+ return attributeCount;
+ } else {
+ throw new IllegalStateException();
+ }
}
+ private Attr getAttribute(int index) {
+ if (event == START_ELEMENT) {
+ loadAttributes();
+ return attributes[index];
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
public String getAttributeLocalName(int index) {
- loadAttributes();
- return attributes[index].getLocalName();
+ return getAttribute(index).getLocalName();
}
public String getAttributeNamespace(int index) {
- loadAttributes();
- return attributes[index].getNamespaceURI();
+ return getAttribute(index).getNamespaceURI();
}
public String getAttributePrefix(int index) {
- loadAttributes();
- return attributes[index].getPrefix();
+ return getAttribute(index).getPrefix();
+ }
+
+ public QName getAttributeName(int index) {
+ return getQName(getAttribute(index));
}
public String getAttributeValue(int index) {
- loadAttributes();
- return attributes[index].getValue();
+ return getAttribute(index).getValue();
}
public String getAttributeType(int index) {
- return "CDATA";
+ if (event == START_ELEMENT) {
+ return "CDATA";
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public boolean isAttributeSpecified(int index) {
+ return getAttribute(index).getSpecified();
+ }
+
+ public String getAttributeValue(String namespaceURI, String localName) {
+ return ((Element)node).getAttributeNS(namespaceURI == null || namespaceURI.length() == 0 ? null : namespaceURI, localName);
}
public int getNamespaceCount() {
- loadAttributes();
- return namespaceCount;
+ switch (event) {
+ case START_ELEMENT:
+ case END_ELEMENT:
+ loadAttributes();
+ return namespaceCount;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ private Attr getNamespace(int index) {
+ switch (event) {
+ case START_ELEMENT:
+ case END_ELEMENT:
+ loadAttributes();
+ return namespaces[index];
+ default:
+ throw new IllegalStateException();
+ }
}
public String getNamespacePrefix(int index) {
- loadAttributes();
- Attr attr = namespaces[index];
- String prefix = attr.getPrefix();
- return prefix == null ? null : attr.getLocalName();
+ return DOMUtils.getNSDeclPrefix(getNamespace(index));
}
public String getNamespaceURI(int index) {
- loadAttributes();
- return namespaces[index].getValue();
+ return getNamespace(index).getValue();
}
+ private String internalGetText() {
+ switch (event) {
+ case CHARACTERS:
+ case SPACE:
+ case CDATA:
+ case COMMENT:
+ return node.getNodeValue();
+ case ENTITY_REFERENCE:
+ return null;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
public String getText() {
if (event == DTD) {
return ((DocumentType)node).getInternalSubset();
} else {
- return node.getNodeValue();
+ return internalGetText();
}
}
- public String getPITarget() {
- return ((ProcessingInstruction)node).getTarget();
- }
-
- public String getPIData() {
- return ((ProcessingInstruction)node).getData();
+ public int getTextStart() {
+ // Call internalGetText to throw an IllegalStateException if appropriate
+ internalGetText();
+ return 0;
}
- public void close() throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException();
+ public int getTextLength() {
+ return internalGetText().length();
}
- public QName getAttributeName(int arg0) {
- // TODO
- throw new UnsupportedOperationException();
+ public char[] getTextCharacters() {
+ return internalGetText().toCharArray();
}
- public String getAttributeValue(String arg0, String arg1) {
- // TODO
- throw new UnsupportedOperationException();
+ public String getPITarget() {
+ if (event == PROCESSING_INSTRUCTION) {
+ return ((ProcessingInstruction)node).getTarget();
+ } else {
+ throw new IllegalStateException();
+ }
}
- public String getElementText() throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException();
+ public String getPIData() {
+ if (event == PROCESSING_INSTRUCTION) {
+ return ((ProcessingInstruction)node).getData();
+ } else {
+ throw new IllegalStateException();
+ }
}
- public QName getName() {
- // TODO
- throw new UnsupportedOperationException();
+ public NamespaceContext getNamespaceContext() {
+ if (nsContext == null) {
+ nsContext = new DOMNamespaceContext(this);
+ }
+ return nsContext;
}
- public NamespaceContext getNamespaceContext() {
- // TODO
- throw new UnsupportedOperationException();
+ public String getNamespaceURI(String prefix) {
+ Node current = node;
+ do {
+ NamedNodeMap attributes = current.getAttributes();
+ if (attributes != null) {
+ for (int i=0, l=attributes.getLength(); i<l; i++) {
+ Attr attr = (Attr)attributes.item(i);
+ if (DOMUtils.isNSDecl(attr)) {
+ String candidatePrefix = DOMUtils.getNSDeclPrefix(attr);
+ if (candidatePrefix == null) {
+ candidatePrefix = "";
+ }
+ if (candidatePrefix.equals(prefix)) {
+ return attr.getValue();
+ }
+ }
+ }
+ }
+ current = current.getParentNode();
+ } while (current != null);
+ return null;
}
- public String getNamespaceURI(String arg0) {
+ public void close() throws XMLStreamException {
// TODO
throw new UnsupportedOperationException();
}
- public char[] getTextCharacters() {
+ public String getElementText() throws XMLStreamException {
// TODO
throw new UnsupportedOperationException();
}
@@ -314,33 +426,13 @@ class DOMXMLStreamReader extends Abstrac
throw new UnsupportedOperationException();
}
- public int getTextLength() {
- // TODO
- throw new UnsupportedOperationException();
- }
-
- public int getTextStart() {
- // TODO
- throw new UnsupportedOperationException();
- }
-
- public boolean hasNext() throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException();
- }
-
- public boolean isAttributeSpecified(int arg0) {
- // TODO
- throw new UnsupportedOperationException();
- }
-
- public boolean isWhiteSpace() {
- // TODO
- throw new UnsupportedOperationException();
- }
-
public boolean standaloneSet() {
// TODO
throw new UnsupportedOperationException();
}
+
+ private static QName getQName(Node node) {
+ String prefix = node.getPrefix();
+ return new QName(node.getNamespaceURI(), node.getLocalName(), prefix == null ? "" : prefix);
+ }
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Sat Aug 4 12:25:16 2012
@@ -24,6 +24,7 @@ import junit.framework.TestSuite;
import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
import org.apache.axiom.ts.om.OMTestSuiteBuilder;
import org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromDOMSource;
+import org.apache.axiom.ts.om.container.TestGetXMLStreamReader;
import org.apache.axiom.ts.om.container.TestSerialize;
import org.apache.axiom.ts.om.document.TestClone;
import org.apache.axiom.ts.om.document.TestDigest;
@@ -62,6 +63,9 @@ public class OMImplementationTest extend
// TODO
builder.exclude(TestSerializationWithTwoNonBuiltOMElements.class);
+ // TODO
+ builder.exclude(TestGetXMLStreamReader.class, "(&(source=dom)(|(file=entity-reference-external-subset.xml)(file=entity-reference-internal-subset.xml)))");
+
return builder.build();
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java Sat Aug 4 12:25:16 2012
@@ -24,6 +24,7 @@ import junit.framework.TestSuite;
import org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory;
import org.apache.axiom.ts.om.OMTestSuiteBuilder;
import org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromDOMSource;
+import org.apache.axiom.ts.om.container.TestGetXMLStreamReader;
import org.apache.axiom.ts.om.container.TestSerialize;
import org.apache.axiom.ts.om.document.TestClone;
import org.apache.axiom.ts.om.document.TestDigest;
@@ -50,6 +51,9 @@ public class OMImplementationTest extend
// TODO: if there is a comment node surrounded by text, then these text nodes need to be merged
builder.exclude(TestDigest.class, "(|(file=digest3.xml)(file=digest4.xml))");
+ // TODO
+ builder.exclude(TestGetXMLStreamReader.class, "(&(source=dom)(|(file=entity-reference-external-subset.xml)(file=entity-reference-internal-subset.xml)))");
+
return builder.build();
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java Sat Aug 4 12:25:16 2012
@@ -30,7 +30,7 @@ import org.apache.axiom.util.stax.dialec
import org.apache.commons.io.output.NullOutputStream;
public abstract class AxiomTestCase extends TestCaseEx {
- protected static final StAXParserConfiguration TEST_PARSER_CONFIGURATION = new StAXParserConfiguration() {
+ public static final StAXParserConfiguration TEST_PARSER_CONFIGURATION = new StAXParserConfiguration() {
public XMLInputFactory configure(XMLInputFactory factory, StAXDialect dialect) {
// For the tests, preserve as much of the syntactic structure of the test documents
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Sat Aug 4 12:25:16 2012
@@ -25,6 +25,7 @@ import javax.xml.namespace.QName;
import org.apache.axiom.om.OMMetaFactory;
import org.apache.axiom.testutils.conformance.ConformanceTestFile;
import org.apache.axiom.testutils.suite.TestSuiteBuilder;
+import org.apache.axiom.ts.om.container.BuilderFactory;
import org.apache.axiom.ts.om.container.OMContainerFactory;
import org.apache.axiom.ts.om.container.OMElementFactory;
import org.apache.axiom.ts.om.container.SerializationMethod;
@@ -36,6 +37,10 @@ import org.apache.axiom.ts.om.xpath.AXIO
import org.apache.axiom.ts.om.xpath.TestAXIOMXPath;
public class OMTestSuiteBuilder extends TestSuiteBuilder {
+ private static final BuilderFactory[] builderFactories = {
+ BuilderFactory.PARSER,
+ BuilderFactory.DOM };
+
private static final OMContainerFactory[] containerFactories = {
OMContainerFactory.DOCUMENT,
new OMElementFactory(false),
@@ -103,8 +108,11 @@ public class OMTestSuiteBuilder extends
ConformanceTestFile file = conformanceFiles[i];
for (int j=0; j<containerFactories.length; j++) {
OMContainerFactory cf = containerFactories[j];
- addTest(new org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory, file, cf, true));
- addTest(new org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory, file, cf, false));
+ for (int k=0; k<builderFactories.length; k++) {
+ BuilderFactory bf = builderFactories[k];
+ addTest(new org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory, file, bf, cf, true));
+ addTest(new org.apache.axiom.ts.om.container.TestGetXMLStreamReader(metaFactory, file, bf, cf, false));
+ }
// On a document containing entity references, serialization tests will only work correctly if
// the entire document is serialized (so that the DTD is available)
if (!file.hasEntityReferences() || cf == OMContainerFactory.DOCUMENT) {
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/BuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/BuilderFactory.java?rev=1369301&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/BuilderFactory.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/BuilderFactory.java Sat Aug 4 12:25:16 2012
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.axiom.ts.om.container;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+/**
+ * Defines a strategy to create an {@link OMXMLParserWrapper} from a given test file.
+ */
+public interface BuilderFactory {
+ /**
+ * Creates an {@link OMXMLParserWrapper} directly from the given {@link InputSource}, i.e. let
+ * instantiate an appropriate parser.
+ */
+ BuilderFactory PARSER = new BuilderFactory() {
+ public void addTestProperties(AxiomTestCase testCase) {
+ testCase.addTestProperty("source", "parser");
+ }
+
+ public OMXMLParserWrapper getBuilder(OMMetaFactory metaFactory, InputSource inputSource) throws Exception {
+ return metaFactory.createOMBuilder(metaFactory.getOMFactory(),
+ AxiomTestCase.TEST_PARSER_CONFIGURATION, inputSource);
+ }
+ };
+
+ /**
+ * Creates an {@link OMXMLParserWrapper} by parsing the input using DOM and passing it as a
+ * {@link DOMSource} to Axiom.
+ */
+ BuilderFactory DOM = new BuilderFactory() {
+ public void addTestProperties(AxiomTestCase testCase) {
+ testCase.addTestProperty("source", "dom");
+ }
+
+ public OMXMLParserWrapper getBuilder(OMMetaFactory metaFactory, InputSource inputSource) throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ dbf.setExpandEntityReferences(false);
+ Document document = dbf.newDocumentBuilder().parse(inputSource);
+ return OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new DOMSource(document), false);
+ }
+ };
+
+ void addTestProperties(AxiomTestCase testCase);
+
+ OMXMLParserWrapper getBuilder(OMMetaFactory metaFactory, InputSource inputSource) throws Exception;
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/BuilderFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/OMContainerFactory.java Sat Aug 4 12:25:16 2012
@@ -29,7 +29,7 @@ import org.apache.axiom.ts.AxiomTestCase
import org.xml.sax.InputSource;
/**
- * Prepares {@link OMContainer} instances from a test file.
+ * Extracts an {@link OMContainer} instance from a test file.
*/
public interface OMContainerFactory {
OMContainerFactory DOCUMENT = new OMContainerFactory() {
@@ -51,7 +51,33 @@ public interface OMContainerFactory {
};
void addTestProperties(AxiomTestCase testCase);
+
+ /**
+ * Prepare a control document that has the same content as the container returned by
+ * {@link #getContainer(OMXMLParserWrapper)}.
+ *
+ * @param testFileContent
+ * the content of the test file
+ * @return the {@link InputSource} for the control document
+ * @throws Exception
+ */
InputSource getControl(InputStream testFileContent) throws Exception;
+
+ /**
+ * Extract the {@link OMContainer} from the given test file.
+ *
+ * @param builder the builder for the test file
+ * @return the container
+ */
OMContainer getContainer(OMXMLParserWrapper builder);
+
+ /**
+ * Filter the given stream so that its content matches the content of the container returned by
+ * {@link #getContainer(OMXMLParserWrapper)}.
+ *
+ * @param reader
+ * the original stream reader representing the content of the test file
+ * @return the filtered stream reader
+ */
XMLStreamReader filter(XMLStreamReader reader);
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetXMLStreamReader.java Sat Aug 4 12:25:16 2012
@@ -36,13 +36,17 @@ import org.xml.sax.InputSource;
* native StAX parser.
*/
public class TestGetXMLStreamReader extends ConformanceTestCase {
+ private final BuilderFactory builderFactory;
private final OMContainerFactory containerFactory;
private final boolean cache;
- public TestGetXMLStreamReader(OMMetaFactory metaFactory, ConformanceTestFile file, OMContainerFactory containerFactory, boolean cache) {
+ public TestGetXMLStreamReader(OMMetaFactory metaFactory, ConformanceTestFile file,
+ BuilderFactory builderFactory, OMContainerFactory containerFactory, boolean cache) {
super(metaFactory, file);
+ this.builderFactory = builderFactory;
this.containerFactory = containerFactory;
this.cache = cache;
+ builderFactory.addTestProperties(this);
containerFactory.addTestProperties(this);
addTestProperty("cache", Boolean.toString(cache));
}
@@ -52,8 +56,7 @@ public class TestGetXMLStreamReader exte
try {
XMLStreamReader expected = StAXUtils.createXMLStreamReader(TEST_PARSER_CONFIGURATION, file.getUrl().toString(), in);
try {
- OMXMLParserWrapper builder = metaFactory.createOMBuilder(metaFactory.getOMFactory(),
- TEST_PARSER_CONFIGURATION, new InputSource(file.getUrl().toString()));
+ OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(file.getUrl().toString()));
try {
XMLStreamReader actual = containerFactory.getContainer(builder).getXMLStreamReader(cache);
new XMLStreamReaderComparator(containerFactory.filter(expected), containerFactory.filter(actual)).compare();
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/Normalizer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/Normalizer.java?rev=1369301&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/Normalizer.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/Normalizer.java Sat Aug 4 12:25:16 2012
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.axiom.testutils.stax;
+
+import java.util.Locale;
+
+public interface Normalizer {
+ Normalizer IDENTITY = new Normalizer() {
+ public Object normalize(Object value) {
+ return value;
+ }
+ };
+
+ Normalizer LOWER_CASE = new Normalizer() {
+ public Object normalize(Object value) {
+ return value == null ? null : ((String)value).toLowerCase(Locale.ENGLISH);
+ }
+ };
+
+ Normalizer DTD = new Normalizer() {
+ public Object normalize(Object value) {
+ return value == null ? null : ((String)value).trim().replaceAll("\n\\s*", "\n");
+ }
+ };
+
+ Normalizer EMPTY_STRING_TO_NULL = new Normalizer() {
+ public Object normalize(Object value) {
+ return "".equals(value) ? null : value;
+ }
+ };
+
+ Object normalize(Object value);
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/Normalizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java?rev=1369301&r1=1369300&r2=1369301&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java Sat Aug 4 12:25:16 2012
@@ -21,7 +21,6 @@ package org.apache.axiom.testutils.stax;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -45,8 +44,6 @@ import junit.framework.Assert;
* (return values or exceptions thrown) of these invocations are compared to each other.
*/
public class XMLStreamReaderComparator extends Assert {
- private static final Map noPrefixValueMap = Collections.singletonMap("", null);
-
private final XMLStreamReader expected;
private final XMLStreamReader actual;
private final LinkedList path = new LinkedList();
@@ -117,7 +114,8 @@ public class XMLStreamReaderComparator e
expectedException.getClass().getName() +
", but the method returned normally (" + getLocation() + ")");
} else {
- assertEquals(expectedException.getClass(), actualException.getClass());
+ assertEquals("Unexpected exception thrown by " + methodName,
+ expectedException.getClass(), actualException.getClass());
}
}
return null;
@@ -128,21 +126,12 @@ public class XMLStreamReaderComparator e
}
private Object assertSameResult(String methodName, Class[] paramTypes, Object[] args,
- Map valueMap) throws Exception {
+ Normalizer normalizer) throws Exception {
Object[] results = invoke(methodName, paramTypes, args);
if (results != null) {
- Object expected = results[0];
- Object actual = results[1];
- if (valueMap != null) {
- // Attention! The value in the map can be null
- if (valueMap.containsKey(expected)) {
- expected = valueMap.get(expected);
- }
- if (valueMap.containsKey(actual)) {
- actual = valueMap.get(actual);
- }
- }
+ Object expected = normalizer.normalize(results[0]);
+ Object actual = normalizer.normalize(results[1]);
assertEquals("Return value of " + methodName + " for arguments " +
Arrays.asList(args) + " (" + getLocation() + ")",
expected, actual);
@@ -153,15 +142,15 @@ public class XMLStreamReaderComparator e
}
private Object assertSameResult(String methodName, Class[] paramTypes, Object[] args) throws Exception {
- return assertSameResult(methodName, paramTypes, args, null);
+ return assertSameResult(methodName, paramTypes, args, Normalizer.IDENTITY);
}
- private Object assertSameResult(String methodName, Map valueMap) throws Exception {
- return assertSameResult(methodName, new Class[0], new Object[0], valueMap);
+ private Object assertSameResult(String methodName, Normalizer normalizer) throws Exception {
+ return assertSameResult(methodName, new Class[0], new Object[0], normalizer);
}
private Object assertSameResult(String methodName) throws Exception {
- return assertSameResult(methodName, null);
+ return assertSameResult(methodName, Normalizer.IDENTITY);
}
private Set toPrefixSet(Iterator it) {
@@ -215,7 +204,7 @@ public class XMLStreamReaderComparator e
path.addLast(expected.getName());
}
assertSameResult("getCharacterEncodingScheme");
- assertSameResult("getEncoding");
+ assertSameResult("getEncoding", Normalizer.LOWER_CASE);
Integer attributeCount = (Integer)assertSameResult("getAttributeCount");
// Test the behavior of the getAttributeXxx methods for all types of events,
// to check that an appropriate exception is thrown for events other than
@@ -226,7 +215,7 @@ public class XMLStreamReaderComparator e
assertSameResult("getAttributeLocalName", paramTypes, args);
assertSameResult("getAttributeName", paramTypes, args);
namespaceURIs.add(assertSameResult("getAttributeNamespace", paramTypes, args));
- prefixes.add(assertSameResult("getAttributePrefix", paramTypes, args, noPrefixValueMap));
+ prefixes.add(assertSameResult("getAttributePrefix", paramTypes, args, Normalizer.EMPTY_STRING_TO_NULL));
assertSameResult("getAttributeType", paramTypes, args);
assertSameResult("getAttributeValue", paramTypes, args);
assertSameResult("isAttributeSpecified", paramTypes, args);
@@ -266,7 +255,7 @@ public class XMLStreamReaderComparator e
assertSameResult("getPIData");
assertSameResult("getPITarget");
prefixes.add(assertSameResult("getPrefix"));
- assertSameResult("getText");
+ assertSameResult("getText", eventType == XMLStreamReader.DTD ? Normalizer.DTD : Normalizer.IDENTITY);
Integer textLength = (Integer)assertSameResult("getTextLength");
Object[] textStart = invoke("getTextStart");
Object[] textCharacters = invoke("getTextCharacters");