ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1767582 - in /webservices/axiom/trunk/aspects/core-aspects/src: main/java/org/apache/axiom/core/stream/stax/pull/ test/java/org/apache/axiom/core/stream/stax/ test/java/org/apache/axiom/core/stream/stax/pull/
Date Tue, 01 Nov 2016 21:34:39 GMT
Author: veithen
Date: Tue Nov  1 21:34:38 2016
New Revision: 1767582

URL: http://svn.apache.org/viewvc?rev=1767582&view=rev
Log:
Implement the require method in StAXPivot.

Added:
    webservices/axiom/trunk/aspects/core-aspects/src/test/java/org/apache/axiom/core/stream/stax/
    webservices/axiom/trunk/aspects/core-aspects/src/test/java/org/apache/axiom/core/stream/stax/pull/
    webservices/axiom/trunk/aspects/core-aspects/src/test/java/org/apache/axiom/core/stream/stax/pull/StAXPivotTest.java
  (with props)
Modified:
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/pull/StAXPivot.java

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/pull/StAXPivot.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/pull/StAXPivot.java?rev=1767582&r1=1767581&r2=1767582&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/pull/StAXPivot.java
(original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/stax/pull/StAXPivot.java
Tue Nov  1 21:34:38 2016
@@ -37,6 +37,7 @@ import org.apache.axiom.core.stream.XmlR
 import org.apache.axiom.core.stream.stax.StAXExceptionUtil;
 import org.apache.axiom.core.stream.util.CharacterDataAccumulator;
 import org.apache.axiom.util.xml.QNameCache;
+import org.apache.axiom.util.xml.stream.XMLEventUtils;
 
 public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
     private class NamespaceContextImpl implements NamespaceContext {
@@ -187,6 +188,7 @@ public final class StAXPivot implements
     // Entity reference name or processing instruction target
     private String name;
     
+    // TODO: The constructor should take an XmlInput object as input
     public StAXPivot(XMLStreamReaderExtensionFactory extensionFactory) {
         this.extensionFactory = extensionFactory;
     }
@@ -519,9 +521,37 @@ public final class StAXPivot implements
     }
 
     @Override
-    public void require(int type, String namespaceURI, String localName) throws XMLStreamException
{
-        // TODO Auto-generated method stub
+    public void require(int expectedType, String expectedNamespaceURI, String expectedLocalName)
throws XMLStreamException {
+        if (expectedType != eventType) {
+            throw new XMLStreamException("Required type " + XMLEventUtils.getEventTypeString(expectedType)
+                    + ", actual type " + XMLEventUtils.getEventTypeString(eventType));
+        }
+
+        if (expectedLocalName != null) {
+            if (eventType != START_ELEMENT && eventType != END_ELEMENT
+                && eventType != ENTITY_REFERENCE) {
+                throw new XMLStreamException("Required a non-null local name, but current
token " +
+                        "not a START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE (was " +
+                        XMLEventUtils.getEventTypeString(eventType) + ")");
+            }
+            String localName = getLocalName();
+            if (!localName.equals(expectedLocalName)) {
+                throw new XMLStreamException("Required local name '" + expectedLocalName
+
+                        "'; current local name '" + localName + "'.");
+            }
+        }
         
+        if (expectedNamespaceURI != null) {
+            if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
+                throw new XMLStreamException("Required non-null namespace URI, but current
token " +
+                        "not a START_ELEMENT or END_ELEMENT (was " +
+                        XMLEventUtils.getEventTypeString(eventType) + ")");
+            }
+            String namespaceURI = elementStack[3*depth];
+            if (!expectedNamespaceURI.equals(namespaceURI)) {
+                throw new XMLStreamException("Required namespace '" + expectedNamespaceURI
+ "'; have '" + namespaceURI +"'.");
+            }
+        }
     }
 
     @Override

Added: webservices/axiom/trunk/aspects/core-aspects/src/test/java/org/apache/axiom/core/stream/stax/pull/StAXPivotTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/test/java/org/apache/axiom/core/stream/stax/pull/StAXPivotTest.java?rev=1767582&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/test/java/org/apache/axiom/core/stream/stax/pull/StAXPivotTest.java
(added)
+++ webservices/axiom/trunk/aspects/core-aspects/src/test/java/org/apache/axiom/core/stream/stax/pull/StAXPivotTest.java
Tue Nov  1 21:34:38 2016
@@ -0,0 +1,83 @@
+/*
+ * 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.core.stream.stax.pull;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.core.stream.dom.DOMInput;
+import org.apache.axiom.ts.jaxp.DOMImplementation;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class StAXPivotTest {
+    private StAXPivot pivot;
+
+    @Before
+    public void setUp() throws Exception {
+        Document document = DOMImplementation.XERCES.newDocument();
+        Element element = document.createElementNS("urn:test", "p:test");
+        document.appendChild(element);
+        element.appendChild(document.createEntityReference("ent"));
+        pivot = new StAXPivot(null);
+        pivot.setReader(new DOMInput(document, false).createReader(pivot));
+    }
+    
+    @Test
+    public void testSuccess() throws Exception {
+        pivot.require(XMLStreamConstants.START_DOCUMENT, null, null);
+        pivot.next();
+        pivot.require(XMLStreamConstants.START_ELEMENT, "urn:test", "test");
+        pivot.next();
+        pivot.require(XMLStreamConstants.ENTITY_REFERENCE, null, "ent");
+        pivot.next();
+        pivot.require(XMLStreamConstants.END_ELEMENT, "urn:test", "test");
+        pivot.next();
+        pivot.require(XMLStreamConstants.END_DOCUMENT, null, null);
+    }
+    
+    @Test(expected=XMLStreamException.class)
+    public void testEventTypeMismatch() throws Exception {
+        pivot.require(XMLStreamConstants.CHARACTERS, null, null);
+    }
+    
+    @Test(expected=XMLStreamException.class)
+    public void testLocalNameOnStartDocument() throws Exception {
+        pivot.require(XMLStreamConstants.START_DOCUMENT, null, "test");
+    }
+    
+    @Test(expected=XMLStreamException.class)
+    public void testLocalNameMismatchOnStartElement() throws Exception {
+        pivot.next();
+        pivot.require(XMLStreamConstants.START_ELEMENT, "urn:test", "wrong_name");
+    }
+    
+    @Test(expected=XMLStreamException.class)
+    public void testNamespaceURIOnStartDocument() throws Exception {
+        pivot.require(XMLStreamConstants.START_DOCUMENT, "http://example.org", null);
+    }
+    
+    @Test(expected=XMLStreamException.class)
+    public void testNamespaceURIMismatchOnStartElement() throws Exception {
+        pivot.next();
+        pivot.require(XMLStreamConstants.START_ELEMENT, "urn:wrong_uri", "test");
+    }
+}

Propchange: webservices/axiom/trunk/aspects/core-aspects/src/test/java/org/apache/axiom/core/stream/stax/pull/StAXPivotTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message