ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1336371 - in /webservices/axiom/branches/AXIOM-420/modules: axiom-api/src/main/java/org/apache/axiom/om/ds/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/m...
Date Wed, 09 May 2012 20:02:12 GMT
Author: veithen
Date: Wed May  9 20:02:12 2012
New Revision: 1336371

URL: http://svn.apache.org/viewvc?rev=1336371&view=rev
Log:
Finalized the code for AXIOM-420.

Added:
    webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestGetNamespaceContext.java
  (with props)
Modified:
    webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPushOMDataSource.java
    webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
    webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPushOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPushOMDataSource.java?rev=1336371&r1=1336370&r2=1336371&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPushOMDataSource.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/AbstractPushOMDataSource.java
Wed May  9 20:02:12 2012
@@ -18,11 +18,16 @@
  */
 package org.apache.axiom.om.ds;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.util.StAXUtils;
 
 /**
  * Base class for {@link OMDataSourceExt} implementations that can easily serialize the content
to
@@ -35,7 +40,11 @@ public abstract class AbstractPushOMData
     }
 
     public XMLStreamReader getReader() throws XMLStreamException {
-        // TODO: returning null here for the moment; for completeness we should serialize
to a byte stream and create an XMLStreamReader from it
-        return null;
+        // Note: we don't actually expect this code to be called because OMSourcedElement
should handle
+        // AbstractPushOMDataSource instances differently. Nevertheless the code is functionally
correct
+        // (but not very good from a performance point of view, especially for XOP).
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        serialize(bos, new OMOutputFormat());
+        return StAXUtils.createXMLStreamReader(new ByteArrayInputStream(bos.toByteArray()));
     }
 }

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java?rev=1336371&r1=1336370&r2=1336371&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
Wed May  9 20:02:12 2012
@@ -19,6 +19,7 @@
 package org.apache.axiom.om.impl.llom;
 
 import java.io.IOException;
+import java.util.Iterator;
 
 import javax.activation.DataHandler;
 import javax.xml.stream.XMLStreamException;
@@ -26,6 +27,7 @@ import javax.xml.stream.XMLStreamExcepti
 import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
 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;
@@ -33,15 +35,22 @@ import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.util.stax.AbstractXMLStreamWriter;
 
-// TODO: need to seed the namespace context with the namespace context from the parent!
 public class PushOMBuilder extends AbstractXMLStreamWriter implements DataHandlerWriter {
     private final OMSourcedElementImpl root;
     private final OMFactory factory;
     private OMElement parent;
     
-    public PushOMBuilder(OMSourcedElementImpl root) {
+    public PushOMBuilder(OMSourcedElementImpl root) throws XMLStreamException {
         this.root = root;
         factory = root.getOMFactory();
+        // Seed the namespace context with the namespace context from the parent
+        OMContainer parent = root.getParent();
+        if (parent instanceof OMElement) {
+            for (Iterator it = ((OMElement)parent).getNamespacesInScope(); it.hasNext();
) {
+                OMNamespace ns = (OMNamespace)it.next();
+                setPrefix(ns.getPrefix(), ns.getNamespaceURI());
+            }
+        }
     }
     
     public Object getProperty(String name) throws IllegalArgumentException {
@@ -109,8 +118,7 @@ public class PushOMBuilder extends Abstr
     }
 
     protected void doWriteStartElement(String localName) throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+        throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter)
MUST NOT use XMLStreamWriter#writeStartElement(String)");
     }
 
     protected void doWriteEndElement() {
@@ -127,8 +135,7 @@ public class PushOMBuilder extends Abstr
     }
 
     protected void doWriteEmptyElement(String localName) throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+        throw new UnsupportedOperationException("OMDataSource#serialize(XMLStreamWriter)
MUST NOT use XMLStreamWriter#writeEmptyElement(String)");
     }
 
     protected void doWriteAttribute(String prefix, String namespaceURI, String localName,
String value) {
@@ -168,8 +175,8 @@ public class PushOMBuilder extends Abstr
     }
 
     protected void doWriteEntityRef(String name) throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+        // TODO: this is equivalent to what StAXOMBuilder does; however, it doesn't look
correct
+        factory.createOMText(parent, name, OMNode.ENTITY_REFERENCE_NODE);
     }
 
     protected void doWriteProcessingInstruction(String target, String data) {

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1336371&r1=1336370&r2=1336371&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Wed May  9 20:02:12 2012
@@ -380,6 +380,7 @@ public class OMTestSuiteBuilder extends 
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestSetLocalName(metaFactory,
true));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestWrappedTextNodeOMDataSourceFromReader(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestWriteTextToWithNonDestructiveOMDataSource(metaFactory));
+            addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestGetNamespaceContext(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteAttributeNoNamespace(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteDataHandler(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteDataHandlerProvider(metaFactory));

Added: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestGetNamespaceContext.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestGetNamespaceContext.java?rev=1336371&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestGetNamespaceContext.java
(added)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestGetNamespaceContext.java
Wed May  9 20:02:12 2012
@@ -0,0 +1,60 @@
+/*
+ * 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.sourcedelement.push;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link XMLStreamWriter#getNamespaceContext()} gives access to pre-existing
namespace
+ * bindings (defined by the ancestors of the {@link OMSourcedElement}).
+ */
+public class TestGetNamespaceContext extends AxiomTestCase {
+    public TestGetNamespaceContext(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement parent = factory.createOMElement("parent", factory.createOMNamespace("urn:test",
"p"));
+        final String[] resultHolder = new String[1];
+        OMElement element = factory.createOMElement(new AbstractPushOMDataSource() {
+            public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+                resultHolder[0] = writer.getNamespaceContext().getNamespaceURI("p");
+                writer.writeStartElement(null, "root", null);
+                writer.writeEndElement();
+            }
+            
+            public boolean isDestructiveWrite() {
+                return false;
+            }
+        });
+        parent.addChild(element);
+        // Expand element
+        element.getFirstOMChild();
+        assertEquals("urn:test", resultHolder[0]);
+    }
+}

Propchange: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestGetNamespaceContext.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message