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/07/07 20:24:12 UTC

svn commit: r1358610 [2/10] - in /webservices/axiom/branches/AXIOM-201: ./ modules/axiom-api/ modules/axiom-api/src/main/java/org/apache/axiom/attachments/ modules/axiom-api/src/main/java/org/apache/axiom/locator/ modules/axiom-api/src/main/java/org/ap...

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/pom.xml?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/pom.xml (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/pom.xml Sat Jul  7 18:24:00 2012
@@ -100,11 +100,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <!-- We need this to be able to test Woodstox 4 -->
+            <!-- We need this in the StAX dialect for Woodstox 4 -->
             <groupId>org.codehaus.woodstox</groupId>
             <artifactId>stax2-api</artifactId>
-            <version>3.0.2</version>
-            <scope>test</scope>
+            <version>3.1.1</version>
+            <scope>provided</scope>
             <exclusions>
                 <exclusion>
                     <groupId>javax.xml.stream</groupId>
@@ -114,45 +114,8 @@
         </dependency>
     </dependencies>
     <build>
-        <testResources>
-            <testResource>
-                <directory>src/test/resources</directory>
-            </testResource>
-            <testResource>
-                <directory>${project.build.directory}/generated-test-resources</directory>
-            </testResource>
-        </testResources>
         <plugins>
             <plugin>
-                <groupId>org.codehaus.gmaven</groupId>
-                <artifactId>gmaven-plugin</artifactId>
-                <version>1.2</version>
-                <executions>
-                    <execution>
-                        <phase>generate-test-resources</phase>
-                        <goals>
-                            <goal>execute</goal>
-                        </goals>
-                        <configuration>
-                            <source>
-                                <!-- This generates a list of the files in src/test/resources/conformance.
-                                     This is useful when loading these files from the classpath. -->
-                                <![CDATA[
-                                    def filelist = new File(project.build.directory, "generated-test-resources/conformance/filelist");
-                                    filelist.parentFile.mkdirs();
-                                    filelist.delete();
-                                    new File(project.basedir, "src/test/resources/conformance").eachFile({
-                                        if (it.file) {
-                                            filelist.append("$it.name\n");
-                                        }
-                                    })
-                                ]]>
-                            </source>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
                 <artifactId>maven-dependency-plugin</artifactId>
                 <executions>
                     <execution>
@@ -194,6 +157,11 @@
                                     <version>4.1.2</version>
                                 </artifactItem>
                                 <artifactItem>
+                                    <groupId>org.codehaus.woodstox</groupId>
+                                    <artifactId>woodstox-core-asl</artifactId>
+                                    <version>4.1.3</version>
+                                </artifactItem>
+                                <artifactItem>
                                     <groupId>com.sun.xml.stream</groupId>
                                     <artifactId>sjsxp</artifactId>
                                     <version>1.0.1</version>

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentSet.java Sat Jul  7 18:24:00 2012
@@ -62,7 +62,7 @@ class AttachmentSet extends AttachmentsD
         attachmentsMap.remove(blobContentID);
     }
 
-    InputStream getRootPartInputStream() throws OMException {
+    InputStream getRootPartInputStream(boolean preserve) throws OMException {
         throw new OMException("Invalid operation. Attachments are created programatically.");
     }
 

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java Sat Jul  7 18:24:00 2012
@@ -240,12 +240,33 @@ public class Attachments implements OMAt
     
     /**
      * Get an input stream for the root part of the MIME message. The root part is located as
-     * described in the documentation of the {@link #getRootPartContentID()} method.
+     * described in the documentation of the {@link #getRootPartContentID()} method. Note that a new
+     * stream is returned each time this method is called, i.e. the method does not consume the root
+     * part. Instead it loads the root part into memory so that it can be read several times.
      * 
      * @return the input stream for the root part
      */
     public InputStream getRootPartInputStream() throws OMException {
-        return delegate.getRootPartInputStream();
+        return delegate.getRootPartInputStream(true);
+    }
+
+    /**
+     * Get an input stream for the root part of the MIME message. This method is similar to
+     * {@link #getRootPartInputStream()}, but can be instructed to consume the root part. This
+     * allows streaming of the root part. If that feature is used, the root part will not be loaded
+     * into memory unless an attempt is made to access another part of the MIME message, in which
+     * case the remaining (i.e. unconsumed) content of the root part will be buffered. If the
+     * feature is not enabled, then this method behaves in the same way as
+     * {@link #getRootPartInputStream()}.
+     * 
+     * @param preserve
+     *            <code>true</code> if the content of the root part should be fetched into memory so
+     *            that it can be read several times, <code>false</code> if the root part should be
+     *            consumed
+     * @return the input stream for the root part
+     */
+    public InputStream getRootPartInputStream(boolean preserve) throws OMException {
+        return delegate.getRootPartInputStream(preserve);
     }
 
     /**

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/AttachmentsDelegate.java Sat Jul  7 18:24:00 2012
@@ -55,7 +55,7 @@ abstract class AttachmentsDelegate {
     abstract DataHandler getDataHandler(String contentID);
     abstract void addDataHandler(String contentID, DataHandler dataHandler);
     abstract void removeDataHandler(String blobContentID);
-    abstract InputStream getRootPartInputStream() throws OMException;
+    abstract InputStream getRootPartInputStream(boolean preserve) throws OMException;
     abstract String getRootPartContentID();
     abstract String getRootPartContentType();
     abstract IncomingAttachmentStreams getIncomingAttachmentStreams();

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Sat Jul  7 18:24:00 2012
@@ -31,6 +31,7 @@ import javax.activation.DataHandler;
 import javax.mail.internet.ContentType;
 import javax.mail.internet.ParseException;
 
+import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
 import org.apache.axiom.attachments.lifecycle.LifecycleManager;
 import org.apache.axiom.attachments.lifecycle.impl.LifecycleManagerImpl;
 import org.apache.axiom.mime.Header;
@@ -185,7 +186,7 @@ class MIMEMessage extends AttachmentsDel
         } while (getNextPartDataHandler() != null);
     }
 
-    InputStream getRootPartInputStream() throws OMException {
+    InputStream getRootPartInputStream(boolean preserve) throws OMException {
         DataHandler dh;
         try {
             dh = getDataHandler(getRootPartContentID());
@@ -193,7 +194,11 @@ class MIMEMessage extends AttachmentsDel
                 throw new OMException(
                         "Mandatory root MIME part is missing");
             }
-            return dh.getInputStream();
+            if (!preserve && dh instanceof DataHandlerExt) {
+                return ((DataHandlerExt)dh).readOnce();
+            } else {
+                return dh.getInputStream();
+            }
         } catch (IOException e) {
             throw new OMException(
                     "Problem with DataHandler of the Root Mime Part. ", e);

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartContentFactory.java Sat Jul  7 18:24:00 2012
@@ -22,6 +22,7 @@ import org.apache.axiom.attachments.impl
 import org.apache.axiom.attachments.lifecycle.LifecycleManager;
 import org.apache.axiom.attachments.utils.BAAInputStream;
 import org.apache.axiom.attachments.utils.BAAOutputStream;
+import org.apache.axiom.ext.io.StreamCopyException;
 import org.apache.axiom.om.OMException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -100,6 +101,12 @@ class PartContentFactory {
                                           attachmentDir);
                 }
             } 
+        } catch (StreamCopyException ex) {
+            if (ex.getOperation() == StreamCopyException.READ) {
+                throw new OMException("Failed to fetch the MIME part content", ex.getCause());
+            } else {
+                throw new OMException("Failed to write the MIME part content to temporary storage", ex.getCause());
+            }
         } catch (Exception e) {
             throw new OMException(e);
         } 

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/DefaultOMMetaFactoryLocator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/DefaultOMMetaFactoryLocator.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/DefaultOMMetaFactoryLocator.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/DefaultOMMetaFactoryLocator.java Sat Jul  7 18:24:00 2012
@@ -26,11 +26,15 @@ import java.util.List;
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMMetaFactoryLocator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * The default {@link OMMetaFactoryLocator} implementation used in non OSGi environments.
  */
 public final class DefaultOMMetaFactoryLocator extends PriorityBasedOMMetaFactoryLocator {
+    private static final Log log = LogFactory.getLog(DefaultOMMetaFactoryLocator.class);
+    
     public DefaultOMMetaFactoryLocator() {
         ClassLoader classLoader = DefaultOMMetaFactoryLocator.class.getClassLoader();
         
@@ -53,6 +57,9 @@ public final class DefaultOMMetaFactoryL
             // Ignore and continue
         }
         if (metaFactoryClassName != null) {
+            if (log.isDebugEnabled()) {
+                log.debug(OMAbstractFactory.META_FACTORY_NAME_PROPERTY + " system property is set; value=" + metaFactoryClassName);
+            }
             Implementation implementation = ImplementationFactory.createDefaultImplementation(loader, metaFactoryClassName);
             if (implementation != null) {
                 implementations.add(implementation);
@@ -60,6 +67,7 @@ public final class DefaultOMMetaFactoryL
         }
 
         // Now discover the available implementations by looking for the axiom.xml descriptor.
+        log.debug("Starting class path based discovery");
         try {
             Enumeration e = classLoader.getResources(ImplementationFactory.DESCRIPTOR_RESOURCE);
             while (e.hasMoreElements()) {

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/Feature.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/Feature.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/Feature.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/Feature.java Sat Jul  7 18:24:00 2012
@@ -34,4 +34,8 @@ final class Feature {
     int getPriority() {
         return priority;
     }
+
+    public String toString() {
+        return name + "(priority=" + priority + ")";
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/Implementation.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/Implementation.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/Implementation.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/Implementation.java Sat Jul  7 18:24:00 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.locator;
 
+import java.util.Arrays;
+
 import org.apache.axiom.om.OMMetaFactory;
 
 final class Implementation {
@@ -42,4 +44,9 @@ final class Implementation {
     Feature[] getFeatures() {
         return features;
     }
+
+    public String toString() {
+        return name + "(metaFactory=" + metaFactory.getClass().getName()
+                + ",features=" + (features != null ? Arrays.asList(features) : null) + ")";
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java Sat Jul  7 18:24:00 2012
@@ -49,6 +49,9 @@ final class ImplementationFactory {
     private ImplementationFactory() {}
     
     static Implementation createDefaultImplementation(Loader loader, String className) {
+        if (log.isDebugEnabled()) {
+            log.debug("Creating default implementation for class " + className);
+        }
         OMMetaFactory metaFactory = (OMMetaFactory)load(loader, className);
         return metaFactory == null ? null : new Implementation(null, metaFactory,
                 new Feature[] { new Feature(OMAbstractFactory.FEATURE_DEFAULT, Integer.MAX_VALUE) });
@@ -71,6 +74,9 @@ final class ImplementationFactory {
     }
     
     static List/*<Implementation>*/ parseDescriptor(Loader loader, URL url) {
+        if (log.isDebugEnabled()) {
+            log.debug("Loading " + url);
+        }
         List implementations = new ArrayList();
         try {
             // Since this code is used to discover Axiom implementations, we have to use DOM here.
@@ -107,6 +113,9 @@ final class ImplementationFactory {
         } catch (SAXException ex) {
             log.error("Parser error while reading " + url, ex);
         }
+        if (log.isDebugEnabled()) {
+            log.debug("Discovered implementations: " + implementations);
+        }
         return implementations;
     }
     

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/PriorityBasedOMMetaFactoryLocator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/PriorityBasedOMMetaFactoryLocator.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/PriorityBasedOMMetaFactoryLocator.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/locator/PriorityBasedOMMetaFactoryLocator.java Sat Jul  7 18:24:00 2012
@@ -25,8 +25,12 @@ import java.util.Map;
 
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMMetaFactoryLocator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 class PriorityBasedOMMetaFactoryLocator implements OMMetaFactoryLocator {
+    private static final Log log = LogFactory.getLog(PriorityBasedOMMetaFactoryLocator.class);
+    
     private final Map/*<String,OMMetaFactory>*/ factories = new HashMap();
     
     void loadImplementations(List/*<Implementation>*/ implementations) {
@@ -46,6 +50,17 @@ class PriorityBasedOMMetaFactoryLocator 
                 }
             }
         }
+        if (log.isDebugEnabled()) {
+            StringBuilder buffer = new StringBuilder("Meta factories:");
+            for (Iterator it = factories.entrySet().iterator(); it.hasNext(); ) {
+                Map.Entry entry = (Map.Entry)it.next();
+                buffer.append("\n  ");
+                buffer.append(entry.getKey());
+                buffer.append(": ");
+                buffer.append(entry.getValue().getClass().getName());
+            }
+            log.debug(buffer);
+        }
     }
     
     public OMMetaFactory getOMMetaFactory(String feature) {

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMAttribute.java Sat Jul  7 18:24:00 2012
@@ -21,13 +21,21 @@ package org.apache.axiom.om;
 
 /** Interface OMAttribute */
 public interface OMAttribute extends OMNamedInformationItem {
-    /** @return Returns String. */
+    /**
+     * Get the attribute value.
+     * 
+     * @return the attribute value; never <code>null</code
+     */
     String getAttributeValue();
 
     /** @param value  */
     void setAttributeValue(String value);
 
-    /** @return Returns String. */
+    /**
+     * Get the attribute type. For most attributes, the type is <code>CDATA</code>.
+     * 
+     * @return the attribute type
+     */
     String getAttributeType();
 
     /** @param value  */

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java Sat Jul  7 18:24:00 2012
@@ -46,10 +46,10 @@ public interface OMContainer extends OMS
     OMXMLParserWrapper getBuilder();
 
     /**
-     * Adds the given node as the last child. One must preserve the order of children, in this
-     * operation. Tip : appending the new child is preferred.
-     *
+     * Adds the given node as the last child of this container.
+     * 
      * @param omNode
+     *            the node to be added to this container
      */
     // TODO: specify whether the node is removed from its original location
     // TODO: specify what happens if the node has been created by a foreign OMFactory

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDataSource.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDataSource.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDataSource.java Sat Jul  7 18:24:00 2012
@@ -25,6 +25,7 @@ package org.apache.axiom.om;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+
 import java.io.OutputStream;
 import java.io.Writer;
 
@@ -35,41 +36,104 @@ import java.io.Writer;
 public interface OMDataSource {
     /**
      * Serializes element data directly to stream.
-     *
-     * @param output destination stream for element XML text
-     * @param format Output format information. The implementation must use this information
-     *               to choose the correct character set encoding when writing to the
-     *               output stream. This parameter must not be null.
+     * <p>
+     * It is assumed that this method consumes the content (i.e. destroys the backing object) unless
+     * the data source also implements {@link OMDataSourceExt} and
+     * {@link OMDataSourceExt#isDestructiveWrite()} returns <code>false</code>.
+     * 
+     * @param output
+     *            destination stream for element XML text
+     * @param format
+     *            Output format information. The implementation must use this information to choose
+     *            the correct character set encoding when writing to the output stream. This
+     *            parameter must not be null.
      * @throws XMLStreamException
      */
-    void serialize(OutputStream output, OMOutputFormat format)
-            throws XMLStreamException;
+    void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException;
 
     /**
      * Serializes element data directly to writer.
-     *
-     * @param writer destination writer for element XML text
-     * @param format output format information (<code>null</code> if none; may be ignored if not
-     *               supported by data binding even if supplied)
+     * <p>
+     * It is assumed that this method consumes the content (i.e. destroys the backing object) unless
+     * the data source also implements {@link OMDataSourceExt} and
+     * {@link OMDataSourceExt#isDestructiveWrite()} returns <code>false</code>.
+     * 
+     * @param writer
+     *            destination writer for element XML text
+     * @param format
+     *            output format information (<code>null</code> if none; may be ignored if not
+     *            supported by data binding even if supplied)
      * @throws XMLStreamException
      */
-    void serialize(Writer writer, OMOutputFormat format)
-            throws XMLStreamException;
+    void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException;
 
     /**
      * Serializes element data directly to StAX writer.
-     *
-     * @param xmlWriter destination writer
+     * <p>
+     * The implementation of this method must satisfy the following requirements:
+     * <ul>
+     * <li>The implementation MUST NOT not write any start document or end document event, i.e. it
+     * MUST NOT use {@link XMLStreamWriter#writeStartDocument()},
+     * {@link XMLStreamWriter#writeStartDocument(String)},
+     * {@link XMLStreamWriter#writeStartDocument(String, String)} or
+     * {@link XMLStreamWriter#writeEndElement()}.
+     * <li>The implementation MUST output a single element (hereafter called the root element). It
+     * MUST NOT output any other content before or after that element.
+     * <li>The implementation MUST specify the namespace URI when writing an element, i.e. it MUST
+     * NOT use the namespace unaware methods {@link XMLStreamWriter#writeStartElement(String)} or
+     * {@link XMLStreamWriter#writeEmptyElement(String)}. On the other hand, it MAY use the
+     * namespace unaware {@link XMLStreamWriter#writeAttribute(String, String)} method, provided
+     * that the specified name is an <tt>NCName</tt>.
+     * <li>The implementation MUST ensure that the produced XML is well formed with respect to
+     * namespaces, i.e. it MUST generate the required namespace declarations using
+     * {@link XMLStreamWriter#writeNamespace(String, String)} and
+     * {@link XMLStreamWriter#writeDefaultNamespace(String)}. It MUST NOT assume that the
+     * {@link XMLStreamWriter} performs any kind of namespace repairing (although that may be the
+     * case).
+     * <li>In addition the implementation MAY use {@link XMLStreamWriter#setPrefix(String, String)}
+     * and {@link XMLStreamWriter#setDefaultNamespace(String)} to track the namespace declarations
+     * it generates, so that the namespace context maintained by the {@link XMLStreamWriter}
+     * accurately reflects the namespace context in the output document. However, it MUST NOT call
+     * these methods before the start of the root element or after the end of the root element.
+     * <li>Since the element may be serialized as part of a larger document, the implementation MUST
+     * take into account the pre-existing namespace context (which can be queried using
+     * {@link XMLStreamWriter#getPrefix(String)} and {@link XMLStreamWriter#getNamespaceContext()}).
+     * This means that the implementation MUST NOT assume that the empty prefix is bound to the
+     * empty namespace URI. Therefore if the implementation outputs elements that have no namespace,
+     * it MUST generate namespace declarations of the form <tt>xmlns=""</tt> in the appropriate
+     * locations. In addition it MAY use the namespace context information to minimize the number of
+     * generated namespace declarations (by reusing already bound prefixes).
+     * </ul>
+     * <p>
+     * On the other hand, the caller of this method (typically an {@link OMSourcedElement} instance)
+     * must ensure that the following requirements are satisfied:
+     * <ul>
+     * <li>The namespace context information provided by {@link XMLStreamWriter#getPrefix(String)}
+     * and {@link XMLStreamWriter#getNamespaceContext()} MUST accurately reflect the actual
+     * namespace context at the location in the output document where the root element is
+     * serialized. Note that this requirement may be relaxed if the caller implements some form of
+     * namespace repairing.
+     * </ul>
+     * <p>
+     * It is assumed that this method consumes the content (i.e. destroys the backing object) unless
+     * the data source also implements {@link OMDataSourceExt} and
+     * {@link OMDataSourceExt#isDestructiveWrite()} returns <code>false</code>.
+     * 
+     * @param xmlWriter
+     *            destination writer
      * @throws XMLStreamException
      */
-    // TODO: specify whether the implementation MUST, MAY or MUST NOT write START_DOCUMENT and END_DOCUMENT events to the stream
-    void serialize(XMLStreamWriter xmlWriter)
-            throws XMLStreamException;
+    // TODO: specify how optimizable base64 binary data (MTOM) is handled
+    void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException;
 
     /**
      * Get parser for element data. In the general case this may require the data source to
      * serialize data as XML text and then parse that text.
-     *
+     * <p>
+     * It is assumed that this method consumed the content (i.e. destroys the backing object) unless
+     * the data source also implements {@link OMDataSourceExt} and
+     * {@link OMDataSourceExt#isDestructiveRead()} returns <code>false</code>.
+     * 
      * @return element parser
      * @throws XMLStreamException
      */

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDataSourceExt.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDataSourceExt.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDataSourceExt.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMDataSourceExt.java Sat Jul  7 18:24:00 2012
@@ -18,14 +18,8 @@
  */
 package org.apache.axiom.om;
 
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
-import java.io.Writer;
 
 /**
  * Interface to a backing object that can can be read and written as XML.
@@ -43,63 +37,25 @@ import java.io.Writer;
  * @see OMSourcedElement
  */
 public interface OMDataSourceExt extends OMDataSource {
-    
-    /* Property lossyPrefix
-     * Value null or Boolean.TRUE or Boolean.FALSE
-     * If Boolean.TRUE, this indicates that expansion is needed to 
-     * obtain the actual prefix name. 
-     */
-    public static final String LOSSY_PREFIX = "lossyPrefix";
-
-    /**
-     * Serializes element data directly to stream.
-     * Assumes that the backing object is destroyed during serialization if isDestructiveWrite
-     * @see OMDataSourceExt
-     *
-     * @param output destination stream for element XML text
-     * @param format Output format information. The implementation must use this information
-     *               to choose the correct character set encoding when writing to the
-     *               output stream. This parameter must not be null.
-     * @throws XMLStreamException
-     */
-    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException;
-
-    /**
-     * Serializes element data directly to writer.
-     * Assumes that the backing object is destroyed during serialization isDestructiveWrite
-     * @see OMDataSourceExt
-     *
-     * @param writer destination writer for element XML text
-     * @param format output format information (<code>null</code> if none; may
-     * be ignored if not supported by data binding even if supplied)
-     * @throws XMLStreamException
-     */
-    public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException;
-
-    /**
-     * Serializes element data directly to StAX writer.
-     * Assumes that the backing object is destroyed during serialization isDestructiveWrite
-     * @see OMDataSourceExt
-     *
-     * @param xmlWriter destination writer
-     * @throws XMLStreamException
-     */
-    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException;
-
-    /**
-     * Get parser for element data. In the general case this may require the
-     * data source to serialize data as XML text and then parse that text.
-     *
-     * @return element parser
-     * @throws XMLStreamException
-     */
-    public XMLStreamReader getReader() throws XMLStreamException;
-    
     /**
-     * Returns the backing Object.
-     * @return Object
+     * @deprecated To create an {@link OMSourcedElement} with unknown prefix, use
+     *             {@link OMFactory#createOMElement(OMDataSource, String, OMNamespace)} and pass
+     *             <code>null</code> as prefix.
+     */
+    String LOSSY_PREFIX = "lossyPrefix";
+    
+    /**
+     * Get the object that backs this data source. Application code should in general not call this
+     * method directly, but use {@link OMSourcedElement#getObject(Class)} instead.
+     * <p>
+     * Data sources that support non destructive read/write should return the object from which the
+     * XML is produced. Data sources with destructive read/write should return a non null value only
+     * if the backing object has not been consumed yet (even partially).
+     * 
+     * @return the backing object, or <code>null</code> if the data source has no backing object or
+     *         if the backing object can't be accessed in a safe way
      */
-    public Object getObject();
+    Object getObject();
     
     /**
      * Returns true if reading the backing object is destructive.
@@ -108,7 +64,7 @@ public interface OMDataSourceExt extends
      * expansion is needed when reading the OMDataSourceExt.
      * @return boolean
      */
-    public boolean isDestructiveRead();
+    boolean isDestructiveRead();
     
     /**
      * Returns true if writing the backing object is destructive.
@@ -117,14 +73,14 @@ public interface OMDataSourceExt extends
      * expansion is needed when writing the OMDataSourceExt.
      * @return boolean
      */
-    public boolean isDestructiveWrite();
+    boolean isDestructiveWrite();
     
     /**
      * Returns a InputStream representing the xml data
      * @param encoding String encoding of InputStream
      * @return InputStream
      */
-    public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException;
+    InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException;
     
     /**
      * Returns a byte[] representing the xml data
@@ -132,32 +88,38 @@ public interface OMDataSourceExt extends
      * @return byte[]
      * @see #getXMLInputStream(String)
      */
-    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException;
+    byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException;
     
     /**
      * Close the DataSource and free its resources.
      */
-    public void close();
+    void close();
     
     /**
-     * Create a copy of the OMDataSourceExt
-     * @return OMDataSourceExt
+     * Create a copy of the data source. This method is used by
+     * {@link OMElement#cloneOMElement(OMCloneOptions)} when the
+     * {@link OMCloneOptions#isCopyOMDataSources()} option is enabled. If the data source is
+     * immutable and stateless, then it may return a reference to itself instead of creating a new
+     * data source instance.
+     * 
+     * @return the copy of the data source, or <code>null</code> if the data source can't be copied
+     *         (e.g. because it is destructive)
      */
-    public OMDataSourceExt copy();
+    OMDataSourceExt copy();
     
     /**
      * Returns true if property is set
      * @param key
      * @return TODO
      */
-    public boolean hasProperty(String key);
+    boolean hasProperty(String key);
     
     /**
      * Query a property stored on the OMDataSource
      * @param key
      * @return value or null
      */
-    public Object getProperty(String key);
+    Object getProperty(String key);
     
     /**
      * Set a property on the OMDataSource
@@ -165,5 +127,5 @@ public interface OMDataSourceExt extends
      * @param value
      * @return old property object or null
      */
-    public Object setProperty(String key, Object value);
+    Object setProperty(String key, Object value);
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java Sat Jul  7 18:24:00 2012
@@ -565,13 +565,27 @@ public interface OMElement extends OMNod
     QName resolveQName(String qname);
 
     /**
-     * Clones this element. Since both elements are build compleletely, you will lose the differed
-     * building capability.
-     *
-     * @return Returns OMElement.
+     * Clones this element and its descendants using default options. This method has the same
+     * effect as {@link #cloneOMElement(OMCloneOptions)} with default options.
+     * 
+     * @return the cloned element
      */
     OMElement cloneOMElement();
 
+    /**
+     * Clones this element and its descendants. Note that this method will traverse the descendants
+     * and create clones immediately. It will also preserve the original nodes. This means that
+     * after the execution of this method, both the returned clone and the original element will be
+     * completely built.
+     * 
+     * @param options
+     *            the options to use when cloning this element and its descendants; for object
+     *            models with domain specific extensions (such as SOAP), this may be a subclass of
+     *            {@link OMCloneOptions}
+     * @return the cloned element
+     */
+    OMElement cloneOMElement(OMCloneOptions options);
+    
     void setLineNumber(int lineNumber);
 
     int getLineNumber();

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java Sat Jul  7 18:24:00 2012
@@ -41,8 +41,6 @@ public interface OMFactory {
     /** Creates a new OMDocument. */
     OMDocument createOMDocument();
 
-    OMDocument createOMDocument(OMXMLParserWrapper builder);
-
 
     /**
      * Create an element with the given name. If a namespace is given, a namespace declaration will
@@ -86,17 +84,38 @@ public interface OMFactory {
             throws OMException;
 
     /**
-     * @param localName
-     * @param ns        - this can be null
-     * @param parent
-     * @param builder
+     * Create a sourced element. If the data source implements {@link QNameAwareOMDataSource} then
+     * the returned {@link OMSourcedElement} will use the information provided through this
+     * interface to determine the local name, namespace URI and namespace prefix. For information
+     * that is not available (either because the data source doesn't implement
+     * {@link QNameAwareOMDataSource} or because some of the methods defined by that interface
+     * return <code>null</code>) the element will be expanded to determine the missing information.
+     * This is done lazily, i.e. only when the information is really required. E.g. this will not
+     * occur during serialization of the element.
+     * <p>
+     * This is an optional operation which may not be supported by all factories.
+     * 
+     * @param source
+     *            the data source; must not be <code>null</code>
+     * @return the newly created element
+     * @throws IllegalArgumentException
+     *             if <code>source</code> is <code>null</code>
      */
-    OMElement createOMElement(String localName, OMNamespace ns,
-                                     OMContainer parent,
-                                     OMXMLParserWrapper builder);
-
+    OMSourcedElement createOMElement(OMDataSource source);
+    
     /**
-     * Create a sourced element with a known local name, namespace URI and namespace prefix.
+     * Create a sourced element with a known local name and namespace URI. If the namespace prefix
+     * is known in advance, then the caller should specify it in the provided {@link OMNamespace}
+     * object. The caller may pass an {@link OMNamespace} instance with a <code>null</code> prefix.
+     * This indicates that the prefix is unknown and will be determined lazily by expanding the
+     * element.
+     * <p>
+     * Note that if the provided data source implements {@link QNameAwareOMDataSource}, then the
+     * information returned by {@link QNameAwareOMDataSource#getPrefix()} may be used to determine
+     * the prefix. However, this is an unusual use case.
+     * <p>
+     * Also note that if the specified namespace URI is empty, then the element can't have a prefix
+     * and it is not necessary to expand the element to determine its prefix.
      * <p>
      * This is an optional operation which may not be supported by all factories.
      * 
@@ -280,9 +299,6 @@ public interface OMFactory {
     OMText createOMText(String contentID, DataHandlerProvider dataHandlerProvider,
             boolean optimize);
 
-    OMText createOMText(String contentID, OMContainer parent,
-                               OMXMLParserWrapper builder);
-
     /**
      * Create an attribute with the given name and value. If the provided {@link OMNamespace} object
      * has a <code>null</code> prefix, then a prefix will be generated, except if the namespace URI

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamespace.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamespace.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamespace.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamespace.java Sat Jul  7 18:24:00 2012
@@ -20,7 +20,7 @@
 package org.apache.axiom.om;
 
 /**
- * Interface OMNamespace.
+ * A namespace binding specifying a namespace prefix and a namespace URI.
  * <p>
  * Implementations of this interface must be immutable or behave as if they were immutable,
  * i.e. {@link #getPrefix()} and {@link #getNamespaceURI()} must always return the same
@@ -41,9 +41,14 @@ public interface OMNamespace {
     boolean equals(String uri, String prefix);
 
     /**
-     * Method getPrefix.
-     *
-     * @return Returns String.
+     * Get the namespace prefix. This method may return <code>null</code> for instances returned by
+     * {@link OMFactory#createOMNamespace(String, String)}. This indicates that Axiom should
+     * generate a namespace prefix when this instance is passed to one of the factory methods in
+     * {@link OMFactory}. In all other cases the return value is not null. In particular, an empty
+     * string indicates that no prefix is used, i.e. that the namespace is used as default
+     * namespace.
+     * 
+     * @return the namespace prefix
      */
     String getPrefix();
 
@@ -56,9 +61,14 @@ public interface OMNamespace {
     String getName();
 
     /**
-     * Provides the namespace URI of this namespace.
-     *
-     * @return - the namespace URI of the namespace.
+     * Get the namespace URI. This method never returns <code>null</code>. It may return an empty
+     * string if this instance represents a namespace declaration of type <tt>xmlns=""</tt>. This
+     * may be the case for instances returned by {@link OMElement#getAllDeclaredNamespaces()}. On
+     * the other hand, methods such as {@link OMNamedInformationItem#getNamespace()} will return
+     * <code>null</code> for information items that have no namespace. In that case the returned
+     * string is never empty.
+     * 
+     * @return the namespace URI
      */
     String getNamespaceURI();
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMSourcedElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMSourcedElement.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMSourcedElement.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMSourcedElement.java Sat Jul  7 18:24:00 2012
@@ -44,18 +44,42 @@ public interface OMSourcedElement extend
     /**
      * @return true if tree is expanded or being expanded.
      */
-    public boolean isExpanded();
+    boolean isExpanded();
     
     /**
      * @return OMDataSource
      */
-    public OMDataSource getDataSource();
+    OMDataSource getDataSource();
     
     /**
      * Replace an existing OMDataSource with a new one. 
      * @param dataSource new OMDataSource
      * @return null or old OMDataSource
      */
-    public OMDataSource setDataSource(OMDataSource dataSource);
+    OMDataSource setDataSource(OMDataSource dataSource);
     
+    /**
+     * Get the object that backs the data source set on this element. This method provides a safe
+     * way to access that object. It will return a non null value if all of the following conditions
+     * are satisfied:
+     * <ol>
+     * <li>The element is configured with an {@link OMDataSource} of the type specified by the
+     * <code>dataSourceClass</code> parameter (in the sense of {@link Class#isInstance(Object)}).
+     * <li>The {@link OMDataSourceExt#getObject()} method returns a non null value on the configured
+     * data source.
+     * <li>The instance can ensure that the content of the element has not been modified. This is
+     * always the case if the element has not been expanded (i.e. if {@link #isExpanded()} returns
+     * <code>false</code>), but the implementation may use additional mechanisms to detect changes
+     * after expansion of the element.
+     * </ol>
+     * These are exactly the conditions that must be satisfied if the application code wants to
+     * implement optimized processing of the sourced element by accessing the backing object.
+     * 
+     * @param dataSourceClass
+     *            the expected data source class; must be assignment compatible with
+     *            {@link OMDataSourceExt}
+     * @return the backing Java object or <code>null</code> if the conditions specified above are
+     *         not satisfied
+     */
+    Object getObject(Class dataSourceClass);
 } 

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java Sat Jul  7 18:24:00 2012
@@ -18,11 +18,9 @@
  */
 package org.apache.axiom.om;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
 
-import javax.activation.DataHandler;
 import javax.mail.internet.ContentType;
 import javax.mail.internet.ParseException;
 import javax.xml.stream.XMLStreamConstants;
@@ -30,7 +28,6 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.Source;
 
 import org.apache.axiom.attachments.Attachments;
-import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
 import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider;
 import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAPFactory;
@@ -511,21 +508,7 @@ public class OMXMLBuilderFactory {
     }
     
     private static InputSource getRootPartInputSource(Attachments attachments, ContentType contentType) {
-        DataHandler dh = attachments.getDataHandler(attachments.getRootPartContentID());
-        if (dh == null) {
-            throw new OMException("Root part not found in MIME message");
-        }
-        InputStream in;
-        try {
-            if (dh instanceof DataHandlerExt) {
-                in = ((DataHandlerExt)dh).readOnce();
-            } else {
-                in = dh.getInputStream();
-            }
-        } catch (IOException ex) {
-            throw new OMException("Unable to get input stream from root MIME part", ex);
-        }
-        InputSource rootPart = new InputSource(in);
+        InputSource rootPart = new InputSource(attachments.getRootPartInputStream(false));
         rootPart.setEncoding(contentType.getParameter("charset"));
         return rootPart;
     }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java Sat Jul  7 18:24:00 2012
@@ -34,6 +34,7 @@ import org.apache.axiom.om.OMProcessingI
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.soap.SOAPFactory;
 import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
 import org.w3c.dom.Comment;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.DOMImplementation;
@@ -74,10 +75,14 @@ import org.w3c.dom.Text;
  * <td>{@link Attr} [2]</td>
  * </tr>
  * <tr>
- * <td>{@link OMText}</td>
+ * <td>{@link OMText} with type {@link OMNode#TEXT_NODE} or {@link OMNode#SPACE_NODE}</td>
  * <td>{@link Text}</td>
  * </tr>
  * <tr>
+ * <td>{@link OMText} with type {@link OMNode#CDATA_SECTION_NODE}</td>
+ * <td>{@link CDATASection}</td>
+ * </tr>
+ * <tr>
  * <td>{@link OMComment}</td>
  * <td>{@link Comment}</td>
  * </tr>
@@ -111,7 +116,9 @@ import org.w3c.dom.Text;
  * fact that DOM is designed such that two nodes that are part of the same tree must have the same
  * owner document.
  * <li>Nodes created using the Axiom API and for which no parent node is specified will get a new
- * owner document.
+ * owner document. This applies to methods in {@link OMFactory} that don't have an
+ * {@link OMContainer} parameter or that are invoked with a <code>null</code> {@link OMContainer}
+ * as well as to methods such as {@link OMElement#cloneOMElement()}.
  * <li>When the Axiom API is used to add a node A as a child of another node B, then the owner
  * document of B becomes the new owner document of A and all its descendants. In DOM parlance, this
  * means that node A is automatically adopted by the owner document of B. This implies that no
@@ -130,10 +137,12 @@ import org.w3c.dom.Text;
  * {@link OMElement#addAttribute(String, String, OMNamespace)} (in the case where the new attribute
  * replaces an existing one, which will be removed from its owner)
  * </ul>
- * <li>Any node created using the DOM API as well as the {@link Document} instance implicitly
- * created for the owner document (when the Axiom API is used) will have as its {@link OMFactory}
- * (as reported by {@link OMInformationItem#getOMFactory()}) the instance returned by
- * {@link OMMetaFactory#getOMFactory()}.
+ * <li>{@link Document} instances created using the {@link DocumentBuilderFactory} and
+ * {@link DOMImplementation} APIs as well as the {@link Document} instances implicitly created (as
+ * owner documents) by the Axiom API will have as their {@link OMFactory} (as reported by
+ * {@link OMInformationItem#getOMFactory()}) the instance returned by
+ * {@link OMMetaFactory#getOMFactory()}. Any additional nodes created using the DOM API will inherit
+ * the {@link OMFactory} of the owner document.
  * </ol>
  * <p>
  * The implementation SHOULD instantiate the implicitly created owner documents lazily (typically

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/InputStreamDataSource.java Sat Jul  7 18:24:00 2012
@@ -19,11 +19,8 @@
 package org.apache.axiom.om.ds;
 
 import org.apache.axiom.om.OMDataSourceExt;
-import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.StAXUtils;
 
 import javax.xml.stream.XMLStreamException;
@@ -36,7 +33,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
-import java.util.Iterator;
 
 /**
  * InputStream is an example OMDataSourceExt.
@@ -181,30 +177,6 @@ public class InputStreamDataSource exten
     }
     
     /**
-     * Simple utility that takes an XMLStreamReader and writes it
-     * to an XMLStreamWriter
-     * @param reader
-     * @param writer
-     * @throws XMLStreamException
-     */
-    private static void reader2writer(XMLStreamReader reader, 
-                                     XMLStreamWriter writer)
-    throws XMLStreamException {
-        StAXOMBuilder builder = new StAXOMBuilder(reader);
-        builder.releaseParserOnClose(true);
-        try {
-            OMDocument omDocument = builder.getDocument();
-            Iterator it = omDocument.getChildren();
-            while (it.hasNext()) {
-                OMNode omNode = (OMNode) it.next();
-                omNode.serializeAndConsume(writer);
-            }
-        } finally {
-            builder.close();
-        }
-    }
-    
-    /**
      * Object containing the InputStream/encoding pair
      */
     public class Data {

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/WrappedTextNodeOMDataSourceFromDataSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/WrappedTextNodeOMDataSourceFromDataSource.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/WrappedTextNodeOMDataSourceFromDataSource.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/WrappedTextNodeOMDataSourceFromDataSource.java Sat Jul  7 18:24:00 2012
@@ -16,65 +16,36 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.axiom.om.ds;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
 import java.nio.charset.Charset;
 
 import javax.activation.DataSource;
 import javax.xml.namespace.QName;
 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.impl.MTOMXMLStreamWriter;
-import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.util.stax.WrappedTextNodeStreamReader;
 
 /**
- * {@link org.apache.axiom.om.OMDataSource} implementation that represents a text node wrapped
- * inside an element. The text data is provided by a {@link DataSource} object.
+ * {@link WrappedTextNodeOMDataSource} that pulls the text data from a {@link DataSource} object.
+ * The {@link #getObject()} method returns the {@link DataSource} instance.
  */
-public class WrappedTextNodeOMDataSourceFromDataSource extends OMDataSourceExtBase {
-    private final QName wrapperElementName;
+public class WrappedTextNodeOMDataSourceFromDataSource extends WrappedTextNodeOMDataSource {
     private final DataSource binaryData;
     private final Charset charset;
 
     public WrappedTextNodeOMDataSourceFromDataSource(QName wrapperElementName, DataSource binaryData,
             Charset charset) {
-        this.wrapperElementName = wrapperElementName;
+        super(wrapperElementName);
         this.binaryData = binaryData;
         this.charset = charset;
     }
     
-    public void serialize(OutputStream out, OMOutputFormat format) throws XMLStreamException {
-        XMLStreamWriter writer = new MTOMXMLStreamWriter(out, format);
-        serialize(writer);
-        writer.flush();
-    }
-
-    public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
-        MTOMXMLStreamWriter xmlWriter =
-            new MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writer));
-        xmlWriter.setOutputFormat(format);
-        serialize(xmlWriter);
-        xmlWriter.flush();
-    }
-
-    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
-        StreamingOMSerializer serializer = new StreamingOMSerializer();
-        serializer.serialize(getReader(), xmlWriter);
-    }
-
     public XMLStreamReader getReader() throws XMLStreamException {
         InputStream is;
         try {
@@ -94,17 +65,6 @@ public class WrappedTextNodeOMDataSource
         return false;
     }
 
-    public boolean isDestructiveWrite() {
-        return false;
-    }
-    
-    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
-        throw new UnsupportedOperationException();
-    }
-
-    public void close() {
-    }
-
     public OMDataSourceExt copy() {
         return new WrappedTextNodeOMDataSourceFromDataSource(wrapperElementName, binaryData, charset);
     }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/WrappedTextNodeOMDataSourceFromReader.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/WrappedTextNodeOMDataSourceFromReader.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/WrappedTextNodeOMDataSourceFromReader.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/WrappedTextNodeOMDataSourceFromReader.java Sat Jul  7 18:24:00 2012
@@ -16,73 +16,44 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.axiom.om.ds;
 
 import java.io.IOException;
 import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
 
 import javax.xml.namespace.QName;
 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.impl.MTOMXMLStreamWriter;
-import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.util.stax.WrappedTextNodeStreamReader;
 
 /**
- * {@link org.apache.axiom.om.OMDataSource} implementation that represents a text node wrapped
- * inside an element. The text data is provided by a {@link Reader} object. Since the stream
- * can only be read once, this data source is destructive.
+ * {@link WrappedTextNodeOMDataSource} that pulls text data from a {@link Reader} object. Since the
+ * stream can only be read once, this data source is destructive. The {@link #getObject()} method
+ * returns the {@link Reader} object if it has not been accessed yet.
  */
-public class WrappedTextNodeOMDataSourceFromReader extends OMDataSourceExtBase {
-    private final QName wrapperElementName;
+public class WrappedTextNodeOMDataSourceFromReader extends WrappedTextNodeOMDataSource {
     private final Reader reader;
+    private boolean isAccessed;
     
     public WrappedTextNodeOMDataSourceFromReader(QName wrapperElementName, Reader reader) {
-        this.wrapperElementName = wrapperElementName;
+        super(wrapperElementName);
         this.reader = reader;
     }
 
-    public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
-        MTOMXMLStreamWriter xmlWriter =
-            new MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writer));
-        xmlWriter.setOutputFormat(format);
-        serialize(xmlWriter);
-        xmlWriter.flush();
-    }
-
-    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
-        StreamingOMSerializer serializer = new StreamingOMSerializer();
-        serializer.serialize(getReader(), xmlWriter);
-    }
-
     public XMLStreamReader getReader() throws XMLStreamException {
+        isAccessed = true;
         return new WrappedTextNodeStreamReader(wrapperElementName, reader);
     }
 
     public Object getObject() {
-        return null;
+        return isAccessed ? null : reader;
     }
 
     public boolean isDestructiveRead() {
         return true;
     }
 
-    public boolean isDestructiveWrite() {
-        return true;
-    }
-    
-    public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
-        throw new UnsupportedOperationException();
-    }
-
     public void close() {
         try {
             reader.close();
@@ -90,8 +61,4 @@ public class WrappedTextNodeOMDataSource
             // Ignore
         }
     }
-
-    public OMDataSourceExt copy() {
-        throw new UnsupportedOperationException();
-    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java Sat Jul  7 18:24:00 2012
@@ -67,6 +67,9 @@ public class ByteArrayCustomBuilder impl
         try {
             // Get the prefix of the start tag
             String prefix = reader.getPrefix();
+            if (prefix == null) {
+                prefix = "";
+            }
             
             // Stream the events to a writer starting with the current event
             StreamingOMSerializer ser = new StreamingOMSerializer();

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java Sat Jul  7 18:24:00 2012
@@ -23,10 +23,8 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMNode;
 
 /**
- * Interface OMContainerEx
- * <p/>
- * Internal Implementation detail. Adding special interface to stop folks from accidently using
- * OMContainer. Please use at your own risk. May corrupt the data integrity.
+ * Interface that is used internally by Axiom and that should not be considered being part of the
+ * public API.
  */
 public interface OMContainerEx extends OMContainer {
     public void setComplete(boolean state);
@@ -54,4 +52,8 @@ public interface OMContainerEx extends O
      *         the builder has not yet started to build the first child
      */
     public OMNode getFirstOMChildIfAvailable();
+    
+    public OMNode getLastKnownOMChild();
+    
+    public void addChild(OMNode omNode, boolean fromBuilder);
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java Sat Jul  7 18:24:00 2012
@@ -20,7 +20,6 @@
 package org.apache.axiom.om.impl;
 
 import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMSerializable;
 
@@ -28,10 +27,8 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamWriter;
 
 /**
- * Interface OMNodeEx
- * <p/>
- * Internal Implementation detail. Adding special interface to stop folks from accidently using
- * OMNode. Please use at your own risk. May corrupt the data integrity.
+ * Interface that is used internally by Axiom and that should not be considered being part of the
+ * public API.
  */
 public interface OMNodeEx extends OMNode {
     public void setNextOMSibling(OMNode node);
@@ -42,8 +39,6 @@ public interface OMNodeEx extends OMNode
 
     public void setComplete(boolean state);
 
-    public void setType(int nodeType) throws OMException;
-
     /**
      * Serializes the node. Note that this is an internal method that MUST NOT be used outside of
      * Axiom. Please use {@link OMSerializable#serialize(XMLStreamWriter, boolean)} instead.

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java Sat Jul  7 18:24:00 2012
@@ -28,6 +28,7 @@ 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.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMElementEx;
 import org.apache.axiom.om.impl.OMNodeEx;
@@ -42,7 +43,7 @@ import java.util.List;
 
 import javax.xml.XMLConstants;
 
-public class SAXOMBuilder extends DefaultHandler implements LexicalHandler {
+public class SAXOMBuilder extends DefaultHandler implements LexicalHandler, OMXMLParserWrapper {
     private OMDocument document;
     
     OMElement root = null;
@@ -51,14 +52,14 @@ public class SAXOMBuilder extends Defaul
 
     OMElement nextElem = null;
 
-    private final OMFactory factory;
+    private final OMFactoryEx factory;
 
     List prefixMappings = new ArrayList();
     
     int textNodeType = OMNode.TEXT_NODE;
 
     public SAXOMBuilder(OMFactory factory) {
-        this.factory = factory;
+        this.factory = (OMFactoryEx)factory;
     }
     
     public SAXOMBuilder() {
@@ -96,7 +97,7 @@ public class SAXOMBuilder extends Defaul
     }
 
     public void startDocument() throws SAXException {
-        document = factory.createOMDocument(null);
+        document = factory.createOMDocument(this);
     }
 
     public void endDocument() throws SAXException {
@@ -111,7 +112,7 @@ public class SAXOMBuilder extends Defaul
     }
 
     protected OMElement createNextElement(String localName) throws OMException {
-        OMElement element = factory.createOMElement(localName, null, getContainer(), null);
+        OMElement element = factory.createOMElement(localName, getContainer(), this);
         addNode(element);
         return element;
     }
@@ -125,7 +126,7 @@ public class SAXOMBuilder extends Defaul
     public void startPrefixMapping(String prefix, String uri)
             throws SAXException {
         if (nextElem == null) {
-            nextElem = createNextElement(null);
+            nextElem = createNextElement("DUMMY");
         }
         ((OMElementEx)nextElem).addNamespaceDeclaration(uri, prefix);
     }
@@ -214,7 +215,7 @@ public class SAXOMBuilder extends Defaul
 
     public void characterData(char[] ch, int start, int length, int nodeType)
             throws SAXException {
-        addNode(factory.createOMText(getContainer(), new String(ch, start, length), nodeType));
+        addNode(factory.createOMText(getContainer(), new String(ch, start, length), nodeType, true));
     }
 
     public void characters(char[] ch, int start, int length)
@@ -229,7 +230,7 @@ public class SAXOMBuilder extends Defaul
 
     public void processingInstruction(String target, String data)
             throws SAXException {
-        addNode(factory.createOMProcessingInstruction(getContainer(), target, data));
+        addNode(factory.createOMProcessingInstruction(getContainer(), target, data, true));
     }
 
     public void comment(char[] ch, int start, int length) throws SAXException {
@@ -237,7 +238,7 @@ public class SAXOMBuilder extends Defaul
             // Do nothing: the comment appears before the root element.
             return;
         } 
-        addNode(factory.createOMComment(getContainer(), new String(ch, start, length)));
+        addNode(factory.createOMComment(getContainer(), new String(ch, start, length), true));
     }
 
     public void skippedEntity(String name) throws SAXException {
@@ -270,4 +271,56 @@ public class SAXOMBuilder extends Defaul
             throw new OMException("Tree not complete");
         }
     }
+
+    public int next() throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void discard(OMElement el) throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setCache(boolean b) throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isCache() {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object getParser() {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isCompleted() {
+        throw new UnsupportedOperationException();
+    }
+
+    public OMElement getDocumentElement() {
+        throw new UnsupportedOperationException();
+    }
+
+    public OMElement getDocumentElement(boolean discardDocument) {
+        throw new UnsupportedOperationException();
+    }
+
+    public short getBuilderType() {
+        throw new UnsupportedOperationException();
+    }
+
+    public void registerExternalContentHandler(Object obj) {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object getRegisteredContentHandler() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getCharacterEncoding() {
+        throw new UnsupportedOperationException();
+    }
+
+    public void close() {
+        throw new UnsupportedOperationException();
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java Sat Jul  7 18:24:00 2012
@@ -33,6 +33,7 @@ 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.OMElementEx;
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.om.util.StAXUtils;
@@ -41,7 +42,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
@@ -62,7 +62,7 @@ public abstract class StAXBuilder implem
     protected XMLStreamReader parser;
 
     /** Field omfactory */
-    protected OMFactory omfactory;
+    protected OMFactoryEx omfactory;
 
     /** Field lastNode */
     protected OMNode lastNode;
@@ -120,7 +120,7 @@ public abstract class StAXBuilder implem
      * @param parser
      */
     protected StAXBuilder(OMFactory ombuilderFactory, XMLStreamReader parser) {
-        omfactory = ombuilderFactory;
+        omfactory = (OMFactoryEx)ombuilderFactory;
         
         // The getEncoding information is only available at the START_DOCUMENT event.
         charEncoding = parser.getEncoding();
@@ -139,7 +139,7 @@ public abstract class StAXBuilder implem
     protected StAXBuilder(OMFactory ombuilderFactory, 
                           XMLStreamReader parser, 
                           String characterEncoding) {
-        omfactory = ombuilderFactory;
+        omfactory = (OMFactoryEx)ombuilderFactory;
         charEncoding = characterEncoding;
         initParser(parser);
     }
@@ -175,7 +175,7 @@ public abstract class StAXBuilder implem
         } catch (XMLStreamException e1) {
             throw new OMException(e1);
         }
-        omfactory = OMAbstractFactory.getOMFactory();
+        omfactory = (OMFactoryEx)OMAbstractFactory.getOMFactory();
     }
 
     /**
@@ -184,7 +184,7 @@ public abstract class StAXBuilder implem
      * @param ombuilderFactory
      */
     public void setOMBuilderFactory(OMFactory ombuilderFactory) {
-        this.omfactory = ombuilderFactory;
+        this.omfactory = (OMFactoryEx)ombuilderFactory;
     }
 
     /**
@@ -271,12 +271,11 @@ public abstract class StAXBuilder implem
                     throw new OMException(ex);
                 }
             }
-            OMText text = omfactory.createOMText(dataHandlerObject, dataHandlerReader.isOptimized());
+            OMText text = omfactory.createOMText(omContainer, dataHandlerObject, dataHandlerReader.isOptimized(), true);
             String contentID = dataHandlerReader.getContentID();
             if (contentID != null) {
                 text.setContentID(contentID);
             }
-            omContainer.addChild(text);
             return text;
         } else {
             // Some parsers (like Woodstox) parse text nodes lazily and may throw a
@@ -288,7 +287,7 @@ public abstract class StAXBuilder implem
                 parserException = ex;
                 throw ex;
             }
-            return omfactory.createOMText(omContainer, text, textType);
+            return omfactory.createOMText(omContainer, text, textType, true);
         }
     }
 
@@ -310,32 +309,35 @@ public abstract class StAXBuilder implem
      */
     public void discard(OMElement element) throws OMException {
 
-        if (element.isComplete() || !cache) {
-            throw new OMException();
-        }
+//        if (element.isComplete() || !cache) {
+//            throw new OMException();
+//        }
         try {
 
-            // We simply cannot use the parser instance from the builder for this case
-            // it is not safe to assume that the parser inside the builder will be in
-            // sync with the parser of the element in question
-            // Note 1 - however  calling getXMLStreamReaderWithoutCaching sets off two flags
-            // the cache flag for this builder and the parserAccessed flag. These flags will be
-            // reset later in this procedure
-
-            int event =0;
-            XMLStreamReader elementParser = element.getXMLStreamReaderWithoutCaching();
-            do{
-               event = elementParser.next();
-            }while(!(event == XMLStreamConstants.END_ELEMENT &&
-                     element.getLocalName().equals(elementParser.getLocalName())));
+            // Calculate the depth of the element to be discarded. This determines how many
+            // END_ELEMENT events we need to consume.
+            int targetDepth = elementLevel;
+            if (!lastNode.isComplete()) {
+                targetDepth--;
+            }
+            OMNode current = lastNode;
+            while (current != element) {
+                OMContainer parent = current.getParent();
+                if (parent instanceof OMElement) {
+                    current = (OMElement)parent;
+                } else {
+                    throw new OMException("Called discard for an element that is not being built by this builder");
+                }
+                targetDepth--;
+            }
+            
+            while (elementLevel > targetDepth) {
+                parserNext();
+            }
 
             //at this point we are safely at the end_element event of the element we discarded
             lastNode = element.getPreviousOMSibling();
 
-            // resetting the flags - see Note 1 above
-            cache = true;
-            parserAccessed = false;
-            
             if (lastNode != null) {
                 // if the last node is not an element, we are in trouble because leaf nodes
                 // (such as text) cannot build themselves. worst the lastchild of the
@@ -349,22 +351,21 @@ public abstract class StAXBuilder implem
                  }
 
             } else {
-                OMElement parent = (OMElement) element.getParent();
+                OMContainer parent = element.getParent();
                 if (parent == null) {
                     throw new OMException();
+                } else {
+                    ((OMContainerEx) parent).setFirstChild(null);
+                    lastNode = parent instanceof OMDocument ? null : (OMNode)parent;
                 }
-                ((OMContainerEx) parent).setFirstChild(null);
-                lastNode = parent;
             }
             
-        } catch (OMException e) {
-            throw e;
-        } catch (Exception e) {
+            ((OMElementEx)element).setParent(null);
+            ((OMElementEx)element).setPreviousOMSibling(null);
+            ((OMElementEx)element).setNextOMSibling(null);
+        } catch (XMLStreamException e) {
             throw new OMException(e);
         } 
-        // when an element is discarded the element index that was incremented
-        //at creation needs to be decremented !
-        elementLevel--;
     }
 
     /**
@@ -564,6 +565,8 @@ public abstract class StAXBuilder implem
      */
     protected abstract OMNode createOMElement() throws OMException;
 
+    abstract int parserNext() throws XMLStreamException;
+    
     /**
      * Forwards the parser one step further, if parser is not completed yet. If this is called after
      * parser is done, then throw an OMException. If the cache is set to false, then returns the