ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1334607 - in /webservices/axiom/branches/AXIOM-420/modules: axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-tests...
Date Sun, 06 May 2012 11:35:59 GMT
Author: veithen
Date: Sun May  6 11:35:59 2012
New Revision: 1334607

URL: http://svn.apache.org/viewvc?rev=1334607&view=rev
Log:
Initial implementation for AXIOM-420.

Added:
    webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/PushOMDataSource.java
  (with props)
    webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetXMLStreamReaderWithPushOMDataSource.java
  (with props)
    webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/
    webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteAttributeNoNamespace.java
  (with props)
    webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteStartElementAutoPrefix.java
  (with props)
Modified:
    webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
    webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
    webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.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/impl/builder/BuilderUtil.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java?rev=1334607&r1=1334606&r2=1334607&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
Sun May  6 11:35:59 2012
@@ -18,14 +18,19 @@
  */
 package org.apache.axiom.om.impl.builder;
 
+import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.OMElementEx;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
 
-class BuilderUtil {
+/**
+ * For internal use only.
+ */
+public class BuilderUtil {
     private BuilderUtil() {}
     
-    static void setNamespace(OMElement element, String namespaceURI, String prefix, boolean
namespaceURIInterning) {
+    public static void setNamespace(OMElement element, String namespaceURI, String prefix,
boolean namespaceURIInterning) {
         if (prefix == null) {
             prefix = "";
         }
@@ -49,4 +54,29 @@ class BuilderUtil {
             element.setNamespaceWithNoFindInCurrentScope(namespace);
         }
     }
+    
+    public static void processAttribute(OMElement element, String prefix, String namespaceURI,
String localName, String value, String type) {
+        OMNamespace namespace = null;
+        if (namespaceURI != null && namespaceURI.length() > 0) {
+
+            // prefix being null means this elements has a default namespace or it has inherited
+            // a default namespace from its parent
+            namespace = element.findNamespace(namespaceURI, prefix);
+            if (namespace == null) {
+                if (prefix == null || "".equals(prefix)) {
+                    prefix = OMSerializerUtil.getNextNSPrefix();
+                }
+                namespace = element.declareNamespace(namespaceURI, prefix);
+            }
+        }
+
+        // todo if the attributes are supposed to namespace qualified all the time
+        // todo then this should throw an exception here
+
+        OMAttribute attr = element.addAttribute(localName,
+                          value, namespace);
+        if (type != null) {
+            attr.setAttributeType(type);
+        }
+    }
 }

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1334607&r1=1334606&r2=1334607&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
Sun May  6 11:35:59 2012
@@ -21,20 +21,17 @@ package org.apache.axiom.om.impl.builder
 
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
 import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.util.stax.XMLStreamReaderUtils;
 import org.apache.commons.logging.Log;
@@ -205,31 +202,9 @@ public abstract class StAXBuilder implem
     protected void processAttributes(OMElement node) {
         int attribCount = parser.getAttributeCount();
         for (int i = 0; i < attribCount; i++) {
-            String uri = parser.getAttributeNamespace(i);
-            String prefix = parser.getAttributePrefix(i);
-
-
-            OMNamespace namespace = null;
-            if (uri != null && uri.length() > 0) {
-
-                // prefix being null means this elements has a default namespace or it has
inherited
-                // a default namespace from its parent
-                namespace = node.findNamespace(uri, prefix);
-                if (namespace == null) {
-                    if (prefix == null || "".equals(prefix)) {
-                        prefix = OMSerializerUtil.getNextNSPrefix();
-                    }
-                    namespace = node.declareNamespace(uri, prefix);
-                }
-            }
-
-            // todo if the attributes are supposed to namespace qualified all the time
-            // todo then this should throw an exception here
-
-            OMAttribute attr = node.addAttribute(parser.getAttributeLocalName(i),
-                              parser.getAttributeValue(i), namespace);
-            attr.setAttributeType(parser.getAttributeType(i));
-            
+            BuilderUtil.processAttribute(node, parser.getAttributePrefix(i),
+                    parser.getAttributeNamespace(i), parser.getAttributeLocalName(i),
+                    parser.getAttributeValue(i), parser.getAttributeType(i));
         }
     }
 

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1334607&r1=1334606&r2=1334607&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
Sun May  6 11:35:59 2012
@@ -33,6 +33,7 @@ import org.apache.axiom.om.OMSourcedElem
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
 import org.apache.axiom.om.QNameAwareOMDataSource;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.util.StAXUtils;
@@ -252,39 +253,53 @@ public class OMSourcedElementImpl extend
                 }
             }
 
-            // Get the XMLStreamReader
-            try {
-                readerFromDS = dataSource.getReader();  
-            } catch (XMLStreamException ex) {
-                throw new OMException("Error obtaining parser from data source for element
" + getPrintableName(), ex);
-            }
-            
-            // Advance past the START_DOCUMENT to the start tag.
-            // Remember the character encoding.
-            String characterEncoding = readerFromDS.getCharacterEncodingScheme();
-            if (characterEncoding != null) {
-                characterEncoding = readerFromDS.getEncoding();
-            }
-            try {
-                if (readerFromDS.getEventType() != XMLStreamConstants.START_ELEMENT) {
-                    while (readerFromDS.next() != XMLStreamConstants.START_ELEMENT) ;
+            if (isPushDataSource()) {
+                // Set this before we start expanding; otherwise this would result in an
infinite recursion
+                isExpanded = true;
+                try {
+                    dataSource.serialize(new PushOMBuilder(this));
+                } catch (XMLStreamException ex) {
+                    throw new OMException("Failed to expand data source", ex);
+                }
+            } else {
+                // Get the XMLStreamReader
+                try {
+                    readerFromDS = dataSource.getReader();  
+                } catch (XMLStreamException ex) {
+                    throw new OMException("Error obtaining parser from data source for element
" + getPrintableName(), ex);
+                }
+                
+                // Advance past the START_DOCUMENT to the start tag.
+                // Remember the character encoding.
+                String characterEncoding = readerFromDS.getCharacterEncodingScheme();
+                if (characterEncoding != null) {
+                    characterEncoding = readerFromDS.getEncoding();
                 }
-            } catch (XMLStreamException ex) {
-                throw new OMException("Error parsing data source document for element " +
getLocalName(), ex);
+                try {
+                    if (readerFromDS.getEventType() != XMLStreamConstants.START_ELEMENT)
{
+                        while (readerFromDS.next() != XMLStreamConstants.START_ELEMENT) ;
+                    }
+                } catch (XMLStreamException ex) {
+                    throw new OMException("Error parsing data source document for element
" + getLocalName(), ex);
+                }
+    
+                validateName(readerFromDS.getPrefix(), readerFromDS.getLocalName(), readerFromDS.getNamespaceURI());
+    
+                // Set the builder for this element. Note that the StAXOMBuilder constructor
will also
+                // update the namespace of the element, so we don't need to do that here.
+                isExpanded = true;
+                super.setBuilder(new StAXOMBuilder(getOMFactory(), 
+                                                   readerFromDS, 
+                                                   this, 
+                                                   characterEncoding));
+                setComplete(false);
             }
-
-            validateName(readerFromDS.getPrefix(), readerFromDS.getLocalName(), readerFromDS.getNamespaceURI());
-
-            // Set the builder for this element. Note that the StAXOMBuilder constructor
will also
-            // update the namespace of the element, so we don't need to do that here.
-            isExpanded = true;
-            super.setBuilder(new StAXOMBuilder(getOMFactory(), 
-                                               readerFromDS, 
-                                               this, 
-                                               characterEncoding));
-            setComplete(false);
         }
     }
+    
+    private boolean isPushDataSource() {
+        return dataSource instanceof AbstractPushOMDataSource;
+    }
 
     /**
      * Validates that the actual name of the element obtained from StAX matches the information
@@ -465,7 +480,7 @@ public class OMSourcedElementImpl extend
         if (isExpanded) {
             return super.getXMLStreamReader(cache, configuration);
         } else {
-            if (cache && isDestructiveRead()) {
+            if ((cache && isDestructiveRead()) || isPushDataSource()) {
                 forceExpand();
                 return super.getXMLStreamReader(true, configuration);
             } else {

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=1334607&r1=1334606&r2=1334607&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
Sun May  6 11:35:59 2012
@@ -22,17 +22,19 @@ import javax.xml.stream.XMLStreamExcepti
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.builder.BuilderUtil;
 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 {
+    private final OMSourcedElementImpl root;
     private final OMFactory factory;
     private OMElement parent;
-    private int depth;
     
     public PushOMBuilder(OMSourcedElementImpl root) {
+        this.root = root;
         factory = root.getOMFactory();
-        parent = root;
     }
     
     public Object getProperty(String name) throws IllegalArgumentException {
@@ -40,19 +42,19 @@ public class PushOMBuilder extends Abstr
         throw new UnsupportedOperationException();
     }
 
-    protected void doWriteStartDocument() throws XMLStreamException {
+    protected void doWriteStartDocument() {
         // Do nothing
     }
 
-    protected void doWriteStartDocument(String encoding, String version) throws XMLStreamException
{
+    protected void doWriteStartDocument(String encoding, String version) {
         // Do nothing
     }
 
-    protected void doWriteStartDocument(String version) throws XMLStreamException {
+    protected void doWriteStartDocument(String version) {
         // Do nothing
     }
 
-    protected void doWriteEndDocument() throws XMLStreamException {
+    protected void doWriteEndDocument() {
         // Do nothing
     }
 
@@ -60,10 +62,14 @@ public class PushOMBuilder extends Abstr
         throw new XMLStreamException("A DTD must not appear in element content");
     }
 
-    protected void doWriteStartElement(String prefix, String localName, String namespaceURI)
-            throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteStartElement(String prefix, String localName, String namespaceURI)
{
+        if (parent == null) {
+            root.validateName(prefix, localName, namespaceURI);
+            parent = root;
+        } else {
+            parent = factory.createOMElement(localName, null, parent);
+        }
+        BuilderUtil.setNamespace(parent, namespaceURI, prefix, false);
     }
 
     protected void doWriteStartElement(String localName) throws XMLStreamException {
@@ -71,13 +77,15 @@ public class PushOMBuilder extends Abstr
         throw new UnsupportedOperationException();
     }
 
-    protected void doWriteEndElement() throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteEndElement() {
+        if (parent == root) {
+            parent = null;
+        } else {
+            parent = (OMElement)parent.getParent();
+        }
     }
 
-    protected void doWriteEmptyElement(String prefix, String localName, String namespaceURI)
-            throws XMLStreamException {
+    protected void doWriteEmptyElement(String prefix, String localName, String namespaceURI)
{
         doWriteStartElement(prefix, localName, namespaceURI);
         doWriteEndElement();
     }
@@ -87,45 +95,38 @@ public class PushOMBuilder extends Abstr
         throw new UnsupportedOperationException();
     }
 
-    protected void doWriteAttribute(String prefix, String namespaceURI, String localName,
-            String value) throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteAttribute(String prefix, String namespaceURI, String localName,
String value) {
+        BuilderUtil.processAttribute(parent, prefix, namespaceURI, localName, value, null);
     }
 
     protected void doWriteAttribute(String localName, String value) throws XMLStreamException
{
-        // TODO
-        throw new UnsupportedOperationException();
+        doWriteAttribute(null, null, localName, value);
     }
 
-    protected void doWriteNamespace(String prefix, String namespaceURI) throws XMLStreamException
{
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteNamespace(String prefix, String namespaceURI) {
+        // Note that the namespace declaration may already have been added automatically
by writeStartElement
+        // or writeAttribute; we count on declareNamespace to do the necessary checks
+        parent.declareNamespace(namespaceURI == null ? "" : namespaceURI, prefix == null
? "" : prefix);
     }
 
-    protected void doWriteDefaultNamespace(String namespaceURI) throws XMLStreamException
{
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteDefaultNamespace(String namespaceURI) {
+        parent.declareDefaultNamespace(namespaceURI == null ? "" : namespaceURI);
     }
 
-    protected void doWriteCharacters(char[] text, int start, int len) throws XMLStreamException
{
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteCharacters(char[] text, int start, int len) {
+        doWriteCharacters(new String(text, start, len));
     }
 
-    protected void doWriteCharacters(String text) throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteCharacters(String text) {
+        factory.createOMText(parent, text);
     }
 
-    protected void doWriteCData(String data) throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteCData(String data) {
+        factory.createOMText(parent, data, OMNode.CDATA_SECTION_NODE);
     }
 
-    protected void doWriteComment(String data) throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteComment(String data) {
+        factory.createOMComment(parent, data);
     }
 
     protected void doWriteEntityRef(String name) throws XMLStreamException {
@@ -133,15 +134,12 @@ public class PushOMBuilder extends Abstr
         throw new UnsupportedOperationException();
     }
 
-    protected void doWriteProcessingInstruction(String target, String data)
-            throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteProcessingInstruction(String target, String data) {
+        factory.createOMProcessingInstruction(parent, target, data);
     }
 
-    protected void doWriteProcessingInstruction(String target) throws XMLStreamException
{
-        // TODO
-        throw new UnsupportedOperationException();
+    protected void doWriteProcessingInstruction(String target) {
+        doWriteProcessingInstruction(target, "");
     }
 
     public void flush() throws XMLStreamException {

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=1334607&r1=1334606&r2=1334607&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
Sun May  6 11:35:59 2012
@@ -348,6 +348,8 @@ public class OMTestSuiteBuilder extends 
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetNamespaceNormalized2(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetObject(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetTextAsStreamWithNonDestructiveOMDataSource(metaFactory));
+            addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetXMLStreamReaderWithPushOMDataSource(metaFactory,
true));
+            addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetXMLStreamReaderWithPushOMDataSource(metaFactory,
false));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestInputStreamDS(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1DefaultPrefix(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1QualifiedPrefix(metaFactory));
@@ -378,6 +380,8 @@ 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.TestWriteAttributeNoNamespace(metaFactory));
+            addTest(new org.apache.axiom.ts.om.sourcedelement.push.TestWriteStartElementAutoPrefix(metaFactory));
         }
         addTest(new org.apache.axiom.ts.om.pi.TestDigest(metaFactory));
         addTest(new org.apache.axiom.ts.om.text.TestBase64Streaming(metaFactory));

Added: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/PushOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/PushOMDataSource.java?rev=1334607&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/PushOMDataSource.java
(added)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/PushOMDataSource.java
Sun May  6 11:35:59 2012
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.QNameAwareOMDataSource;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
+
+public class PushOMDataSource extends AbstractPushOMDataSource implements QNameAwareOMDataSource
{
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeStartElement("p", "root", "urn:test");
+        writer.writeEndElement();
+    }
+
+    public boolean isDestructiveWrite() {
+        return false;
+    }
+
+    public String getLocalName() {
+        return "root";
+    }
+
+    public String getNamespaceURI() {
+        return "urn:test";
+    }
+
+    public String getPrefix() {
+        return "p";
+    }
+}

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

Added: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetXMLStreamReaderWithPushOMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetXMLStreamReaderWithPushOMDataSource.java?rev=1334607&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetXMLStreamReaderWithPushOMDataSource.java
(added)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetXMLStreamReaderWithPushOMDataSource.java
Sun May  6 11:35:59 2012
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestGetXMLStreamReaderWithPushOMDataSource extends AxiomTestCase {
+    private final boolean cache;
+    
+    public TestGetXMLStreamReaderWithPushOMDataSource(OMMetaFactory metaFactory, boolean
cache) {
+        super(metaFactory);
+        this.cache = cache;
+        addTestProperty("cache", String.valueOf(cache));
+    }
+
+    protected void runTest() throws Throwable {
+        PushOMDataSource ds = new PushOMDataSource();
+        OMSourcedElement element = metaFactory.getOMFactory().createOMElement(ds);
+        XMLStreamReader reader = element.getXMLStreamReader(cache);
+        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+        assertEquals(ds.getLocalName(), reader.getLocalName());
+        assertEquals(ds.getNamespaceURI(), reader.getNamespaceURI());
+        assertEquals(ds.getPrefix(), reader.getPrefix());
+        // Since the OMDataSource is push-only, getXMLStreamReader will cause expansion regardless
+        // of the value of the cache flag
+        assertTrue(element.isExpanded());
+        // In addition, if the element is expanded, it will always be complete
+        assertTrue(element.isComplete());
+    }
+}

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

Added: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteAttributeNoNamespace.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/TestWriteAttributeNoNamespace.java?rev=1334607&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteAttributeNoNamespace.java
(added)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteAttributeNoNamespace.java
Sun May  6 11:35:59 2012
@@ -0,0 +1,54 @@
+/*
+ * 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.namespace.QName;
+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.ds.AbstractPushOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link XMLStreamWriter#writeAttribute(String, String)} creates the expected
attribute.
+ */
+public class TestWriteAttributeNoNamespace extends AxiomTestCase {
+    public TestWriteAttributeNoNamespace(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement(new AbstractPushOMDataSource() {
+            public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+                writer.writeStartElement("p", "root", "urn:test");
+                writer.writeAttribute("attr", "value");
+                writer.writeEndElement();
+            }
+            
+            public boolean isDestructiveWrite() {
+                return false;
+            }
+        });
+        assertEquals("value", element.getAttributeValue(new QName("attr")));
+    }
+}

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

Added: webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteStartElementAutoPrefix.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/TestWriteStartElementAutoPrefix.java?rev=1334607&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteStartElementAutoPrefix.java
(added)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/TestWriteStartElementAutoPrefix.java
Sun May  6 11:35:59 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.ds.AbstractPushOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link XMLStreamWriter#writeStartElement(String, String)} automatically selects
an
+ * appropriate prefix.
+ */
+public class TestWriteStartElementAutoPrefix extends AxiomTestCase {
+    public TestWriteStartElementAutoPrefix(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement(new AbstractPushOMDataSource() {
+            public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+                writer.writeStartElement(null, "root", null);
+                writer.writeNamespace("p", "urn:test");
+                writer.setPrefix("p", "urn:test");
+                writer.writeStartElement("urn:test", "child");
+                writer.writeEndElement();
+                writer.writeEndElement();
+            }
+            
+            public boolean isDestructiveWrite() {
+                return false;
+            }
+        });
+        OMElement child = element.getFirstElement();
+        assertEquals("p", child.getPrefix());
+        assertEquals("urn:test", child.getNamespaceURI());
+        assertEquals("child", child.getLocalName());
+    }
+}

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



Mime
View raw message