Committing AXIOM code in to ws-commons
diff --git a/src/org/apache/ws/commons/attachments/ByteArrayDataSource.java b/src/org/apache/ws/commons/attachments/ByteArrayDataSource.java
new file mode 100644
index 0000000..8fbe840
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/ByteArrayDataSource.java
@@ -0,0 +1,66 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import javax.activation.DataSource;

+import java.io.ByteArrayInputStream;

+import java.io.IOException;

+import java.io.InputStream;

+import java.io.OutputStream;

+

+public class ByteArrayDataSource implements DataSource {

+

+    private byte[] data;

+

+    private String type;

+

+    public ByteArrayDataSource(byte[] data, String type) {

+        super();

+        this.data = data;

+        this.type = type;

+    }

+

+    public ByteArrayDataSource(byte[] data) {

+        super();

+        this.data = data;

+    }

+

+    public void setType(String type) {

+        this.type = type;

+    }

+

+    public String getContentType() {

+        if (type == null)

+            return "application/octet-stream";

+        else

+            return type;

+    }

+

+    public InputStream getInputStream() throws IOException {

+        return new ByteArrayInputStream(data);

+    }

+

+    public String getName() {

+

+        return "ByteArrayDataSource";

+    }

+

+    public OutputStream getOutputStream() throws IOException {

+        throw new IOException("Not Supported");

+    }

+}

+

diff --git a/src/org/apache/ws/commons/attachments/DataHandlerUtils.java b/src/org/apache/ws/commons/attachments/DataHandlerUtils.java
new file mode 100644
index 0000000..b3a4a64
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/DataHandlerUtils.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright  2004 The Apache Software Foundation.
+ *
+ *  Licensed 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.ws.commons.attachments;
+
+
+import org.apache.ws.commons.om.util.Base64;
+
+import javax.activation.DataHandler;
+
+public class DataHandlerUtils {
+
+  public static Object getDataHandlerFromText(String value, String mimeType)
+  {
+      ByteArrayDataSource dataSource;
+      byte[] data = Base64.decode(value);
+      if (mimeType != null) {
+          dataSource = new ByteArrayDataSource(data, mimeType);
+      } else {
+          // Assumes type as application/octet-stream
+          dataSource = new ByteArrayDataSource(data);
+      }
+      return new DataHandler(dataSource);
+  }
+}
diff --git a/src/org/apache/ws/commons/attachments/MIMEBodyPartInputStream.java b/src/org/apache/ws/commons/attachments/MIMEBodyPartInputStream.java
new file mode 100644
index 0000000..dc6a846
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/MIMEBodyPartInputStream.java
@@ -0,0 +1,111 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import java.io.IOException;

+import java.io.InputStream;

+import java.io.PushbackInputStream;

+

+public class MIMEBodyPartInputStream extends InputStream {

+    PushbackInputStream inStream;

+

+    boolean boundaryFound;

+

+    MIMEHelper parent;

+

+    byte[] boundary;

+

+    public MIMEBodyPartInputStream(PushbackInputStream inStream, byte[] boundary) {

+        super();

+        this.inStream = inStream;

+        this.boundary = boundary;

+    }

+

+    public MIMEBodyPartInputStream(PushbackInputStream inStream,

+            byte[] boundary, MIMEHelper parent) {

+        this(inStream, boundary);

+        this.parent = parent;

+    }

+

+    public int read() throws IOException {

+        if (boundaryFound) {

+            return -1;

+        }

+        // read the next value from stream

+        int value = inStream.read();

+

+        // A problem occured because all the mime parts tends to have a /r/n at

+        // the end. Making it hard to transform them to correct DataSources.

+        // This logic introduced to handle it

+        //TODO look more in to this && for a better way to do this

+        if (value == 13) {

+            value = inStream.read();

+            if (value != 10) {

+                inStream.unread(value);

+                return 13;

+            } else {

+                value = inStream.read();

+                if ((byte) value != boundary[0]) {

+                    inStream.unread(value);

+                    inStream.unread(10);

+                    return 13;

+                }

+            }

+        } else if ((byte) value != boundary[0]) {

+            return value;

+        }

+

+        // read value is the first byte of the boundary. Start matching the

+        // next characters to find a boundary

+        int boundaryIndex = 0;

+        while ((boundaryIndex < (boundary.length - 1))

+                && ((byte) value == boundary[boundaryIndex])) {

+            value = inStream.read();

+            boundaryIndex++;

+        }

+

+        if (boundaryIndex == (boundary.length - 1)) { // boundary found

+            boundaryFound = true;

+            // read the end of line character

+            if ((value = inStream.read()) == 45) {

+                //check whether end of stream

+                //Last mime boundary should have a succeeding "--"

+                if ((value = inStream.read()) == 45 && parent!=null) {

+                    parent.setEndOfStream(true);

+                }

+            } else {

+                inStream.read();

+            }

+

+            return -1;

+        }

+

+        // Boundary not found. Restoring bytes skipped.

+        // write first skipped byte, push back the rest

+

+        if (value != -1) { // Stream might have ended

+            inStream.unread(value);

+        }

+        inStream.unread(boundary, 1, boundaryIndex - 1);

+        return boundary[0];

+    }

+    

+    public boolean getBoundaryStatus()

+    {

+        return boundaryFound;

+    }

+}
\ No newline at end of file
diff --git a/src/org/apache/ws/commons/attachments/MIMEHelper.java b/src/org/apache/ws/commons/attachments/MIMEHelper.java
new file mode 100644
index 0000000..dff3871
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/MIMEHelper.java
@@ -0,0 +1,405 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.impl.MTOMConstants;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+import javax.activation.DataHandler;

+import javax.mail.MessagingException;

+import javax.mail.internet.ContentType;

+import javax.mail.internet.ParseException;

+import java.io.ByteArrayInputStream;

+import java.io.IOException;

+import java.io.InputStream;

+import java.io.PushbackInputStream;

+import java.util.HashMap;

+

+public class MIMEHelper {

+

+    /**

+     * <code>ContentType</code> of the MIME message

+     */

+    ContentType contentType;

+

+    /**

+     * Mime <code>boundary</code> which separates mime parts

+     */

+    byte[] boundary;

+

+    /**

+     * <code>applicationType</code> used to distinguish between MTOM & SWA If

+     * the message is MTOM optimised type is application/xop+xml If the message

+     * is SWA, type is ??have to find out

+     */

+    String applicationType;

+

+    /**

+     * <code>pushbackInStream</code> stores the reference to the incoming

+     * stream A PushbackStream has the ability to "push back" or "unread" one

+     * byte.

+     */

+    PushbackInputStream pushbackInStream;

+

+    /**

+     * <code>mimeBodyPartsMap</code> stores the already parsed Mime Body

+     * Parts. This Map will be keyed using the content-ID's

+     */

+    HashMap bodyPartsMap;

+

+    /**

+     * <code>partIndex</code>- Number of Mime parts parsed

+     */

+    int partIndex = 0;

+

+    /**

+     * <code>endOfStreamReached</code> flag which is to be set by

+     * MIMEBodyPartStream when MIME message terminator is found.

+     */

+    boolean endOfStreamReached;

+

+    String firstPartId;

+

+    boolean fileCacheEnable;

+

+    String attachmentRepoDir;

+

+    int fileStorageThreshold;

+

+    protected Log log = LogFactory.getLog(getClass());

+

+

+    /**

+     * Moves the pointer to the beginning of the first MIME part. Reads

+     * till first MIME boundary is found or end of stream is reached.

+     *

+     * @param inStream

+     * @param contentTypeString

+     * @param fileCacheEnable

+     * @param attachmentRepoDir

+     * @throws OMException 

+     */

+    public MIMEHelper(InputStream inStream, String contentTypeString,

+                      boolean fileCacheEnable, String attachmentRepoDir,

+                      String fileThreshold) throws OMException {

+        this.attachmentRepoDir = attachmentRepoDir;

+        this.fileCacheEnable = fileCacheEnable;

+        if (fileThreshold != null && (!"".equals(fileThreshold))) {

+            this.fileStorageThreshold = Integer.parseInt(fileThreshold);

+        } else {

+            this.fileStorageThreshold = 1;

+        }

+        bodyPartsMap = new HashMap();

+        try {

+            contentType = new ContentType(contentTypeString);

+        } catch (ParseException e) {

+            throw new OMException(

+                    "Invalid Content Type Field in the Mime Message"

+                            ,e);

+        }

+        // Boundary always have the prefix "--".

+        this.boundary = ("--" + contentType.getParameter("boundary"))

+                .getBytes();

+

+        // do we need to wrap InputStream from a BufferedInputStream before

+        // wrapping from PushbackStream

+        pushbackInStream = new PushbackInputStream(inStream,

+                (this.boundary.length + 2));

+

+        // Move the read pointer to the beginning of the first part

+        // read till the end of first boundary

+        while (true) {

+            int value;

+            try {

+                value = pushbackInStream.read();

+                if ((byte) value == boundary[0]) {

+                    int boundaryIndex = 0;

+                    while ((boundaryIndex < boundary.length)

+                            && ((byte) value == boundary[boundaryIndex])) {

+                        value = pushbackInStream.read();

+                        if (value == -1)

+                            throw new OMException(

+                                    "Unexpected End of Stream while searching for first Mime Boundary");

+                        boundaryIndex++;

+                    }

+                    if (boundaryIndex == boundary.length) { // boundary found

+                        pushbackInStream.read();

+                        break;

+                    }

+                } else if ((byte) value == -1) {

+                    throw new OMException(

+                            "Mime parts not found. Stream ended while searching for the boundary");

+                }

+            } catch (IOException e1) {

+                throw new OMException("Stream Error" + e1.toString(), e1);

+            }

+        }

+    }

+

+    /**

+     * Sets file cache to false.

+     *

+     * @param inStream

+     * @param contentTypeString

+     * @throws OMException

+     */

+    public MIMEHelper(InputStream inStream, String contentTypeString)

+            throws OMException {

+        this(inStream, contentTypeString, false, null, null);

+    }

+

+    /**

+     * @return whether Message Type is SOAP with Attachments or MTOM optimized,

+     *         by checking the application type parameter in the Content Type.

+     */

+    public String getAttachmentSpecType() {

+        if (this.applicationType == null) {

+            applicationType = contentType.getParameter("type");

+            if ((MTOMConstants.MTOM_TYPE).equalsIgnoreCase(applicationType)) {

+                this.applicationType = MTOMConstants.MTOM_TYPE;

+            } else if ((MTOMConstants.SWA_TYPE).equalsIgnoreCase(applicationType)) {

+                this.applicationType = MTOMConstants.SWA_TYPE;

+            } else {

+                throw new OMException(

+                        "Invalid Application type. Support available for MTOM/SOAP 1.2 & SwA/SOAP 1.l only.");

+            }

+        }

+        return this.applicationType;

+    }

+

+    /**

+     * @return the InputStream which includes the SOAP Envelope. It assumes that

+     *         the root mime part is always pointed by "start" parameter in

+     *         content-type.

+     */

+    public InputStream getSOAPPartInputStream() throws OMException {

+        DataHandler dh;

+        try {

+            dh = getDataHandler(getSOAPPartContentID());

+            if (dh == null) {

+                throw new OMException(

+                        "Mandatory Root MIME part containing the SOAP Envelope is missing");

+            }

+            return dh.getInputStream();

+        } catch (IOException e) {

+            throw new OMException(

+                    "Problem with DataHandler of the Root Mime Part. ",e);

+        }

+    }

+

+    /**

+     * @return the Content-ID of the SOAP part It'll be the value Start

+     *         Parameter of Content-Type header if given in the Content type of

+     *         the MIME message. Else it'll be the content-id of the first MIME

+     *         part of the MIME message

+     */

+    private String getSOAPPartContentID() {

+        String rootContentID = contentType.getParameter("start");

+

+        // to handle the Start parameter not mentioned situation

+        if (rootContentID == null) {

+            if (partIndex == 0) {

+                getNextPart();

+            }

+            rootContentID = firstPartId;

+        } else {

+            rootContentID.trim();

+

+            if ((rootContentID.indexOf("<") > -1)

+                    & (rootContentID.indexOf(">") > -1))

+                rootContentID = rootContentID.substring(1, (rootContentID

+                        .length() - 1));

+        }

+        // Strips off the "cid" part from content-id

+        if ("cid".equalsIgnoreCase(rootContentID.substring(0, 3))) {

+            rootContentID = rootContentID.substring(4);

+        }

+        return rootContentID;

+    }

+

+    public String getSOAPPartContentType() {

+        Part soapPart = getPart(getSOAPPartContentID());

+        try {

+            return soapPart.getContentType();

+        } catch (MessagingException e) {

+            log.error(e.getMessage());

+            throw new OMException(e);

+        }

+    }

+

+    /**

+     * @param blobContentID

+     *            (without the surrounding angle brackets and "cid:" prefix)

+     * @return The DataHandler of the mime part referred by the Content-Id

+     * @throws OMException

+     */

+    public DataHandler getDataHandler(String blobContentID) throws OMException {

+

+        try {

+            return getPart(blobContentID).getDataHandler();

+        } catch (MessagingException e) {

+            throw new OMException("Problem with Mime Body Part No " + partIndex

+                    + ".  ", e);

+        }

+

+    }

+

+    /**

+     * Checks whether the MIME part is already parsed by checking the

+     * parts HashMap. If it is not parsed yet then call the getNextPart()

+     * till the required part is found.

+     *

+     * @param blobContentID

+     * @return The Part referred by the Content-Id

+     * @throws OMException

+     * 

+     */

+    public Part getPart(String blobContentID) {

+        Part bodyPart;

+        if (bodyPartsMap.containsKey(blobContentID)) {

+            bodyPart = (Part) bodyPartsMap.get(blobContentID);

+            return bodyPart;

+        } else {

+            //This loop will be terminated by the Exceptions thrown if the Mime

+            // part searching was not found

+            while (true) {

+                bodyPart = this.getNextPart();

+                if (bodyPart == null) {

+                    return null;

+                }

+                if (bodyPartsMap.containsKey(blobContentID)) {

+                    bodyPart = (Part) bodyPartsMap.get(blobContentID);

+                    return bodyPart;

+                }

+            }

+        }

+    }

+

+    protected void setEndOfStream(boolean value) {

+        this.endOfStreamReached = value;

+

+    }

+

+    /**

+     * @return the Next valid MIME part + store the Part in the Parts List

+     * @throws OMException

+     *             throw if content id is null or if two MIME parts contain the

+     *             same content-ID & the exceptions throws by getPart()

+     */

+    private Part getNextPart() throws OMException {

+        Part nextPart;

+        nextPart = getPart();

+        if (nextPart != null) {

+            String partContentID;

+            try {

+                partContentID = nextPart.getContentID();

+

+                if (partContentID == null & partIndex == 1) {

+                    bodyPartsMap.put("firstPart", nextPart);

+                    firstPartId = "firstPart";

+                    return nextPart;

+                }

+                if (partContentID == null) {

+                    throw new OMException(

+                            "Part content ID cannot be blank for non root MIME parts");

+                }

+                if ((partContentID.indexOf("<") > -1)

+                        & (partContentID.indexOf(">") > -1)) {

+                    partContentID = partContentID.substring(1, (partContentID

+                            .length() - 1));

+

+                } else if (partIndex == 1) {

+                    firstPartId = partContentID;

+                }

+                if (bodyPartsMap.containsKey(partContentID)) {

+                    throw new OMException(

+                            "Two MIME parts with the same Content-ID not allowed.");

+                }

+                bodyPartsMap.put(partContentID, nextPart);

+                return nextPart;

+            } catch (MessagingException e) {

+                throw new OMException("Error reading Content-ID from the Part."

+                        + e);

+            }

+        } else

+            return null;

+    }

+

+    /**

+     * @return This will return the next available MIME part in the stream.

+     * @throws OMException

+     *             if Stream ends while reading the next part...

+     */

+    private Part getPart() throws OMException {

+        // endOfStreamReached will be set to true if the message ended in MIME

+        // Style having "--" suffix with the last mime boundary

+        if (endOfStreamReached)

+            throw new OMException(

+                    "Referenced MIME part not found.End of Stream reached.");

+

+        Part part = null;

+

+        try {

+            if (fileCacheEnable) {

+                try {

+                    MIMEBodyPartInputStream partStream;

+                    byte[] buffer = new byte[fileStorageThreshold];

+                    partStream = new MIMEBodyPartInputStream(pushbackInStream,

+                            boundary, this);

+                    int count = 0;

+                    int value;

+                    // Make sure not to modify this to a Short Circuit "&". If

+                    // removed a byte will be lost

+                    while (count != fileStorageThreshold

+                            && (!partStream.getBoundaryStatus())) {

+                        value = partStream.read();

+                        buffer[count] = (byte) value;

+                        count++;

+                    }

+                    if (count == fileStorageThreshold) {

+                        PushbackFilePartInputStream filePartStream = new PushbackFilePartInputStream(

+                                partStream, buffer);

+                        part = new PartOnFile(filePartStream, attachmentRepoDir);

+                    } else {

+                        ByteArrayInputStream byteArrayInStream = new ByteArrayInputStream(

+                                buffer,0,count-1);

+                        part = new PartOnMemory(byteArrayInStream);

+                    }

+                } catch (Exception e) {

+                    throw new OMException("Error creating temporary File.", e);

+                }

+            } else {

+                MIMEBodyPartInputStream partStream;

+                partStream = new MIMEBodyPartInputStream(pushbackInStream,

+                        boundary, this);

+                part = new PartOnMemory(partStream);

+            }

+            // This will take care if stream ended without having MIME

+            // message terminator

+            if (part.getSize() <= 0) {

+                throw new OMException(

+                        "Referenced MIME part not found.End of Stream reached.");

+            }

+        } catch (MessagingException e) {

+            throw new OMException(e);

+        }

+        partIndex++;

+        return part;

+    }

+}
\ No newline at end of file
diff --git a/src/org/apache/ws/commons/attachments/Part.java b/src/org/apache/ws/commons/attachments/Part.java
new file mode 100644
index 0000000..4987608
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/Part.java
@@ -0,0 +1,44 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import javax.activation.DataHandler;

+import javax.mail.MessagingException;

+import java.io.IOException;

+import java.io.InputStream;

+import java.util.Enumeration;

+

+public interface Part{

+

+    

+    public int getSize() throws MessagingException ;

+

+    public String getContentType() throws MessagingException;

+    

+    public String getContentID() throws MessagingException;

+    

+    public String getFileName() throws MessagingException;

+

+    public InputStream getInputStream() throws IOException, MessagingException ;

+    

+    public DataHandler getDataHandler() throws MessagingException ;

+    

+    public String getHeader(String arg0) throws MessagingException ;

+    

+    public Enumeration getAllHeaders() throws MessagingException ;

+    

+}

diff --git a/src/org/apache/ws/commons/attachments/PartOnFile.java b/src/org/apache/ws/commons/attachments/PartOnFile.java
new file mode 100644
index 0000000..7f55df2
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/PartOnFile.java
@@ -0,0 +1,184 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import org.apache.ws.commons.om.OMException;

+

+import javax.activation.DataHandler;

+import javax.activation.FileDataSource;

+import javax.mail.MessagingException;

+import java.io.File;

+import java.io.FileInputStream;

+import java.io.FileOutputStream;

+import java.io.IOException;

+import java.io.InputStream;

+import java.io.OutputStream;

+import java.util.Enumeration;

+import java.util.HashMap;

+

+public class PartOnFile implements Part {

+

+    File cacheFile;

+

+    Part bodyPart;

+

+    String contentType;

+

+    String contentID;

+

+    HashMap headers;

+

+    public PartOnFile(PushbackFilePartInputStream inStream, String repoDir) {

+        super();

+

+        headers = new HashMap();

+

+        if (repoDir == null) {

+            repoDir = ".";

+        }

+        try {

+            cacheFile = File.createTempFile("Axis2", ".att",

+                    (repoDir == null) ? null : new File(repoDir));

+

+            FileOutputStream fileOutStream = new FileOutputStream(cacheFile);

+            int value;

+            value = parseTheHeaders(inStream);

+            fileOutStream.write(value);

+            while (!inStream.getBoundaryStatus()) {

+                value = inStream.read();

+                if (!inStream.getBoundaryStatus()) {

+                    fileOutStream.write(value);

+                }

+

+            }

+

+            fileOutStream.flush();

+            fileOutStream.close();

+        } catch (IOException e) {

+            throw new OMException("Error creating temporary File.", e);

+        }

+    }

+

+    private int parseTheHeaders(InputStream inStream) throws IOException {

+        int value;

+        boolean readingHeaders = true;

+        StringBuffer header = new StringBuffer();

+        while (readingHeaders & (value = inStream.read()) != -1) {

+            if (value == 13) {

+                if ((value = inStream.read()) == 10) {

+                    if ((value = inStream.read()) == 13) {

+                        if ((value = inStream.read()) == 10) {

+                            putToMap(header);

+                            readingHeaders = false;

+                        }

+                    } else {

+                        putToMap(header);

+                        header = new StringBuffer();

+                        header.append((char) value);

+                    }

+                } else {

+                    header.append(13);

+                    header.append(value);

+                }

+            } else {

+                header.append((char) value);

+            }

+        }

+        return value;

+    }

+

+    private void putToMap(StringBuffer header) {

+        String headerString = header.toString();

+        int delimiter = headerString.indexOf(":");

+        headers.put(headerString.substring(0, delimiter).trim(), headerString

+                .substring(delimiter + 1, headerString.length()).trim());

+    }

+

+    public String getContentID() {

+        String cID = (String) headers.get("Content-ID");

+        if (cID == null) {

+            cID = (String) headers.get("Content-Id");

+            if (cID == null) {

+                cID = (String) headers.get("Content-id");

+                if (cID == null) {

+                    cID = (String) headers.get("content-id");

+                }

+            }

+

+        }

+        return cID;

+    }

+

+    public int getSize() throws MessagingException {

+        return (int) cacheFile.length();

+    }

+

+    public int getLineCount() throws MessagingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public String getDescription() throws MessagingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public void setDescription(String arg0) throws MessagingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public String getFileName() throws MessagingException {

+        return cacheFile.getAbsolutePath();

+    }

+

+    public InputStream getInputStream() throws IOException, MessagingException {

+        return new FileInputStream(cacheFile);

+    }

+

+    public DataHandler getDataHandler() throws MessagingException {

+        return new DataHandler(new FileDataSource(cacheFile));

+    }

+

+    public Object getContent() throws IOException, MessagingException {

+        return getDataHandler().getContent();

+    }

+

+    public void writeTo(OutputStream outStream) throws IOException,

+            MessagingException {

+        getDataHandler().writeTo(outStream);

+    }

+

+    public String getHeader(String arg0) throws MessagingException {

+        String header;

+        header = (String) headers.get(arg0);

+        return header;

+    }

+

+    public Enumeration getAllHeaders() throws MessagingException {

+        return null;

+    }

+

+    public String getContentType() throws MessagingException {

+        String cType = (String) headers.get("Content-Type");

+        if (cType == null) {

+            cType = (String) headers.get("Content-type");

+            if (cType == null) {

+                cType = (String) headers.get("content-type");

+            }

+        }

+        return cType;

+    }

+

+}
\ No newline at end of file
diff --git a/src/org/apache/ws/commons/attachments/PartOnMemory.java b/src/org/apache/ws/commons/attachments/PartOnMemory.java
new file mode 100644
index 0000000..c8e68b1
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/PartOnMemory.java
@@ -0,0 +1,66 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import javax.activation.DataHandler;

+import javax.mail.MessagingException;

+import javax.mail.internet.MimeBodyPart;

+import java.io.IOException;

+import java.io.InputStream;

+import java.util.Enumeration;

+

+public class PartOnMemory implements Part{

+

+    MimeBodyPart part;

+    public PartOnMemory(InputStream partInStream) throws MessagingException

+    {

+        part =  new MimeBodyPart(partInStream);

+    }

+

+    public int getSize() throws MessagingException {

+        return part.getSize();

+    }

+

+    public String getContentType() throws MessagingException {

+        return part.getContentType();

+    }

+

+    public String getFileName() throws MessagingException {

+        return part.getFileName();

+    }

+

+    public InputStream getInputStream() throws IOException, MessagingException {

+        return part.getInputStream();

+    }

+

+    public DataHandler getDataHandler() throws MessagingException {

+        return part.getDataHandler();

+    }

+

+    public String getHeader(String arg0) throws MessagingException {

+       return part.getHeader(arg0)[0];

+    }

+

+    public Enumeration getAllHeaders() throws MessagingException {

+       return part.getAllHeaders();

+    }

+

+

+    public String getContentID() throws MessagingException {

+        return part.getContentID();

+    }

+}

diff --git a/src/org/apache/ws/commons/attachments/PushbackFilePartInputStream.java b/src/org/apache/ws/commons/attachments/PushbackFilePartInputStream.java
new file mode 100644
index 0000000..b78061f
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/PushbackFilePartInputStream.java
@@ -0,0 +1,58 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import java.io.IOException;

+import java.io.InputStream;

+

+public class PushbackFilePartInputStream extends InputStream {

+

+    MIMEBodyPartInputStream inStream;

+

+    byte[] buffer;

+

+    int count;

+

+    /**

+     * @param inStream

+     * @param buffer

+     */

+    public PushbackFilePartInputStream(MIMEBodyPartInputStream inStream,

+            byte[] buffer) {

+        super();

+        this.inStream = inStream;

+        this.buffer = buffer;

+        count = buffer.length;

+    }

+

+    public int read() throws IOException {

+        int data;

+        if (count > 0) {

+            data = buffer[buffer.length - count];

+            count--;

+        } else {

+            data = inStream.read();

+        }

+        return data;

+    }

+    

+    public boolean getBoundaryStatus()

+    {

+        return inStream.getBoundaryStatus();

+    }

+

+}
\ No newline at end of file
diff --git a/src/org/apache/ws/commons/attachments/utils/IOUtils.java b/src/org/apache/ws/commons/attachments/utils/IOUtils.java
new file mode 100644
index 0000000..1f01bee
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/utils/IOUtils.java
@@ -0,0 +1,61 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments.utils;

+

+import java.io.IOException;

+import java.io.InputStream;

+

+/**

+ * Utility class containing IO helper methods

+ */

+public class IOUtils {

+    private IOUtils() {

+    }

+

+    /**

+     * Reads into a byte array. Ensures that the full buffer is read.

+     * Helper method, just calls <tt>readFully(in, b, 0, b.length)</tt>

+     *

+     * @see #readFully(java.io.InputStream, byte[], int, int)

+     */

+    public static int readFully(InputStream in, byte[] b)

+            throws IOException {

+        return readFully(in, b, 0, b.length);

+    }

+

+    /**

+     * Same as the normal <tt>in.read(b, off, len)</tt>, but tries to ensure that

+     * the entire len number of bytes is read.

+     * 

+     * @return Returns the number of bytes read, or -1 if the end of file is

+     * reached before any bytes are read

+     */

+    public static int readFully(InputStream in, byte[] b, int off, int len)

+            throws IOException {

+        int total = 0;

+        for (; ;) {

+            int got = in.read(b, off + total, len - total);

+            if (got < 0) {

+                return (total == 0) ? -1 : total;

+            } else {

+                total += got;

+                if (total == len)

+                    return total;

+            }

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/attachments/utils/ImageDataSource.java b/src/org/apache/ws/commons/attachments/utils/ImageDataSource.java
new file mode 100644
index 0000000..506d804
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/utils/ImageDataSource.java
@@ -0,0 +1,79 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments.utils;

+

+import javax.activation.DataSource;

+import java.awt.*;

+import java.io.ByteArrayInputStream;

+import java.io.ByteArrayOutputStream;

+import java.io.IOException;

+import java.io.InputStream;

+import java.io.OutputStream;

+

+public class ImageDataSource implements DataSource {

+

+    public static final String CONTENT_TYPE = "image/jpeg";

+

+    private final String name;

+

+    private final String contentType;

+

+    private byte[] data;

+

+    private ByteArrayOutputStream os;

+

+    public ImageDataSource(String name, Image data) throws Exception {

+        this(name, CONTENT_TYPE, data);

+    } // ctor

+

+    public ImageDataSource(String name, String contentType, Image data) throws Exception {

+        this.name = name;

+        this.contentType = contentType == null ? CONTENT_TYPE : contentType;

+        os = new ByteArrayOutputStream();

+        try {

+            if (data != null) {

+                new ImageIO().saveImage(this.contentType, data, os);

+            }

+        } catch (Exception e) {

+            throw e;

+        }

+    }

+

+    public String getName() {

+        return name;

+    } // getName

+

+    public String getContentType() {

+        return contentType;

+    } // getOptimizedContentType

+

+    public InputStream getInputStream() throws IOException {

+        if (os.size() != 0) {

+            data = os.toByteArray();

+            os.reset();

+        }

+        return new ByteArrayInputStream(data == null ? new byte[0] : data);

+    } // getInputStream

+

+    public OutputStream getOutputStream() throws IOException {

+        if (os.size() != 0) {

+            data = os.toByteArray();

+            os.reset();

+        }

+        return os;

+    } // getOutputStream

+} // class ImageDataSource

diff --git a/src/org/apache/ws/commons/attachments/utils/ImageIO.java b/src/org/apache/ws/commons/attachments/utils/ImageIO.java
new file mode 100644
index 0000000..d17d707
--- /dev/null
+++ b/src/org/apache/ws/commons/attachments/utils/ImageIO.java
@@ -0,0 +1,77 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments.utils;

+

+

+import javax.imageio.IIOImage;

+import javax.imageio.ImageWriter;

+import java.awt.*;

+import java.awt.image.BufferedImage;

+import java.io.InputStream;

+import java.io.OutputStream;

+import java.util.Iterator;

+

+/**

+ * JDK1.4 based Image I/O

+ */

+public class ImageIO extends Component {

+	

+    private static final long serialVersionUID = 4697911685739683266L;

+

+	/**

+     * Saves an image.

+     *

+     * @param mimeType the mime-type of the format to save the image

+     * @param image    the image to save

+     * @param os       the stream to write to

+     * @throws Exception if an error prevents image encoding

+     */

+    public void saveImage(String mimeType, Image image, OutputStream os)

+            throws Exception {

+

+        ImageWriter writer = null;

+        Iterator iter = javax.imageio.ImageIO.getImageWritersByMIMEType(mimeType);

+        if (iter.hasNext()) {

+            writer = (ImageWriter) iter.next();

+        }

+        writer.setOutput(javax.imageio.ImageIO.createImageOutputStream(os));

+        BufferedImage rendImage = null;

+        if (image instanceof BufferedImage) {

+            rendImage = (BufferedImage) image;

+        } else {

+            MediaTracker tracker = new MediaTracker(this);

+            tracker.addImage(image, 0);

+            tracker.waitForAll();

+            rendImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 1);

+            Graphics g = rendImage.createGraphics();

+            g.drawImage(image, 0, 0, null);

+        }

+        writer.write(new IIOImage(rendImage, null, null));

+        writer.dispose();

+    } // saveImage

+

+    /**

+     * Loads an Image.

+     *

+     * @param in the stream to load the image

+     * @return the Image

+     */

+    public Image loadImage(InputStream in) throws Exception {

+        return javax.imageio.ImageIO.read(in);

+    } // loadImage

+}

+

diff --git a/src/org/apache/ws/commons/om/FactoryFinder.java b/src/org/apache/ws/commons/om/FactoryFinder.java
new file mode 100644
index 0000000..9578864
--- /dev/null
+++ b/src/org/apache/ws/commons/om/FactoryFinder.java
@@ -0,0 +1,132 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.soap.SOAPFactory;

+

+

+/**

+ * Class FactoryFinder

+ */

+class FactoryFinder {

+    private static final String DEFAULT_OM_FACTORY_CLASS_NAME =

+            "org.apache.ws.commons.om.impl.llom.factory.OMLinkedListImplFactory";

+    private static final String DEFAULT_SOAP11_FACTORY_CLASS_NAME =

+            "org.apache.ws.commons.soap.impl.llom.soap11.SOAP11Factory";

+    private static final String DEFAULT_SOAP12_FACTORY_CLASS_NAME =

+            "org.apache.ws.commons.soap.impl.llom.soap12.SOAP12Factory";

+

+    /**

+     * @param loader

+     * @return

+     * @throws OMFactoryException

+     */

+

+

+    private static Object findFactory(ClassLoader loader,

+                                      String factoryClass,

+                                      String systemPropertyName)

+            throws OMFactoryException {

+

+        String factoryClassName = factoryClass;

+

+        //first look for a java system property

+        if (systemPropertyName != null &&

+            System.getProperty(systemPropertyName) != null) {

+            factoryClassName = System.getProperty(systemPropertyName);

+        }

+

+        Object factory;

+        try {

+            if (loader == null) {

+                factory = Class.forName(factoryClassName).newInstance();

+            } else {

+                factory = loader.loadClass(factoryClassName).newInstance();

+            }

+        } catch (Exception e) {

+            throw new OMFactoryException(e);

+        }

+        return factory;

+    }

+

+    /**

+     * The searching for the factory class happens in the following order

+     * 1. look for a system property called <b>soap11.factory</b>. this can be set by

+     * passing the -Dsoap11.factory="classname"

+     * 2. Pick the default factory class.

+     * it is the class hardcoded at the constant DEFAULT_SOAP11_FACTORY_CLASS_NAME

+     *

+     * @param loader

+     * @return

+     * @throws OMFactoryException

+     */

+    public static SOAPFactory findSOAP11Factory(ClassLoader loader)

+            throws OMFactoryException {

+        return (SOAPFactory) findFactory(loader,

+                                         DEFAULT_SOAP11_FACTORY_CLASS_NAME,

+                                         OMAbstractFactory.SOAP11_FACTORY_NAME_PROPERTY);

+    }

+

+    /**

+     * The searching for the factory class happens in the following order

+     * 1. look for a system property called <b>soap12.factory</b>. this can be set by

+     * passing the -Dsoap12.factory="classname"

+     * 2. Pick the default factory class.

+     * it is the class hardcoded at the constant DEFAULT_SOAP12_FACTORY_CLASS_NAME

+     *

+     * @param loader

+     * @return

+     * @throws OMFactoryException

+     */

+    public static SOAPFactory findSOAP12Factory(ClassLoader loader)

+            throws OMFactoryException {

+        return (SOAPFactory) findFactory(loader,

+                                         DEFAULT_SOAP12_FACTORY_CLASS_NAME,

+                                         OMAbstractFactory.SOAP12_FACTORY_NAME_PROPERTY);

+    }

+

+    /**

+     * The searching for the factory class happens in the following order

+     * 1. look for a system property called <b>om.factory</b>. this can be set by

+     * passing the -Dom.factory="classname"

+     * 2. Pick the default factory class.

+     * it is the class hardcoded at the constant DEFAULT_OM_FACTORY_CLASS_NAME

+     *

+     * @param loader

+     * @return

+     * @throws OMFactoryException

+     */

+    public static OMFactory findOMFactory(ClassLoader loader)

+            throws OMFactoryException {

+        return (OMFactory) findFactory(loader,

+                                       DEFAULT_OM_FACTORY_CLASS_NAME,

+                                       OMAbstractFactory.OM_FACTORY_NAME_PROPERTY);

+    }

+

+    /**

+     *

+     * @param classLoader

+     * @param soapFactory

+     * @return The SOAPFactory

+     */

+    public static SOAPFactory findSOAPFactory(final ClassLoader classLoader,

+                                              final String soapFactory) {

+        return (SOAPFactory) findFactory(classLoader,

+                                         soapFactory,

+                                         null);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/OMAbstractFactory.java b/src/org/apache/ws/commons/om/OMAbstractFactory.java
new file mode 100644
index 0000000..c9a0925
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMAbstractFactory.java
@@ -0,0 +1,123 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.impl.llom.factory.SOAPLinkedListImplFactory;

+

+public class OMAbstractFactory {

+    public static final String OM_FACTORY_NAME_PROPERTY = "om.factory";

+    public static final String SOAP11_FACTORY_NAME_PROPERTY = "soap11.factory";

+    public static final String SOAP12_FACTORY_NAME_PROPERTY = "soap12.factory";

+    public static final String SOAP_FACTORY_NAME_PROPERTY = "soap.factory";

+

+    /**

+     * Picks up the default factory implementation from the classpath.

+     *

+     * @return Returns OMFactory.

+     */

+    public static OMFactory getOMFactory() {

+        return FactoryFinder.findOMFactory(null);

+    }

+

+    /**

+     * If user needs to provide his own factory implementation, provide the

+     * Class Loader here.

+     *

+     * @param classLoader

+     * @return Returns OMFactory.

+     */

+    public static OMFactory getOMFactory(ClassLoader classLoader) {

+        return FactoryFinder.findOMFactory(classLoader);

+    }

+

+    /**

+     * Gets the <code>soapFactory</code> factory implementation from the classpath

+     *

+     * @param soapFactory Fully qualified SOAP 1.1 or SOAP 1.2 Factory implementation class name

+     * @return Returns the SOAP 1.1 or 1.2 Factory implementation instance corresponding to <code>soapFactory</code>

+     */

+    public static SOAPFactory getSOAPFactory(String soapFactory) {

+        return FactoryFinder.findSOAPFactory(null, soapFactory);

+    }

+

+    /**

+     * Gets the <code>soapFactory</code> factory implementation using the provided

+     * <code>classLoader</code>

+     *

+     * @param classLoader

+     * @param soapFactory Fully qualified SOAP 1.1 or SOAP 1.2 Factory implementation class name

+     * @return Returns the SOAP 1.1 or 1.2 Factory implementation instance corresponding to <code>soapFactory</code>

+     */

+    public static SOAPFactory getSOAPFactory(ClassLoader classLoader, String soapFactory) {

+        return FactoryFinder.findSOAPFactory(classLoader, soapFactory);

+    }

+

+    /**

+     * Gets the default factory implementation from the classpath.

+     *

+     * @return Returns SOAPFactory.

+     */

+    public static SOAPFactory getSOAP11Factory() {

+        return FactoryFinder.findSOAP11Factory(null);

+    }

+

+    /**

+     * If user needs to provide his own factory implementation, provide the

+     * Class Loader here.

+     *

+     * @param classLoader

+     * @return Returns SOAPFactory.

+     */

+    public static SOAPFactory getSOAP11Factory(ClassLoader classLoader) {

+        return FactoryFinder.findSOAP11Factory(classLoader);

+    }

+

+    /**

+     * Gets the default factory implementation from the classpath.

+     *

+     * @return Returns SOAPFactory.

+     */

+    public static SOAPFactory getSOAP12Factory() {

+        return FactoryFinder.findSOAP12Factory(null);

+    }

+

+    /**

+     * If user needs to provide his own factory implementation, provide the

+     * Class Loader here.

+     *

+     * @param classLoader

+     * @return Returns SOAPFactory.

+     */

+    public static SOAPFactory getSOAP12Factory(ClassLoader classLoader) {

+        return FactoryFinder.findSOAP12Factory(classLoader);

+    }

+

+    /**

+     * WARNING - DO NOT USE THIS METHOD !!!!!.

+     * This method is used in the case where we do not know the correct SOAP version to be used.

+     * We can do some operation using the factory returned from this, without knowing the SOAP version.

+     * But most of the methods have not been implemented.

+     * We use this in the builder, where we want to first create the SOAP envelope to get the SOAP version.

+     * So this method is to solve the chicken and egg problem, we have. If you do not know the SOAP version to be used

+     * to process a particluar SOAP message you have recd, use this method to buid the SOAP envelope, and then extract the SOAP

+     * version from that envlope and switch to the proper factory using that.

+     */

+    public static SOAPFactory getDefaultSOAPFactory() {

+        return new SOAPLinkedListImplFactory();

+    }

+}

diff --git a/src/org/apache/ws/commons/om/OMAttribute.java b/src/org/apache/ws/commons/om/OMAttribute.java
new file mode 100644
index 0000000..66e03ca
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMAttribute.java
@@ -0,0 +1,59 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import javax.xml.namespace.QName;

+

+/**

+ * Interface OMAttribute

+ */

+public interface OMAttribute {

+    /**

+     * @return Returns localName.

+     */

+    public String getLocalName();

+

+    /**

+     * @param localName

+     */

+    public void setLocalName(String localName);

+

+    /**

+     * @return Returns String.

+     */

+    public String getAttributeValue();

+

+    /**

+     * @param value

+     */

+    public void setAttributeValue(String value);

+

+    /**

+     * @param omNamespace

+     */

+    public void setOMNamespace(OMNamespace omNamespace);

+

+    /**

+     * @return Returns OMNamespace.

+     */

+    public OMNamespace getNamespace();

+

+    /**

+     * @return Returns javax.xml.namespace.QName

+     */

+    public QName getQName();

+}

diff --git a/src/org/apache/ws/commons/om/OMComment.java b/src/org/apache/ws/commons/om/OMComment.java
new file mode 100644
index 0000000..c8e68f4
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMComment.java
@@ -0,0 +1,34 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+/**

+ * Interface OMComment

+ */

+public interface OMComment extends OMNode {

+    /**

+     * Returns the value of this comment as defined by XPath 1.0.

+     * @return Returns String.

+     */

+    public String getValue();

+

+    /**

+     * Sets the content of this comment to the specified string.

+     * @param text

+     */

+    public void setValue(String text);

+}

diff --git a/src/org/apache/ws/commons/om/OMConstants.java b/src/org/apache/ws/commons/om/OMConstants.java
new file mode 100644
index 0000000..8b812f5
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMConstants.java
@@ -0,0 +1,75 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+/**

+ * Interface OMConstants

+ */

+public interface OMConstants {

+

+

+    // OMBuilder constants

+    /**

+     * Field PUSH_TYPE_BUILDER

+     */

+    public static final short PUSH_TYPE_BUILDER = 0;

+

+    /**

+     * Field PULL_TYPE_BUILDER

+     */

+    public static final short PULL_TYPE_BUILDER = 1;

+

+    /**

+     * Field ARRAY_ITEM_NSURI

+     */

+    public static final String ARRAY_ITEM_NSURI =

+            "http://axis.apache.org/encoding/Arrays";

+

+    /**

+     * Field ARRAY_ITEM_LOCALNAME

+     */

+    public static final String ARRAY_ITEM_LOCALNAME = "item";

+

+    /**

+     * Field ARRAY_ITEM_NS_PREFIX

+     */

+    public static final String ARRAY_ITEM_NS_PREFIX = "arrays";

+

+    /**

+     * Field ARRAY_ITEM_QNAME

+     */

+    public static final String ARRAY_ITEM_QNAME =

+            OMConstants.ARRAY_ITEM_NS_PREFIX + ':'

+            + OMConstants.ARRAY_ITEM_LOCALNAME;

+

+    /**

+     * Field DEFAULT_CHAR_SET_ENCODING specifies the default

+     * character encoding scheme to be used

+     */

+    public static final String DEFAULT_CHAR_SET_ENCODING = "utf-8";

+    public static final String DEFAULT_XML_VERSION = "1.0";

+    

+    

+    public static final String XMLNS_URI =

+        "http://www.w3.org/XML/1998/namespace";

+

+    public static final String XMLNS_NS_URI = "http://www.w3.org/2000/xmlns/";

+	public final static String XMLNS_NS_PREFIX = "xmlns";

+    

+    public static final String XMLNS_PREFIX =

+        "xml";

+}

diff --git a/src/org/apache/ws/commons/om/OMContainer.java b/src/org/apache/ws/commons/om/OMContainer.java
new file mode 100644
index 0000000..09972d0
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMContainer.java
@@ -0,0 +1,100 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import javax.xml.namespace.QName;

+import java.util.Iterator;

+

+/**

+ * Captures the operations related to containment shared by both a document and an element.

+ *

+ * <p>Exposes the ability to add, find, and iterate over the children of a document or

+ * element.</p>

+ */

+public interface OMContainer {

+

+    /**

+     * 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.

+     *

+     * @param omNode

+     */

+    public void addChild(OMNode omNode);

+

+    /**

+     * Returns an iterator for child nodes matching the criteria indicated by the given QName.

+     *

+     * <p>This function searches in three ways:

+     *  <ul>

+     *   <li>Exact match - Both parts of the passed QName are non-null.  Only children with the

+     *      same namespace and local name will be returned.

+     *   </li>

+     *  <li>Namespace match - The local name of the passed QName is null.  All children matching the

+     *      namespace will be returned by the iterator.

+     *  </li>

+     *  <li>Local name match - The namespace of the passed QName is null.  All children with the

+     *      matching local name will be returned by the iterator.

+     *  </li>

+     * </ul>

+     *

+     * <p>

+     * <b>Example:</b> <code>header.getChildrenWithName( new QName(ADDRESSING_NAMESPACE, null));</code>

+     *  will return all of the "addressing" headers.

+     * </p>

+     *

+     * @param elementQName The QName specifying namespace and local name to match.

+     * @return Returns an iterator of {@link OMElement} items that match the given QName appropriately.

+     */

+    public Iterator getChildrenWithName(QName elementQName);

+

+    /**

+     * Returns the first child in document order that matches the given QName criteria.

+     *

+     * <p>The QName filter is applied as in the function {@link #getChildrenWithName}.</p>

+     *

+     * @param elementQName The QName to use for matching.

+     *

+     * @return Returns the first element in document order that matches the <tt>elementQName</tt> criteria.

+     *

+     * @see #getChildrenWithName

+     *

+     * @throws OMException Could indirectly trigger building of child nodes.

+     */

+    public OMElement getFirstChildWithName(QName elementQName) throws OMException;

+

+    /**

+     * Returns an iterator for the children of the container.

+     *

+     * @return Returns a {@link Iterator} of children, all of which implement {@link OMNode}.

+     *

+     * @see #getFirstChildWithName

+     * @see #getChildrenWithName

+     */

+    public Iterator getChildren();

+

+    /**

+     * Gets the first child.

+     *

+     * @return Returns the first child.  May return null if the container has no children.

+     */

+    public OMNode getFirstOMChild();

+

+    public boolean isComplete();

+

+    public void buildNext();

+}

diff --git a/src/org/apache/ws/commons/om/OMDocType.java b/src/org/apache/ws/commons/om/OMDocType.java
new file mode 100644
index 0000000..31fd3c6
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMDocType.java
@@ -0,0 +1,34 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+/**

+ * Interface OMDocType

+ */

+public interface OMDocType extends OMNode {

+    /**

+     * Returns the value of this DocType.

+     * @return Returns String.

+     */

+    public String getValue();

+

+    /**

+     * Sets the content of this DocType to the specified string.

+     * @param text

+     */

+    public void setValue(String text);

+}

diff --git a/src/org/apache/ws/commons/om/OMDocument.java b/src/org/apache/ws/commons/om/OMDocument.java
new file mode 100644
index 0000000..7242506
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMDocument.java
@@ -0,0 +1,110 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import javax.xml.stream.XMLStreamException;

+import java.io.OutputStream;

+

+

+public interface OMDocument extends OMContainer {

+

+    /**

+     * Field XML_10 XML Version 1.0

+     */

+    public final static String XML_10 = "1.0";

+

+    /**

+     * Field XML_11 XML Version 1.1

+     */

+    public final static String XML_11 = "1.1";

+

+    /**

+     * Returns the document element.

+     * @return Returns OMElement.

+     */

+    public OMElement getOMDocumentElement();

+

+    /**

+     * Sets the document element of the XML document.

+     * @param rootElement

+     */

+    public void setOMDocumentElement(OMElement rootElement);

+

+    /**

+     * Returns the XML version.

+     * @return Returns String.

+     */

+    public String getXMLVersion();

+

+    /**

+     * Sets the XML version.

+     * @see org.apache.ws.commons.om.impl.llom.OMDocumentImpl#XML_10 XML 1.0

+     * @see org.apache.ws.commons.om.impl.llom.OMDocumentImpl#XML_11 XML 1.1

+     * @param version

+     */

+    public void setXMLVersion(String version);

+

+    /**

+     * Returns the character set encoding scheme.

+     * @return Returns String.

+     */

+    public String getCharsetEncoding();

+

+    /**

+     * Sets the character set encoding scheme to be used.

+     * @param charsetEncoding

+     */

+    public void setCharsetEncoding(String charsetEncoding);

+

+    /**

+     * XML standalone value.

+     * This will be yes, no or null (if not available)

+     * @return Returns boolean.

+     */

+    public String isStandalone();

+    public void setStandalone(String isStandalone);

+

+    /**

+     * Serializes the OMDocument.

+     * @param output

+     * @param format

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(OutputStream output, OMOutputFormat format) throws XMLStreamException;

+

+    /**

+     * Builds the OM node/tree and then serializes the document.

+     * @param output

+     * @param format

+     * @throws XMLStreamException

+     */

+    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException;

+

+    /**

+     * Serializes the OMDocument.

+     * @param output

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(OutputStream output) throws XMLStreamException;

+

+    /**

+     * Serializes the document with cache on.

+     * @param output

+     * @throws XMLStreamException

+     */

+    public void serialize(OutputStream output) throws XMLStreamException;

+}

diff --git a/src/org/apache/ws/commons/om/OMElement.java b/src/org/apache/ws/commons/om/OMElement.java
new file mode 100644
index 0000000..9c72b21
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMElement.java
@@ -0,0 +1,299 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import javax.xml.namespace.QName;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import java.util.Iterator;

+

+/**

+ * A particular kind of node that represents an element infoset information item.

+ * <p/>

+ * <p>An element has a collection of children, attributes, and namespaces.</p>

+ * <p>In contrast with DOM, this interface exposes namespaces separately from the

+ * attributes.</p>

+ */

+public interface OMElement extends OMNode, OMContainer {

+

+    /**

+     * Returns a filtered list of children - just the elements.

+     *

+     * @return Returns an iterator over the child elements.

+     * @see #getChildren()

+     * @see #getChildrenWithName(javax.xml.namespace.QName)

+     */

+    public Iterator getChildElements();

+

+    /**

+     * Creates a namespace in the current element scope.

+     *

+     * @param uri    The namespace to declare in the current scope.  The

+     *               caller is expected to ensure that the URI is a valid namespace name.

+     * @param prefix The prefix to associate with the given namespace.

+     *               The caller is expected to ensure that this is a valid XML prefix.

+     * @return Returns the created namespace information item.

+     * @see #declareNamespace(OMNamespace)

+     * @see #findNamespace(String, String)

+     * @see #getAllDeclaredNamespaces()

+     */

+    public OMNamespace declareNamespace(String uri, String prefix);

+

+    /**

+     * Declares a namespace with the element as its scope.

+     *

+     * @param namespace The namespace to declare

+     * @return Returns the namespace parameter passed.

+     * @see #declareNamespace(String, String)

+     * @see #findNamespace(String, String)

+     * @see #getAllDeclaredNamespaces()

+     */

+    public OMNamespace declareNamespace(OMNamespace namespace);

+

+    /**

+     * Finds a namespace with the given uri and prefix, in the scope of the hierarchy.

+     * <p/>

+     * <p>Searches from the current element and goes up the hiararchy until a match is found.

+     * If no match is found, returns <tt>null</tt>.</p>

+     * <p/>

+     * <p>Either <tt>prefix</tt> or <tt>uri</tt> should be null.  Results are undefined

+     * if both are specified.</p>

+     *

+     * @param uri    The namespace to look for.  If this is specified, <tt>prefix</tt> should be null.

+     * @param prefix The prefix to look for.  If this is specified, <tt>uri</tt> should be null.

+     * @return Returns the matching namespace declaration, or <tt>null</tt> if none was found.

+     * @see #declareNamespace(String, String)

+     * @see #declareNamespace(OMNamespace)

+     * @see #getAllDeclaredNamespaces()

+     */

+    public OMNamespace findNamespace(String uri, String prefix);

+

+    /**

+     * Checks for a namespace in the context of this element with the given prefix and

+     * returns the relevant namespace object, if available. If not available, returns null.

+     *

+     * @param prefix

+     */

+    public OMNamespace findNamespaceURI(String prefix);

+

+    /**

+     * Returns an iterator for all of the namespaces declared on this element.

+     * <p/>

+     * <p>If you're interested in all namespaces in scope, you need to call this function

+     * for all parent elements as well.  Note that the iterator may be invalidated by

+     * any call to either <tt>declareNamespace</tt> function.

+     * </p>

+     *

+     * @return Returns an iterator over the {@link OMNamespace} items declared on the current element.

+     * @see #findNamespace(String, String)

+     * @see #declareNamespace(String, String)

+     * @see #declareNamespace(OMNamespace)

+     */

+    public Iterator getAllDeclaredNamespaces() throws OMException;

+

+    /**

+     * Returns a list of OMAttributes.

+     * 

+     * <p>Note that the iterator returned by this function will be invalidated by

+     * any <tt>addAttribute</tt> call.

+     * </p>

+     *

+     * @return Returns an {@link Iterator} of {@link OMAttribute} items associated with the element.

+     * @see #getAttribute

+     * @see #addAttribute(OMAttribute)

+     * @see #addAttribute(String, String, OMNamespace)

+     */

+    public Iterator getAllAttributes();

+

+    /**

+     * Returns a named attribute if present.

+     *

+     * @param qname the qualified name to search for

+     * @return Returns an OMAttribute with the given name if found, or null

+     */

+    public OMAttribute getAttribute(QName qname);

+

+    /**

+     * Returns a named attribute's value, if present.

+     *

+     * @param qname the qualified name to search for

+     * @return Returns a String containing the attribute value, or null

+     */

+    public String getAttributeValue(QName qname);

+

+    /**

+     * Adds an attribute to this element.

+     * <p/>

+     * <p>There is no order implied by added attributes.</p>

+     *

+     * @param attr The attribute to add.

+     * @return Returns the passed in attribute.

+     */

+    public OMAttribute addAttribute(OMAttribute attr);

+

+    /**

+     * Adds an attribute to the current element.

+     * <p/>

+     * <p>This function does not check to make sure that the given attribute value can be serialized directly

+     * as an XML value.  The caller may, for example, pass a string with the character 0x01.

+     *

+     * @param attributeName The "local name" for the attribute.

+     * @param value         The string value of the attribute.

+     * @param ns            The namespace has to be one of the in scope namespace. i.e. the passed namespace

+     *                      must be declared in the parent element of this attribute or ancestors of the parent element of the attribute.

+     * @return Returns the added attribute.

+     */

+    public OMAttribute addAttribute(String attributeName, String value,

+                                    OMNamespace ns);

+

+    /**

+     * Method removeAttribute

+     *

+     * @param attr

+     */

+    public void removeAttribute(OMAttribute attr);

+

+    /**

+     * Method setBuilder.

+     *

+     * @param wrapper

+     */

+    public void setBuilder(OMXMLParserWrapper wrapper);

+

+    /**

+     * Returns the builder object.

+     *

+     * @return Returns the builder object used to construct the underlying XML infoset on the fly.

+     */

+    public OMXMLParserWrapper getBuilder();

+

+    /**

+     * Sets the first child.

+     *

+     * @param node

+     */

+    public void setFirstChild(OMNode node);

+

+    /**

+     * Returns the first child element of the element.

+     *

+     * @return Returns the first child element of the element, or <tt>null</tt> if none was found.

+     */

+

+    public OMElement getFirstElement();

+

+

+    /**

+     * Returns the pull parser that will generate the pull

+     * events relevant to THIS element.

+     * <p/>

+     * <p>Caching is on.</p>

+     *

+     * @return Returns an XMLStreamReader relative to this element.

+     */

+    public XMLStreamReader getXMLStreamReader();

+

+    /**

+     * Returns the pull parser that will generate the pull

+     * events relevant to THIS element.

+     * <p/>

+     * <p>Caching is off.</p>

+     *

+     * @return Returns an XMLStreamReader relative to this element, with no caching.

+     */

+    public XMLStreamReader getXMLStreamReaderWithoutCaching();

+

+    /**

+     * @param text

+     */

+    public void setText(String text);

+

+    /**

+     * Returns the non-empty text children as a String.

+     *

+     * @return Returns a String representing the concatenation of the child text nodes.

+     */

+    public String getText();

+

+    /**

+     * Returns the local name of the element.

+     *

+     * @return Returns the local name of the element.

+     */

+    public String getLocalName();

+

+    /**

+     * Method setLocalName

+     *

+     * @param localName

+     */

+    public void setLocalName(String localName);

+

+    /**

+     * @return Returns the OMNamespace object associated with this element

+     * @throws OMException

+     */

+    public OMNamespace getNamespace() throws OMException;

+

+    /**

+     * Sets the Namespace.

+     *

+     * @param namespace

+     */

+    public void setNamespace(OMNamespace namespace);

+

+    /**

+     * Gets the QName of this node.

+     *

+     * @return Returns the {@link QName} for the element.

+     */

+    public QName getQName();

+

+    /**

+     * This is a convenience method only. This will basically serialize the given OMElement

+     * to a String but will build the OMTree in the memory

+     */

+    public String toString();

+

+    /**

+     * This is a convenience method only. This basically serializes the given OMElement

+     * to a String but will NOT build the OMTree in the memory. So you are at your own risk of

+     * losing information.

+     */

+    public String toStringWithConsume() throws XMLStreamException;

+

+

+    /**

+     * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.

+     * Unprefixed qnames resolve to the local namespace.

+     *

+     * @param qname prefixed qname string to resolve

+     * @return Returns null for any failure to extract a qname.

+     */

+    QName resolveQName(String qname);

+

+    /**

+     * Clones this element. Since both elements are build compleletely, you will

+     * lose the differed building capability.

+     * @return Returns OMElement.

+     */

+    public OMElement cloneOMElement();

+

+

+    public void setLineNumber(int lineNumber);

+    public int getLineNumber();

+}

diff --git a/src/org/apache/ws/commons/om/OMException.java b/src/org/apache/ws/commons/om/OMException.java
new file mode 100644
index 0000000..c18d7ef
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMException.java
@@ -0,0 +1,56 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+/**

+ * Class OMException

+ */

+public class OMException extends RuntimeException {

+    /**

+     * Constructor OMException

+     */

+    public OMException() {

+    }

+

+    /**

+     * Constructor OMException

+     *

+     * @param message

+     */

+    public OMException(String message) {

+        super(message);

+    }

+

+    /**

+     * Constructor OMException

+     *

+     * @param message

+     * @param cause

+     */

+    public OMException(String message, Throwable cause) {

+        super(message, cause);

+    }

+

+    /**

+     * Constructor OMException

+     *

+     * @param cause

+     */

+    public OMException(Throwable cause) {

+        super(cause);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/OMFactory.java b/src/org/apache/ws/commons/om/OMFactory.java
new file mode 100644
index 0000000..ce35ffa
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMFactory.java
@@ -0,0 +1,155 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import javax.xml.namespace.QName;

+

+/**

+ * Class OMFactory

+ */

+public interface OMFactory {

+

+	/**

+	 * Creates a new OMDocument.

+	 */

+	public OMDocument createOMDocument();

+	public OMDocument createOMDocument(OMXMLParserWrapper builder);

+	

+	

+    /**

+     * @param localName

+     * @param ns

+     */

+    public OMElement createOMElement(String localName, OMNamespace ns);

+    public OMElement createOMElement(String localName, OMNamespace ns, OMContainer parent) throws OMException;

+

+    /**

+     * @param localName

+     * @param ns

+     * @param parent

+     * @param builder

+     */

+    public OMElement createOMElement(String localName, OMNamespace ns,

+                                     OMContainer parent,

+                                     OMXMLParserWrapper builder);

+

+    /**

+     * This is almost the same as as createOMElement(localName,OMNamespace) method above.

+     * But some people may, for some reason, need to use the conventional method of putting a namespace.

+     * Or in other words people might not want to use the new OMNamespace.

+     * Well, this is for those people.

+     *

+     * @param localName

+     * @param namespaceURI

+     * @param namespacePrefix

+     * @return Returns the newly created OMElement.

+     */

+    public OMElement createOMElement(String localName,

+                                     String namespaceURI,

+                                     String namespacePrefix);

+

+    /**

+     * QName(localPart),

+     * QName(namespaceURI, localPart) - a prefix will be assigned to this

+     * QName(namespaceURI, localPart, prefix)

+     *

+     * @param qname

+     * @param parent

+     * @return Returns the new OMElement.

+     * @throws OMException

+     */

+    public OMElement createOMElement(QName qname, OMContainer parent)

+            throws OMException;

+

+    /**

+     * @param uri

+     * @param prefix

+     * @return Returns OMNameSpace.

+     */

+    public OMNamespace createOMNamespace(String uri, String prefix);

+

+    /**

+     * @param parent

+     * @param text

+     * @return Returns OMText.

+     */

+    public OMText createText(OMElement parent, String text);

+

+    /**

+     *

+     * @param parent

+     * @param text

+     * @param type - this should be either of XMLStreamConstants.CHARACTERS, XMLStreamConstants.CDATA,

+     * XMLStreamConstants.SPACE, XMLStreamConstants.ENTITY_REFERENCE

+     * @return Returns OMText.

+     */

+    public OMText createText(OMElement parent, String text, int type);

+

+    /**

+     * @param s

+     * @return Returns OMText.

+     */

+    public OMText createText(String s);

+

+    /**

+     *

+     * @param s

+     * @param type - OMText node can handle SPACE, CHARACTERS, CDATA and ENTITY REFERENCES. For Constants, use either

+     * XMLStreamConstants or constants found in OMNode.

+     * @return Returns OMText.

+     */ 

+    public OMText createText(String s, int type);

+

+    public OMText createText(String s, String mimeType, boolean optimize);

+

+    public OMText createText(Object dataHandler, boolean optimize);

+

+    public OMText createText(OMElement parent, String s, String mimeType,

+                             boolean optimize);

+

+    public OMText createText(String contentID, OMElement parent,

+            OMXMLParserWrapper builder);

+    

+    public OMAttribute createOMAttribute(String localName,

+                                         OMNamespace ns,

+                                         String value);

+

+    /**

+     * Creates DocType/DTD.

+     * @param parent

+     * @param content

+     * @return Returns doctype.

+     */

+    public OMDocType createOMDocType(OMContainer parent, String content);

+

+    /**

+     * Creates a PI.

+     * @param parent

+     * @param piTarget

+     * @param piData

+     * @return Returns OMProcessingInstruction.

+     */

+    public OMProcessingInstruction createOMProcessingInstruction(OMContainer parent, String piTarget, String piData);

+

+    /**

+     * Creates a comment.

+     * @param parent

+     * @param content

+     * @return Returns OMComment.

+     */

+    public OMComment createOMComment(OMContainer parent, String content);

+}

diff --git a/src/org/apache/ws/commons/om/OMFactoryException.java b/src/org/apache/ws/commons/om/OMFactoryException.java
new file mode 100644
index 0000000..d6136f8
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMFactoryException.java
@@ -0,0 +1,56 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+/**

+ * Class OMFactoryException

+ */

+public class OMFactoryException extends OMException {

+    /**

+     * Constructor OMFactoryException

+     */

+    public OMFactoryException() {

+    }

+

+    /**

+     * Constructor OMFactoryException

+     *

+     * @param message

+     */

+    public OMFactoryException(String message) {

+        super(message);

+    }

+

+    /**

+     * Constructor OMFactoryException

+     *

+     * @param message

+     * @param cause

+     */

+    public OMFactoryException(String message, Throwable cause) {

+        super(message, cause);

+    }

+

+    /**

+     * Constructor OMFactoryException

+     *

+     * @param cause

+     */

+    public OMFactoryException(Throwable cause) {

+        super(cause);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/OMNamespace.java b/src/org/apache/ws/commons/om/OMNamespace.java
new file mode 100644
index 0000000..ea3b909
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMNamespace.java
@@ -0,0 +1,45 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+/**

+ * Interface OMNamespace

+ */

+public interface OMNamespace {

+    /**

+     * Method equals.

+     *

+     * @param uri

+     * @param prefix

+     * @return Returns boolean.

+     */

+    public boolean equals(String uri, String prefix);

+

+    /**

+     * Method getPrefix.

+     *

+     * @return Returns String.

+     */

+    public String getPrefix();

+

+    /**

+     * Method getName.

+     *

+     * @return Returns String.

+     */

+    public String getName();

+}

diff --git a/src/org/apache/ws/commons/om/OMNode.java b/src/org/apache/ws/commons/om/OMNode.java
new file mode 100644
index 0000000..5dfbff6
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMNode.java
@@ -0,0 +1,272 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import javax.xml.stream.XMLStreamConstants;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.OutputStream;

+import java.io.Writer;

+

+/**

+ * Defines the base interface used by most of the XML object model within Axis.

+ *

+ * <p>This tree model for XML captures the idea of deferring the construction of child nodes

+ * until they are needed.  The <code>isComplete</code> function identifies whether or not

+ * a particular node has been fully parsed.  A node may not be fully parsed, for example, if

+ * all of the children of an element have not yet been parsed.</p>

+ *

+ * <p>In comparison to DOM, in this model, you will not find document fragments, or entities.

+ * In addition, while {@link OMDocument} and {@link OMAttribute} exist, neither is an extension

+ * of <code>OMNode</code>.

+ * </p>

+ */

+public interface OMNode {

+    /**

+     * The node is an <code>Element</code>.

+     *

+     * @see #getType()

+     */

+    public static final short ELEMENT_NODE = 1;

+

+    /**

+     * The node is a <code>Text</code> node.

+     *

+     * @see #getType()

+     */

+    public static final short TEXT_NODE = XMLStreamConstants.CHARACTERS;

+

+    /**

+     * The node is a <code>CDATASection</code>.

+     *

+     * @see #getType()

+     */

+    public static final short CDATA_SECTION_NODE = XMLStreamConstants.CDATA;

+

+    /**

+     * The node is a <code>Comment</code>.

+     *

+     * @see #getType()

+     */

+    public static final short COMMENT_NODE = XMLStreamConstants.COMMENT;

+

+    /**

+     * This node is a <code>DTD</code>.

+     *

+     * @see #getType()

+     */

+    public static final short DTD_NODE = XMLStreamConstants.DTD;

+

+    /**

+     * This node is a <code>ProcessingInstruction</code>.

+     *

+     * @see #getType()

+     */

+    public static final short PI_NODE = XMLStreamConstants.PROCESSING_INSTRUCTION;

+

+    /**

+     * This node is an <code>Entity Reference</code>.

+     *

+     * @see #getType()

+     */

+    public static final short ENTITY_REFERENCE_NODE = XMLStreamConstants.ENTITY_REFERENCE;

+

+    /**

+     * This node is an <code>Entity Reference</code>.

+     *

+     * @see #getType()

+     */

+    public static final short SPACE_NODE = XMLStreamConstants.SPACE;

+

+    /**

+     * Returns the parent containing node.

+     *

+     * <p>Returns the parent container, which may be either an {@link OMDocument} or {@link OMElement}.

+     *

+     * @return The {@link OMContainer} of the node.

+     */

+    public OMContainer getParent();

+

+    /**

+     * Returns the next sibling in document order.

+     *

+     * @return Returns the next sibling in document order.

+     */

+    public OMNode getNextOMSibling() throws OMException;

+

+    /**

+     * Indicates whether parser has parsed this information item completely or not.

+     * If some info are not available in the item, one has to check this attribute to make sure that, this

+     * item has been parsed completely or not.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isComplete();

+

+    /**

+     * Removes a node (and all of its children) from its containing parent.

+     *

+     * <p>Removes a node from its parent.  Partially complete nodes will be completed before

+     * they are detached from the model.  A node cannot be detached until its next sibling

+     * has been identified, so that the next sibling and parent can be updated appropriately.

+     * Please note that this will not handle the namespaces. For example, if there you have used a

+     * namespace within the detaching node and which is defined outside the detaching node, user has

+     * to handle it manually.

+     * </p>

+     *

+     * @throws OMException If a node is not complete, the detach can trigger further

+     * parsing, which may cause an exception.

+     */

+    public OMNode detach() throws OMException;

+

+    /**

+     * Discards a node.

+     *

+     * <p>Discard goes to the parser level and if the element is not completely built, then it will be

+     * completely skipped at the parser level.</p>

+     *

+     * @throws OMException

+     */

+    public void discard() throws OMException;

+

+    /**

+     * Inserts a new sibling after the current node.

+     *

+     * @param sibling The node that will be added after the current node.

+     *

+     * @throws OMException

+     */

+    public void insertSiblingAfter(OMNode sibling) throws OMException;

+

+    /**

+     * Inserts a sibling just before the current node.

+     *

+     * @param sibling The node that will be added before the current node.

+     * @throws OMException

+     */

+    public void insertSiblingBefore(OMNode sibling) throws OMException;

+

+    /**

+     * Returns the type of node.

+     *

+     * @return Returns one of {@link #ELEMENT_NODE}, {@link #TEXT_NODE}, {@link #CDATA_SECTION_NODE}, {@link #COMMENT_NODE},

+     *  {@link #DTD_NODE}, {@link #PI_NODE}, {@link #ENTITY_REFERENCE_NODE}, {@link #SPACE_NODE},

+     * or {@link #TEXT_NODE}.

+     */

+    public int getType();

+

+    /**

+     * Gets the previous sibling.

+     *

+     * @return Returns node.

+     */

+    public OMNode getPreviousOMSibling();

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param xmlWriter

+     * @throws XMLStreamException

+     */

+    public void serialize(XMLStreamWriter xmlWriter)

+            throws XMLStreamException;

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param output

+     * @throws XMLStreamException

+     */

+    public void serialize(OutputStream output)

+            throws XMLStreamException;

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param writer

+     * @throws XMLStreamException

+     */

+    public void serialize(Writer writer)

+            throws XMLStreamException;

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param output

+     * @param format

+     * @throws XMLStreamException

+     */

+    public void serialize(OutputStream output, OMOutputFormat format)

+            throws XMLStreamException;

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param writer

+     * @param format

+     * @throws XMLStreamException

+     */

+    public void serialize(Writer writer, OMOutputFormat format)

+            throws XMLStreamException;

+    

+    /**

+     * Serializes the node without caching.

+     *

+     * @param xmlWriter

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException;

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param output

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(OutputStream output) throws XMLStreamException;

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param writer

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(Writer writer) throws XMLStreamException;

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param output

+     * @param format

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(OutputStream output, OMOutputFormat format) throws XMLStreamException;

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param writer

+     * @param format

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(Writer writer, OMOutputFormat format) throws XMLStreamException;

+

+    /**

+     * Builds itself.

+     */

+    public void build();

+}

diff --git a/src/org/apache/ws/commons/om/OMOutputFormat.java b/src/org/apache/ws/commons/om/OMOutputFormat.java
new file mode 100644
index 0000000..54ca345
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMOutputFormat.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.ws.commons.om;
+
+import org.apache.ws.commons.om.impl.MIMEOutputUtils;
+import org.apache.ws.commons.om.util.UUIDGenerator;
+import org.apache.ws.commons.soap.SOAP11Constants;
+import org.apache.ws.commons.soap.SOAP12Constants;
+
+
+/**
+ * Formats options for OM Output.
+ */
+public class OMOutputFormat {
+    private String mimeBoundary = null;
+    private String rootContentId = null;
+    private int nextid = 0;
+    private boolean doOptimize;
+    private boolean isSoap11 = true;
+
+    /**
+     * Field DEFAULT_CHAR_SET_ENCODING. Specifies the default
+     * character encoding scheme to be used.
+     */
+    public static final String DEFAULT_CHAR_SET_ENCODING = "utf-8";
+
+    private String charSetEncoding;
+    private String xmlVersion;
+    private boolean ignoreXMLDeclaration = false;
+
+
+    public OMOutputFormat() {
+    }
+
+    public boolean isOptimized() {
+        return doOptimize;
+    }
+
+    public String getContentType() {
+        String SOAPContentType;
+        if (isOptimized()) {
+            if (isSoap11) {
+                SOAPContentType = SOAP11Constants.SOAP_11_CONTENT_TYPE;
+            } else {
+                SOAPContentType = SOAP12Constants.SOAP_12_CONTENT_TYPE;
+            }
+            return MIMEOutputUtils.getContentTypeForMime(
+                    getMimeBoundary(),
+                    getRootContentId(),
+                    this.getCharSetEncoding(), SOAPContentType);
+        } else {
+            if (!isSoap11) {
+                return SOAP12Constants.SOAP_12_CONTENT_TYPE;
+            } else {
+                return SOAP11Constants.SOAP_11_CONTENT_TYPE;
+            }
+        }
+    }
+
+    public String getMimeBoundary() {
+        if (mimeBoundary == null) {
+            mimeBoundary =
+                    "MIMEBoundary"
+                            + UUIDGenerator.getUUID();
+        }
+        return mimeBoundary;
+    }
+
+    public String getRootContentId() {
+        if (rootContentId == null) {
+            rootContentId =
+                    "0."
+                            + UUIDGenerator.getUUID()
+                            + "@apache.org";
+        }
+        return rootContentId;
+    }
+
+    public String getNextContentId() {
+        nextid++;
+        return nextid
+                + "."
+                + UUIDGenerator.getUUID()
+                + "@apache.org";
+    }
+
+    /**
+     * Returns the character set encoding scheme. If the value of the
+     * charSetEncoding is not set then the default will be returned.
+     *
+     * @return Returns encoding string.
+     */
+    public String getCharSetEncoding() {
+        return this.charSetEncoding;
+    }
+
+    public void setCharSetEncoding(String charSetEncoding) {
+        this.charSetEncoding = charSetEncoding;
+    }
+
+    public String getXmlVersion() {
+        return xmlVersion;
+    }
+
+    public void setXmlVersion(String xmlVersion) {
+        this.xmlVersion = xmlVersion;
+    }
+
+    public void setSOAP11(boolean b) {
+        isSoap11 = b;
+    }
+    
+    public boolean isSOAP11() {
+        return isSoap11;
+    }
+
+    public boolean isIgnoreXMLDeclaration() {
+        return ignoreXMLDeclaration;
+    }
+
+    public void setIgnoreXMLDeclaration(boolean ignoreXMLDeclaration) {
+        this.ignoreXMLDeclaration = ignoreXMLDeclaration;
+    }
+
+    public void setDoOptimize(boolean b) {
+        doOptimize = b;
+    }
+}
diff --git a/src/org/apache/ws/commons/om/OMProcessingInstruction.java b/src/org/apache/ws/commons/om/OMProcessingInstruction.java
new file mode 100644
index 0000000..62caef1
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMProcessingInstruction.java
@@ -0,0 +1,46 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+/**

+ * Interface OMProcessingInstruction

+ */

+public interface OMProcessingInstruction extends OMNode {

+    /**

+     * Sets the target of this Processing Instruction.

+     * @param target

+     */

+    public void setTarget(String target);

+

+    /**

+     * Gets the target of this Processing Instruction.

+      * @return Returns string.

+     */

+    public String getTarget();

+

+    /**

+     * Sets the value of this Processing Instruction.

+     * @param value

+     */

+    public void setValue(String value);

+

+    /**

+     * Gets the value of this Processing Instruction.

+      * @return Returns String.

+     */

+    public String getValue();

+}

diff --git a/src/org/apache/ws/commons/om/OMSerializer.java b/src/org/apache/ws/commons/om/OMSerializer.java
new file mode 100644
index 0000000..ba60136
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMSerializer.java
@@ -0,0 +1,36 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+

+/**

+ * Interface OMSerializer

+ */

+public interface OMSerializer {

+    /**

+     * Method serializeAndConsume

+     *

+     * @param reader

+     * @param writer

+     * @throws XMLStreamException

+     */

+    void serialize(XMLStreamReader reader, XMLStreamWriter writer)

+            throws XMLStreamException;

+}

diff --git a/src/org/apache/ws/commons/om/OMText.java b/src/org/apache/ws/commons/om/OMText.java
new file mode 100644
index 0000000..d3054ac
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMText.java
@@ -0,0 +1,54 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+

+/**

+ * Interface OMText

+ */

+public interface OMText extends OMNode {

+    /**

+     * Returns the text value of this node.

+     *

+     * @return Returns String.

+     */

+    String getText();

+

+    /**

+     * Gets the datahandler.

+     * @return Returns datahandler.

+     */

+    Object getDataHandler();

+

+    /**

+     * @return Returns boolean flag saying whether the node contains

+     *         an optimized text or not.

+     */

+    boolean isOptimized();

+

+    /**

+     * Sets the optimize flag.

+     * @param value

+     */

+    void setOptimize(boolean value);

+

+    /**

+     * Gets the content id.

+     * @return Returns String.

+     */

+    String getContentID();

+}

diff --git a/src/org/apache/ws/commons/om/OMXMLParserWrapper.java b/src/org/apache/ws/commons/om/OMXMLParserWrapper.java
new file mode 100644
index 0000000..da32d15
--- /dev/null
+++ b/src/org/apache/ws/commons/om/OMXMLParserWrapper.java
@@ -0,0 +1,95 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+/**

+ * Interface OMXMLParserWrapper

+ */

+public interface OMXMLParserWrapper {

+    /**

+     * Proceed the parser one step and return the event value.

+     *

+     * @return Returns int.

+     * @throws org.apache.ws.commons.om.OMException

+     *

+     * @throws OMException

+     */

+    int next() throws OMException;

+

+    /**

+     * Discards the current element.

+     * This will remove the given element and its decendants.

+     *

+     * @param el

+     * @throws org.apache.ws.commons.om.OMException

+     *

+     * @throws OMException

+     */

+    void discard(OMElement el) throws OMException;

+

+    /**

+     * @param b

+     * @throws org.apache.ws.commons.om.OMException

+     *

+     * @throws OMException

+     */

+    void setCache(boolean b) throws OMException;

+

+    /**

+     * Allows to access the underlying parser. Since the parser

+     * depends on the underlying implementation, an Object is returned.

+     * However the implementations may have restrictions in letting access to

+     * the parser.

+     *

+     * @return Returns Object.

+     */

+    Object getParser();

+

+    /**

+     * @return Returns the complete status.

+     */

+    boolean isCompleted();

+

+    /**

+     * @return Returns the document element.

+     */

+    OMElement getDocumentElement();

+

+    /**

+     * Returns the type of the builder.

+     * Can be either PUSH_TYPE_BUILDER or PULL_TYPE_BUILDER.

+     *

+     * @return Returns short.

+     */

+    short getBuilderType();

+

+    /**

+     * Registers an external content handler. Especially useful for

+     * push type builders. Throws an unsupportedOperationException if

+     * such handler registration is not supported.

+     *

+     * @param obj

+     */

+    void registerExternalContentHandler(Object obj);

+

+    /**

+     * get the registered external content handler

+     *

+     * @return Returns Object.

+     */

+    Object getRegisteredContentHandler();

+}

diff --git a/src/org/apache/ws/commons/om/impl/MIMEOutputUtils.java b/src/org/apache/ws/commons/om/impl/MIMEOutputUtils.java
new file mode 100644
index 0000000..d2e8c33
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/MIMEOutputUtils.java
@@ -0,0 +1,139 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl;

+

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMText;

+

+import javax.mail.MessagingException;

+import javax.mail.internet.MimeBodyPart;

+import javax.activation.DataHandler;

+import java.io.IOException;

+import java.io.OutputStream;

+import java.io.StringWriter;

+import java.util.Iterator;

+import java.util.LinkedList;

+

+public class MIMEOutputUtils {

+

+    private static byte[] CRLF =  { 13, 10 };

+

+    public static void complete(OutputStream outStream,

+                                StringWriter writer, LinkedList binaryNodeList,

+                                String boundary, String contentId, String charSetEncoding,String SOAPContentType) {

+        try {

+            startWritingMime(outStream, boundary);

+

+            javax.activation.DataHandler dh = new javax.activation.DataHandler(writer.toString(),

+                    "text/xml; charset=" + charSetEncoding);

+            MimeBodyPart rootMimeBodyPart = new MimeBodyPart();

+            rootMimeBodyPart.setDataHandler(dh);

+            

+            rootMimeBodyPart.addHeader("content-type",

+                    "application/xop+xml; charset=" + charSetEncoding + 

+					"; type=\""+SOAPContentType+"\";");

+            rootMimeBodyPart.addHeader("content-transfer-encoding", "binary");

+            rootMimeBodyPart.addHeader("content-id","<"+contentId+">");

+

+            writeBodyPart(outStream, rootMimeBodyPart, boundary);

+

+            Iterator binaryNodeIterator = binaryNodeList.iterator();

+            while (binaryNodeIterator.hasNext()) {

+                OMText binaryNode = (OMText) binaryNodeIterator.next();

+                writeBodyPart(outStream, createMimeBodyPart(binaryNode),

+                        boundary);

+            }

+            finishWritingMime(outStream);

+        } catch (IOException e) {

+            throw new OMException("Problem with the OutputStream.", e);

+        } catch (MessagingException e) {

+            throw new OMException("Problem writing Mime Parts.", e);

+        }

+    }

+

+    public static MimeBodyPart createMimeBodyPart(OMText node)

+            throws MessagingException {

+        MimeBodyPart mimeBodyPart = new MimeBodyPart();

+        final DataHandler dataHandler = (DataHandler) node.getDataHandler();

+        mimeBodyPart.setDataHandler(dataHandler);

+        mimeBodyPart.addHeader("content-id", "<"+node.getContentID()+">");

+        mimeBodyPart.addHeader("content-type", dataHandler.getContentType());

+        mimeBodyPart.addHeader("content-transfer-encoding", "binary");

+        return mimeBodyPart;

+

+    }

+

+    /**

+     * @throws IOException This will write the boundary to output Stream

+     */

+    public static void writeMimeBoundary(OutputStream outStream,

+                                         String boundary) throws IOException {

+        outStream.write(new byte[]{45, 45});

+        outStream.write(boundary.getBytes());

+    }

+

+    /**

+     * @throws IOException This will write the boundary with CRLF

+     */

+    public static void startWritingMime(OutputStream outStream,

+                                        String boundary)

+            throws IOException {

+        writeMimeBoundary(outStream, boundary);

+        //outStream.write(CRLF);

+    }

+

+    /**

+     * Writes a CRLF for the earlier boundary then the BodyPart data

+     * with headers followed by boundary. Writes only the boundary. No more

+     * CRLF's are written after that.

+     *

+     * @throws IOException

+     * @throws MessagingException

+     */

+    public static void writeBodyPart(OutputStream outStream,

+                                     MimeBodyPart part, 

+                                     String boundary) throws IOException,

+            MessagingException {

+        outStream.write(CRLF);

+        part.writeTo(outStream);

+        outStream.write(CRLF);

+        writeMimeBoundary(outStream, boundary);

+    }

+

+    /**

+     * @throws IOException This will write "--" to the end of last boundary

+     */

+    public static void finishWritingMime(OutputStream outStream)

+            throws IOException {

+        outStream.write(new byte[]{45, 45});

+    }

+

+    public static String getContentTypeForMime(String boundary, String contentId, String charSetEncoding, String SOAPContentType) {

+        StringBuffer sb = new StringBuffer();

+        sb.append("multipart/related");

+        sb.append("; ");

+        sb.append("boundary=");

+        sb.append(boundary);

+        sb.append("; ");

+        sb.append("type=\"application/xop+xml\"");

+        sb.append("; ");

+        sb.append("start=\"<" + contentId + ">\"");

+        sb.append("; ");

+        sb.append("start-info=\""+SOAPContentType+"\"");

+        return sb.toString();

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/MTOMConstants.java b/src/org/apache/ws/commons/om/impl/MTOMConstants.java
new file mode 100644
index 0000000..82d14e6
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/MTOMConstants.java
@@ -0,0 +1,37 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl;

+

+public interface MTOMConstants {

+    public static final String XOP_INCLUDE = "Include";

+    public static final String XOP_NAMESPACE_URI = "http://www.w3.org/2004/08/xop/include";

+

+    /**

+     * If the Message is MTOM optimised then <code>MTOM_TYPE</code>

+     */

+    String MTOM_TYPE = "application/xop+xml";

+    /**

+     * If the message is Soap with Attachments <code>SWA_TYPE</code>

+     */

+    String SWA_TYPE = "text/xml";

+    /**

+     * <code>rootPart</code> is used as the key for the root BodyPart in the

+     * Parts HashMap

+     */

+    String ROOT_PART = "SoapPart";

+    String ATTACHMENTS = "Attachments";

+}

diff --git a/src/org/apache/ws/commons/om/impl/OMContainerEx.java b/src/org/apache/ws/commons/om/impl/OMContainerEx.java
new file mode 100644
index 0000000..c9d8fb0
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/OMContainerEx.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.ws.commons.om.impl;
+
+import org.apache.ws.commons.om.OMContainer;
+import org.apache.ws.commons.om.OMNode;
+
+/**
+ * Interface OMContainerEx
+ *
+ * Internal Implementation detail. Adding special interface to stop folks from accidently using OMContainer.
+ * Please use at your own risk. May corrupt the data integrity.
+ */
+public interface OMContainerEx extends OMContainer {
+    public void setComplete(boolean state);
+
+    public void setFirstChild(OMNode omNode);
+}
diff --git a/src/org/apache/ws/commons/om/impl/OMNodeEx.java b/src/org/apache/ws/commons/om/impl/OMNodeEx.java
new file mode 100644
index 0000000..702d361
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/OMNodeEx.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.ws.commons.om.impl;
+
+import org.apache.ws.commons.om.OMContainer;
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.OMNode;
+
+import javax.xml.stream.XMLStreamException;
+
+/**
+ * Interface OMNodeEx
+ *
+ * Internal Implementation detail. Adding special interface to stop folks from accidently using OMNode.
+ * Please use at your own risk. May corrupt the data integrity.
+ */
+public interface OMNodeEx extends OMNode {
+    public void setNextOMSibling(OMNode node);
+
+    public void setPreviousOMSibling(OMNode previousSibling);
+
+    public void setParent(OMContainer element);
+
+    public void setComplete(boolean state);
+
+    public void setType(int nodeType) throws OMException;
+
+    /**
+     * Serializes the node with caching.
+     *
+     * @param omOutput
+     * @throws javax.xml.stream.XMLStreamException
+     * @see #serialize(org.apache.ws.commons.om.impl.OMOutputImpl)
+     */
+    public void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput)
+            throws XMLStreamException;
+
+    /**
+     * Serializes the node without caching.
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     */
+    public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException;
+}
diff --git a/src/org/apache/ws/commons/om/impl/OMOutputImpl.java b/src/org/apache/ws/commons/om/impl/OMOutputImpl.java
new file mode 100644
index 0000000..7aa6aaa
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/OMOutputImpl.java
@@ -0,0 +1,169 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl;

+

+import org.apache.ws.commons.om.OMOutputFormat;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAP12Constants;

+

+import javax.xml.stream.FactoryConfigurationError;

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.OutputStream;

+import java.io.StringWriter;

+import java.util.LinkedList;

+

+

+/**

+ * For the moment this assumes that transport takes the decision of whether

+ * to optimize or not by looking at whether the MTOM optimize is enabled &

+ * also looking at the OM tree whether it has any optimizable content.

+ */

+public class OMOutputImpl {

+    private XMLStreamWriter xmlWriter;

+    private OutputStream outStream;

+    private LinkedList binaryNodeList = new LinkedList();

+    private StringWriter bufferedSOAPBody;

+    private OMOutputFormat format = new OMOutputFormat();

+

+    public OMOutputImpl(XMLStreamWriter xmlWriter) {

+        this.xmlWriter = xmlWriter;

+    }

+

+    /**

+     * Creates a new OMOutputImpl with specified encoding.

+     *

+     * @param outStream

+     * @param format

+     * @throws XMLStreamException

+     * @throws FactoryConfigurationError

+     * @see OMOutputFormat#DEFAULT_CHAR_SET_ENCODING

+     */

+    public OMOutputImpl(OutputStream outStream, OMOutputFormat format)

+            throws XMLStreamException, FactoryConfigurationError {

+        this.format = format;

+        this.outStream = outStream;

+

+        if (format.getCharSetEncoding() == null) //Default encoding is UTF-8

+            format.setCharSetEncoding(OMOutputFormat.DEFAULT_CHAR_SET_ENCODING);

+

+        XMLOutputFactory factory = XMLOutputFactory.newInstance();

+

+        if (format.isOptimized()) {

+            bufferedSOAPBody = new StringWriter();

+            xmlWriter = factory.createXMLStreamWriter(bufferedSOAPBody);

+        } else {

+            xmlWriter = factory.createXMLStreamWriter(outStream,

+                    format.getCharSetEncoding());

+        }

+    }

+

+    public void flush() throws XMLStreamException {

+        xmlWriter.flush();

+        String SOAPContentType;

+        if (format.isOptimized()) {

+            if (format.isSOAP11()) {

+                SOAPContentType = SOAP11Constants.SOAP_11_CONTENT_TYPE;

+            } else {

+                SOAPContentType = SOAP12Constants.SOAP_12_CONTENT_TYPE;

+            }

+            MIMEOutputUtils.complete(

+                    outStream,

+                    bufferedSOAPBody,

+                    binaryNodeList,

+                    format.getMimeBoundary(),

+                    format.getRootContentId(),

+                    format.getCharSetEncoding(), SOAPContentType);

+        }

+    }

+

+    public boolean isOptimized() {

+        return format.isOptimized();

+    }

+

+    public String getContentType() {

+        return format.getContentType();

+    }

+

+    public void writeOptimized(OMText node) {

+        binaryNodeList.add(node);

+    }

+

+    public void setXmlStreamWriter(XMLStreamWriter xmlWriter) {

+        this.xmlWriter = xmlWriter;

+    }

+

+    public XMLStreamWriter getXmlStreamWriter() {

+        return xmlWriter;

+    }

+

+    public String getMimeBoundary() {

+        return format.getMimeBoundary();

+    }

+

+    public String getRootContentId() {

+        return format.getRootContentId();

+    }

+

+    public String getNextContentId() {

+        return format.getNextContentId();

+    }

+

+    /**

+     * Returns the character set encoding scheme. If the value of the

+     * charSetEncoding is not set then the default will be returned.

+     *

+     * @return Returns encoding.

+     */

+    public String getCharSetEncoding() {

+        return format.getCharSetEncoding();

+    }

+

+    public void setCharSetEncoding(String charSetEncoding) {

+        format.setCharSetEncoding(charSetEncoding);

+    }

+

+    public String getXmlVersion() {

+        return format.getXmlVersion();

+    }

+

+    public void setXmlVersion(String xmlVersion) {

+        format.setXmlVersion(xmlVersion);

+    }

+

+    public void setSoap11(boolean b) {

+        format.setSOAP11(b);

+    }

+

+    public boolean isIgnoreXMLDeclaration() {

+        return format.isIgnoreXMLDeclaration();

+    }

+

+    public void setIgnoreXMLDeclaration(boolean ignoreXMLDeclaration) {

+        format.setIgnoreXMLDeclaration(ignoreXMLDeclaration);

+    }

+

+    public void setDoOptimize(boolean b) {

+        format.setDoOptimize(b);

+    }

+

+    public void setOutputFormat(OMOutputFormat format) {

+        this.format = format;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/EmptyOMLocation.java b/src/org/apache/ws/commons/om/impl/llom/EmptyOMLocation.java
new file mode 100644
index 0000000..1d44fdc
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/EmptyOMLocation.java
@@ -0,0 +1,45 @@
+package org.apache.ws.commons.om.impl.llom;

+

+import javax.xml.stream.Location;

+

+/*

+ * Copyright 2001-2004 The Apache Software Foundation.

+ *

+ * Licensed 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.

+ *

+ */

+

+public class EmptyOMLocation implements Location {

+

+

+    public int getLineNumber() {

+        return -1;  //To change body of implemented methods use File | Settings | File Templates.

+    }

+

+    public int getColumnNumber() {

+        return -1;  //To change body of implemented methods use File | Settings | File Templates.

+    }

+

+    public int getCharacterOffset() {

+        return 0;  //To change body of implemented methods use File | Settings | File Templates.

+    }

+

+    public String getPublicId() {

+        return null;  //To change body of implemented methods use File | Settings | File Templates.

+    }

+

+    public String getSystemId() {

+        return null;  //To change body of implemented methods use File | Settings | File Templates.

+    }

+

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMAttributeImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMAttributeImpl.java
new file mode 100644
index 0000000..29aeebc
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMAttributeImpl.java
@@ -0,0 +1,123 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMNamespace;

+

+import javax.xml.namespace.QName;

+

+/**

+ * Class OMAttributeImpl

+ */

+public class OMAttributeImpl implements OMAttribute {

+    /**

+     * Field localName

+     */

+    private String localName;

+

+    /**

+     * Field value

+     */

+    private String value;

+

+    /**

+     * Field namespace

+     */

+    private OMNamespace namespace;

+

+    /**

+     * Constructor OMAttributeImpl.

+     *

+     * @param localName

+     * @param ns

+     * @param value

+     */

+    public OMAttributeImpl(String localName, OMNamespace ns, String value) {

+        setLocalName(localName);

+        setAttributeValue(value);

+        setOMNamespace(ns);

+    }

+

+    /**

+     *

+     * @return Returns QName.

+     */

+    public QName getQName() {

+        if(namespace != null){

+            return new QName(namespace.getName(), localName, namespace.getPrefix());

+        }else{

+            return new QName(localName);

+        }

+    }

+

+    // -------- Getters and Setters

+

+    /**

+     * Method getLocalName.

+     *

+     * @return Returns local name.

+     */

+    public String getLocalName() {

+        return localName;

+    }

+

+    /**

+     * Method setLocalName.

+     *

+     * @param localName

+     */

+    public void setLocalName(String localName) {

+        this.localName = localName;

+    }

+

+    /**

+     * Method getAttributeValue.

+     *

+     * @return Returns value.

+     */

+    public String getAttributeValue() {

+        return value;

+    }

+

+    /**

+     * Method setAttributeValue.

+     *

+     * @param value

+     */

+    public void setAttributeValue(String value) {

+        this.value = value;

+    }

+

+    /**

+     * Method setOMNamespace.

+     *

+     * @param omNamespace

+     */

+    public void setOMNamespace(OMNamespace omNamespace) {

+        this.namespace = omNamespace;

+    }

+

+    /**

+     * Method getNamespace.

+     *

+     * @return Returns namespace.

+     */

+    public OMNamespace getNamespace() {

+        return namespace;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMCommentImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMCommentImpl.java
new file mode 100644
index 0000000..744804c
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMCommentImpl.java
@@ -0,0 +1,107 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMComment;

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+

+public class OMCommentImpl extends OMNodeImpl implements OMComment {

+    protected String value;

+

+    /**

+     * Constructor OMCommentImpl.

+     *

+     * @param parentNode

+     * @param contentText

+     */

+    public OMCommentImpl(OMContainer parentNode, String contentText) {

+        super(parentNode);

+        this.value = contentText;

+        nodeType = OMNode.COMMENT_NODE;

+        this.done = true;

+    }

+

+    /**

+     * Constructor OMCommentImpl.

+     *

+     * @param parentNode

+     */

+    public OMCommentImpl(OMContainer parentNode) {

+        this(parentNode, null);

+    }

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     * @see #serialize(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        writer.writeComment(this.value);

+    }

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     * @see #serializeAndConsume(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {

+        serialize(omOutput);

+    }

+

+    /**

+     * Gets the value of this comment.

+     *

+     * @return Returns String.

+     */

+    public String getValue() {

+        return value;

+    }

+

+    /**

+     * Sets the value of this comment.

+     *

+     * @param text

+     */

+    public void setValue(String text) {

+        this.value = text;

+    }

+

+    /**

+     * Discards this node.

+     *

+     * @throws OMException

+     */

+    public void discard() throws OMException {

+        if (done) {

+            this.detach();

+        } else {

+            builder.discard((OMElement) this.parent);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMDocTypeImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMDocTypeImpl.java
new file mode 100644
index 0000000..8a54fd3
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMDocTypeImpl.java
@@ -0,0 +1,106 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMDocType;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+

+public class OMDocTypeImpl extends OMNodeImpl implements OMDocType {

+    protected String value;

+

+    /**

+     * Constructor OMDocTypeImpl.

+     *

+     * @param parentNode

+     * @param contentText

+     */

+    public OMDocTypeImpl(OMContainer parentNode, String contentText) {

+        super(parentNode);

+        this.value = contentText;

+        nodeType = OMNode.DTD_NODE;

+    }

+

+    /**

+     * Constructor OMDocTypeImpl.

+     *

+     * @param parentNode

+     */

+    public OMDocTypeImpl(OMContainer parentNode) {

+        this(parentNode, null);

+    }

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     * @see #serialize(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        writer.writeDTD(this.value);

+    }

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     * @see #serializeAndConsume(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serializeAndConsume(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        serialize(omOutput);

+    }

+

+    /**

+     * Gets the value of this DocType.

+     *

+     * @return Returns String.

+     */

+    public String getValue() {

+        return value;

+    }

+

+    /**

+     * Sets the value of this DocType.

+     *

+     * @param text

+     */

+    public void setValue(String text) {

+        this.value = text;

+    }

+

+    /**

+     * Discards this node.

+     *

+     * @throws OMException

+     */

+    public void discard() throws OMException {

+        if (done) {

+            this.detach();

+        } else {

+            builder.discard((OMElement) this.parent);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMDocumentImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMDocumentImpl.java
new file mode 100644
index 0000000..5cb9328
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMDocumentImpl.java
@@ -0,0 +1,402 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMDocument;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMOutputFormat;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMContainerEx;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.om.impl.llom.traverse.OMChildrenIterator;

+import org.apache.ws.commons.om.impl.llom.traverse.OMChildrenQNameIterator;

+

+import javax.xml.namespace.QName;

+import javax.xml.stream.XMLStreamException;

+import java.io.OutputStream;

+import java.util.Iterator;

+

+/**

+ * Class OMDocumentImpl

+ */

+public class OMDocumentImpl implements OMDocument, OMContainerEx {

+    /**

+     * Field documentElement

+     */

+    protected OMElement documentElement;

+

+    /**

+     * Field firstChild

+     */

+    protected OMNode firstChild;

+

+    /**

+     * Field lastChild

+     */

+    protected OMNode lastChild;

+

+    /**

+     * Field done

+     */

+    protected boolean done = false;

+

+    /**

+     * Field parserWrapper

+     */

+    protected OMXMLParserWrapper parserWrapper;

+

+    /**

+     * Field charSetEncoding

+     * Default : UTF-8

+     */

+    protected String charSetEncoding = "UTF-8";

+

+    /**

+     * Field xmlVersion

+     */

+    protected String xmlVersion = "1.0";

+

+    protected String isStandalone;

+

+

+    /**

+     * Default constructor

+     */

+    public OMDocumentImpl() {

+        this.done = true;

+    }

+

+    /**

+     * @param documentElement

+     * @param parserWrapper

+     */

+    public OMDocumentImpl(OMElement documentElement, OMXMLParserWrapper parserWrapper) {

+        this.documentElement = documentElement;

+        this.parserWrapper = parserWrapper;

+    }

+

+    /**

+     * @param parserWrapper

+     */

+    public OMDocumentImpl(OMXMLParserWrapper parserWrapper) {

+        this.parserWrapper = parserWrapper;

+    }

+

+    /**

+     * Method getDocumentElement.

+     *

+     * @return Returns OMElement.

+     */

+    public OMElement getOMDocumentElement() {

+        while (documentElement == null) {

+            parserWrapper.next();

+        }

+        return documentElement;

+    }

+

+    /**

+     * Method setDocumentElement.

+     *

+     * @param documentElement

+     */

+    public void setOMDocumentElement(OMElement documentElement) {

+        this.documentElement = documentElement;

+    }

+

+    /**

+     * Indicates whether parser has parsed this information item completely or not.

+     * If some information is not available in the item, one has to check this 

+     * attribute to make sure that, this item has been parsed completely or not.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isComplete() {

+        return done;

+    }

+

+    /**

+     * Method setComplete.

+     *

+     * @param state

+     */

+    public void setComplete(boolean state) {

+        this.done = state;

+    }

+

+    /**

+     * Forces the parser to proceed, if parser has not yet finished with the XML input.

+     */

+    public void buildNext() {

+        if (!parserWrapper.isCompleted())

+            parserWrapper.next();

+    }

+

+    /**

+     * Adds child to the element. One can decide whether to append the child or to add to the

+     * front of the children list.

+     *

+     * @param child

+     */

+    public void addChild(OMNode child) {

+    	if(child instanceof OMElement) {

+    		if(this.documentElement == null) {

+    			addChild((OMNodeImpl) child);

+    			this.documentElement = (OMElement)child;

+    		} else {

+    			throw new OMException("Document element already exists");

+    		}

+    	} else {

+    		addChild((OMNodeImpl) child);

+    	}

+    }

+

+    /**

+     * Method addChild.

+     *

+     * @param child

+     */

+    private void addChild(OMNodeImpl child) {

+        if (firstChild == null) {

+            firstChild = child;

+            child.setPreviousOMSibling(null);

+        } else {

+            child.setPreviousOMSibling(lastChild);

+            ((OMNodeEx)lastChild).setNextOMSibling(child);

+        }

+        child.setNextOMSibling(null);

+        child.setParent(this);

+        lastChild = child;

+

+    }

+

+    /**

+     * Returns a collection of this element.

+     * Children can be of types OMElement, OMText.

+     *

+     * @return Returns iterator.

+     */

+    public Iterator getChildren() {

+        return new OMChildrenIterator(getFirstOMChild());

+    }

+

+    /**

+     * Searches for children with a given QName and returns an iterator to traverse through

+     * the OMNodes.

+     * The QName can contain any combination of prefix, localname and URI.

+     *

+     * @param elementQName

+     * @return Returns Iterator.

+     * @throws org.apache.ws.commons.om.OMException

+     */

+    public Iterator getChildrenWithName(QName elementQName) {

+        return new OMChildrenQNameIterator(getFirstOMChild(),

+                elementQName);

+    }

+

+    /**

+     * Method getFirstOMChild.

+     *

+     * @return Returns first om child.

+     */

+    public OMNode getFirstOMChild() {

+        while ((firstChild == null) && !done) {

+            buildNext();

+        }

+        return firstChild;

+    }

+

+    /**

+     * Method getFirstChildWithName.

+     *

+     * @param elementQName

+     * @return Returns OMElement.

+     * @throws OMException

+     */

+    public OMElement getFirstChildWithName(QName elementQName) throws OMException {

+        OMChildrenQNameIterator omChildrenQNameIterator =

+                new OMChildrenQNameIterator(getFirstOMChild(),

+                        elementQName);

+        OMNode omNode = null;

+        if (omChildrenQNameIterator.hasNext()) {

+            omNode = (OMNode) omChildrenQNameIterator.next();

+        }

+

+        return ((omNode != null) && (OMNode.ELEMENT_NODE == omNode.getType())) ?

+                (OMElement) omNode : null;

+

+    }

+

+    /**

+     * Method setFirstChild.

+     *

+     * @param firstChild

+     */

+    public void setFirstChild(OMNode firstChild) {

+        this.firstChild = firstChild;

+    }

+

+

+    /**

+     * Returns the character set encoding scheme to be used.

+     *

+     * @return Returns charset.

+     */

+    public String getCharsetEncoding() {

+        return charSetEncoding;

+    }

+

+    /**

+     * Sets the character set encoding scheme.

+     *

+     * @param charEncoding

+     */

+    public void setCharsetEncoding(String charEncoding) {

+        this.charSetEncoding = charEncoding;

+    }

+

+    public String isStandalone() {

+        return isStandalone;

+    }

+

+    public void setStandalone(String isStandalone) {

+        this.isStandalone = isStandalone;

+    }

+

+    public String getXMLVersion() {

+        return xmlVersion;

+    }

+

+    public void setXMLVersion(String xmlVersion) {

+        this.xmlVersion = xmlVersion;

+    }

+

+    /**

+     * Serialize the docuement with/without the XML declaration

+     */

+    public void serializeAndConsume(OMOutputImpl omOutput, boolean includeXMLDeclaration) throws XMLStreamException {

+        serialize(omOutput, false, includeXMLDeclaration);

+    }

+

+    /**

+     * Serializes the document with the XML declaration.

+     */

+    public void serializeAndConsume(OMOutputImpl omOutput)

+            throws XMLStreamException {

+        serialize(omOutput, false, !omOutput.isIgnoreXMLDeclaration());

+    }

+

+

+    /**

+     * Serializes the document with cache.

+     */

+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {

+        serialize(omOutput, true, !omOutput.isIgnoreXMLDeclaration());

+

+    }

+

+    /**

+     * Serializes the document directly to the output stream with caching disabled.

+     * 

+     * @param output

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(OutputStream output) throws XMLStreamException {

+        OMOutputImpl omOutput = new OMOutputImpl(output, new OMOutputFormat());

+        serializeAndConsume(omOutput);

+        omOutput.flush();

+    }

+

+    /**

+     * Serializes the document directly to the output stream with caching enabled.

+     * 

+     * @param output

+     * @throws XMLStreamException

+     */

+    public void serialize(OutputStream output) throws XMLStreamException {

+        OMOutputImpl omOutput = new OMOutputImpl(output, new OMOutputFormat());

+        serialize(omOutput);

+        omOutput.flush();

+    }

+

+    /**

+     * Serializes the document directly to the output stream with caching disabled.

+     * 

+     * @param output

+     * @param format

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(OutputStream output, OMOutputFormat format) throws XMLStreamException {

+        OMOutputImpl omOutput = new OMOutputImpl(output, format);

+        serializeAndConsume(omOutput);

+        omOutput.flush();

+    }

+

+    /**

+     * Serializes the document directly to the output stream with caching enabled.

+     * 

+     * @param output

+     * @param format

+     * @throws XMLStreamException

+     */

+    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {

+        OMOutputImpl omOutput = new OMOutputImpl(output, format);

+        serialize(omOutput);

+        omOutput.flush();

+    }

+

+    /**

+     * Serializes the document with cache.

+     */

+    public void serialize(OMOutputImpl omOutput, boolean includeXMLDeclaration) throws XMLStreamException {

+        serialize(omOutput, true, includeXMLDeclaration);

+

+    }

+

+    protected void serialize(OMOutputImpl omOutput, boolean cache, boolean includeXMLDeclaration) throws XMLStreamException {

+        if (includeXMLDeclaration) {

+            //Check whether the OMOutput char encoding and OMDocument char

+            //encoding matches, if not use char encoding of OMOutput

+            String outputCharEncoding = omOutput.getCharSetEncoding();

+            if (outputCharEncoding == null || "".equals(outputCharEncoding)) {

+                omOutput.getXmlStreamWriter().writeStartDocument(charSetEncoding,

+                        xmlVersion);

+            } else {

+                omOutput.getXmlStreamWriter().writeStartDocument(outputCharEncoding,

+                        xmlVersion);

+            }

+        }

+

+        Iterator children = this.getChildren();

+

+        if (cache) {

+            while (children.hasNext()) {

+                OMNodeEx omNode = (OMNodeEx) children.next();

+                omNode.serialize(omOutput);

+            }

+        } else {

+            while (children.hasNext()) {

+                OMNodeEx omNode = (OMNodeEx) children.next();

+                omNode.serializeAndConsume(omOutput);

+            }

+        }

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMElementImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMElementImpl.java
new file mode 100644
index 0000000..37981bf
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMElementImpl.java
@@ -0,0 +1,862 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMConstants;

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMContainerEx;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.om.impl.llom.traverse.OMChildElementIterator;

+import org.apache.ws.commons.om.impl.llom.traverse.OMChildrenIterator;

+import org.apache.ws.commons.om.impl.llom.traverse.OMChildrenQNameIterator;

+import org.apache.ws.commons.om.impl.llom.util.EmptyIterator;

+import org.apache.ws.commons.om.util.ElementHelper;

+

+import javax.xml.namespace.QName;

+import javax.xml.stream.XMLStreamConstants;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import java.io.ByteArrayOutputStream;

+import java.util.HashMap;

+import java.util.Iterator;

+

+/**

+ * Class OMElementImpl

+ */

+public class OMElementImpl extends OMNodeImpl

+        implements OMElement, OMConstants, OMContainerEx {

+    /**

+     * Field ns

+     */

+    protected OMNamespace ns;

+

+    /**

+     * Field localName

+     */

+    protected String localName;

+    /**

+     * Field firstChild

+     */

+    protected OMNode firstChild;

+

+    /**

+     * Field namespaces

+     */

+    protected HashMap namespaces = null;

+

+    /**

+     * Field attributes

+     */

+    protected HashMap attributes = null;

+

+    /**

+     * Field noPrefixNamespaceCounter

+     */

+    protected int noPrefixNamespaceCounter = 0;

+    private OMNode lastChild;

+    private int lineNumber;

+

+    /**

+     * Constructor OMElementImpl.

+     */

+    public OMElementImpl(String localName, OMNamespace ns, OMContainer parent,

+                         OMXMLParserWrapper builder) {

+        super(parent);

+        this.localName = localName;

+        if (ns != null) {

+            setNamespace(ns);

+        }

+        this.builder = builder;

+        firstChild = null;

+    }

+

+

+    /**

+     * Constructor OMElementImpl.

+     */

+    public OMElementImpl(String localName, OMNamespace ns) {

+        this(localName, ns, null);

+    }

+

+    /**

+     * This is the basic constructor for OMElement. All the other constructors 

+     * depends on this.

+     *

+     * @param localName - this MUST always be not null

+     * @param ns        - can be null

+     * @param parent    - this should be an OMContainer

+     */

+    public OMElementImpl(String localName, OMNamespace ns, OMContainer parent) {

+        super(parent);

+        if (localName == null || localName.trim().length() == 0) {

+            throw new OMException("localname can not be null or empty");

+        }

+        this.localName = localName;

+        this.done = true;

+        if (ns != null) {

+            setNamespace(ns);

+        }

+    }

+

+    /**

+     * It is assumed that the QName passed contains, at least, the localName for this element.

+     *

+     * @param qname - this should be valid qname according to javax.xml.namespace.QName

+     * @throws OMException

+     */

+    public OMElementImpl(QName qname, OMContainer parent) throws OMException {

+        this(qname.getLocalPart(), null, parent);

+        this.ns = handleNamespace(qname);

+    }

+

+    /**

+     * Method handleNamespace.

+     */

+    private OMNamespace handleNamespace(QName qname) {

+        OMNamespace ns = null;

+

+        // first try to find a namespace from the scope

+        String namespaceURI = qname.getNamespaceURI();

+        if (namespaceURI != null && namespaceURI.length() > 0) {

+            ns = findNamespace(qname.getNamespaceURI(),

+                    qname.getPrefix());

+

+            /**

+             * What is left now is

+             *  1. nsURI = null & parent != null, but ns = null

+             *  2. nsURI != null, (parent doesn't have an ns with given URI), but ns = null

+             */

+            if (ns == null) {

+                String prefix = qname.getPrefix();

+                ns = declareNamespace(namespaceURI, prefix);

+            }

+            if (ns != null) {

+                this.ns = (ns);

+            }

+        }

+

+        else

+

+        {

+            // no namespace URI in the given QName. No need to bother about this ??

+        }

+

+        return ns;

+    }

+

+    /**

+     * Method handleNamespace.

+     *

+     * @return Returns namespace.

+     */

+    private OMNamespace handleNamespace(OMNamespace ns) {

+        OMNamespace namespace = findNamespace(ns.getName(),

+                ns.getPrefix());

+        if (namespace == null) {

+            namespace = declareNamespace(ns);

+        }

+        return namespace;

+    }

+

+    /**

+     * Adds child to the element. One can decide whether to append the child or to add to the

+     * front of the children list.

+     */

+    public void addChild(OMNode child) {

+        addChild((OMNodeImpl) child);

+    }

+

+    /**

+     * Searches for children with a given QName and returns an iterator to traverse through

+     * the OMNodes.

+     * This QName can contain any combination of prefix, localname and URI.

+     *

+     * @throws OMException

+     */

+    public Iterator getChildrenWithName(QName elementQName) {

+        return new OMChildrenQNameIterator(getFirstOMChild(),

+                elementQName);

+    }

+

+    /**

+     * Method getFirstChildWithName.

+     *

+     * @throws OMException

+     */

+    public OMElement getFirstChildWithName(QName elementQName) throws OMException {

+        OMChildrenQNameIterator omChildrenQNameIterator =

+                new OMChildrenQNameIterator(getFirstOMChild(),

+                        elementQName);

+        OMNode omNode = null;

+        if (omChildrenQNameIterator.hasNext()) {

+            omNode = (OMNode) omChildrenQNameIterator.next();

+        }

+

+        return ((omNode != null) && (OMNode.ELEMENT_NODE == omNode.getType())) ?

+                (OMElement) omNode : null;

+

+    }

+

+    /**

+     * Method addChild.

+     */

+    private void addChild(OMNodeImpl child) {

+        //the order of these statements is VERY important

+        //Since setting the parent has a detach method inside

+        //it strips down all the rerefences to siblings.

+        //setting the siblings should take place AFTER setting the parent

+

+        child.setParent(this);

+

+        if (firstChild == null) {

+            firstChild = child;

+            child.setPreviousOMSibling(null);

+        } else {

+            child.setPreviousOMSibling(lastChild);

+            ((OMNodeEx) lastChild).setNextOMSibling(child);

+        }

+

+        child.setNextOMSibling(null);

+        lastChild = child;

+

+    }

+

+    /**

+     * Gets the next sibling. This can be an OMAttribute or OMText or 

+     * OMELement for others.

+     *

+     * @throws OMException

+     */

+    public OMNode getNextOMSibling() throws OMException {

+        while (!done) {

+            int token = builder.next();

+            if (token == XMLStreamConstants.END_DOCUMENT) {

+                throw new OMException();

+            }

+        }

+        return super.getNextOMSibling();

+    }

+

+    /**

+     * Returns a collection of this element. Children can be of types OMElement, OMText.

+     *

+     * @return Returns children.

+     */

+    public Iterator getChildren() {

+        return new OMChildrenIterator(getFirstOMChild());

+    }

+

+    /**

+     * Returns a filtered list of children - just the elements.

+     *

+     * @return Returns an iterator of the child elements.

+     */

+    public Iterator getChildElements() {

+        return new OMChildElementIterator(getFirstElement());

+    }

+

+    /**

+     * Creates a namespace in the current element scope.

+     *

+     * @return Returns namespace.

+     */

+    public OMNamespace declareNamespace(String uri, String prefix) {

+        OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);

+        return declareNamespace(ns);

+    }

+

+    /**

+     * @return Returns namespace.

+     */

+    public OMNamespace declareNamespace(OMNamespace namespace) {

+        if (namespaces == null) {

+            this.namespaces = new HashMap(5);

+        }

+        namespaces.put(namespace.getPrefix(), namespace);

+        return namespace;

+    }

+

+    /**

+     * Finds a namespace with the given uri and prefix, in the scope of the document.

+     * Starts to find from the current element and goes up in the hiararchy until one is found.

+     * If none is found, returns null.

+     */

+    public OMNamespace findNamespace(String uri, String prefix) {

+

+        // check in the current element

+        OMNamespace namespace = findDeclaredNamespace(uri, prefix);

+        if (namespace != null) {

+            return namespace;

+        }

+

+        // go up to check with ancestors

+        if (parent != null) {

+            //For the OMDocumentImpl there won't be any explicit namespace

+            //declarations, so going up the parent chain till the document

+            //element should be enough.

+            if (parent instanceof OMElement) {

+                namespace = ((OMElementImpl) parent).findNamespace(uri, prefix);

+            }

+        }

+

+        return namespace;

+    }

+

+    public OMNamespace findNamespaceURI(String prefix) {

+        OMNamespace ns = (OMNamespace) this.namespaces.get(prefix);

+        if (ns == null && this.parent instanceof OMElement) {

+            // try with the parent

+            ns = ((OMElement) this.parent).findNamespaceURI(prefix);

+        }

+        return ns;

+    }

+

+    /**

+     * Checks for the namespace <B>only</B> in the current Element.

+     * This is also used to retrieve the prefix of a known namespace URI.

+     */

+    private OMNamespace findDeclaredNamespace(String uri, String prefix) {

+

+

+        if (uri == null) {

+            return null;

+        }

+

+        //If the prefix is available and uri is available and its the xml namespace

+        if (prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX) && uri.equals(OMConstants.XMLNS_URI)) {

+            return new OMNamespaceImpl(uri, prefix);

+        }

+

+        if (namespaces == null) {

+            return null;

+        }

+

+        if (prefix == null || "".equals(prefix)) {

+            Iterator namespaceListIterator = namespaces.values().iterator();

+

+            OMNamespace ns = null;

+

+            while (namespaceListIterator.hasNext()) {

+                OMNamespace omNamespace =

+                        (OMNamespace) namespaceListIterator.next();

+                if (omNamespace.getName() != null &&

+                        omNamespace.getName().equals(uri)) {

+                       if(ns == null){

+                        ns = omNamespace;

+                       }else{

+                               if(omNamespace.getPrefix() == null || omNamespace.getPrefix().length() == 0){

+                                       ns = omNamespace;

+                               }

+                       }

+                }

+            }

+            return ns;

+        } else {

+            OMNamespace namespace = (OMNamespace) namespaces.get(prefix);

+            if (namespace != null && uri.equalsIgnoreCase(namespace.getName())) {

+                return namespace;

+            } else {

+                return null;

+            }

+        }

+    }

+

+

+    /**

+     * Method getAllDeclaredNamespaces.

+     *

+     * @return Returns Iterator.

+     */

+    public Iterator getAllDeclaredNamespaces() {

+        if (namespaces == null) {

+            return new Iterator() {

+                public void remove() {

+                    throw new UnsupportedOperationException();

+                }

+

+                public boolean hasNext() {

+                    return false;

+                }

+

+                public Object next() {

+                    return null;

+                }

+            };

+        }

+        return namespaces.values().iterator();

+    }

+

+    /**

+     * Returns a List of OMAttributes.

+     *

+     * @return Returns iterator.

+     */

+    public Iterator getAllAttributes() {

+        if (attributes == null) {

+            return new EmptyIterator();

+        }

+        return attributes.values().iterator();

+    }

+

+    /**

+     * Returns a named attribute if present.

+     *

+     * @param qname the qualified name to search for

+     * @return Returns an OMAttribute with the given name if found, or null

+     */

+    public OMAttribute getAttribute(QName qname) {

+        return attributes == null ? null : (OMAttribute) attributes.get(qname);

+    }

+

+    /**

+     * Returns a named attribute's value, if present.

+     *

+     * @param qname the qualified name to search for

+     * @return Returns a String containing the attribute value, or null.

+     */

+    public String getAttributeValue(QName qname) {

+        OMAttribute attr = getAttribute(qname);

+        return (attr == null) ? null : attr.getAttributeValue();

+    }

+

+    /**

+     * Inserts an attribute to this element. Implementor can decide as to insert this

+     * in the front or at the end of set of attributes.

+     *

+     * @return Returns attribute.

+     */

+    public OMAttribute addAttribute(OMAttribute attr) {

+        if (attributes == null) {

+            this.attributes = new HashMap(5);

+        }

+        OMNamespace namespace = attr.getNamespace();

+        if (namespace != null && this.findNamespace(namespace.getName(), namespace.getPrefix()) == null) {

+            this.declareNamespace(namespace.getName(), namespace.getPrefix());

+        }

+

+        attributes.put(attr.getQName(), attr);

+        return attr;

+    }

+

+    /**

+     * Method removeAttribute.

+     */

+    public void removeAttribute(OMAttribute attr) {

+        if (attributes != null) {

+            attributes.remove(attr.getQName());

+        }

+    }

+

+    /**

+     * Method addAttribute.

+     *

+     * @return Returns OMAttribute.

+     */

+    public OMAttribute addAttribute(String attributeName, String value,

+                                    OMNamespace ns) {

+        OMNamespace namespace;

+        if (ns != null) {

+            namespace = findNamespace(ns.getName(), ns.getPrefix());

+            if (namespace == null) {

+                throw new OMException("Given OMNamespace(" + ns.getName() +

+                        ns.getPrefix()

+                        + ") for "

+                        +

+                        "this attribute is not declared in the scope of this element. First declare the namespace"

+                        + " and then use it with the attribute");

+            }

+        }

+        return addAttribute(new OMAttributeImpl(attributeName, ns, value));

+    }

+

+    /**

+     * Method setBuilder.

+     */

+    public void setBuilder(OMXMLParserWrapper wrapper) {

+        this.builder = wrapper;

+    }

+

+    /**

+     * Method getBuilder.

+     *

+     * @return Returns OMXMLParserWrapper.

+     */

+    public OMXMLParserWrapper getBuilder() {

+        return builder;

+    }

+

+    /**

+     * Forces the parser to proceed, if parser has not yet finished with the XML input.

+     */

+    public void buildNext() {

+        builder.next();

+    }

+

+    /**

+     * Method getFirstOMChild.

+     *

+     * @return Returns child.

+     */

+    public OMNode getFirstOMChild() {

+        while ((firstChild == null) && !done) {

+            buildNext();

+        }

+        return firstChild;

+    }

+

+    /**

+     * Method setFirstChild.

+     */

+    public void setFirstChild(OMNode firstChild) {

+        if (firstChild != null) {

+            ((OMNodeEx) firstChild).setParent(this);

+        }

+        this.firstChild = firstChild;

+    }

+

+    /**

+     * Removes this information item and its children, from the model completely.

+     *

+     * @throws OMException

+     */

+    public OMNode detach() throws OMException {

+        if (!done) {

+            build();

+        } else {

+            super.detach();

+        }

+        return this;

+    }

+

+    /**

+     * Method isComplete.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isComplete() {

+        return done;

+    }

+

+    /**

+     * Gets the type of node, as this is the super class of all the nodes.

+     */

+    public int getType() {

+        return OMNode.ELEMENT_NODE;

+    }

+

+    /**

+     * Method getXMLStreamReader.

+     *

+     * @see OMElement#getXMLStreamReader()

+     */

+    public XMLStreamReader getXMLStreamReader() {

+        return getXMLStreamReader(true);

+    }

+

+    /**

+     * Method getXMLStreamReaderWithoutCaching.

+     *

+     * @see OMElement#getXMLStreamReaderWithoutCaching()

+     */

+    public XMLStreamReader getXMLStreamReaderWithoutCaching() {

+        return getXMLStreamReader(false);

+    }

+

+    /**

+     * Method getXMLStreamReader.

+     *

+     * @return Returns reader.

+     */

+    private XMLStreamReader getXMLStreamReader(boolean cache) {

+        if ((builder == null) && !cache) {

+            throw new UnsupportedOperationException(

+                    "This element was not created in a manner to be switched");

+        }

+        if (builder != null && builder.isCompleted() && !cache) {

+            throw new UnsupportedOperationException(

+                    "The parser is already consumed!");

+        }

+        return new OMStAXWrapper(builder, this, cache);

+    }

+

+    /**

+     * Sets the text of the given element.

+     * caution - This method will wipe out all the text elements (and hence any

+     * mixed content) before setting the text.

+     */

+    public void setText(String text) {

+

+        OMNode child = this.getFirstOMChild();

+        while (child != null) {

+            if (child.getType() == OMNode.TEXT_NODE) {

+                child.detach();

+            }

+            child = child.getNextOMSibling();

+        }

+

+        this.addChild(OMAbstractFactory.getOMFactory().createText(this, text));

+    }

+

+    /**

+     * Selects all the text children and concatinates them to a single string.

+     *

+     * @return Returns String.

+     */

+    public String getText() {

+        String childText = "";

+        OMNode child = this.getFirstOMChild();

+        OMText textNode;

+

+        while (child != null) {

+            if (child.getType() == OMNode.TEXT_NODE) {

+                textNode = (OMText) child;

+                if (textNode.getText() != null &&

+                        !"".equals(textNode.getText())) {

+                    childText += textNode.getText();

+                }

+            }

+            child = child.getNextOMSibling();

+        }

+

+        return childText;

+    }

+

+    /**

+     * Returns the concatination string of TRIMMED values of all

+     * OMText  child nodes of this element.

+     * This is included purely to improve usability.

+     */

+    public String getTrimmedText() {

+        String childText = "";

+        OMNode child = this.getFirstOMChild();

+        OMText textNode;

+

+        while (child != null) {

+            if (child.getType() == OMNode.TEXT_NODE) {

+                textNode = (OMText) child;

+                if (textNode.getText() != null &&

+                        !"".equals(textNode.getText().trim())) {

+                    childText += textNode.getText().trim();

+                }

+            }

+            child = child.getNextOMSibling();

+        }

+

+        return childText;

+    }

+

+    /**

+     * Method serialize.

+     *

+     * @throws XMLStreamException

+     */

+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {

+        serialize(omOutput, true);

+    }

+

+///////////////////////////////////////////////////////////////////////////////////////////////

+//////////////////////////////////////////////////////////////////////////////////////////////

+

+    protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+

+        if (cache) {

+            //in this case we don't care whether the elements are built or not

+            //we just call the serializeAndConsume methods

+            OMSerializerUtil.serializeStartpart(this, omOutput);

+            //serialize children

+            Iterator children = this.getChildren();

+            while (children.hasNext()) {

+                ((OMNodeEx) children.next()).serialize(omOutput);

+            }

+            OMSerializerUtil.serializeEndpart(omOutput);

+

+        } else {

+            //Now the caching is supposed to be off. However caching been switched off

+            //has nothing to do if the element is already built!

+            if (this.done) {

+                OMSerializerUtil.serializeStartpart(this, omOutput);

+                OMNodeImpl child = (OMNodeImpl) firstChild;

+                while(child != null && ((!(child instanceof OMElement)) || child.isComplete())) {

+                    child.serializeAndConsume(omOutput);

+                    child = child.nextSibling;

+                }

+                if(child != null) {

+                    OMElement element = (OMElement) child;

+                    element.getBuilder().setCache(false);

+                    OMSerializerUtil.serializeByPullStream(element, omOutput, cache);

+                }

+                OMSerializerUtil.serializeEndpart(omOutput);

+            } else {

+                OMSerializerUtil.serializeByPullStream(this, omOutput, cache);

+            }

+

+

+        }

+    }

+

+////////////////////////////////////////////////////////////////////////////////////////////////

+////////////////////////////////////////////////////////////////////////////////////////////////

+

+    /**

+     * This method serializes and consumes without building the object structure in memory. 

+     * Misuse of this method will cause loss of data. So it is advised to use 

+     * populateYourSelf() method, before calling this method, if one wants to 

+     * preserve data in the stream. This was requested during the second Axis2 summit. 

+     *

+     * @throws XMLStreamException

+     */

+    public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {

+        this.serialize(omOutput, false);

+    }

+

+    /**

+     * Gets first element.

+     *

+     * @return Returns element.

+     */

+    public OMElement getFirstElement() {

+        OMNode node = getFirstOMChild();

+        while (node != null) {

+            if (node.getType() == OMNode.ELEMENT_NODE) {

+                return (OMElement) node;

+            } else {

+                node = node.getNextOMSibling();

+            }

+        }

+        return null;

+    }

+

+    /**

+     * Method getLocalName.

+     *

+     * @return Returns local name.

+     */

+    public String getLocalName() {

+        return localName;

+    }

+

+    /**

+     * Method setLocalName.

+     */

+    public void setLocalName(String localName) {

+        this.localName = localName;

+    }

+

+    /**

+     * Method getNamespace.

+     *

+     * @throws OMException

+     */

+    public OMNamespace getNamespace() throws OMException {

+        return ns;

+    }

+

+    /**

+     * Method setNamespace.

+     */

+    public void setNamespace(OMNamespace namespace) {

+        OMNamespace nsObject = null;

+        if (namespace != null) {

+            nsObject = handleNamespace(namespace);

+        }

+        this.ns = nsObject;

+    }

+

+    /**

+     * Method getQName.

+     *

+     * @return Returns QName.

+     */

+    public QName getQName() {

+        QName qName;

+        if (ns != null) {

+            if (ns.getPrefix() != null) {

+                qName = new QName(ns.getName(), localName, ns.getPrefix());

+            } else {

+                qName = new QName(ns.getName(), localName);

+            }

+        } else {

+            qName = new QName(localName);

+        }

+        return qName;

+    }

+

+    public String toStringWithConsume() throws XMLStreamException {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        this.serializeAndConsume(baos);

+        return new String(baos.toByteArray());

+    }

+

+    public String toString() {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        try {

+            this.serialize(baos);

+        } catch (XMLStreamException e) {

+            throw new RuntimeException("Can not serialize OM Element " + this.getLocalName(), e);

+        }

+        return new String(baos.toByteArray());

+    }

+

+    /**

+     * Method discard.

+     *

+     * @throws OMException

+     */

+    public void discard() throws OMException {

+        if (done) {

+            this.detach();

+        } else {

+            builder.discard(this);

+        }

+    }

+

+    /**

+     * Converts a prefix:local qname string into a proper QName, evaluating it 

+     * in the OMElement context. Unprefixed qnames resolve to the local namespace.

+     *

+     * @param qname prefixed qname string to resolve

+     * @return Returns null for any failure to extract a qname.

+     */

+    public QName resolveQName(String qname) {

+        ElementHelper helper = new ElementHelper(this);

+        return helper.resolveQName(qname);

+    }

+

+    public OMElement cloneOMElement() {

+        OMElement clonedElement = new StAXOMBuilder(this.getXMLStreamReader(true)).getDocumentElement();

+        clonedElement.build();

+        return clonedElement;

+    }

+

+    public void setLineNumber(int lineNumber) {

+        this.lineNumber = lineNumber;

+    }

+

+    public int getLineNumber() {

+        return lineNumber;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMNamespaceImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMNamespaceImpl.java
new file mode 100644
index 0000000..15571ce
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMNamespaceImpl.java
@@ -0,0 +1,74 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMNamespace;

+

+/**

+ * Class OMNamespaceImpl

+ */

+public class OMNamespaceImpl implements OMNamespace {

+    /**

+     * Field prefix

+     */

+    private String prefix;

+

+    /**

+     * Field uri

+     */

+    private String uri;

+

+    /**

+     * @param uri

+     * @param prefix

+     */

+    public OMNamespaceImpl(String uri, String prefix) {

+        this.uri = uri;

+        this.prefix = prefix;

+    }

+

+    /**

+     * Method equals.

+     *

+     * @param uri

+     * @param prefix

+     * @return Returns boolean.

+     */

+    public boolean equals(String uri, String prefix) {

+        return (((prefix == null) && (this.prefix == null)) ||

+                ((prefix != null) && prefix.equals(this.prefix))) &&

+                uri.equals(uri);

+    }

+

+    /**

+     * Method getPrefix.

+     *

+     * @return Returns String.

+     */

+    public String getPrefix() {

+        return prefix;

+    }

+

+    /**

+     * Method getName.

+     *

+     * @return Returns String.

+     */

+    public String getName() {

+        return uri;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMNavigator.java b/src/org/apache/ws/commons/om/impl/llom/OMNavigator.java
new file mode 100644
index 0000000..d090afb
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMNavigator.java
@@ -0,0 +1,193 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNode;

+

+/**

+ * Refer to the testClass to find out how to use

+ * features like isNavigable, isComplete and step.

+ */

+public class OMNavigator {

+    /**

+     * Field node

+     */

+    protected OMNode node;

+

+    /**

+     * Field visited

+     */

+    private boolean visited;

+

+    /**

+     * Field next

+     */

+    private OMNode next;

+

+    // root is the starting element. Once the navigator comes back to the

+    // root, the traversal is terminated

+

+    /**

+     * Field root

+     */

+    private OMNode root;

+

+    /**

+     * Field backtracked

+     */

+    private boolean backtracked;

+

+    // flags that tell the status of the navigator

+

+    /**

+     * Field end

+     */

+    private boolean end = false;

+

+    /**

+     * Field start

+     */

+    private boolean start = true;

+

+    /**

+     * Constructor OMNavigator.

+     */

+    public OMNavigator() {

+    }

+

+    /**

+     * Constructor OMNavigator.

+     *

+     * @param node

+     */

+    public OMNavigator(OMNode node) {

+        init(node);

+    }

+

+    /**

+     * Method init.

+     *

+     * @param node

+     */

+    public void init(OMNode node) {

+        next = node;

+        root = node;

+        backtracked = false;

+    }

+

+    /**

+     * Gets the next node.

+     *

+     * @return Returns OMnode in the sequence of preorder traversal. Note however 

+     *         that an element node is treated slightly differently. Once the 

+     *         element is passed it returns the same element in the next encounter as well.

+     */

+    public OMNode next() {

+        if (next == null) {

+            return null;

+        }

+        node = next;

+        visited = backtracked;

+        backtracked = false;

+        updateNextNode();

+

+        // set the starting and ending flags

+        if (root.equals(node)) {

+            if (!start) {

+                end = true;

+            } else {

+                start = false;

+            }

+        }

+        return node;

+    }

+

+    /**

+     * Private method to encapsulate the searching logic.

+     */

+    private void updateNextNode() {

+        if ((next instanceof OMElement) && !visited) {

+            OMElementImpl e = (OMElementImpl) next;

+            if (e.firstChild != null) {

+                next = e.firstChild;

+            } else if (e.isComplete()) {

+                backtracked = true;

+            } else {

+                next = null;

+            }

+        } else {

+            OMNode nextSibling = ((OMNodeImpl) next).nextSibling;

+            //OMNode parent = next.getParent();

+            OMContainer parent = next.getParent();

+            if (nextSibling != null) {

+                next = nextSibling;

+            } else if ((parent != null) && parent.isComplete()) {

+                next = (OMNodeImpl) parent;

+                backtracked = true;

+            } else {

+                next = null;

+            }

+        }

+    }

+

+    /**

+     * Method visited.

+     *

+     * @return Returns boolean.

+     */

+    public boolean visited() {

+        return visited;

+    }

+

+    /**

+     * This is a very special method. This allows the navigator to step

+     * once it has reached the existing OM. At this point the isNavigable

+     * method will return false but the isComplete method may return false

+     * which means that the navigating the given element is not complete and

+     * the navigator cannot proceed.

+     */

+    public void step() {

+        if (!end) {

+            next = node;

+            updateNextNode();

+        }

+    }

+

+    /**

+     * Returns the navigable status.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isNavigable() {

+        if (end) {

+            return false;

+        } else {

+            return !(next == null);

+        }

+    }

+

+    /**

+     * Returns the completed status.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isCompleted() {

+        return end;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMNodeImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMNodeImpl.java
new file mode 100644
index 0000000..e648f91
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMNodeImpl.java
@@ -0,0 +1,378 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMOutputFormat;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMContainerEx;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.OutputStream;

+import java.io.Writer;

+

+/**

+ * Class OMNodeImpl

+ */

+public abstract class OMNodeImpl implements OMNode, OMNodeEx {

+    /**

+     * Field parent

+     */

+    protected OMContainerEx parent;

+

+    /**

+     * Field nextSibling

+     */

+    protected OMNodeImpl nextSibling;

+

+    /**

+     * Field previousSibling

+     */

+    protected OMNodeImpl previousSibling;

+    /**

+     * Field builder

+     */

+    protected OMXMLParserWrapper builder;

+

+    /**

+     * Field done

+     */

+    protected boolean done = false;

+

+    /**

+     * Field nodeType

+     */

+    protected int nodeType;

+

+    /**

+     * Constructor OMNodeImpl

+     */

+    public OMNodeImpl() {

+    }

+

+    /**

+     * For a node to exist there must be a parent.

+     *

+     * @param parent

+     */

+    public OMNodeImpl(OMContainer parent) {

+        if ((parent != null)) {

+            this.parent = (OMContainerEx)parent;

+            parent.addChild(this);

+        }

+    }

+

+    /**

+     * Returns the immediate parent of the node. Parent is always an Element.

+     *

+     * @return Returns OMContainer.

+     *

+     * @throws OMException

+     */

+    public OMContainer getParent() {

+        return parent;

+    }

+

+    /**

+     * Method setParent.

+     *

+     * @param element

+     */

+    public void setParent(OMContainer element) {

+

+        if ((this.parent) == element) {

+            return;

+        }

+

+        //If we are asked to assign a new parent in place 

+        //of an existing one. We should detach this node

+        //from the aegis of previous parent.

+        if (this.parent != null) {

+            this.detach();

+        }

+        this.parent = (OMContainerEx)element;

+    }

+

+    /**

+     * Returns the next sibling. This can be an OMAttribute or 

+     * OMText or OMElement for others.

+     *

+     * @return Returns OMNode.

+     * @throws org.apache.ws.commons.om.OMException

+     */

+    public OMNode getNextOMSibling() throws OMException {

+        if ((nextSibling == null) && (parent != null) && !parent.isComplete()) {

+            parent.buildNext();

+        }

+        return nextSibling;

+    }

+

+    /**

+     * Method setNextOMSibling.

+     *

+     * @param node

+     */

+    public void setNextOMSibling(OMNode node) {

+        this.nextSibling = (OMNodeImpl) node;

+    }

+

+

+    /**

+     * Indicates whether parser has parsed this information item completely or not.

+     * If some information is not available in the item, one has to check this 

+     * attribute to make sure that, this item has been parsed completely or not.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isComplete() {

+        return done;

+    }

+

+    /**

+     * Method setComplete.

+     *

+     * @param state

+     */

+    public void setComplete(boolean state) {

+        this.done = state;

+    }

+

+    /**

+     * Removes this information item and its children, from the model completely.

+     *

+     * @throws OMException

+     */

+    public OMNode detach() throws OMException {

+        if (parent == null) {

+            throw new OMException(

+                    "Elements that doesn't have a parent can not be detached");

+        }

+        OMNodeImpl nextSibling = (OMNodeImpl) getNextOMSibling();

+        if (previousSibling == null) {

+            parent.setFirstChild(nextSibling);

+        } else {

+            ((OMNodeEx)getPreviousOMSibling()).setNextOMSibling(nextSibling);

+        }

+        if (nextSibling != null) {

+            nextSibling.setPreviousOMSibling(getPreviousOMSibling());

+        }

+        this.parent = null;

+        return this;

+    }

+

+    /**

+     * Inserts a sibling just after the current information item.

+     *

+     * @param sibling

+     * @throws OMException

+     */

+    public void insertSiblingAfter(OMNode sibling) throws OMException {

+        if (parent == null) {

+            throw new OMException();

+        }

+        ((OMNodeEx)sibling).setParent(parent);

+        if (sibling instanceof OMNodeImpl) {

+            OMNodeImpl siblingImpl = (OMNodeImpl) sibling;

+            if (nextSibling == null) {

+                getNextOMSibling();

+            }

+            siblingImpl.setPreviousOMSibling(this);

+            if (nextSibling != null) {

+                nextSibling.setPreviousOMSibling(sibling);

+            }

+            ((OMNodeEx)sibling).setNextOMSibling(nextSibling);

+            nextSibling = siblingImpl;

+        }

+    }

+

+    /**

+     * Inserts a sibling just before the current information item.

+     *

+     * @param sibling

+     * @throws OMException

+     */

+    public void insertSiblingBefore(OMNode sibling) throws OMException {

+        if (parent == null) {

+            throw new OMException();

+        }

+        if (sibling instanceof OMNodeImpl) {

+            OMNodeImpl siblingImpl = (OMNodeImpl) sibling;

+            siblingImpl.nextSibling = this;

+            if (previousSibling == null) {

+                parent.setFirstChild(siblingImpl);

+                siblingImpl.previousSibling = null;

+            } else {

+                siblingImpl.setParent(parent);

+                previousSibling.setNextOMSibling(siblingImpl);

+                siblingImpl.setPreviousOMSibling(previousSibling);

+            }

+            previousSibling = siblingImpl;

+

+        }

+    }

+

+    /**

+     * Gets the type of node, as this is the super class of all the nodes.

+     *

+     * @return Returns the type of node as indicated by {@link #setType}

+     *

+     * @see #setType

+     */

+    public int getType() {

+        return nodeType;

+    }

+

+    /**

+     * Method setType.

+     *

+     * @param nodeType

+     * @throws OMException

+     */

+    public void setType(int nodeType) throws OMException {

+        this.nodeType = nodeType;

+    }

+

+    /**

+     * Gets the previous sibling.

+     *

+     * @return boolean

+     */

+    public OMNode getPreviousOMSibling() {

+        return previousSibling;

+    }

+

+    /**

+     * Method setPreviousOMSibling.

+     *

+     * @param previousSibling

+     */

+    public void setPreviousOMSibling(OMNode previousSibling) {

+        this.previousSibling = (OMNodeImpl) previousSibling;

+    }

+

+

+    /**

+     * Parses this node and builds the object structure in memory.

+     * However a node, created programmatically, will have done set to true by 

+     * default and this will cause populateyourself not to work properly!

+     *

+     * @throws OMException

+     */

+    public void build() throws OMException {

+        while (!done) {

+            builder.next();

+        }

+    }

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param xmlWriter

+     * @throws javax.xml.stream.XMLStreamException

+     *

+     * @see #serialize(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {

+        OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);

+        serialize(omOutput);

+        omOutput.flush();

+    }

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param xmlWriter

+     * @throws javax.xml.stream.XMLStreamException

+     *

+     * @see #serializeAndConsume(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {

+        OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);

+        serializeAndConsume(omOutput);

+        omOutput.flush();

+    }

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     * @see #serialize(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {

+        throw new RuntimeException("Not implemented yet!");

+    }

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     * @see #serializeAndConsume(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {

+        throw new RuntimeException("Not implemented yet!");

+    }

+

+    public void serialize(OutputStream output) throws XMLStreamException {

+        serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(output));

+    }

+

+    public void serialize(Writer writer) throws XMLStreamException {

+        serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));

+    }

+

+    public void serializeAndConsume(OutputStream output) throws XMLStreamException {

+        serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(output));

+    }

+

+    public void serializeAndConsume(Writer writer) throws XMLStreamException {

+        serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));

+    }

+

+    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {    

+        OMOutputImpl omOutput = new  OMOutputImpl(output, format);

+        serialize(omOutput);

+        omOutput.flush();

+    }

+

+    public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {

+        OMOutputImpl omOutput = new  OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));

+        omOutput.setOutputFormat(format);

+        serialize(omOutput);

+        omOutput.flush();

+    }

+

+    public void serializeAndConsume(OutputStream output, OMOutputFormat format) throws XMLStreamException {

+        OMOutputImpl omOutput = new  OMOutputImpl(output, format);

+        serializeAndConsume(omOutput);

+        omOutput.flush();

+    }

+

+    public void serializeAndConsume(Writer writer, OMOutputFormat format) throws XMLStreamException {

+        OMOutputImpl omOutput = new  OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));

+        omOutput.setOutputFormat(format);

+        serializeAndConsume(omOutput);

+        omOutput.flush();

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMProcessingInstructionImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMProcessingInstructionImpl.java
new file mode 100644
index 0000000..1bb5d35
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMProcessingInstructionImpl.java
@@ -0,0 +1,126 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMProcessingInstruction;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+

+public class OMProcessingInstructionImpl extends OMNodeImpl implements OMProcessingInstruction {

+    protected String target;

+    protected String value;

+

+    /**

+     * Constructor OMProcessingInstructionImpl.

+     *

+     * @param parentNode

+     * @param target

+     * @param value

+     */

+    public OMProcessingInstructionImpl(OMContainer parentNode, String target, String value) {

+        super(parentNode);

+        this.target = (target == null) ? null : target.trim();

+        this.value = (value == null) ? null : value.trim();

+        nodeType = OMNode.PI_NODE;

+    }

+

+    /**

+     * Constructor OMProcessingInstructionImpl.

+     *

+     * @param parentNode

+     */

+    public OMProcessingInstructionImpl(OMContainer parentNode) {

+        this(parentNode, null, null);

+    }

+

+    /**

+     * Serializes the node with caching.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     * @see #serialize(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        writer.writeProcessingInstruction(this.target+" ", this.value);

+    }

+

+    /**

+     * Serializes the node without caching.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     * @see #serializeAndConsume(org.apache.ws.commons.om.impl.OMOutputImpl)

+     */

+    public void serializeAndConsume(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        serialize(omOutput);

+    }

+

+    /**

+     * Gets the value of this Processing Instruction.

+     *

+     * @return string

+     */

+    public String getValue() {

+        return value;

+    }

+

+    /**

+     * Sets the target of this Processing Instruction.

+     *

+     * @param target

+     */

+    public void setTarget(String target) {

+        this.target = target;

+    }

+

+    /**

+     * Gets the target of this Processing Instruction.

+     *

+     * @return Returns String.

+     */

+    public String getTarget() {

+        return target;

+    }

+

+    /**

+     * Sets the value of this Processing Instruction.

+     *

+     * @param text

+     */

+    public void setValue(String text) {

+        this.value = text;

+    }

+

+    /**

+     * Discards this node.

+     *

+     * @throws OMException

+     */

+    public void discard() throws OMException {

+        if (done) {

+            this.detach();

+        } else {

+            builder.discard((OMElement) this.parent);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMSerializerUtil.java b/src/org/apache/ws/commons/om/impl/llom/OMSerializerUtil.java
new file mode 100644
index 0000000..1204a31
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMSerializerUtil.java
@@ -0,0 +1,210 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamingOMSerializer;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+import java.util.Iterator;

+

+public class OMSerializerUtil {

+

+    /**

+     * Method serializeEndpart.

+     *

+     * @param omOutput

+     * @throws javax.xml.stream.XMLStreamException

+     *

+     */

+    public static void serializeEndpart(OMOutputImpl omOutput)

+            throws XMLStreamException {

+        omOutput.getXmlStreamWriter().writeEndElement();

+    }

+

+    /**

+     * Method serializeAttribute.

+     *

+     * @param attr

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    public static void serializeAttribute(OMAttribute attr, OMOutputImpl omOutput)

+            throws XMLStreamException {

+

+        // first check whether the attribute is associated with a namespace

+        OMNamespace ns = attr.getNamespace();

+        String prefix = null;

+        String namespaceName = null;

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        if (ns != null) {

+

+            // add the prefix if it's availble

+            prefix = ns.getPrefix();

+            namespaceName = ns.getName();

+            if (prefix != null) {

+                writer.writeAttribute(prefix, namespaceName,

+                        attr.getLocalName(), attr.getAttributeValue());

+            } else {

+                writer.writeAttribute(namespaceName, attr.getLocalName(),

+                        attr.getAttributeValue());

+            }

+        } else {

+            writer.writeAttribute(attr.getLocalName(), attr.getAttributeValue());

+        }

+    }

+

+    /**

+     * Method serializeNamespace.

+     *

+     * @param namespace

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    public static void serializeNamespace(OMNamespace namespace, org.apache.ws.commons.om.impl.OMOutputImpl omOutput)

+            throws XMLStreamException {

+

+        if (namespace != null) {

+            XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+            String uri = namespace.getName();

+            String prefix = writer.getPrefix(uri);

+            String ns_prefix = namespace.getPrefix();

+            if (ns_prefix != null && !ns_prefix.equals(prefix)) {

+                writer.writeNamespace(ns_prefix, namespace.getName());

+            }

+        }

+    }

+

+

+    /**

+     * Method serializeStartpart.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    public static void serializeStartpart(OMElement element, OMOutputImpl omOutput)

+            throws XMLStreamException {

+        String nameSpaceName = null;

+        String writer_prefix = null;

+        String prefix = null;

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        if (element.getNamespace() != null) {

+            nameSpaceName = element.getNamespace().getName();

+            writer_prefix = writer.getPrefix(nameSpaceName);

+            prefix = element.getNamespace().getPrefix();

+            if (nameSpaceName != null) {

+                if (writer_prefix != null) {

+                    writer.writeStartElement(nameSpaceName,

+                            element.getLocalName());

+                } else {

+                    prefix = (prefix == null) ? "" : prefix;

+                    writer.writeStartElement(prefix, element.getLocalName(),

+                            nameSpaceName);

+                    writer.writeNamespace(prefix, nameSpaceName);

+                    writer.setPrefix(prefix, nameSpaceName);

+                }

+            } else {

+                writer.writeStartElement(element.getLocalName());

+            }

+        } else {

+            writer.writeStartElement(element.getLocalName());

+            // we need to check whether there's a default namespace visible at this point because

+            // otherwise this element will go into that namespace unintentionally. So we check

+            // whether there is a default NS visible and if so turn it off.

+            if (writer.getNamespaceContext().getNamespaceURI("") != null) {

+                writer.writeDefaultNamespace("");

+            }

+        }

+

+        // add the namespaces

+        serializeNamespaces(element, omOutput);

+

+        // add the elements attributes

+        serializeAttributes(element, omOutput);

+    }

+

+    public static void serializeNamespaces(OMElement element,

+                                           org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        Iterator namespaces = element.getAllDeclaredNamespaces();

+        if (namespaces != null) {

+            while (namespaces.hasNext()) {

+                serializeNamespace((OMNamespace) namespaces.next(), omOutput);

+            }

+        }

+    }

+

+    public static void serializeAttributes(OMElement element,

+                                           org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        if (element.getAllAttributes() != null) {

+            Iterator attributesList = element.getAllAttributes();

+            while (attributesList.hasNext()) {

+                serializeAttribute((OMAttribute) attributesList.next(),

+                        omOutput);

+            }

+        }

+    }

+

+

+    /**

+     * Method serializeNormal.

+     *

+     * @param omOutput

+     * @param cache

+     * @throws XMLStreamException

+     */

+    public static void serializeNormal(OMElement element, OMOutputImpl omOutput, boolean cache)

+            throws XMLStreamException {

+

+        if (cache) {

+            element.build();

+        }

+

+        serializeStartpart(element, omOutput);

+        OMNode firstChild = element.getFirstOMChild();

+        if (firstChild != null) {

+            if (cache) {

+                ((OMNodeEx)firstChild).serialize(omOutput);

+            } else {

+                ((OMNodeEx)firstChild).serializeAndConsume(omOutput);

+            }

+        }

+        serializeEndpart(omOutput);

+    }

+

+    public static void serializeByPullStream(OMElement element, org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        serializeByPullStream(element, omOutput, false);

+    }

+

+    public static void serializeByPullStream(OMElement element, org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+        StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer();

+        if (cache) {

+            streamingOMSerializer.serialize(element.getXMLStreamReader(),

+                    omOutput);

+        } else {

+            XMLStreamReader xmlStreamReaderWithoutCaching = element.getXMLStreamReaderWithoutCaching();

+            streamingOMSerializer.serialize(xmlStreamReaderWithoutCaching,

+                    omOutput);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMStAXWrapper.java b/src/org/apache/ws/commons/om/impl/llom/OMStAXWrapper.java
new file mode 100644
index 0000000..62413da
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMStAXWrapper.java
@@ -0,0 +1,1233 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMComment;

+import org.apache.ws.commons.om.OMDocument;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.exception.OMStreamingException;

+

+import javax.xml.namespace.NamespaceContext;

+import javax.xml.namespace.QName;

+import javax.xml.stream.Location;

+import javax.xml.stream.XMLStreamConstants;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import java.util.Iterator;

+import java.util.Stack;

+

+/**

+ * Note  - This class also implements the streaming constants interface

+ * to get access to the StAX constants

+ */

+public class OMStAXWrapper implements XMLStreamReader, XMLStreamConstants {

+    /**

+     * Field navigator

+     */

+    private OMNavigator navigator;

+

+    /**

+     * Field builder

+     */

+    private OMXMLParserWrapper builder;

+

+    /**

+     * Field parser

+     */

+    private XMLStreamReader parser;

+

+    /**

+     * Field rootNode

+     */

+    private OMNode rootNode;

+

+    /**

+     * Field isFirst

+     */

+    private boolean isFirst = true;

+

+    // Navigable means the output should be taken from the navigator.

+    // As soon as the navigator returns a null navigable will be reset

+    // to false and the subsequent events will be taken from the builder

+    // or the parser directly.

+

+    /**

+     * Field NAVIGABLE

+     */

+    private static final short NAVIGABLE = 0;

+    private static final short SWITCH_AT_NEXT = 1;

+    private static final short COMPLETED = 2;

+    private static final short SWITCHED = 3;

+    private static final short DOCUMENT_COMPLETE = 4;

+

+

+    /**

+     * Field state

+     */

+    private short state;

+

+    /**

+     * Field currentEvent

+     * Default set to START_DOCUMENT

+     */

+    private int currentEvent = START_DOCUMENT;

+

+    // SwitchingAllowed is set to false by default.

+    // This means that unless the user explicitly states

+    // that he wants things not to be cached, everything will

+    // be cached.

+

+    /**

+     * Field switchingAllowed

+     */

+    boolean switchingAllowed = false;

+

+    /**

+     * Field elementStack

+     */

+    private Stack elementStack = new Stack();

+

+    // keeps the next event. The parser actually keeps one step ahead to

+    // detect the end of navigation. (at the end of the stream the navigator

+    // returns a null

+

+    /**

+     * Field nextNode

+     */

+    private OMNode nextNode = null;

+

+    // holder for the current node. Needs this to generate events from the current node

+

+    /**

+     * Field currentNode

+     */

+    private OMNode currentNode = null;

+

+    // needs this to refer to the last known node

+

+    /**

+     * Field lastNode

+     */

+    private OMNode lastNode = null;

+

+    /**

+     * Track depth to ensure we stop generating events when we are done with the root node.  

+     */

+    int depth = 0;

+

+    private boolean needToThrowEndDocument = false;

+

+    /**

+     * Method setAllowSwitching.

+     *

+     * @param b

+     */

+    public void setAllowSwitching(boolean b) {

+        this.switchingAllowed = b;

+    }

+

+    /**

+     * Method isAllowSwitching.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isAllowSwitching() {

+        return switchingAllowed;

+    }

+

+    /**

+     * When constructing the OMStaxWrapper, the creator must produce the

+     * builder (an instance of the OMXMLparserWrapper of the input) and the

+     * Element Node to start parsing. The wrapper will parse(proceed) until

+     * the end of the given element. Hence care should be taken to pass the

+     * root element if the entire document is needed.

+     *

+     * @param builder

+     * @param startNode

+     */

+    public OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode) {

+        this(builder, startNode, false);

+    }

+

+    /**

+     * Constructor OMStAXWrapper.

+     *

+     * @param builder

+     * @param startNode

+     * @param cache

+     */

+    public OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode,

+                         boolean cache) {

+

+        // create a navigator

+        this.navigator = new OMNavigator(startNode);

+        this.builder = builder;

+        this.rootNode = startNode;

+        if (rootNode != null && rootNode.getParent() != null && rootNode.getParent() instanceof OMDocument) {

+            needToThrowEndDocument = true;

+        }

+

+        // initaite the next and current nodes

+        // Note -  navigator is written in such a way that it first

+        // returns the starting node at the first call to it

+        currentNode = navigator.next();

+        updateNextNode();

+        switchingAllowed = !cache;

+    }

+

+    /**

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getPrefix()

+     */

+    public String getPrefix() {

+        String returnStr = null;

+        if (parser != null) {

+            returnStr = parser.getPrefix();

+        } else {

+            if ((currentEvent == START_ELEMENT)

+                    || (currentEvent == END_ELEMENT)) {

+                OMNamespace ns = ((OMElement) lastNode).getNamespace();

+                returnStr = (ns == null)

+                        ? null

+                        : ns.getPrefix();

+            }

+        }

+        return returnStr;

+    }

+

+    /**

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getNamespaceURI()

+     */

+    public String getNamespaceURI() {

+        String returnStr = null;

+        if (parser != null) {

+            returnStr = parser.getNamespaceURI();

+        } else {

+            if ((currentEvent == START_ELEMENT)

+                    || (currentEvent == END_ELEMENT)

+                    || (currentEvent == NAMESPACE)) {

+                OMNamespace ns = ((OMElement) lastNode).getNamespace();

+                returnStr = (ns == null)

+                        ? null

+                        : ns.getName();

+            }

+        }

+        return returnStr;

+    }

+

+    /**

+     * @return Returns boolean.

+     * @see javax.xml.stream.XMLStreamReader#hasName()

+     */

+    public boolean hasName() {

+        if (parser != null) {

+            return parser.hasName();

+        } else {

+            return ((currentEvent == START_ELEMENT)

+                    || (currentEvent == END_ELEMENT));

+        }

+    }

+

+    /**

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getLocalName()

+     */

+    public String getLocalName() {

+        String returnStr = null;

+        if (parser != null) {

+            returnStr = parser.getLocalName();

+        } else {

+            if ((currentEvent == START_ELEMENT)

+                    || (currentEvent == END_ELEMENT)

+                    || (currentEvent == ENTITY_REFERENCE)) {

+                returnStr = ((OMElement) lastNode).getLocalName();

+            }

+        }

+        return returnStr;

+    }

+

+    /**

+     * @return Returns QName.

+     * @see javax.xml.stream.XMLStreamReader#getName()

+     */

+    public QName getName() {

+        QName returnName = null;

+        if (parser != null) {

+            returnName = parser.getName();

+        } else {

+            if ((currentEvent == START_ELEMENT)

+                    || (currentEvent == END_ELEMENT)) {

+                returnName = getQName((OMElement) lastNode);

+            }

+        }

+        return returnName;

+    }

+

+    /**

+     * @return Returns boolean.

+     * @see javax.xml.stream.XMLStreamReader#hasText()

+     */

+    public boolean hasText() {

+        return ((currentEvent == CHARACTERS) || (currentEvent == DTD)

+                || (currentEvent == ENTITY_REFERENCE)

+                || (currentEvent == COMMENT) || (currentEvent == SPACE));

+    }

+

+    /**

+     * @return Returns int.

+     * @see javax.xml.stream.XMLStreamReader#getTextLength()

+     */

+    public int getTextLength() {

+        int returnLength = 0;

+        if (parser != null) {

+            returnLength = parser.getTextLength();

+        } else {

+            OMText textNode = (OMText) lastNode;

+            returnLength = textNode.getText().length();

+        }

+        return returnLength;

+    }

+

+    /**

+     * @return Returns int.

+     * @see javax.xml.stream.XMLStreamReader#getTextStart()

+     */

+    public int getTextStart() {

+        int returnLength = 0;

+        if (parser != null) {

+            returnLength = parser.getTextStart();

+        }

+

+        // Note - this has no relevant method in the OM

+        return returnLength;

+    }

+

+    /**

+     * @param i

+     * @param chars

+     * @param i1

+     * @param i2

+     * @return Returns int.

+     * @throws XMLStreamException

+     * @see javax.xml.stream.XMLStreamReader#getTextCharacters(int, char[], int, int)

+     */

+    public int getTextCharacters(int i, char[] chars, int i1, int i2)

+            throws XMLStreamException {

+        int returnLength = 0;

+        if (parser != null) {

+            try {

+                returnLength = parser.getTextCharacters(i, chars, i1, i2);

+            } catch (XMLStreamException e) {

+                throw new OMStreamingException(e);

+            }

+        } else {

+            if (hasText()) {

+                OMText textNode = (OMText) lastNode;

+                String str = textNode.getText();

+                str.getChars(i, i + i2, chars, i1);

+            }

+        }

+        return returnLength;

+    }

+

+    /**

+     * @return Returns char[].

+     * @see javax.xml.stream.XMLStreamReader#getTextCharacters()

+     */

+    public char[] getTextCharacters() {

+        char[] returnArray = null;

+        if (parser != null) {

+            returnArray = parser.getTextCharacters();

+        } else {

+            if (hasText()) {

+                OMText textNode = (OMText) lastNode;

+                String str = textNode.getText();

+                returnArray = str.toCharArray();

+            }

+        }

+        return returnArray;

+    }

+

+    /**

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getText()

+     */

+    public String getText() {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getText();

+        } else {

+            if (hasText()) {

+                if (lastNode instanceof OMText) {

+                    returnString = ((OMText) lastNode).getText();

+                } else if (lastNode instanceof OMComment) {

+                    returnString = ((OMComment) lastNode).getValue();

+                }

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * @return Returns int.

+     * @see javax.xml.stream.XMLStreamReader#getEventType()

+     */

+

+    // todo this should be improved

+    public int getEventType() {

+        return currentEvent;

+    }

+

+    /**

+     * @param i

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getNamespaceURI

+     */

+    public String getNamespaceURI(int i) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getNamespaceURI(i);

+        } else {

+            if (isStartElement() || isEndElement()

+                    || (currentEvent == NAMESPACE)) {

+                OMNamespace ns = (OMNamespace) getItemFromIterator(

+                        ((OMElement) lastNode).getAllDeclaredNamespaces(), i);

+                returnString = (ns == null)

+                        ? null

+                        : ns.getName();

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * @param i

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getNamespacePrefix

+     */

+    public String getNamespacePrefix(int i) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getNamespacePrefix(i);

+        } else {

+            if (isStartElement() || isEndElement()

+                    || (currentEvent == NAMESPACE)) {

+                OMNamespace ns = (OMNamespace) getItemFromIterator(

+                        ((OMElement) lastNode).getAllDeclaredNamespaces(), i);

+                returnString = (ns == null)

+                        ? null

+                        : ns.getPrefix();

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * @return Returns int.

+     * @see javax.xml.stream.XMLStreamReader#getNamespaceCount()

+     */

+    public int getNamespaceCount() {

+        int returnCount = 0;

+        if (parser != null) {

+            returnCount = parser.getNamespaceCount();

+        } else {

+            if (isStartElement() || isEndElement()

+                    || (currentEvent == NAMESPACE)) {

+                returnCount =

+                        getCount(

+                                ((OMElement) lastNode).getAllDeclaredNamespaces());

+            }

+        }

+        return returnCount;

+    }

+

+    /**

+     * @param i

+     * @return Returns boolean.

+     * @see javax.xml.stream.XMLStreamReader#isAttributeSpecified

+     */

+    public boolean isAttributeSpecified(int i) {

+        boolean returnValue = false;

+        if (parser != null) {

+            returnValue = parser.isAttributeSpecified(i);

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+

+                // theres nothing to be returned here

+            } else {

+                throw new IllegalStateException(

+                        "attribute type accessed in illegal event!");

+            }

+        }

+        return returnValue;

+    }

+

+    /**

+     * @param i

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getAttributeValue

+     */

+    public String getAttributeValue(int i) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getAttributeValue(i);

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+                OMAttribute attrib = getAttribute((OMElement) lastNode, i);

+                if (attrib != null) {

+                    returnString = attrib.getAttributeValue();

+                }

+            } else {

+                throw new IllegalStateException(

+                        "attribute type accessed in illegal event!");

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * @param i

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getAttributeType

+     */

+    public String getAttributeType(int i) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getAttributeType(i);

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+

+                // todo implement this

+            } else {

+                throw new IllegalStateException(

+                        "attribute type accessed in illegal event!");

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * @param i

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getAttributePrefix

+     */

+    public String getAttributePrefix(int i) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getAttributePrefix(i);

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+                OMAttribute attrib = getAttribute((OMElement) lastNode, i);

+                if (attrib != null) {

+                    OMNamespace nameSpace = attrib.getNamespace();

+                    if (nameSpace != null) {

+                        returnString = nameSpace.getPrefix();

+                    }

+                }

+            } else {

+                throw new IllegalStateException(

+                        "attribute prefix accessed in illegal event!");

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * @param i

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getAttributeLocalName

+     */

+    public String getAttributeLocalName(int i) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getAttributeLocalName(i);

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+                OMAttribute attrib = getAttribute((OMElement) lastNode, i);

+                if (attrib != null) {

+                    returnString = attrib.getLocalName();

+                }

+            } else {

+                throw new IllegalStateException(

+                        "attribute localName accessed in illegal event!");

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * @param i

+     * @return Returns String.

+     * @see javax.xml.stream.XMLStreamReader#getAttributeNamespace

+     */

+    public String getAttributeNamespace(int i) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getAttributeNamespace(i);

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+                OMAttribute attrib = getAttribute((OMElement) lastNode, i);

+                if (attrib != null) {

+                    OMNamespace nameSpace = attrib.getNamespace();

+                    if (nameSpace != null) {

+                        returnString = nameSpace.getName();

+                    }

+                }

+            } else {

+                throw new IllegalStateException(

+                        "attribute nameSpace accessed in illegal event!");

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * @param i

+     * @return Returns QName.

+     * @see javax.xml.stream.XMLStreamReader#getAttributeName

+     */

+    public QName getAttributeName(int i) {

+        QName returnQName = null;

+        if (parser != null) {

+            returnQName = parser.getAttributeName(i);

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+                returnQName = getAttribute((OMElement) lastNode, i).getQName();

+            } else {

+                throw new IllegalStateException(

+                        "attribute count accessed in illegal event!");

+            }

+        }

+        return returnQName;

+    }

+

+    /**

+     * @return Returns int.

+     * @see javax.xml.stream.XMLStreamReader#getAttributeCount

+     */

+    public int getAttributeCount() {

+        int returnCount = 0;

+        if (parser != null) {

+            returnCount = parser.getAttributeCount();

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+                OMElement elt = (OMElement) lastNode;

+                returnCount = getCount(elt.getAllAttributes());

+            } else {

+                throw new IllegalStateException(

+                        "attribute count accessed in illegal event (" +

+                                currentEvent + ")!");

+            }

+        }

+        return returnCount;

+    }

+

+    // todo

+

+    /**

+     * Method getAttributeValue.

+     *

+     * @param s

+     * @param s1

+     * @return Returns String.

+     */

+    public String getAttributeValue(String s, String s1) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getAttributeValue(s, s1);

+        } else {

+            if (isStartElement() || (currentEvent == ATTRIBUTE)) {

+                QName qname = new QName(s, s1);

+                OMAttribute attrib = ((OMElement) lastNode).getAttribute(qname);

+                if (attrib != null) {

+                    returnString = attrib.getAttributeValue();

+                }

+            } else {

+                throw new IllegalStateException(

+                        "attribute type accessed in illegal event!");

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * Method isWhiteSpace.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isWhiteSpace() {

+        boolean b;

+        if (parser != null) {

+            b = parser.isWhiteSpace();

+        } else {

+            b = (currentEvent == SPACE);

+        }

+        return b;

+    }

+

+    /**

+     * Method isCharacters.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isCharacters() {

+        boolean b;

+        if (parser != null) {

+            b = parser.isCharacters();

+        } else {

+            b = (currentEvent == CHARACTERS);

+        }

+        return b;

+    }

+

+    /**

+     * Method isEndElement.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isEndElement() {

+        boolean b;

+        if (parser != null) {

+            b = parser.isEndElement();

+        } else {

+            b = (currentEvent == END_ELEMENT);

+        }

+        return b;

+    }

+

+    /**

+     * @param i

+     * @param s

+     * @param s1

+     * @throws XMLStreamException

+     * @see javax.xml.stream.XMLStreamReader#require(int, String, String)

+     */

+    public void require(int i, String s, String s1) throws XMLStreamException {

+        throw new XMLStreamException();

+    }

+

+    /**

+     * Method isStartElement.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isStartElement() {

+        boolean b;

+        if (parser != null) {

+            b = parser.isStartElement();

+        } else {

+            b = (currentEvent == START_ELEMENT);

+        }

+        return b;

+    }

+

+    /**

+     * Method getNamespaceURI.

+     *

+     * @param s

+     * @return Returns String.

+     */

+    public String getNamespaceURI(String s) {

+        String returnString = null;

+        if (parser != null) {

+            returnString = parser.getNamespaceURI(s);

+        } else {

+            if (isStartElement() || isEndElement()

+                    || (currentEvent == NAMESPACE)) {

+

+                // Nothing to do here! How to get the namespacace references

+            }

+        }

+        return returnString;

+    }

+

+    /**

+     * Method close.

+     *

+     * @throws XMLStreamException

+     */

+    public void close() throws XMLStreamException {

+

+        // this doesnot mean anything with respect to the OM

+        if (parser != null) {

+            parser.close();

+        }

+    }

+

+    /**

+     * Method hasNext.

+     *

+     * @return Returns boolean.

+     * @throws XMLStreamException

+     */

+    public boolean hasNext() throws XMLStreamException {

+        if(needToThrowEndDocument){

+            return !(state == DOCUMENT_COMPLETE);

+        } else {

+            return (state != COMPLETED && currentEvent != END_DOCUMENT);

+        }

+    }

+

+    /**

+     * Returns the next tag.

+     *

+     * @return Returns int.

+     * @throws org.apache.ws.commons.om.impl.llom.exception.OMStreamingException

+     *

+     * @throws XMLStreamException

+     */

+    public int nextTag() throws XMLStreamException {

+        int eventType = next();

+        while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace

+            || (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) // skip whitespace

+            || eventType == XMLStreamConstants.SPACE

+            || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION

+            || eventType == XMLStreamConstants.COMMENT) {

+            eventType = next();

+         }

+         if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {

+             throw new XMLStreamException("expected start or end tag", getLocation());

+         }

+         return eventType;    

+    }

+    

+    /**

+     * @return Returns String.

+     * @throws XMLStreamException

+     * @see javax.xml.stream.XMLStreamReader#getElementText()

+     */

+    public String getElementText() throws XMLStreamException {

+        if (parser != null) {

+            try {

+                return parser.getElementText();

+            } catch (XMLStreamException e) {

+                throw new OMStreamingException(e);

+            }

+        } else {

+            if (currentNode.getType() == OMNode.ELEMENT_NODE) {

+                return ((OMElement)currentNode).getText();

+            }else if (currentNode.getType() == OMNode.TEXT_NODE){

+                 return ((OMText)currentNode).getText();

+            }

+        }

+        return "";

+    }

+

+    /**

+     * Method next.

+     *

+     * @return Returns int.

+     * @throws XMLStreamException

+     */

+    public int next() throws XMLStreamException {

+        switch (state) {

+            case DOCUMENT_COMPLETE:

+                throw new XMLStreamException("End of the document reached");

+            case COMPLETED:

+                state = DOCUMENT_COMPLETE;

+                currentEvent = END_DOCUMENT;

+                break;

+            case SWITCH_AT_NEXT:

+                state = SWITCHED;

+

+                // load the parser

+                try {

+                    parser = (XMLStreamReader) builder.getParser();

+                } catch (Exception e) {

+                    throw new XMLStreamException("problem accessing the parser", e);

+                }

+

+                // We should throw an END_DOCUMENT

+                needToThrowEndDocument = true;

+                if ((currentEvent == START_DOCUMENT) &&

+                        (currentEvent == parser.getEventType())) {

+                    currentEvent = parser.next();

+                } else {

+                    currentEvent = parser.getEventType();

+                }

+

+                if(currentEvent == START_ELEMENT) {

+                    depth = 0;

+                } else if(currentEvent == END_ELEMENT) {

+                    depth ++;

+                }

+                updateCompleteStatus();

+                break;

+            case NAVIGABLE:

+                currentEvent = generateEvents(currentNode);

+                updateCompleteStatus();

+                updateLastNode();

+                break;

+            case SWITCHED:

+                if(parser.hasNext()) {

+                    currentEvent = parser.next();

+                }

+                updateCompleteStatus();

+                break;

+            default :

+                throw new OMStreamingException("unsuppported state!");

+        }

+        return currentEvent;

+    }

+

+    /**

+     * Method getProperty.

+     *

+     * @param s

+     * @return Returns Object.

+     * @throws IllegalArgumentException

+     */

+    public Object getProperty(String s) throws IllegalArgumentException {

+        throw new UnsupportedOperationException();

+    }

+

+    /**

+     * This is a very important method. It keeps the navigator one step ahead 

+     * and pushes it one event ahead. If the nextNode is null then navigable is 

+     * set to false. At the same time the parser and builder are set up for 

+     * the upcoming event generation.

+     *

+     * @throws XMLStreamException

+     */

+    private void updateLastNode() throws XMLStreamException {

+        lastNode = currentNode;

+        currentNode = nextNode;

+        try {

+            updateNextNode();

+        } catch (Exception e) {

+            throw new XMLStreamException(e);

+        }

+    }

+

+    /**

+     * Method updateNextNode.

+     */

+    private void updateNextNode() {

+        if (navigator.isNavigable()) {

+            nextNode = navigator.next();

+        } else {

+            if (!switchingAllowed) {

+                if (navigator.isCompleted()) {

+                    nextNode = null;

+

+                } else {

+                    builder.next();

+                    navigator.step();

+                    nextNode = navigator.next();

+                }

+            } else {

+

+                // reset caching (the default is ON so it was not needed in the

+                // earlier case!

+                builder.setCache(false);

+                state = SWITCH_AT_NEXT;

+            }

+        }

+    }

+

+    /**

+     * Method updateCompleteStatus.

+     */

+    private void updateCompleteStatus() {

+        if (state == NAVIGABLE) {

+            if (rootNode == currentNode) {

+                if (isFirst) {

+                    isFirst = false;

+                } else {

+                    state = COMPLETED;

+                }

+            }

+        } else {

+            if (state == SWITCHED) {

+                if (currentEvent == START_ELEMENT) {

+                    ++depth;

+                } else if (currentEvent == END_ELEMENT) {

+                    --depth;

+                    if(depth < 0) {

+                        state = COMPLETED;

+                    }

+                }

+            }

+            state = (currentEvent == END_DOCUMENT)

+                    ? DOCUMENT_COMPLETE

+                    : state;

+        }

+    }

+

+    /**

+     * Method getNamespaceContext.

+     *

+     * @return Returns NamespaceContext.

+     */

+    public NamespaceContext getNamespaceContext() {

+        throw new UnsupportedOperationException();

+    }

+

+    /**

+     * Method getEncoding.

+     *

+     * @return Returns String.

+     */

+    public String getEncoding() {

+        return null;

+    }

+

+    /**

+     * Method getLocation.

+     *

+     * @return Returns Location.

+     */

+    public Location getLocation() {

+         return new EmptyOMLocation();

+    }

+

+    /**

+     * Method getVersion.

+     *

+     * @return Returns String.

+     */

+    public String getVersion() {

+        return "1.0"; //todo put the constant

+    }

+

+

+    /**

+     * Method isStandalone.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isStandalone() {

+        return true;

+    }

+

+    /**

+     * Method standaloneSet.

+     *

+     * @return Returns boolean.

+     */

+    public boolean standaloneSet() {

+        return false;

+    }

+

+    /**

+     * Method getCharacterEncodingScheme.

+     *

+     * @return Returns String.

+     */

+    public String getCharacterEncodingScheme() {

+        return "utf-8";

+    }

+

+    /**

+     * Method getPITarget.

+     *

+     * @return Returns String.

+     */

+    public String getPITarget() {

+        throw new UnsupportedOperationException();

+    }

+

+    /**

+     * Method getPIData.

+     *

+     * @return Returns String.

+     */

+    public String getPIData() {

+        throw new UnsupportedOperationException();

+    }

+

+    /*

+     *

+     * ################################################################

+     * Generator methods for the OMNodes returned by the navigator

+     * ################################################################

+     *

+     */

+

+    /**

+     * Method generateEvents.

+     *

+     * @param node

+     * @return Returns int.

+     */

+    private int generateEvents(OMNode node) {

+        int returnEvent = 0;

+        int nodeType = node.getType();

+        switch (nodeType) {

+            case OMNode.ELEMENT_NODE:

+                OMElement element = (OMElement) node;

+                returnEvent = generateElementEvents(element);

+                break;

+            case OMNode.TEXT_NODE:

+                returnEvent = generateTextEvents();

+                break;

+            case OMNode.COMMENT_NODE:

+                returnEvent = generateCommentEvents();

+                break;

+            case OMNode.CDATA_SECTION_NODE:

+                returnEvent = generateCdataEvents();

+                break;

+            default :

+                break;    // just ignore any other nodes

+        }

+        return returnEvent;

+    }

+

+    /**

+     * Method generateElementEvents.

+     *

+     * @param elt

+     * @return Returns int.

+     */

+    private int generateElementEvents(OMElement elt) {

+        int returnValue = START_ELEMENT;

+        if (!elementStack.isEmpty() && elementStack.peek().equals(elt)) {

+            returnValue = END_ELEMENT;

+            elementStack.pop();

+        } else {

+            elementStack.push(elt);

+        }

+        return returnValue;

+    }

+

+    /**

+     * Method generateTextEvents.

+     *

+     * @return Returns int.

+     */

+    private int generateTextEvents() {

+        return CHARACTERS;

+    }

+

+    /**

+     * Method generateCommentEvents

+     *

+     * @return Returns int.

+     */

+    private int generateCommentEvents() {

+        return COMMENT;

+    }

+

+    /**

+     * Method generateCdataEvents

+     *

+     * @return Returns int.

+     */

+    private int generateCdataEvents() {

+        return CDATA;

+    }

+

+    /*

+     * ####################################################################

+     * Other helper methods

+     * ####################################################################

+     */

+

+    /**

+     * helper method getCount.

+     *

+     * @param it

+     * @return Returns int.

+     */

+    private int getCount(Iterator it) {

+        int count = 0;

+        if (it != null) {

+            while (it.hasNext()) {

+                it.next();

+                count++;

+            }

+        }

+        return count;

+    }

+

+    /**

+     * Helper method getItemFromIterator.

+     *

+     * @param it

+     * @param index

+     * @return Returns Object.

+     */

+    private Object getItemFromIterator(Iterator it, int index) {

+        int count = 0;

+        Object returnObject = null;

+        boolean found = false;

+        if (it != null) {

+            while (it.hasNext()) {

+                returnObject = it.next();

+                if (index == count++) {

+                    found = true;

+                    break;

+                }

+            }

+        }

+        if (found) {

+            return returnObject;

+        } else {

+            return null;

+        }

+    }

+

+    /**

+     * Helper method getQName.

+     *

+     * @param element

+     * @return Returns QName.

+     */

+    private QName getQName(OMElement element) {

+        QName returnName;

+        OMNamespace ns = element.getNamespace();

+        String localPart = element.getLocalName();

+        if (ns != null) {

+            String prefix = ns.getPrefix();

+            String uri = ns.getName();

+            if ((prefix == null) || prefix.equals("")) {

+                returnName = new QName(uri, localPart);

+            } else {

+                returnName = new QName(uri, localPart, prefix);

+            }

+        } else {

+            returnName = new QName(localPart);

+        }

+        return returnName;

+    }

+

+    /**

+     * @param elt

+     * @param index

+     * @return Returns OMAttribute.

+     */

+    private OMAttribute getAttribute(OMElement elt, int index) {

+        OMAttribute returnAttrib = null;

+        if (elt != null) {

+            returnAttrib =

+                    (OMAttribute) getItemFromIterator(elt.getAllAttributes(),

+                            index);

+        }

+        return returnAttrib;

+    }

+

+    public void setParser(XMLStreamReader parser) {

+        this.parser = parser;

+    }

+

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/OMTextImpl.java b/src/org/apache/ws/commons/om/impl/llom/OMTextImpl.java
new file mode 100644
index 0000000..99546fa
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/OMTextImpl.java
@@ -0,0 +1,433 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMConstants;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.util.Base64;

+import org.apache.ws.commons.om.util.UUIDGenerator;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.IOException;

+import java.io.InputStream;

+

+public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {

+    protected String value = null;

+

+    protected String mimeType;

+

+    protected boolean optimize = false;

+

+    protected boolean isBinary = false;

+

+    /**

+     * Field contentID for the mime part used when serializing Binary stuff as

+     * MTOM optimized.

+     */

+    private String contentID = null;

+

+    /**

+     * Field dataHandler contains the DataHandler

+     * Declaring as Object to remove the dependency on 

+     * Javax.activation.DataHandler

+     */

+    private Object dataHandlerObject = null;

+

+    /**

+     * Field nameSpace used when serializing Binary stuff as MTOM optimized.

+     */

+    protected OMNamespace ns = new OMNamespaceImpl(

+            "http://www.w3.org/2004/08/xop/include", "xop");

+

+    /**

+     * Field localName used when serializing Binary stuff as MTOM optimized.

+     */

+    protected String localName = "Include";

+

+    /**

+     * Field attributes used when serializing Binary stuff as MTOM optimized.

+     */

+    protected OMAttribute attribute;

+

+    /**

+     * Constructor OMTextImpl.

+     *

+     * @param s

+     */

+    public OMTextImpl(String s) {

+        this.value = s;

+        this.nodeType = TEXT_NODE;

+    }

+

+    /**

+     * @param s

+     * @param nodeType - OMText can handle CHARACTERS, SPACES, CDATA and ENTITY REFERENCES.

+     *                 Constants for this can be found in OMNode.

+     */

+    public OMTextImpl(String s, int nodeType) {

+        this.value = s;

+        this.nodeType = nodeType;

+    }

+

+    /**

+     * Constructor OMTextImpl.

+     *

+     * @param parent

+     * @param text

+     */

+    public OMTextImpl(OMElement parent, String text) {

+        super(parent);

+        this.value = text;

+        done = true;

+        this.nodeType = TEXT_NODE;

+    }

+

+    public OMTextImpl(OMElement parent, String text, int nodeType) {

+        super(parent);

+        this.value = text;

+        done = true;

+        this.nodeType = nodeType;

+    }

+

+    /**

+     * @param s        - base64 encoded String representation of Binary

+     * @param mimeType of the Binary

+     */

+    public OMTextImpl(String s, String mimeType, boolean optimize) {

+        this(null, s, mimeType, optimize);

+    }

+

+    /**

+     * @param parent

+     * @param s        -

+     *                 base64 encoded String representation of Binary

+     * @param mimeType of the Binary

+     */

+    public OMTextImpl(OMElement parent, String s, String mimeType,

+                      boolean optimize) {

+        this(parent, s);

+        this.mimeType = mimeType;

+        this.optimize = optimize;

+        this.isBinary = true;

+        done = true;

+        this.nodeType = TEXT_NODE;

+    }

+

+    /**

+     * @param dataHandler To send binary optimised content Created programatically.

+     */

+    public OMTextImpl(Object dataHandler) {

+        this(dataHandler, true);

+    }

+

+    /**

+     * @param dataHandler

+     * @param optimize    To send binary content. Created progrmatically.

+     */

+    public OMTextImpl(Object dataHandler, boolean optimize) {

+        this.dataHandlerObject = dataHandler;

+        this.isBinary = true;

+        this.optimize = optimize;

+        done = true;

+        this.nodeType = TEXT_NODE;

+    }

+

+    /**

+     * @param contentID

+     * @param parent

+     * @param builder   Used when the builder is encountered with a XOP:Include tag

+     *                  Stores a reference to the builder and the content-id. Supports

+     *                  deferred parsing of MIME messages.

+     */

+    public OMTextImpl(String contentID, OMElement parent,

+                      OMXMLParserWrapper builder) {

+        super(parent);

+        this.contentID = contentID;

+        this.optimize = true;

+        this.isBinary = true;

+        this.builder = builder;

+        this.nodeType = TEXT_NODE;

+    }

+

+    /**

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    public void serialize(OMOutputImpl omOutput) throws XMLStreamException {

+        serializeLocal(omOutput);

+

+    }

+

+    /**

+     * Writes the relevant output.

+     *

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    private void writeOutput(OMOutputImpl omOutput) throws XMLStreamException {

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        int type = getType();

+        if (type == TEXT_NODE || type == SPACE_NODE) {

+            writer.writeCharacters(this.getText());

+        } else if (type == CDATA_SECTION_NODE) {

+            writer.writeCData(this.getText());

+        } else if (type == ENTITY_REFERENCE_NODE) {

+            writer.writeEntityRef(this.getText());

+        }

+    }

+

+    /**

+     * Returns the value.

+     */

+    public String getText() throws OMException {

+        if (this.value != null) {

+            return this.value;

+        } else {

+            try {

+                InputStream inStream;

+                inStream = this.getInputStream();

+                byte[] data;

+                StringBuffer text = new StringBuffer();

+                do {

+                	data = new byte[1024];

+                	int len;

+                	while((len = inStream.read(data)) > 0) {

+                		byte[] temp = new byte[len];

+                		System.arraycopy(data,0,temp,0,len);

+                		text.append(Base64.encode(temp));

+                	}

+

+                } while (inStream.available() > 0);

+                

+                return text.toString();

+            } catch (Exception e) {

+                throw new OMException(e);

+            }

+        }

+    }

+

+    public boolean isOptimized() {

+        return optimize;

+    }

+

+    public void setOptimize(boolean value) {

+        this.optimize = value;

+	if (value)

+	{

+	     isBinary = true;

+	}

+    }

+

+    

+    /**

+     * Gets the datahandler.

+     * @return Returns javax.activation.DataHandler

+     */

+    public Object getDataHandler() {

+        /*

+         * this should return a DataHandler containing the binary data

+         * reperesented by the Base64 strings stored in OMText

+         */

+        if (value != null & isBinary) {

+        	return org.apache.ws.commons.attachments.DataHandlerUtils.getDataHandlerFromText(value,mimeType);

+        } else {

+

+            if (dataHandlerObject == null) {

+                if (contentID == null) {

+                    throw new RuntimeException("ContentID is null");

+                }

+                dataHandlerObject = ((MTOMStAXSOAPModelBuilder) builder)

+                        .getDataHandler(contentID);

+            }

+            return dataHandlerObject;

+        }

+    }

+

+    public String getLocalName() {

+        return localName;

+    }

+

+    public java.io.InputStream getInputStream() throws OMException {

+        if (isBinary) {

+            if (dataHandlerObject == null) {

+                getDataHandler();

+            }

+            InputStream inStream;

+            javax.activation.DataHandler dataHandler = (javax.activation.DataHandler)dataHandlerObject;

+            try {

+                inStream = dataHandler.getDataSource().getInputStream();

+            } catch (IOException e) {

+                throw new OMException(

+                        "Cannot get InputStream from DataHandler." + e);

+            }

+            return inStream;

+        } else {

+            throw new OMException("Unsupported Operation");

+        }

+    }

+

+    public String getContentID() {

+        if (contentID == null) {

+            contentID = UUIDGenerator.getUUID()

+                    + "@apache.org";

+        }

+        return this.contentID;

+    }

+

+    public boolean isComplete() {

+        return done;

+    }

+

+    public void serializeAndConsume(OMOutputImpl omOutput)

+            throws XMLStreamException {

+        serializeLocal(omOutput);

+    }

+

+    private void serializeLocal(OMOutputImpl omOutput) throws XMLStreamException {

+        if (!this.isBinary) {

+            writeOutput(omOutput);

+        } else {

+            if (omOutput.isOptimized()) {

+                if (contentID == null) {

+                    contentID = omOutput.getNextContentId();

+                }

+                // send binary as MTOM optimised

+                this.attribute = new OMAttributeImpl("href",

+                        new OMNamespaceImpl("", ""), "cid:" + getContentID());

+                this.serializeStartpart(omOutput);

+                omOutput.writeOptimized(this);

+                omOutput.getXmlStreamWriter().writeEndElement();

+            } else {

+                omOutput.getXmlStreamWriter().writeCharacters(this.getText());

+            } 

+        }

+    }

+

+    /*

+     * Methods to copy from OMSerialize utils

+     */

+    private void serializeStartpart(OMOutputImpl omOutput)

+            throws XMLStreamException {

+        String nameSpaceName;

+        String writer_prefix;

+        String prefix;

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        if (this.ns != null) {

+            nameSpaceName = this.ns.getName();

+            writer_prefix = writer.getPrefix(nameSpaceName);

+            prefix = this.ns.getPrefix();

+            if (nameSpaceName != null) {

+                if (writer_prefix != null) {

+                    writer

+                            .writeStartElement(nameSpaceName, this

+                                    .getLocalName());

+                } else {

+                    if (prefix != null) {

+                        writer.writeStartElement(prefix, this.getLocalName(),

+                                nameSpaceName);

+                        //TODO FIX ME

+                        //writer.writeNamespace(prefix, nameSpaceName);

+                        writer.setPrefix(prefix, nameSpaceName);

+                    } else {

+                        writer.writeStartElement(nameSpaceName, this

+                                .getLocalName());

+                        writer.writeDefaultNamespace(nameSpaceName);

+                        writer.setDefaultNamespace(nameSpaceName);

+                    }

+                }

+            } else {

+                writer.writeStartElement(this.getLocalName());

+            }

+        } else {

+            writer.writeStartElement(this.getLocalName());

+        }

+        // add the elements attribute "href"

+        serializeAttribute(this.attribute, omOutput);

+        // add the namespace

+        serializeNamespace(this.ns, omOutput);

+    }

+

+    /**

+     * Method serializeAttribute.

+     *

+     * @param attr

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    static void serializeAttribute(OMAttribute attr, OMOutputImpl omOutput)

+            throws XMLStreamException {

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        // first check whether the attribute is associated with a namespace

+        OMNamespace ns = attr.getNamespace();

+        String prefix;

+        String namespaceName;

+        if (ns != null) {

+            // add the prefix if it's availble

+            prefix = ns.getPrefix();

+            namespaceName = ns.getName();

+            if (prefix != null) {

+                writer.writeAttribute(prefix, namespaceName, attr

+                        .getLocalName(), attr.getAttributeValue());

+            } else {

+                writer.writeAttribute(namespaceName, attr.getLocalName(), attr

+                        .getAttributeValue());

+            }

+        } else {

+            writer.writeAttribute(attr.getLocalName(), attr.getAttributeValue());

+        }

+    }

+

+    /**

+     * Method serializeNamespace.

+     *

+     * @param namespace

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    static void serializeNamespace(OMNamespace namespace, OMOutputImpl omOutput)

+            throws XMLStreamException {

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        if (namespace != null) {

+            String uri = namespace.getName();

+            String ns_prefix = namespace.getPrefix();

+            writer.writeNamespace(ns_prefix, namespace.getName());

+            writer.setPrefix(ns_prefix, uri);

+        }

+    }

+

+    /**

+     * A slightly different implementation of the discard method.

+     *

+     * @throws OMException

+     */

+    public void discard() throws OMException {

+        if (done) {

+            this.detach();

+        } else {

+            builder.discard((OMElement) this.parent);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/builder/SAXOMBuilder.java b/src/org/apache/ws/commons/om/impl/llom/builder/SAXOMBuilder.java
new file mode 100644
index 0000000..c41891a
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/builder/SAXOMBuilder.java
@@ -0,0 +1,174 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.builder;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.xml.sax.Attributes;

+import org.xml.sax.Locator;

+import org.xml.sax.SAXException;

+import org.xml.sax.helpers.DefaultHandler;

+

+import java.util.ArrayList;

+import java.util.List;

+

+public class SAXOMBuilder extends DefaultHandler {

+    OMElement root = null;

+

+    OMNode lastNode = null;

+

+    OMElement nextElem = null;

+

+    OMFactory factory = OMAbstractFactory.getOMFactory();

+

+    List prefixMappings = new ArrayList();

+

+    public void setDocumentLocator(Locator arg0) {

+    }

+

+    public void startDocument() throws SAXException {

+

+    }

+

+    public void endDocument() throws SAXException {

+    }

+

+    protected OMElement createNextElement(String localName) throws OMException {

+        OMElement e;

+        if (lastNode == null) {

+            root = e = factory.createOMElement(localName, null, null, null);

+        } else if (lastNode.isComplete()) {

+            e = factory.createOMElement(localName, null, lastNode.getParent(),

+                    null);

+            ((OMNodeEx)lastNode).setNextOMSibling(e);

+            ((OMNodeEx)e).setPreviousOMSibling(lastNode);

+        } else {

+            OMElement parent = (OMElement) lastNode;

+            e = factory.createOMElement(localName, null, (OMElement) lastNode,

+                    null);

+            parent.setFirstChild(e);

+        }

+        return e;

+    }

+

+    /*

+     * (non-Javadoc)

+     *

+     * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,

+     *      java.lang.String)

+     */

+    public void startPrefixMapping(String prefix, String uri)

+            throws SAXException {

+        if (nextElem == null)

+            nextElem = createNextElement(null);

+        nextElem.declareNamespace(uri, prefix);

+    }

+

+    public void endPrefixMapping(String arg0) throws SAXException {

+    }

+

+    /*

+     * (non-Javadoc)

+     *

+     * @see org.xml.sax.ContentHandler#startElement(java.lang.String,

+     *      java.lang.String, java.lang.String, org.xml.sax.Attributes)

+     */

+    public void startElement(String namespaceURI, String localName,

+                             String qName, Attributes atts) throws SAXException {

+        if (localName == null || localName.trim().equals(""))

+            localName = qName.substring(qName.indexOf(':') + 1);

+        if (nextElem == null)

+            nextElem = createNextElement(localName);

+        else

+            nextElem.setLocalName(localName);

+        nextElem

+                .setNamespace(nextElem.findNamespace(namespaceURI, null));

+        int j = atts.getLength();

+        for (int i = 0; i < j; i++)

+            nextElem.addAttribute(atts.getLocalName(i), atts.getValue(i),

+                    nextElem.findNamespace(atts.getURI(i), null));

+        lastNode = nextElem;

+        nextElem = null;

+    }

+

+    /*

+     * (non-Javadoc)

+     *

+     * @see org.xml.sax.ContentHandler#endElement(java.lang.String,

+     *      java.lang.String, java.lang.String)

+     */

+    public void endElement(String arg0, String arg1, String arg2)

+            throws SAXException {

+        if (lastNode.isComplete()) {

+            OMContainer parent = lastNode.getParent();

+            ((OMNodeEx)parent).setComplete(true);

+            lastNode = (OMNode) parent;

+        } else {

+            OMElement e = (OMElement) lastNode;

+            ((OMNodeEx)e).setComplete(true);

+        }

+    }

+

+    /*

+     * (non-Javadoc)

+     *

+     * @see org.xml.sax.ContentHandler#characters(char[], int, int)

+     */

+    public void characters(char[] ch, int start, int length)

+            throws SAXException {

+        if (lastNode == null) {

+            throw new SAXException("");

+        }

+        OMNode node;

+        if (lastNode.isComplete()) {

+            node =

+                    factory.createText((OMElement) lastNode.getParent(),

+                            new String(ch,

+                                    start, length));

+            ((OMNodeEx)lastNode).setNextOMSibling(node);

+            ((OMNodeEx)node).setPreviousOMSibling(lastNode);

+        } else {

+            OMElement e = (OMElement) lastNode;

+            node = factory.createText(e, new String(ch, start, length));

+            e.setFirstChild(node);

+        }

+        lastNode = node;

+    }

+

+    public void ignorableWhitespace(char[] arg0, int arg1, int arg2)

+            throws SAXException {

+    }

+

+    public void processingInstruction(String arg0, String arg1)

+            throws SAXException {

+    }

+

+    public void skippedEntity(String arg0) throws SAXException {

+    }

+

+    /**

+     * @return Returns the root.

+     */

+    public OMElement getRootElement() {

+        return root;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/builder/StAXBuilder.java b/src/org/apache/ws/commons/om/impl/llom/builder/StAXBuilder.java
new file mode 100644
index 0000000..e3136aa
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/builder/StAXBuilder.java
@@ -0,0 +1,424 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.builder;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMConstants;

+import org.apache.ws.commons.om.OMDocument;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+

+import javax.xml.stream.XMLStreamConstants;

+import javax.xml.stream.XMLStreamReader;

+

+/**

+ * OM should be able to be built from any data source. And the model it builds 

+ * may be a SOAP specific one or just an XML model. This class will give 

+ * some common functionality of OM Building from StAX.

+ */

+public abstract class StAXBuilder implements OMXMLParserWrapper {

+

+    /**

+     * Field parser

+     */

+    protected XMLStreamReader parser;

+

+    /**

+     * Field omfactory

+     */

+    protected OMFactory omfactory;

+

+    /**

+     * Field lastNode

+     */

+    protected OMNode lastNode;

+

+    // returns the state of completion

+

+    /**

+     * Field done

+     */

+    protected boolean done = false;

+

+    // keeps the state of the cache

+

+    /**

+     * Field cache

+     */

+    protected boolean cache = true;

+

+    // keeps the state of the parser access. if the parser is

+    // accessed atleast once,this flag will be set

+

+    /**

+     * Field parserAccessed

+     */

+    protected boolean parserAccessed = false;

+    protected OMDocument document;

+

+

+

+    /**

+     * Constructor StAXBuilder.

+     *

+     * @param ombuilderFactory

+     * @param parser

+     */

+    protected StAXBuilder(OMFactory ombuilderFactory, XMLStreamReader parser) {

+        this.parser = parser;

+        omfactory = ombuilderFactory;

+    }

+

+    /**

+     * Constructor StAXBuilder.

+     *

+     * @param parser

+     */

+    protected StAXBuilder(XMLStreamReader parser) {

+        this(OMAbstractFactory.getOMFactory(), parser);

+    }

+

+    /**

+     * Method setOmbuilderFactory.

+     *

+     * @param ombuilderFactory

+     */

+    public void setOmbuilderFactory(OMFactory ombuilderFactory) {

+        this.omfactory = ombuilderFactory;

+    }

+

+    /**

+     * Method processNamespaceData.

+     *

+     * @param node

+     * @param isSOAPElement

+     */

+    protected abstract void processNamespaceData(OMElement node,

+                                                 boolean isSOAPElement);

+

+    // since the behaviors are different when it comes to namespaces

+    // this must be implemented differently

+

+    /**

+     * Method processAttributes.

+     *

+     * @param node

+     */

+    protected void processAttributes(OMElement node) {

+        int attribCount = parser.getAttributeCount();

+        for (int i = 0; i < attribCount; i++) {

+            OMNamespace ns = null;

+            String uri = parser.getAttributeNamespace(i);

+            String prefix = parser.getAttributePrefix(i);

+            if (uri != null && uri.hashCode() != 0) {

+                ns = node.findNamespace(uri, prefix);

+            }

+            // todo if the attributes are supposed to namespace qualified all the time

+            // todo then this should throw an exception here

+            node.addAttribute(parser.getAttributeLocalName(i),

+                    parser.getAttributeValue(i), ns);

+        }

+    }

+

+    /**

+     * Method createOMText.

+     *

+     * @return Returns OMNode.

+     * @throws OMException

+     */

+    protected OMNode createOMText(int textType) throws OMException {

+        OMNode node = null;

+        if (lastNode == null) {

+            return null;

+        } else if (!lastNode.isComplete()) {

+            node = omfactory.createText((OMElement) lastNode, parser.getText(), textType);

+        } else if (!(lastNode.getParent() instanceof OMDocument)) {

+            node = omfactory.createText((OMElement)lastNode.getParent(), parser.getText(), textType);

+        }

+        return node;

+    }

+

+    /**

+     * Method reset.

+     *

+     * @param node

+     * @throws OMException

+     */

+    public void reset(OMNode node) throws OMException {

+        lastNode = null;

+    }

+

+    /**

+     * Method discard.

+     *

+     * @param el

+     * @throws OMException

+     */

+    public void discard(OMElement el) throws OMException {

+        OMElement element = null;

+

+        if (element.isComplete() || !cache) {

+            throw new OMException();

+        }

+        try {

+            cache = false;

+            do {

+                while (parser.next() != XMLStreamConstants.END_ELEMENT) ;

+

+                // TODO:

+            } while (!parser.getName().equals(element.getQName()));

+            lastNode = element.getPreviousOMSibling();

+            if (lastNode != null) {

+                ((OMNodeEx)lastNode).setNextOMSibling(null);

+            } else {

+                OMElement parent = (OMElement) element.getParent();

+                if (parent == null) {

+                    throw new OMException();

+                }

+                parent.setFirstChild(null);

+                lastNode = parent;

+            }

+            cache = true;

+        } catch (OMException e) {

+            throw e;

+        } catch (Exception e) {

+            throw new OMException(e);

+        }

+    }

+

+    /**

+     * Method getText.

+     *

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getText() throws OMException {

+        return parser.getText();

+    }

+

+    /**

+     * Method getNamespace. 

+     *

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getNamespace() throws OMException {

+        return parser.getNamespaceURI();

+    }

+

+    /**

+     * Method getNamespaceCount.

+     *

+     * @return Returns int.

+     * @throws OMException

+     */

+    public int getNamespaceCount() throws OMException {

+        try {

+            return parser.getNamespaceCount();

+        } catch (Exception e) {

+            throw new OMException(e);

+        }

+    }

+

+    /**

+     * Method getNamespacePrefix.

+     *

+     * @param index

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getNamespacePrefix(int index) throws OMException {

+        try {

+            return parser.getNamespacePrefix(index);

+        } catch (Exception e) {

+            throw new OMException(e);

+        }

+    }

+

+    /**

+     * Method getNamespaceUri.

+     *

+     * @param index

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getNamespaceUri(int index) throws OMException {

+        try {

+            return parser.getNamespaceURI(index);

+        } catch (Exception e) {

+            throw new OMException(e);

+        }

+    }

+

+    /**

+     * Method setCache.

+     *

+     * @param b

+     */

+    public void setCache(boolean b) {

+        if (parserAccessed && b) {

+            throw new UnsupportedOperationException(

+                    "parser accessed. cannot set cache");

+        }

+        cache = b;

+    }

+

+    /**

+     * Method getName.

+     *

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getName() throws OMException {

+        return parser.getLocalName();

+    }

+

+    /**

+     * Method getPrefix.

+     *

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getPrefix() throws OMException {

+        return parser.getPrefix();

+    }

+

+    /**

+     * Method getAttributeCount.

+     *

+     * @return Returns int.

+     * @throws OMException

+     */

+    public int getAttributeCount() throws OMException {

+        return parser.getAttributeCount();

+    }

+

+    /**

+     * Method getAttributeNamespace.

+     *

+     * @param arg

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getAttributeNamespace(int arg) throws OMException {

+        return parser.getAttributeNamespace(arg);

+    }

+

+    /**

+     * Method getAttributeName.

+     *

+     * @param arg

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getAttributeName(int arg) throws OMException {

+        return parser.getAttributeNamespace(arg);

+    }

+

+    /**

+     * Method getAttributePrefix.

+     *

+     * @param arg

+     * @return Returns String.

+     * @throws OMException

+     */

+    public String getAttributePrefix(int arg) throws OMException {

+        return parser.getAttributeNamespace(arg);

+    }

+

+    /**

+     * Method getParser.

+     *

+     * @return Returns Object.

+     */

+    public Object getParser() {

+        if (parserAccessed){

+            throw new IllegalStateException(

+                    "Parser already accessed!");  

+        }

+        if (!cache) {

+            parserAccessed = true;

+            return parser;

+        } else {

+            throw new IllegalStateException(

+                    "cache must be switched off to access the parser");

+        }

+    }

+

+    /**

+     * Method isCompleted.

+     *

+     * @return Returns boolean.

+     */

+    public boolean isCompleted() {

+        return done;

+    }

+

+    /**

+     * This method is called with the XMLStreamConstants.START_ELEMENT event.

+     *

+     * @return Returns OMNode.

+     * @throws OMException

+     */

+    protected abstract OMNode createOMElement() throws OMException;

+

+    /**

+     * 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 event, *without* building the OM tree.

+     * If the cache is set to true, then handles all the events within this, and 

+     * builds the object structure appropriately and returns the event.

+     *

+     * @return Returns int.

+     * @throws OMException

+     */

+    public abstract int next() throws OMException;

+

+    /**

+     * @return Returns short.

+     */ 

+    public short getBuilderType() {

+        return OMConstants.PULL_TYPE_BUILDER;

+    }

+

+    /**

+     * Method registerExternalContentHandler.

+     *

+     * @param obj

+     */

+    public void registerExternalContentHandler(Object obj) {

+        throw new UnsupportedOperationException();

+    }

+

+    /**

+     * Method getRegisteredContentHandler.

+     * 

+     * @return Returns Object.

+     */

+    public Object getRegisteredContentHandler() {

+        throw new UnsupportedOperationException();

+    }

+

+    public OMDocument getDocument() {

+        return document;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/builder/StAXOMBuilder.java b/src/org/apache/ws/commons/om/impl/llom/builder/StAXOMBuilder.java
new file mode 100644
index 0000000..75901e9
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/builder/StAXOMBuilder.java
@@ -0,0 +1,341 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.builder;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.impl.OMContainerEx;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamConstants;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import java.io.FileInputStream;

+import java.io.FileNotFoundException;

+import java.io.InputStream;

+

+

+/**

+ * Constructs an OM without using SOAP specific classes like SOAPEnvelope,

+ * SOAPHeader, SOAPHeaderBlock and SOAPBody. This has the document concept also.

+ */

+public class StAXOMBuilder extends StAXBuilder {

+    /**

+     * Field document

+     */

+

+    private boolean doDebug = false;

+    private static int nsCount = 0;

+

+    /**

+     * Constructor StAXOMBuilder.

+     *

+     * @param ombuilderFactory

+     * @param parser

+     */

+    public StAXOMBuilder(OMFactory ombuilderFactory, XMLStreamReader parser) {

+        super(ombuilderFactory, parser);

+        document = ombuilderFactory.createOMDocument(this);

+    }

+

+    /**

+     * @param filePath - Path to the XML file

+     * @throws XMLStreamException

+     * @throws FileNotFoundException

+     */

+    public StAXOMBuilder(String filePath) throws XMLStreamException, FileNotFoundException {

+        this(XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(filePath)));

+    }

+

+    /**

+     * @param inStream - instream which contains the XML

+     * @throws XMLStreamException

+     */

+    public StAXOMBuilder(InputStream inStream) throws XMLStreamException {

+        this(XMLInputFactory.newInstance().createXMLStreamReader(inStream));

+    }

+

+    /**

+     * Constructor StAXOMBuilder.

+     *

+     * @param parser

+     */

+    public StAXOMBuilder(XMLStreamReader parser) {

+        super(parser);

+        omfactory = OMAbstractFactory.getOMFactory();

+        document = omfactory.createOMDocument(this);

+    }

+

+    /**

+     * Method createOMElement.

+     *

+     * @return Returns OMNode.

+     * @throws OMException

+     */

+    protected OMNode createOMElement() throws OMException {

+        OMElement node;

+        String elementName = parser.getLocalName();

+        if (lastNode == null) {

+            node = omfactory.createOMElement(elementName, null, document, this);

+        } else if (lastNode.isComplete()) {

+            node = omfactory.createOMElement(elementName, null,

+                    lastNode.getParent(), this);

+            ((OMNodeEx) lastNode).setNextOMSibling(node);

+            ((OMNodeEx) node).setPreviousOMSibling(lastNode);

+        } else {

+            OMElement e = (OMElement) lastNode;

+            node = omfactory.createOMElement(elementName, null,

+                    (OMElement) lastNode, this);

+            e.setFirstChild(node);

+        }

+        // create the namespaces

+        processNamespaceData(node, false);

+        // fill in the attributes

+        processAttributes(node);

+        node.setLineNumber(parser.getLocation().getLineNumber());

+        return node;

+    }

+

+    /**

+     * Method createOMText.

+     *

+     * @return Returns OMNode.

+     * @throws OMException

+     */

+    protected OMNode createComment() throws OMException {

+        OMNode node;

+        if (lastNode == null) {

+            node = omfactory.createOMComment(document, parser.getText());

+        } else if (lastNode.isComplete()) {

+            node = omfactory.createOMComment(lastNode.getParent(), parser.getText());

+        } else {

+            node = omfactory.createOMComment((OMElement) lastNode, parser.getText());

+        }

+        return node;

+    }

+

+    /**

+     * Method createDTD.

+     *

+     * @return Returns OMNode.

+     * @throws OMException

+     */

+    protected OMNode createDTD() throws OMException {

+        if (!parser.hasText())

+            return null;

+        return omfactory.createOMDocType(document, parser.getText());

+    }

+

+    /**

+     * Method createPI.

+     *

+     * @return Returns OMNode.

+     * @throws OMException

+     */

+    protected OMNode createPI() throws OMException {

+        OMNode node;

+        String target = parser.getPITarget();

+        String data = parser.getPIData();

+        if (lastNode == null) {

+            node = omfactory.createOMProcessingInstruction(document, target, data);

+        } else if (lastNode.isComplete()) {

+            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data);

+        } else if (lastNode instanceof OMText) {

+            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data);

+        } else {

+            node = omfactory.createOMProcessingInstruction((OMContainer) lastNode, target, data);

+        }

+        return node;

+    }

+

+    protected void endElement() {

+        if (lastNode.isComplete()) {

+            OMElement parent = (OMElement) lastNode.getParent();

+            ((OMNodeEx) parent).setComplete(true);

+            lastNode = parent;

+        } else {

+            OMElement e = (OMElement) lastNode;

+            ((OMNodeEx) e).setComplete(true);

+        }

+

+        //return lastNode;

+    }

+

+    /**

+     * Method next.

+     *

+     * @return Returns int.

+     * @throws OMException

+     */

+    public int next() throws OMException {

+        try {

+            if (done) {

+                throw new OMException();

+            }

+            int token = parser.next();

+            if (!cache) {

+                return token;

+            }

+            switch (token) {

+                case XMLStreamConstants.START_ELEMENT:

+                    if (doDebug) {

+                        System.out.println("START_ELEMENT: " + parser.getName() + ":" + parser.getLocalName());

+                    }

+                    lastNode = createOMElement();

+                    break;

+                case XMLStreamConstants.START_DOCUMENT:

+                    // Document has already being created.

+

+                    document.setXMLVersion(parser.getVersion());

+                    document.setCharsetEncoding(parser.getEncoding());

+                    document.setStandalone(parser.isStandalone() ? "yes" : "no");

+                    if (doDebug) {

+                        System.out.println("START_DOCUMENT: ");

+                    }

+                    break;

+                case XMLStreamConstants.CHARACTERS:

+                    if (doDebug) {

+                        System.out.println("CHARACTERS: [" + parser.getText() + "]");

+                    }

+                    lastNode = createOMText(XMLStreamConstants.CHARACTERS);

+                    break;

+                case XMLStreamConstants.CDATA:

+                    if (doDebug) {

+                        System.out.println("CDATA: [" + parser.getText() + "]");

+                    }

+                    lastNode = createOMText(XMLStreamConstants.CDATA);

+                    break;

+                case XMLStreamConstants.END_ELEMENT:

+                    if (doDebug) {

+                        System.out.println("END_ELEMENT: " + parser.getName() + ":" + parser.getLocalName());

+                    }

+                    endElement();

+                    break;

+                case XMLStreamConstants.END_DOCUMENT:

+                    if (doDebug) {

+                        System.out.println("END_DOCUMENT: ");

+                    }

+                    done = true;

+                    ((OMContainerEx) this.document).setComplete(true);

+                    break;

+                case XMLStreamConstants.SPACE:

+                    if (doDebug) {

+                        System.out.println("SPACE: [" + parser.getText() + "]");

+                    }

+                    lastNode = createOMText(XMLStreamConstants.SPACE);

+                    break;

+                case XMLStreamConstants.COMMENT:

+                    if (doDebug) {

+                        System.out.println("COMMENT: [" + parser.getText() + "]");

+                    }

+                    createComment();

+                    break;

+                case XMLStreamConstants.DTD:

+                    if (doDebug) {

+                        System.out.println("DTD: [" + parser.getText() + "]");

+                    }

+                    createDTD();

+                    break;

+                case XMLStreamConstants.PROCESSING_INSTRUCTION:

+                    if (doDebug) {

+                        System.out.println("PROCESSING_INSTRUCTION: [" + parser.getPITarget() + "][" + parser.getPIData() + "]");

+                    }

+                    createPI();

+                    break;

+                case XMLStreamConstants.ENTITY_REFERENCE:

+                    if (doDebug) {

+                        System.out.println("ENTITY_REFERENCE: " + parser.getLocalName() + "[" + parser.getText() + "]");

+                    }

+                    lastNode = createOMText(XMLStreamConstants.ENTITY_REFERENCE);

+                    break;

+                default :

+                    throw new OMException();

+            }

+            return token;

+        } catch (OMException e) {

+            throw e;

+        } catch (Exception e) {

+            throw new OMException(e);

+        }

+    }

+

+    /**

+     * Method getDocumentElement.

+     *

+     * @return Returns root element.

+     */

+    public OMElement getDocumentElement() {

+        return document.getOMDocumentElement();

+    }

+

+    /**

+     * Method processNamespaceData.

+     *

+     * @param node

+     * @param isSOAPElement

+     */

+    protected void processNamespaceData(OMElement node, boolean isSOAPElement) {

+        // set the own namespace

+        String namespaceURI = parser.getNamespaceURI();

+        String prefix = parser.getPrefix();

+

+        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

+            prefix = prefix == null ? "" : prefix;

+            namespace = node.findNamespace(namespaceURI, prefix);

+

+            if (namespace == null) {

+                namespace = node.declareNamespace(namespaceURI, prefix);

+            }

+            node.setNamespace(namespace);

+        }

+

+

+        int namespaceCount = parser.getNamespaceCount();

+        for (int i = 0; i < namespaceCount; i++) {

+            String nsprefix = parser.getNamespacePrefix(i);

+            nsprefix = (nsprefix == null ? "" : nsprefix);

+

+            //if the namespace is not defined already when we write the start tag declare it

+

+            if (!nsprefix.equals(prefix)) {

+                node.declareNamespace(parser.getNamespaceURI(i),

+                        parser.getNamespacePrefix(i));

+            }

+        }

+    }

+

+

+    public void setDoDebug(boolean doDebug) {

+        this.doDebug = doDebug;

+    }

+

+    protected String createPrefix() {

+        return "ns" + nsCount++;

+    }

+

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/exception/OMBuilderException.java b/src/org/apache/ws/commons/om/impl/llom/exception/OMBuilderException.java
new file mode 100644
index 0000000..30e3e52
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/exception/OMBuilderException.java
@@ -0,0 +1,40 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.exception;

+

+import org.apache.ws.commons.om.OMException;

+

+/**

+ * Class OMBuilderException

+ */

+public class OMBuilderException extends OMException {

+	

+    private static final long serialVersionUID = -7447667411291193889L;

+

+	/**

+     * Constructor OMBuilderException

+     *

+     * @param s

+     */

+    public OMBuilderException(String s) {

+        super(s);

+    }

+

+    public OMBuilderException(Throwable cause) {

+        super(cause);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/exception/OMStreamingException.java b/src/org/apache/ws/commons/om/impl/llom/exception/OMStreamingException.java
new file mode 100644
index 0000000..d668817
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/exception/OMStreamingException.java
@@ -0,0 +1,61 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.exception;

+

+import org.apache.ws.commons.om.OMException;

+

+/**

+ * Class OMStreamingException

+ */

+public class OMStreamingException extends OMException {

+	

+    private static final long serialVersionUID = 8108888406034145092L;

+

+	/**

+     * Constructor OMStreamingException

+     */

+    public OMStreamingException() {

+    }

+

+    /**

+     * Constructor OMStreamingException

+     *

+     * @param message

+     */

+    public OMStreamingException(String message) {

+        super(message);

+    }

+

+    /**

+     * Constructor OMStreamingException

+     *

+     * @param message

+     * @param cause

+     */

+    public OMStreamingException(String message, Throwable cause) {

+        super(message, cause);

+    }

+

+    /**

+     * Constructor OMStreamingException

+     *

+     * @param cause

+     */

+    public OMStreamingException(Throwable cause) {

+        super(cause);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/exception/XMLComparisonException.java b/src/org/apache/ws/commons/om/impl/llom/exception/XMLComparisonException.java
new file mode 100644
index 0000000..b3e1117
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/exception/XMLComparisonException.java
@@ -0,0 +1,37 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.exception;

+

+public class XMLComparisonException extends Exception {

+	/**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+	

+    private static final long serialVersionUID = -7918497983548520994L;

+

+    public XMLComparisonException(String message) {

+        super(message);

+    }

+

+    public XMLComparisonException(Throwable cause) {

+        super(cause);

+    }

+

+    public XMLComparisonException(String message, Throwable cause) {

+        super(message, cause);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/factory/OMLinkedListImplFactory.java b/src/org/apache/ws/commons/om/impl/llom/factory/OMLinkedListImplFactory.java
new file mode 100644
index 0000000..055cc14
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/factory/OMLinkedListImplFactory.java
@@ -0,0 +1,266 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.factory;

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMComment;

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMDocType;

+import org.apache.ws.commons.om.OMDocument;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMProcessingInstruction;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.OMAttributeImpl;

+import org.apache.ws.commons.om.impl.llom.OMCommentImpl;

+import org.apache.ws.commons.om.impl.llom.OMDocTypeImpl;

+import org.apache.ws.commons.om.impl.llom.OMDocumentImpl;

+import org.apache.ws.commons.om.impl.llom.OMElementImpl;

+import org.apache.ws.commons.om.impl.llom.OMNamespaceImpl;

+import org.apache.ws.commons.om.impl.llom.OMProcessingInstructionImpl;

+import org.apache.ws.commons.om.impl.llom.OMTextImpl;

+

+import javax.xml.namespace.QName;

+import java.util.HashMap;

+import java.util.Map;

+

+/**

+ * Class OMLinkedListImplFactory

+ */

+public class OMLinkedListImplFactory implements OMFactory {

+

+    private static final String uriAndPrefixSeparator = ";";

+    /**

+     * This is a map of namespaces with the namespace URI as the key and

+     * Namespace object itself as the value.

+     */

+    protected Map namespaceTable = new HashMap(5);

+

+    /**

+     * Method createOMElement.

+     *

+     * @param localName

+     * @param ns

+     * @return Returns OMElement.

+     */

+    public OMElement createOMElement(String localName, OMNamespace ns) {

+        return new OMElementImpl(localName, ns);

+    }

+

+    public OMElement createOMElement(String localName, OMNamespace ns, OMContainer parent) {

+        return new OMElementImpl(localName, ns, parent);

+    }

+

+    /**

+     * Method createOMElement.

+     *

+     * @param localName

+     * @param ns

+     * @param parent

+     * @param builder

+     * @return Returns OMElement.

+     */

+    public OMElement createOMElement(String localName, OMNamespace ns,

+                                     OMContainer parent,

+                                     OMXMLParserWrapper builder) {

+        return new OMElementImpl(localName, ns, parent,

+                builder);

+    }

+

+    /**

+     * Method createOMElement.

+     *

+     * @param localName

+     * @param namespaceURI

+     * @param namespacePrefix

+     * @return Returns OMElement.

+     */

+    public OMElement createOMElement(String localName, String namespaceURI,

+                                     String namespacePrefix) {

+        return this.createOMElement(localName,

+                this.createOMNamespace(namespaceURI,

+                        namespacePrefix));

+    }

+

+    /**

+     * Method createOMElement.

+     *

+     * @param qname

+     * @param parent

+     * @return Returns OMElement.

+     * @throws OMException

+     */

+    public OMElement createOMElement(QName qname, OMContainer parent)

+            throws OMException {

+        return new OMElementImpl(qname, parent);

+    }

+

+    /**

+     * Method createOMNamespace.

+     *

+     * @param uri

+     * @param prefix

+     * @return Returns OMNamespace.

+     */

+    public OMNamespace createOMNamespace(String uri, String prefix) {

+        String key = uri + uriAndPrefixSeparator + prefix;

+        OMNamespace existingNamespaceObject = (OMNamespace) namespaceTable.get(key);

+        if (existingNamespaceObject == null) {

+            existingNamespaceObject = new OMNamespaceImpl(uri, prefix);

+            namespaceTable.put(key, existingNamespaceObject);

+        }

+        return existingNamespaceObject;

+    }

+

+    /**

+     * Method createText.

+     *

+     * @param parent

+     * @param text

+     * @return Returns OMText.

+     */

+    public OMText createText(OMElement parent, String text) {

+        return new OMTextImpl(parent, text);

+    }

+

+    public OMText createText(OMElement parent, String text, int type) {

+        return new OMTextImpl(parent, text, type);

+    }

+

+    /**

+     * Method createText.

+     *

+     * @param s

+     * @return Returns OMText.

+     */

+    public OMText createText(String s) {

+        return new OMTextImpl(s);

+    }

+

+    public OMText createText(String s, int type) {

+        return new OMTextImpl(s, type);

+    }

+

+    /**

+     * Creates text.

+     *

+     * @param s

+     * @param mimeType

+     * @param optimize

+     * @return Returns OMText.

+     */

+    public OMText createText(String s, String mimeType, boolean optimize) {

+        return new OMTextImpl(s, mimeType, optimize);

+    }

+

+    /**

+     * Creates text.

+     *

+     * @param dataHandler

+     * @param optimize

+     * @return Returns OMText.

+     */

+    public OMText createText(Object dataHandler, boolean optimize) {

+        return new OMTextImpl(dataHandler, optimize);

+    }

+

+    public OMText createText(String contentID, OMElement parent,

+                             OMXMLParserWrapper builder) {

+        return new OMTextImpl(contentID, parent, builder);

+    }

+

+    /**

+     * Creates text.

+     *

+     * @param parent

+     * @param s

+     * @param mimeType

+     * @param optimize

+     * @return Returns OMText.

+     */

+    public OMText createText(OMElement parent,

+                             String s,

+                             String mimeType,

+                             boolean optimize) {

+        return new OMTextImpl(parent, s, mimeType, optimize);

+    }

+

+    /**

+     * Creates attribute.

+     *

+     * @param localName

+     * @param ns

+     * @param value

+     * @return Returns OMAttribute.

+     */

+    public OMAttribute createOMAttribute(String localName,

+                                         OMNamespace ns,

+                                         String value) {

+        return new OMAttributeImpl(localName, ns, value);

+    }

+

+    /**

+     * Creates DocType/DTD.

+     *

+     * @param parent

+     * @param content

+     * @return Returns doctype.

+     */

+    public OMDocType createOMDocType(OMContainer parent, String content) {

+        return new OMDocTypeImpl(parent, content);

+    }

+

+    /**

+     * Creates a PI.

+     *

+     * @param parent

+     * @param piTarget

+     * @param piData

+     * @return Returns OMProcessingInstruction.

+     */

+    public OMProcessingInstruction createOMProcessingInstruction(OMContainer parent, String piTarget, String piData) {

+        return new OMProcessingInstructionImpl(parent, piTarget, piData);

+    }

+

+    /**

+     * Creates a comment.

+     *

+     * @param parent

+     * @param content

+     * @return Returns OMComment.

+     */

+    public OMComment createOMComment(OMContainer parent, String content) {

+        return new OMCommentImpl(parent, content);

+    }

+

+    /* (non-Javadoc)

+    * @see org.apache.ws.commons.om.OMFactory#createOMDocument()

+    */

+    public OMDocument createOMDocument() {

+        return new OMDocumentImpl();

+    }

+

+    /* (non-Javadoc)

+      * @see org.apache.ws.commons.om.OMFactory#createOMDocument(org.apache.ws.commons.om.OMXMLParserWrapper)

+      */

+    public OMDocument createOMDocument(OMXMLParserWrapper builder) {

+        return new OMDocumentImpl(builder);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/factory/OMXMLBuilderFactory.java b/src/org/apache/ws/commons/om/impl/llom/factory/OMXMLBuilderFactory.java
new file mode 100644
index 0000000..c705cc5
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/factory/OMXMLBuilderFactory.java
@@ -0,0 +1,73 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.factory;

+

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+import javax.xml.stream.XMLStreamReader;

+

+/**

+ * Class OMXMLBuilderFactory

+ */

+public class OMXMLBuilderFactory {

+    /**

+     * Field PARSER_XPP

+     */

+    public static final String PARSER_XPP = "XPP";

+

+    /**

+     * Field PARSER_STAX

+     */

+    public static final String PARSER_STAX = "StAX";

+

+    /**

+     * Field MODEL_SOAP_SPECIFIC

+     */

+    public static final String MODEL_SOAP_SPECIFIC = "SOAP_SPECIFIC";

+

+    /**

+     * Field MODEL_OM

+     */

+    public static final String MODEL_OM = "OM_ONLY";

+

+    /**

+     * Method createStAXSOAPModelBuilder.

+     *

+     * @param soapFactory

+     * @param parser

+     * @return Returns StAXSOAPModelBuilder.

+     */

+    public static StAXSOAPModelBuilder createStAXSOAPModelBuilder(

+            SOAPFactory soapFactory, XMLStreamReader parser) {

+        return new StAXSOAPModelBuilder(parser, soapFactory, null);

+    }

+

+    /**

+     * Method createStAXOMBuilder.

+     *

+     * @param ombuilderFactory

+     * @param parser

+     * @return Returns StAXOMBuilder.

+     */

+    public static StAXOMBuilder createStAXOMBuilder(OMFactory ombuilderFactory,

+                                                    XMLStreamReader parser) {

+        return new StAXOMBuilder(ombuilderFactory, parser);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java b/src/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java
new file mode 100644
index 0000000..d6f4bd0
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java
@@ -0,0 +1,153 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.mtom;

+

+import org.apache.ws.commons.attachments.MIMEHelper;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.impl.MTOMConstants;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+import javax.activation.DataHandler;

+import javax.xml.stream.XMLStreamReader;

+import java.io.UnsupportedEncodingException;

+import java.net.URLDecoder;

+

+public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder implements MTOMConstants {

+	

+    /**

+     * <code>mimeHelper</code> handles deferred parsing of incoming MIME

+     * Messages.

+     */

+    MIMEHelper mimeHelper;

+

+    int partIndex = 0;

+

+    public MTOMStAXSOAPModelBuilder(XMLStreamReader parser,

+                                    SOAPFactory factory,

+                                    MIMEHelper mimeHelper, String soapVersion) {

+        super(parser, factory, soapVersion);

+        this.mimeHelper = mimeHelper;

+    }

+

+    /**

+     * @param reader

+     * @param mimeHelper

+     */

+    public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,

+                                    MIMEHelper mimeHelper, String soapVersion) {

+        super(reader, soapVersion);

+        this.mimeHelper = mimeHelper;

+    }

+

+    protected OMNode createOMElement() throws OMException {

+

+        elementLevel++;

+        String elementName = parser.getLocalName();

+

+        String namespaceURI = parser.getNamespaceURI();

+

+        // create an OMBlob if the element is an <xop:Include>

+

+        if (XOP_INCLUDE.equalsIgnoreCase(elementName)

+                && XOP_NAMESPACE_URI

+                .equalsIgnoreCase(namespaceURI)) {

+            // do we need to check prfix as well. Meaning, should it be "XOP" ?

+

+

+            OMText node;

+            String contentID = null;

+            String contentIDName = null;

+            if (lastNode == null) {

+                // Decide whether to ckeck the level >3 or not

+                throw new OMException(

+                        "XOP:Include element is not supported here");

+            }

+            if (parser.getAttributeCount() > 0) {

+                contentID = parser.getAttributeValue(0);

+                contentID = contentID.trim();

+                contentIDName = parser.getAttributeLocalName(0);

+                if (contentIDName.equalsIgnoreCase("href")

+                        & contentID.substring(0, 3).equalsIgnoreCase("cid")) {

+                    contentID = contentID.substring(4);

+                    String charsetEncoding = getDocument().getCharsetEncoding();

+                    String charEnc = charsetEncoding == null || "".equals(charsetEncoding) ? "UTF-8" : charsetEncoding;

+                    try {

+                        contentID = URLDecoder.decode(contentID, charEnc);

+                    } catch (UnsupportedEncodingException e) {

+                        throw new OMException("Unsupported Character Encoding Found", e);

+                    }

+                } else if (!(contentIDName.equalsIgnoreCase("href")

+                        & (!contentID.equals("")))) {

+                    throw new OMException(

+                            "contentID not Found in XOP:Include element");

+                }

+            } else {

+                throw new OMException(

+                        "Href attribute not found in XOP:Include element");

+            }

+

+            // This cannot happen. XOP:Include is always the only child of an parent element

+            // cause it is same as having some text

+            try {

+                OMElement e = (OMElement) lastNode;

+                //node = new OMTextImpl(contentID, (OMElement) lastNode, this);

+                node = this.omfactory.createText(contentID, (OMElement) lastNode, this);

+                e.setFirstChild(node);

+            } catch (ClassCastException e) {

+                throw new OMException(

+                        "Last Node & Parent of an OMText should be an Element" +

+                                e);

+            }

+

+            return node;

+

+        } else {

+            OMElement node;

+            if (lastNode == null) {

+                node = constructNode(null, elementName, true);

+                setSOAPEnvelope(node);

+            } else if (lastNode.isComplete()) {

+                node =

+                        constructNode((OMElement) lastNode.getParent(),

+                                elementName,

+                                false);

+                ((OMNodeEx)lastNode).setNextOMSibling(node);

+                ((OMNodeEx)node).setPreviousOMSibling(lastNode);

+            } else {

+                OMElement e = (OMElement) lastNode;

+                node = constructNode((OMElement) lastNode, elementName, false);

+                e.setFirstChild(node);

+            }

+

+            // fill in the attributes

+            processAttributes(node);

+            //TODO Exception when trying to log . check this

+            //			log.info("Build the OMElelment {" + node.getLocalName() + '}'

+            //					+ node.getLocalName() + "By the StaxSOAPModelBuilder");

+            return node;

+        }

+    }

+

+    public DataHandler getDataHandler(String blobContentID) throws OMException {

+        return mimeHelper.getDataHandler(blobContentID);

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java b/src/org/apache/ws/commons/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java
new file mode 100644
index 0000000..5c00843
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java
@@ -0,0 +1,234 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.serialize;

+

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+import org.xml.sax.Attributes;

+import org.xml.sax.ContentHandler;

+import org.xml.sax.Locator;

+import org.xml.sax.SAXException;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+

+/**

+ * Class StreamWriterToContentHandlerConverter

+ */

+public class StreamWriterToContentHandlerConverter implements ContentHandler {

+    /**

+     * Field log

+     */

+    private Log log = LogFactory.getLog(getClass());

+

+    /**

+     * Field writer

+     */

+    private XMLStreamWriter writer;

+

+    /**

+     * Constructor StreamWriterToContentHandlerConverter.

+     *

+     * @param omOutput

+     */

+    public StreamWriterToContentHandlerConverter(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) {

+        this.writer = omOutput.getXmlStreamWriter();

+    }

+

+    /**

+     * Method endDocument.

+     *

+     * @throws SAXException

+     */

+    public void endDocument() throws SAXException {

+

+        // do nothing

+    }

+

+    /**

+     * Method startDocument.

+     *

+     * @throws SAXException

+     */

+    public void startDocument() throws SAXException {

+

+        // 

+    }

+

+    /**

+     * Method characters.

+     *

+     * @param ch

+     * @param start

+     * @param length

+     * @throws SAXException

+     */

+    public void characters(char ch[], int start, int length)

+            throws SAXException {

+        try {

+            writer.writeCharacters(ch, start, length);

+        } catch (XMLStreamException e) {

+            throw new SAXException(e);

+        }

+    }

+

+    /**

+     * Method ignorableWhitespace.

+     *

+     * @param ch

+     * @param start

+     * @param length

+     * @throws SAXException

+     */

+    public void ignorableWhitespace(char ch[], int start, int length)

+            throws SAXException {

+

+        // throw new UnsupportedOperationException();

+    }

+

+    /**

+     * Method endPrefixMapping.

+     *

+     * @param prefix

+     * @throws SAXException

+     */

+    public void endPrefixMapping(String prefix) throws SAXException {

+

+        // throw new UnsupportedOperationException();

+    }

+

+    /**

+     * Method skippedEntity.

+     *

+     * @param name

+     * @throws SAXException

+     */

+    public void skippedEntity(String name) throws SAXException {

+

+        // throw new UnsupportedOperationException();

+    }

+

+    /**

+     * Method setDocumentLocator.

+     *

+     * @param locator

+     */

+    public void setDocumentLocator(Locator locator) {

+

+        // throw new UnsupportedOperationException();

+    }

+

+    /**

+     * Method processingInstruction.

+     *

+     * @param target

+     * @param data

+     * @throws SAXException

+     */

+    public void processingInstruction(String target, String data)

+            throws SAXException {

+

+        // throw new UnsupportedOperationException();

+    }

+

+    /**

+     * Method startPrefixMapping.

+     *

+     * @param prefix

+     * @param uri

+     * @throws SAXException

+     */

+    public void startPrefixMapping(String prefix, String uri)

+            throws SAXException {

+        try {

+            writer.writeNamespace(prefix, uri);

+            writer.setPrefix(prefix, uri);

+        } catch (XMLStreamException e) {

+            throw new SAXException(e);

+        }

+    }

+

+    /**

+     * Method endElement.

+     *

+     * @param namespaceURI

+     * @param localName

+     * @param qName

+     * @throws SAXException

+     */

+    public void endElement(String namespaceURI,

+                           String localName,

+                           String qName)

+            throws SAXException {

+        try {

+            writer.writeEndElement();

+        } catch (XMLStreamException e) {

+            throw new SAXException(e);

+        }

+    }

+

+    /**

+     * Method getPrefix.

+     *

+     * @param qName

+     * @return Returns String.

+     */

+    private String getPrefix(String qName) {

+        if (qName != null) {

+            return qName.substring(0, qName.indexOf(":"));

+        }

+        return null;

+    }

+

+    /**

+     * Method startElement.

+     *

+     * @param namespaceURI

+     * @param localName

+     * @param qName

+     * @param atts

+     * @throws SAXException

+     */

+    public void startElement(String namespaceURI,

+                             String localName,

+                             String qName,

+                             Attributes atts)

+            throws SAXException {

+        try {

+            log.info("writing element {" + namespaceURI + '}' + localName

+                    + " directly to stream ");

+            String prefix = getPrefix(qName);

+

+            // it is only the prefix we want to learn from the QName! so we can get rid of the

+            // spliting QName

+            if (prefix == null) {

+                writer.writeStartElement(namespaceURI, localName);

+            } else {

+                writer.writeStartElement(prefix, localName, namespaceURI);

+            }

+            if (atts != null) {

+                int attCount = atts.getLength();

+                for (int i = 0; i < attCount; i++) {

+                    writer.writeAttribute(atts.getURI(i), localName,

+                            atts.getValue(i));

+                }

+            }

+        } catch (XMLStreamException e) {

+            throw new SAXException(e);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/serialize/StreamingOMSerializer.java b/src/org/apache/ws/commons/om/impl/llom/serialize/StreamingOMSerializer.java
new file mode 100644
index 0000000..d8948cc
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/serialize/StreamingOMSerializer.java
@@ -0,0 +1,248 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.serialize;

+

+import org.apache.ws.commons.om.OMSerializer;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+

+import javax.xml.stream.XMLStreamConstants;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+

+/**

+ * Class StreamingOMSerializer

+ */

+public class StreamingOMSerializer implements XMLStreamConstants, OMSerializer {

+

+    /*

+     * The behavior of the serializer is such that it returns when it encounters the

+     * starting element for the second time. The depth variable tracks the depth of the

+     * serilizer and tells it when to return.

+     * Note that it is assumed that this serialization starts on an Element.

+     */

+

+    /**

+     * Field depth

+     */

+    private int depth = 0;

+

+    /**

+     * Method serialize.

+     *

+     * @param node

+     * @param writer

+     * @throws XMLStreamException

+     */

+    public void serialize(XMLStreamReader node, XMLStreamWriter writer)

+            throws XMLStreamException {

+        serializeNode(node, new OMOutputImpl(writer));

+    }

+

+    /**

+     * Method serialize.

+     *

+     * @param obj

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    public void serialize(XMLStreamReader obj, OMOutputImpl omOutput)

+            throws XMLStreamException {

+        XMLStreamReader node = obj;

+        serializeNode(node, omOutput);

+    }

+

+    /**

+     * Method serializeNode.

+     *

+     * @param reader

+     * @param omOutput

+     * @throws XMLStreamException

+     */

+    protected void serializeNode(XMLStreamReader reader, OMOutputImpl omOutput)

+            throws XMLStreamException {

+        //TODO We get the StAXWriter at this point and uses it hereafter assuming that this is the only entry point to this class.

+        // If there can be other classes calling methodes of this we might need to change methode signatures to OMOutputer

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        while (reader.hasNext()) {

+            int event = reader.next();

+            if (event == START_ELEMENT) {

+                serializeElement(reader, writer);

+                depth++;

+            } else if (event == ATTRIBUTE) {

+                serializeAttributes(reader, writer);

+            } else if (event == CHARACTERS) {

+                serializeText(reader, writer);

+            } else if (event == COMMENT) {

+                serializeComment(reader, writer);

+            } else if (event == CDATA) {

+                serializeCData(reader, writer);

+            } else if (event == END_ELEMENT) {

+                serializeEndElement(writer);

+                depth--;

+            } else if (event == END_DOCUMENT) {

+                try {

+                    serializeEndElement(writer);

+                } catch (Exception e) {

+                    //TODO: log exceptions

+                }

+            }

+            if (depth == 0) {

+                break;

+            }

+        }

+    }

+

+    /**

+     * @param reader

+     * @param writer

+     * @throws XMLStreamException

+     */

+    protected void serializeElement(XMLStreamReader reader,

+                                    XMLStreamWriter writer)

+            throws XMLStreamException {

+        String prefix = reader.getPrefix();

+        String nameSpaceName = reader.getNamespaceURI();

+        if (nameSpaceName != null) {

+            String writer_prefix = writer.getPrefix(nameSpaceName);

+            if (writer_prefix != null) {

+                writer.writeStartElement(nameSpaceName, reader.getLocalName());

+            } else {

+                if (prefix != null) {

+                    writer.writeStartElement(prefix, reader.getLocalName(),

+                            nameSpaceName);

+                    writer.writeNamespace(prefix, nameSpaceName);

+                    writer.setPrefix(prefix, nameSpaceName);

+                } else {

+                    writer.writeStartElement(nameSpaceName,

+                            reader.getLocalName());

+                    writer.writeDefaultNamespace(nameSpaceName);

+                    writer.setDefaultNamespace(nameSpaceName);

+                }

+            }

+        } else {

+            writer.writeStartElement(reader.getLocalName());

+        }

+

+        // add attributes

+        serializeAttributes(reader, writer);

+

+        // add the namespaces

+        int count = reader.getNamespaceCount();

+        String namespacePrefix;

+        for (int i = 0; i < count; i++) {

+            namespacePrefix = reader.getNamespacePrefix(i);

+            if(namespacePrefix != null && namespacePrefix.length()==0)

+                continue;

+            

+            serializeNamespace(namespacePrefix,

+                    reader.getNamespaceURI(i), writer);

+        }

+    }

+

+    /**

+     * Method serializeEndElement.

+     *

+     * @param writer

+     * @throws XMLStreamException

+     */

+    protected void serializeEndElement(XMLStreamWriter writer)

+            throws XMLStreamException {

+        writer.writeEndElement();

+    }

+

+    /**

+     * @param reader

+     * @param writer

+     * @throws XMLStreamException

+     */

+    protected void serializeText(XMLStreamReader reader,

+                                 XMLStreamWriter writer)

+            throws XMLStreamException {

+        writer.writeCharacters(reader.getText());

+    }

+

+    /**

+     * Method serializeCData.

+     *

+     * @param reader

+     * @param writer

+     * @throws XMLStreamException

+     */

+    protected void serializeCData(XMLStreamReader reader,

+                                  XMLStreamWriter writer)

+            throws XMLStreamException {

+        writer.writeCData(reader.getText());

+    }

+

+    /**

+     * Method serializeComment.

+     *

+     * @param reader

+     * @param writer

+     * @throws XMLStreamException

+     */

+    protected void serializeComment(XMLStreamReader reader,

+                                    XMLStreamWriter writer)

+            throws XMLStreamException {

+        writer.writeComment(reader.getText());

+    }

+

+    /**

+     * @param reader

+     * @param writer

+     * @throws XMLStreamException

+     */

+    protected void serializeAttributes(XMLStreamReader reader,

+                                       XMLStreamWriter writer)

+            throws XMLStreamException {

+        int count = reader.getAttributeCount();

+        String prefix = null;

+        String namespaceName = null;

+        for (int i = 0; i < count; i++) {

+            prefix = reader.getAttributePrefix(i);

+            namespaceName = reader.getAttributeNamespace(i);

+            if ((prefix != null) && !namespaceName.equals("")) {

+                writer.writeAttribute(prefix, namespaceName,

+                        reader.getAttributeLocalName(i),

+                        reader.getAttributeValue(i));

+            } else {

+                writer.writeAttribute(reader.getAttributeLocalName(i),

+                        reader.getAttributeValue(i));

+            }

+        }

+    }

+

+    /**

+     * Method serializeNamespace.

+     *

+     * @param prefix

+     * @param URI

+     * @param writer

+     * @throws XMLStreamException

+     */

+    private void serializeNamespace(String prefix,

+                                    String URI,

+                                    XMLStreamWriter writer)

+            throws XMLStreamException {

+        String prefix1 = writer.getPrefix(URI);

+        if (prefix1 == null) {

+            writer.writeNamespace(prefix, URI);

+            writer.setPrefix(prefix, URI);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildElementIterator.java b/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildElementIterator.java
new file mode 100644
index 0000000..e89379c
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildElementIterator.java
@@ -0,0 +1,120 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.traverse;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+

+import java.util.Iterator;

+

+public class OMChildElementIterator implements Iterator {

+

+    /**

+     * Field currentChild

+     */

+    protected OMNode currentChild;

+

+    /**

+     * Field lastChild

+     */

+    protected OMNode lastChild;

+

+    /**

+     * Field nextCalled

+     */

+    protected boolean nextCalled = false;

+

+    /**

+     * Field removeCalled

+     */

+    protected boolean removeCalled = false;

+

+    /**

+     * Constructor OMChildrenIterator.

+     *

+     * @param currentChild

+     */

+    public OMChildElementIterator(OMElement currentChild) {

+        this.currentChild = currentChild;

+    }

+

+    /**

+     * Removes the last element returned by the iterator (optional operation) 

+     * from the underlying collection. This method can be called only once per

+     * call to <tt>next</tt>.  The behavior of an iterator is unspecified if

+     * the underlying collection is modified while the iteration is in

+     * progress in any way other than by calling this method.

+     *

+     * @throws UnsupportedOperationException if the <tt>remove</tt>

+     *                                       operation is not supported by this Iterator.

+     * @throws IllegalStateException         if the <tt>next</tt> method has not

+     *                                       yet been called, or the <tt>remove</tt> method has already

+     *                                       been called after the last call to the <tt>next</tt>

+     *                                       method.

+     */

+    public void remove() {

+        if (!nextCalled) {

+            throw new IllegalStateException(

+                    "next method has not yet being called");

+        }

+        if (removeCalled) {

+            throw new IllegalStateException("remove has already being called");

+        }

+        removeCalled = true;

+

+        // since this acts on the last child there is no need to mess with the current child

+        if (lastChild == null) {

+            throw new OMException("cannot remove a child at this stage!");

+        }

+        lastChild.detach();

+    }

+

+    /**

+     * Returns <tt>true</tt> if the iteration has more elements. (In other

+     * words, returns <tt>true</tt> if <tt>next</tt> would return an element

+     * rather than throwing an exception.)

+     *

+     * @return Returns <tt>true</tt> if the iterator has more elements.

+     */

+    public boolean hasNext() {

+        return (currentChild != null);

+    }

+

+    /**

+     * Returns the next element in the iteration.

+     *

+     * @return Returns the next element in the iteration.

+     * @throws java.util.NoSuchElementException

+     *          iteration has no more elements.

+     */

+    public Object next() {

+        nextCalled = true;

+        removeCalled = false;

+

+        if (hasNext()) {

+            lastChild = currentChild;

+            do{

+                currentChild = currentChild.getNextOMSibling();

+            }while(currentChild!=null && currentChild.getType()!=OMNode.ELEMENT_NODE);

+

+

+            return lastChild;

+        }

+        return null;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenIterator.java b/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenIterator.java
new file mode 100644
index 0000000..b528b8c
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenIterator.java
@@ -0,0 +1,116 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.traverse;

+

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+

+import java.util.Iterator;

+

+/**

+ * Class OMChildrenIterator

+ */

+public class OMChildrenIterator implements Iterator {

+    /**

+     * Field currentChild

+     */

+    protected OMNode currentChild;

+

+    /**

+     * Field lastChild

+     */

+    protected OMNode lastChild;

+

+    /**

+     * Field nextCalled

+     */

+    protected boolean nextCalled = false;

+

+    /**

+     * Field removeCalled

+     */

+    protected boolean removeCalled = false;

+

+    /**

+     * Constructor OMChildrenIterator.

+     *

+     * @param currentChild

+     */

+    public OMChildrenIterator(OMNode currentChild) {

+        this.currentChild = currentChild;

+    }

+

+    /**

+     * Removes the last element returned by the iterator (optional operation) 

+     * from the underlying collection.   This method must be called only once per

+     * call to <tt>next</tt>.  The behavior of an iterator is unspecified if

+     * the underlying collection is modified while the iteration is in

+     * progress in any way other than by calling this method.

+     *

+     * @throws UnsupportedOperationException if the <tt>remove</tt>

+     *                                       operation is not supported by this Iterator.

+     * @throws IllegalStateException         if the <tt>next</tt> method has not

+     *                                       yet been called, or the <tt>remove</tt> method has already

+     *                                       been called after the last call to the <tt>next</tt>

+     *                                       method.

+     */

+    public void remove() {

+        if (!nextCalled) {

+            throw new IllegalStateException(

+                    "next method has not yet being called");

+        }

+        if (removeCalled) {

+            throw new IllegalStateException("remove has already being called");

+        }

+        removeCalled = true;

+

+        // since this acts on the last child there is no need to mess with the current child

+        if (lastChild == null) {

+            throw new OMException("cannot remove a child at this stage!");

+        }

+        lastChild.detach();

+    }

+

+    /**

+     * Returns <tt>true</tt> if the iteration has more elements. (In other

+     * words, returns <tt>true</tt> if <tt>next</tt> would return an element

+     * rather than throwing an exception.)

+     *

+     * @return Returns <tt>true</tt> if the iterator has more elements.

+     */

+    public boolean hasNext() {

+        return (currentChild != null);

+    }

+

+    /**

+     * Returns the next element in the iteration.

+     *

+     * @return Returns the next element in the iteration.

+     * @throws java.util.NoSuchElementException

+     *          iteration has no more elements.

+     */

+    public Object next() {

+        nextCalled = true;

+        removeCalled = false;

+        if (hasNext()) {

+            lastChild = currentChild;

+            currentChild = currentChild.getNextOMSibling();

+            return lastChild;

+        }

+        return null;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenQNameIterator.java b/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenQNameIterator.java
new file mode 100644
index 0000000..ddc8d93
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenQNameIterator.java
@@ -0,0 +1,141 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.traverse;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNode;

+

+import javax.xml.namespace.QName;

+

+/**

+ * Class OMChildrenQNameIterator

+ */

+public class OMChildrenQNameIterator extends OMChildrenIterator {

+    /**

+     * Field givenQName

+     */

+    private QName givenQName;

+

+    /**

+     * Field needToMoveForward

+     */

+    private boolean needToMoveForward = true;

+

+    /**

+     * Field isMatchingNodeFound

+     */

+    private boolean isMatchingNodeFound = false;

+

+    /**

+     * Constructor OMChildrenQNameIterator.

+     *

+     * @param currentChild

+     * @param givenQName

+     */

+    public OMChildrenQNameIterator(OMNode currentChild, QName givenQName) {

+        super(currentChild);

+        this.givenQName = givenQName;

+    }

+

+    /**

+     * Returns <tt>true</tt> if the iteration has more elements. (In other

+     * words, returns <tt>true</tt> if <tt>next</tt> would return an element

+     * rather than throwing an exception.)

+     *

+     * @return Returns <tt>true</tt> if the iterator has more elements.

+     */

+    public boolean hasNext() {

+        while (needToMoveForward) {

+            if (currentChild != null) {

+

+                // check the current node for the criteria

+                if ((currentChild instanceof OMElement)

+                        && (isQNamesMatch(

+                                ((OMElement) currentChild).getQName(),

+                                this.givenQName))) {

+                    isMatchingNodeFound = true;

+                    needToMoveForward = false;

+                } else {

+

+                    // get the next named node

+                    currentChild = currentChild.getNextOMSibling();

+                    isMatchingNodeFound = needToMoveForward = !(currentChild

+                            == null);

+                }

+            } else {

+                needToMoveForward = false;

+            }

+        }

+        return isMatchingNodeFound;

+    }

+

+    /**

+     * Returns the next element in the iteration.

+     *

+     * @return Returns the next element in the iteration.

+     * @throws java.util.NoSuchElementException

+     *          iteration has no more elements.

+     */

+    public Object next() {

+

+        // reset the flags

+        needToMoveForward = true;

+        isMatchingNodeFound = false;

+        nextCalled = true;

+        removeCalled = false;

+        lastChild = currentChild;

+        currentChild = currentChild.getNextOMSibling();

+        return lastChild;

+    }

+

+    /**

+     * Cannot use the overridden equals method of QName, as one might want to get

+     * some element just by giving the localname, even though a matching element 

+     * has a namespace uri as well.

+     * This is not supported in the equals method of the QName.

+     *

+     * @param elementQName

+     * @param qNameToBeMatched

+     * @return Returns boolean.

+     */

+    private boolean isQNamesMatch(QName elementQName, QName qNameToBeMatched) {

+

+        // if no QName was given, that means user is asking for all

+        if (qNameToBeMatched == null) {

+            return true;

+        }

+

+        // if the given localname is null, whatever value this.qname has, its a match. But can one give a QName without a localName ??

+        boolean localNameMatch =

+                (qNameToBeMatched.getLocalPart() == null)

+                || (qNameToBeMatched.getLocalPart() == "")

+                ||

+                ((elementQName != null)

+                &&

+                elementQName.getLocalPart().equalsIgnoreCase(

+                        qNameToBeMatched.getLocalPart()));

+        boolean namespaceURIMatch =

+                (qNameToBeMatched.getNamespaceURI() == null)

+                || (qNameToBeMatched.getNamespaceURI() == "")

+                ||

+                ((elementQName != null)

+                &&

+                elementQName.getNamespaceURI().equalsIgnoreCase(

+                        qNameToBeMatched.getNamespaceURI()));

+        return localNameMatch && namespaceURIMatch;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java b/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java
new file mode 100644
index 0000000..577985e
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java
@@ -0,0 +1,118 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.traverse;

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNode;

+

+import javax.xml.namespace.QName;

+

+/**

+ * Class OMChildrenWithSpecificAttributeIterator

+ */

+public class OMChildrenWithSpecificAttributeIterator

+        extends OMChildrenIterator {

+    /**

+     * Field attributeName

+     */

+    private QName attributeName;

+

+    /**

+     * Field attributeValue

+     */

+    private String attributeValue;

+

+    /**

+     * Field detach

+     */

+    private boolean detach;

+

+    /**

+     * Constructor OMChildrenWithSpecificAttributeIterator.

+     *

+     * @param currentChild

+     * @param attributeName

+     * @param attributeValue

+     * @param detach

+     */

+    public OMChildrenWithSpecificAttributeIterator(OMNode currentChild,

+                                                   QName attributeName,

+                                                   String attributeValue,

+                                                   boolean detach) {

+        super(currentChild);

+        this.attributeName = attributeName;

+        this.attributeValue = attributeValue;

+        this.detach = detach;

+    }

+

+    /**

+     * Method hasNext.

+     *

+     * @return Returns boolean.

+     */

+    public boolean hasNext() {

+

+        // First check whether we have a child, using the super class

+        if (currentChild == null) {

+            return false;

+        }

+        boolean isMatchingNodeFound = false;

+        boolean needToMoveForward = true;

+

+        // now we have a child to check. If its an OMElement and matches the criteria, then we are done

+        while (needToMoveForward) {

+

+            // check the current node for the criteria

+            if (currentChild instanceof OMElement) {

+                OMAttribute attr =

+                        ((OMElement) currentChild).getAttribute(

+                                attributeName);

+                if ((attr != null)

+                        && attr.getAttributeValue().equalsIgnoreCase(attributeValue)) {

+                    isMatchingNodeFound = true;

+                    needToMoveForward = false;

+                } else {

+                    currentChild = currentChild.getNextOMSibling();

+                    needToMoveForward = !(currentChild == null);

+                }

+            } else {

+

+                // get the next named node

+                currentChild = currentChild.getNextOMSibling();

+                needToMoveForward = !(currentChild == null);

+            }

+        }

+        return isMatchingNodeFound;

+    }

+

+    /**

+     * Method next.

+     *

+     * @return Returns Object.

+     */

+    public Object next() {

+        nextCalled = true;

+        removeCalled = false;

+        lastChild = currentChild;

+        currentChild = currentChild.getNextOMSibling();

+        if ((lastChild != null) && detach && lastChild.getParent() != null) {

+            lastChild.detach();

+        }

+        return lastChild;

+    }

+}

diff --git a/src/org/apache/ws/commons/om/impl/llom/util/EmptyIterator.java b/src/org/apache/ws/commons/om/impl/llom/util/EmptyIterator.java
new file mode 100644
index 0000000..7206a8a
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/util/EmptyIterator.java
@@ -0,0 +1,35 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.util;

+

+import java.util.Iterator;

+

+public class EmptyIterator implements Iterator {

+    public void remove() {

+        throw new UnsupportedOperationException();

+

+    }

+

+    public boolean hasNext() {

+        return false;

+    }

+

+    public Object next() {

+        throw new UnsupportedOperationException();

+    }

+}

+

diff --git a/src/org/apache/ws/commons/om/impl/llom/util/XMLComparator.java b/src/org/apache/ws/commons/om/impl/llom/util/XMLComparator.java
new file mode 100644
index 0000000..d697a87
--- /dev/null
+++ b/src/org/apache/ws/commons/om/impl/llom/util/XMLComparator.java
@@ -0,0 +1,222 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.util;

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.impl.llom.exception.XMLComparisonException;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+import java.util.Iterator;

+import java.util.Vector;

+

+public class XMLComparator {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    private Log log = LogFactory.getLog(getClass());

+

+    private Vector ignorableNamespaceList = new Vector();

+

+    public void addIgnorableNamespace(String nsURI){

+        ignorableNamespaceList.add(nsURI);

+    }

+

+    public void clearIgnorableNamespaces(){

+        ignorableNamespaceList.clear();

+    }

+

+

+    public boolean compare(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {

+

+        //ignore if the elements belong to any of the ignorable namespaces list

+        if (isIgnorable(elementOne) ||

+                isIgnorable(elementTwo)){

+            return true;

+        }

+

+        if (elementOne == null && elementTwo == null) {

+            log.info("Both Elements are null.");

+            return true;

+        }

+        if (elementOne == null && elementTwo != null) {

+            throw new XMLComparisonException(

+                    "Element One is null and Element Two is not null");

+        }

+        if (elementOne != null && elementTwo == null) {

+            throw new XMLComparisonException(

+                    "Element Two is null and Element One is not null");

+        }

+

+        log.info(

+                "Now Checking " + elementOne.getLocalName() + " and " +

+                elementTwo.getLocalName() +

+                "=============================");

+

+        log.info("Comparing Element Names .......");

+        compare("Elements names are not equal. ",

+                elementOne.getLocalName(),

+                elementTwo.getLocalName());

+

+        log.info("Comparing Namespaces .........");

+        compare("Element namespaces are not equal",

+                elementOne.getNamespace(),

+                elementTwo.getNamespace());

+

+        log.info("Comparing attributes .....");

+        compareAllAttributes(elementOne, elementTwo);

+

+        log.info("Comparing texts .....");

+

+        /*

+        * Trimming the value of the XMLElement is not correct

+        * since this compare method cannot be used to compare

+        * element contents with trailing and leading whitespaces

+        * BUT for the practicalltiy of tests and to get the current

+        * tests working we have to trim() the contents

+        */

+        compare("Elements texts are not equal ",

+                elementOne.getText().trim(),

+                elementTwo.getText().trim());

+

+        log.info("Comparing Children ......");

+        compareAllChildren(elementOne, elementTwo);

+

+

+        return true;

+    }

+

+    private void compareAllAttributes(OMElement elementOne,

+                                      OMElement elementTwo) throws XMLComparisonException {

+        compareAttibutes(elementOne, elementTwo);

+        compareAttibutes(elementTwo, elementOne);

+    }

+

+    private void compareAllChildren(OMElement elementOne,

+                                    OMElement elementTwo) throws XMLComparisonException {

+        compareChildren(elementOne, elementTwo);

+        compareChildren(elementTwo, elementOne);

+    }

+

+

+    private boolean isIgnorable(OMElement elt){

+        if (elt!=null){

+            OMNamespace namespace = elt.getNamespace();

+            if (namespace!=null){

+            return ignorableNamespaceList.contains(namespace.getName());

+            }else{

+                return false; 

+            }

+        }else{

+            return false;

+        }

+    }

+

+

+    private void compareChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {

+        //ignore if the elements belong to any of the ignorable namespaces list

+        if (isIgnorable(elementOne) ||

+                isIgnorable(elementTwo)){

+            return ;

+        }

+        Iterator elementOneChildren = elementOne.getChildren();

+        while (elementOneChildren.hasNext()) {

+            OMNode omNode = (OMNode) elementOneChildren.next();

+            if (omNode instanceof OMElement) {

+                OMElement elementOneChild = (OMElement) omNode;

+                OMElement elementTwoChild = null;

+                //Do the comparison only if the element is not ignorable

+                if (!isIgnorable(elementOneChild)){

+                    elementTwoChild = elementTwo.getFirstChildWithName(

+                            elementOneChild.getQName());

+                    //Do the comparison only if the element is not ignorable

+                    if (!isIgnorable(elementTwoChild)){

+                        if (elementTwoChild == null) {

+                            throw new XMLComparisonException(

+                                    " There is no " + elementOneChild.getLocalName() +

+                                    " element under " +

+                                    elementTwo.getLocalName());

+                        }

+                    }

+                }

+                compare(elementOneChild, elementTwoChild);

+            }

+        }

+    }

+

+

+    private void compareAttibutes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {

+        int elementOneAtribCount = 0;

+        int elementTwoAtribCount = 0;

+        Iterator attributes = elementOne.getAllAttributes();

+        while (attributes.hasNext()) {

+            OMAttribute omAttribute = (OMAttribute) attributes.next();

+            OMAttribute attr = elementTwo.getAttribute(

+                    omAttribute.getQName());

+            if (attr == null) {

+                throw new XMLComparisonException(

+                        "Attributes are not the same in two elements. Attribute " +

+                        omAttribute.getLocalName() +

+                        " != ");

+            }

+            elementOneAtribCount++;

+        }

+

+        Iterator elementTwoIter = elementTwo.getAllAttributes();

+        while (elementTwoIter.hasNext()) {

+            elementTwoIter.next();

+            elementTwoAtribCount++;

+

+        }

+

+        if (elementOneAtribCount != elementTwoAtribCount) {

+            throw new XMLComparisonException(

+                    "Attributes are not the same in two elements.");

+        }

+    }

+

+    private void compare(String failureNotice, String one, String two) throws XMLComparisonException {

+        if (!one.equals(two)) {

+            throw new XMLComparisonException(

+                    failureNotice + one + " != " + two);

+        }

+    }

+

+    private void compare(String failureNotice,

+                         OMNamespace one,

+                         OMNamespace two) throws XMLComparisonException {

+        if (one == null && two == null) {

+            return;

+        } else if (one != null && two == null) {

+            throw new XMLComparisonException(

+                    "First Namespace is NOT null. But the second is null");

+        } else if (one == null && two != null) {

+            throw new XMLComparisonException(

+                    "First Namespace is null. But the second is NOT null");

+        }

+

+        if (!one.getName().equals(two.getName())) {

+            throw new XMLComparisonException(

+                    failureNotice + one + " != " + two);

+        }

+

+        // Do we need to compare prefixes as well

+    }

+}

diff --git a/src/org/apache/ws/commons/om/util/Base64.java b/src/org/apache/ws/commons/om/util/Base64.java
new file mode 100644
index 0000000..d240b83
--- /dev/null
+++ b/src/org/apache/ws/commons/om/util/Base64.java
@@ -0,0 +1,295 @@
+package org.apache.ws.commons.om.util;

+

+import java.io.OutputStream;

+import java.io.IOException;

+import java.io.Writer;

+

+/*

+ * Copyright 2001-2004 The Apache Software Foundation.

+ *

+ * Licensed 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.

+ *

+ */

+

+public class Base64 {

+    private static final char[] S_BASE64CHAR = {'A', 'B', 'C', 'D', 'E', 'F',

+            'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',

+            'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',

+            'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',

+            't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',

+            '6', '7', '8', '9', '+', '/'};

+

+    private static final char S_BASE64PAD = '=';

+

+    private static final byte[] S_DECODETABLE = new byte[128];

+

+    static {

+        for (int i = 0; i < S_DECODETABLE.length; i++)

+            S_DECODETABLE[i] = Byte.MAX_VALUE; // 127

+        for (int i = 0; i < S_BASE64CHAR.length; i++)

+            // 0 to 63

+            S_DECODETABLE[S_BASE64CHAR[i]] = (byte) i;

+    }

+

+    private static int decode0(char[] ibuf, byte[] obuf, int wp) {

+        int outlen = 3;

+        if (ibuf[3] == S_BASE64PAD)

+            outlen = 2;

+        if (ibuf[2] == S_BASE64PAD)

+            outlen = 1;

+        int b0 = S_DECODETABLE[ibuf[0]];

+        int b1 = S_DECODETABLE[ibuf[1]];

+        int b2 = S_DECODETABLE[ibuf[2]];

+        int b3 = S_DECODETABLE[ibuf[3]];

+        switch (outlen) {

+            case 1:

+                obuf[wp] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);

+                return 1;

+            case 2:

+                obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);

+                obuf[wp] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);

+                return 2;

+            case 3:

+                obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);

+                obuf[wp++] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);

+                obuf[wp] = (byte) (b2 << 6 & 0xc0 | b3 & 0x3f);

+                return 3;

+            default:

+                throw new RuntimeException("internalError00");

+        }

+    }

+

+    /**

+     *

+     */

+    public static byte[] decode(char[] data, int off, int len) {

+        char[] ibuf = new char[4];

+        int ibufcount = 0;

+        byte[] obuf = new byte[len / 4 * 3 + 3];

+        int obufcount = 0;

+        for (int i = off; i < off + len; i++) {

+            char ch = data[i];

+            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length

+                    && S_DECODETABLE[ch] != Byte.MAX_VALUE) {

+                ibuf[ibufcount++] = ch;

+                if (ibufcount == ibuf.length) {

+                    ibufcount = 0;

+                    obufcount += decode0(ibuf, obuf, obufcount);

+                }

+            }

+        }

+        if (obufcount == obuf.length)

+            return obuf;

+        byte[] ret = new byte[obufcount];

+        System.arraycopy(obuf, 0, ret, 0, obufcount);

+        return ret;

+    }

+

+    /**

+     *

+     */

+    public static byte[] decode(String data) {

+        char[] ibuf = new char[4];

+        int ibufcount = 0;

+        byte[] obuf = new byte[data.length() / 4 * 3 + 3];

+        int obufcount = 0;

+        for (int i = 0; i < data.length(); i++) {

+            char ch = data.charAt(i);

+            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length

+                    && S_DECODETABLE[ch] != Byte.MAX_VALUE) {

+                ibuf[ibufcount++] = ch;

+                if (ibufcount == ibuf.length) {

+                    ibufcount = 0;

+                    obufcount += decode0(ibuf, obuf, obufcount);

+                }

+            }

+        }

+        if (obufcount == obuf.length)

+            return obuf;

+        byte[] ret = new byte[obufcount];

+        System.arraycopy(obuf, 0, ret, 0, obufcount);

+        return ret;

+    }

+

+    /**

+     *

+     */

+    public static void decode(char[] data, int off, int len,

+                              OutputStream ostream) throws IOException {

+        char[] ibuf = new char[4];

+        int ibufcount = 0;

+        byte[] obuf = new byte[3];

+        for (int i = off; i < off + len; i++) {

+            char ch = data[i];

+            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length

+                    && S_DECODETABLE[ch] != Byte.MAX_VALUE) {

+                ibuf[ibufcount++] = ch;

+                if (ibufcount == ibuf.length) {

+                    ibufcount = 0;

+                    int obufcount = decode0(ibuf, obuf, 0);

+                    ostream.write(obuf, 0, obufcount);

+                }

+            }

+        }

+    }

+

+    /**

+     *

+     */

+    public static void decode(String data, OutputStream ostream)

+            throws IOException {

+        char[] ibuf = new char[4];

+        int ibufcount = 0;

+        byte[] obuf = new byte[3];

+        for (int i = 0; i < data.length(); i++) {

+            char ch = data.charAt(i);

+            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length

+                    && S_DECODETABLE[ch] != Byte.MAX_VALUE) {

+                ibuf[ibufcount++] = ch;

+                if (ibufcount == ibuf.length) {

+                    ibufcount = 0;

+                    int obufcount = decode0(ibuf, obuf, 0);

+                    ostream.write(obuf, 0, obufcount);

+                }

+            }

+        }

+    }

+

+    /**

+     * Returns base64 representation of specified byte array.

+     */

+    public static String encode(byte[] data) {

+        return encode(data, 0, data.length);

+    }

+

+    /**

+     * Returns base64 representation of specified byte array.

+     */

+    public static String encode(byte[] data, int off, int len) {

+        if (len <= 0)

+            return "";

+        char[] out = new char[len / 3 * 4 + 4];

+        int rindex = off;

+        int windex = 0;

+        int rest = len - off;

+        while (rest >= 3) {

+            int i = ((data[rindex] & 0xff) << 16)

+                    + ((data[rindex + 1] & 0xff) << 8)

+                    + (data[rindex + 2] & 0xff);

+            out[windex++] = S_BASE64CHAR[i >> 18];

+            out[windex++] = S_BASE64CHAR[(i >> 12) & 0x3f];

+            out[windex++] = S_BASE64CHAR[(i >> 6) & 0x3f];

+            out[windex++] = S_BASE64CHAR[i & 0x3f];

+            rindex += 3;

+            rest -= 3;

+        }

+        if (rest == 1) {

+            int i = data[rindex] & 0xff;

+            out[windex++] = S_BASE64CHAR[i >> 2];

+            out[windex++] = S_BASE64CHAR[(i << 4) & 0x3f];

+            out[windex++] = S_BASE64PAD;

+            out[windex++] = S_BASE64PAD;

+        } else if (rest == 2) {

+            int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);

+            out[windex++] = S_BASE64CHAR[i >> 10];

+            out[windex++] = S_BASE64CHAR[(i >> 4) & 0x3f];

+            out[windex++] = S_BASE64CHAR[(i << 2) & 0x3f];

+            out[windex++] = S_BASE64PAD;

+        }

+        return new String(out, 0, windex);

+    }

+

+    /**

+     * Outputs base64 representation of the specified byte array to a byte

+     * stream.

+     */

+    public static void encode(byte[] data, int off, int len,

+                              OutputStream ostream) throws IOException {

+        if (len <= 0)

+            return;

+        byte[] out = new byte[4];

+        int rindex = off;

+        int rest = len - off;

+        while (rest >= 3) {

+            int i = ((data[rindex] & 0xff) << 16)

+                    + ((data[rindex + 1] & 0xff) << 8)

+                    + (data[rindex + 2] & 0xff);

+            out[0] = (byte) S_BASE64CHAR[i >> 18];

+            out[1] = (byte) S_BASE64CHAR[(i >> 12) & 0x3f];

+            out[2] = (byte) S_BASE64CHAR[(i >> 6) & 0x3f];

+            out[3] = (byte) S_BASE64CHAR[i & 0x3f];

+            ostream.write(out, 0, 4);

+            rindex += 3;

+            rest -= 3;

+        }

+        if (rest == 1) {

+            int i = data[rindex] & 0xff;

+            out[0] = (byte) S_BASE64CHAR[i >> 2];

+            out[1] = (byte) S_BASE64CHAR[(i << 4) & 0x3f];

+            out[2] = (byte) S_BASE64PAD;

+            out[3] = (byte) S_BASE64PAD;

+            ostream.write(out, 0, 4);

+        } else if (rest == 2) {

+            int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);

+            out[0] = (byte) S_BASE64CHAR[i >> 10];

+            out[1] = (byte) S_BASE64CHAR[(i >> 4) & 0x3f];

+            out[2] = (byte) S_BASE64CHAR[(i << 2) & 0x3f];

+            out[3] = (byte) S_BASE64PAD;

+            ostream.write(out, 0, 4);

+        }

+    }

+

+    /**

+     * Outputs base64 representation of the specified byte array to a character

+     * stream.

+     */

+    public static void encode(byte[] data, int off, int len, Writer writer)

+            throws IOException {

+        if (len <= 0)

+            return;

+        char[] out = new char[4];

+        int rindex = off;

+        int rest = len - off;

+        int output = 0;

+        while (rest >= 3) {

+            int i = ((data[rindex] & 0xff) << 16)

+                    + ((data[rindex + 1] & 0xff) << 8)

+                    + (data[rindex + 2] & 0xff);

+            out[0] = S_BASE64CHAR[i >> 18];

+            out[1] = S_BASE64CHAR[(i >> 12) & 0x3f];

+            out[2] = S_BASE64CHAR[(i >> 6) & 0x3f];

+            out[3] = S_BASE64CHAR[i & 0x3f];

+            writer.write(out, 0, 4);

+            rindex += 3;

+            rest -= 3;

+            output += 4;

+            if (output % 76 == 0)

+                writer.write("\n");

+        }

+        if (rest == 1) {

+            int i = data[rindex] & 0xff;

+            out[0] = S_BASE64CHAR[i >> 2];

+            out[1] = S_BASE64CHAR[(i << 4) & 0x3f];

+            out[2] = S_BASE64PAD;

+            out[3] = S_BASE64PAD;

+            writer.write(out, 0, 4);

+        } else if (rest == 2) {

+            int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);

+            out[0] = S_BASE64CHAR[i >> 10];

+            out[1] = S_BASE64CHAR[(i >> 4) & 0x3f];

+            out[2] = S_BASE64CHAR[(i << 2) & 0x3f];

+            out[3] = S_BASE64PAD;

+            writer.write(out, 0, 4);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/om/util/ElementHelper.java b/src/org/apache/ws/commons/om/util/ElementHelper.java
new file mode 100644
index 0000000..8ddb306
--- /dev/null
+++ b/src/org/apache/ws/commons/om/util/ElementHelper.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.ws.commons.om.util;
+
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMNamespace;
+import org.apache.ws.commons.om.OMNode;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * Helper class to provide extra utility stuff against elements.
+ * The code is designed to work with any element implementation.
+ */
+
+public class ElementHelper {
+
+    private OMElement element;
+
+    /**
+     * Constructs and binds to an element.
+     * @param element element to work with
+     */
+    public ElementHelper(OMElement element) {
+        this.element = element;
+    }
+
+    /**
+     * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.
+     *
+     * @param qname                    qname to resolve
+     * @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
+     * @return Returns null for any failure to extract a qname.
+     */
+    public QName resolveQName(String qname, boolean defaultToParentNameSpace) {
+        int colon = qname.indexOf(':');
+        if (colon < 0) {
+            if (defaultToParentNameSpace) {
+                //get the parent ns and use it for the child
+                OMNamespace namespace = element.getNamespace();
+                return new QName(namespace.getName(), qname, namespace.getPrefix());
+            } else {
+                //else things without no prefix are local.
+                return new QName(qname);
+            }
+        }
+        String prefix = qname.substring(0, colon);
+        String local = qname.substring(colon + 1);
+        if (local.length() == 0) {
+            //empy local, exit accordingly
+            return null;
+        }
+
+        OMNamespace namespace = element.findNamespaceURI(prefix);
+        if (namespace == null) {
+            return null;
+        }
+        return new QName(namespace.getName(), local, prefix);
+    }
+
+    /**
+     * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.
+     * Unprefixed qnames resolve to the local namespace.
+     *
+     * @param qname prefixed qname string to resolve
+     * @return Returns null for any failure to extract a qname.
+     */
+    public QName resolveQName(String qname) {
+        return resolveQName(qname, true);
+    }
+
+    public static void setNewElement(OMElement parent,
+                                     OMElement myElement,
+                                     OMElement newElement) {
+        if (myElement != null) {
+            myElement.discard();
+        }
+        parent.addChild(newElement);
+        myElement = newElement;
+    }
+
+    public static OMElement getChildWithName(OMElement parent,
+                                             String childName) {
+        Iterator childrenIter = parent.getChildren();
+        while (childrenIter.hasNext()) {
+            OMNode node = (OMNode) childrenIter.next();
+            if (node.getType() == OMNode.ELEMENT_NODE &&
+                    childName.equals(((OMElement) node).getLocalName())) {
+                return (OMElement) node;
+            }
+        }
+        return null;
+    }
+}
diff --git a/src/org/apache/ws/commons/om/util/UUIDGenerator.java b/src/org/apache/ws/commons/om/util/UUIDGenerator.java
new file mode 100644
index 0000000..f3c95d6
--- /dev/null
+++ b/src/org/apache/ws/commons/om/util/UUIDGenerator.java
@@ -0,0 +1,104 @@
+package org.apache.ws.commons.om.util;

+

+/*

+ * Copyright 2001-2004 The Apache Software Foundation.

+ *

+ * Licensed 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.

+ *

+ */

+

+import java.net.InetAddress;

+import java.net.UnknownHostException;

+import java.security.MessageDigest;

+import java.security.NoSuchAlgorithmException;

+import java.util.Date;

+import java.util.Random;

+

+public class UUIDGenerator {

+    /**

+     * This class will give UUIDs for axis2.

+     */

+

+    private static String baseUUID = null;

+    private static long incrementingValue = 0;

+

+

+    private static Random myRand = null;

+

+    /**

+     * MD5 a random string with localhost/date etc will return 128 bits

+     * construct a string of 18 characters from those bits.

+     *

+     * @return string

+     */

+    public static String getUUID() {

+        if (baseUUID == null) {

+            baseUUID = getInitialUUID();

+        }

+        if (++incrementingValue >= Long.MAX_VALUE) {

+            incrementingValue = 0;

+        }

+        return "urn:uuid:" + baseUUID + new Date().getTime() + incrementingValue;

+    }

+

+    protected static String getInitialUUID() {

+        if (myRand == null) {

+            myRand = new Random();

+        }

+        long rand = myRand.nextLong();

+        String sid;

+        try {

+            sid = InetAddress.getLocalHost().toString();

+        } catch (UnknownHostException e) {

+            sid = Thread.currentThread().getName();

+        }

+        StringBuffer sb = new StringBuffer();

+        sb.append(sid);

+        sb.append(":");

+        sb.append(Long.toString(rand));

+        MessageDigest md5 = null;

+        try {

+            md5 = MessageDigest.getInstance("MD5");

+        } catch (NoSuchAlgorithmException e) {

+            //System.out.println("Error: " + e);

+            //todo heve to be properly handle

+        }

+        md5.update(sb.toString().getBytes());

+        byte[] array = md5.digest();

+        StringBuffer sb2 = new StringBuffer();

+        for (int j = 0; j < array.length; ++j) {

+            int b = array[j] & 0xFF;

+            sb2.append(Integer.toHexString(b));

+        }

+        int begin = myRand.nextInt();

+        if (begin < 0) begin = begin * -1;

+        begin = begin % 8;

+        return sb2.toString().substring(begin, begin + 18).toUpperCase();

+    }

+

+    public static void main(String[] args) {

+        long startTime = new Date().getTime();

+        for (int i = 0; i < 100000; i++) {

+            UUIDGenerator.getInitialUUID();

+        }

+        long endTime = new Date().getTime();

+        System.out.println("getInitialUUID Difference = " + (endTime - startTime));

+

+        startTime = new Date().getTime();

+        for (int i = 0; i < 100000; i++) {

+            UUIDGenerator.getUUID();

+        }

+        endTime = new Date().getTime();

+        System.out.println("getUUID Difference = " + (endTime - startTime));

+    }

+}

diff --git a/src/org/apache/ws/commons/om/util/XPathEvaluator.java b/src/org/apache/ws/commons/om/util/XPathEvaluator.java
new file mode 100644
index 0000000..35a5c82
--- /dev/null
+++ b/src/org/apache/ws/commons/om/util/XPathEvaluator.java
@@ -0,0 +1,21 @@
+package org.apache.ws.commons.om.util;

+

+import org.apache.ws.commons.om.xpath.AXIOMXPath;

+import org.jaxen.SimpleNamespaceContext;

+

+import java.util.List;

+

+public class XPathEvaluator {

+

+    public List evaluateXpath(String xpathExpression, Object element, String nsURI) throws Exception{

+        AXIOMXPath xpath = new AXIOMXPath(xpathExpression);

+        if (nsURI!=null){

+            SimpleNamespaceContext nsContext = new SimpleNamespaceContext();

+            nsContext.addNamespace(null,nsURI);

+            xpath.setNamespaceContext(nsContext);

+        }

+        return xpath.selectNodes(element);

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/om/xpath/AXIOMXPath.java b/src/org/apache/ws/commons/om/xpath/AXIOMXPath.java
new file mode 100644
index 0000000..31e091e
--- /dev/null
+++ b/src/org/apache/ws/commons/om/xpath/AXIOMXPath.java
@@ -0,0 +1,20 @@
+package org.apache.ws.commons.om.xpath;

+

+import org.jaxen.BaseXPath;

+import org.jaxen.JaxenException;

+

+public class AXIOMXPath extends BaseXPath {

+	

+    private static final long serialVersionUID = -5839161412925154639L;

+

+	/**

+     * Construct given an XPath expression string.

+     *

+     * @param xpathExpr the XPath expression.

+     * @throws org.jaxen.JaxenException if there is a syntax error while

+     *                                  parsing the expression

+     */

+    public AXIOMXPath(String xpathExpr) throws JaxenException {

+        super(xpathExpr, new DocumentNavigator());

+    }

+}

diff --git a/src/org/apache/ws/commons/om/xpath/DocumentNavigator.java b/src/org/apache/ws/commons/om/xpath/DocumentNavigator.java
new file mode 100644
index 0000000..8e3f37b
--- /dev/null
+++ b/src/org/apache/ws/commons/om/xpath/DocumentNavigator.java
@@ -0,0 +1,738 @@
+package org.apache.ws.commons.om.xpath;

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMComment;

+import org.apache.ws.commons.om.OMContainer;

+import org.apache.ws.commons.om.OMDocument;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMProcessingInstruction;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.impl.llom.OMNamespaceImpl;

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.jaxen.BaseXPath;

+import org.jaxen.DefaultNavigator;

+import org.jaxen.FunctionCallException;

+import org.jaxen.JaxenConstants;

+import org.jaxen.UnsupportedAxisException;

+import org.jaxen.XPath;

+import org.jaxen.saxpath.SAXPathException;

+import org.jaxen.util.SingleObjectIterator;

+

+import javax.xml.namespace.QName;

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.io.FileInputStream;

+import java.net.URL;

+import java.util.ArrayList;

+import java.util.HashSet;

+import java.util.Iterator;

+import java.util.List;

+

+public class DocumentNavigator extends DefaultNavigator {

+	

+    private static final long serialVersionUID = 7325116153349780805L;

+

+	/**

+     * Returns a parsed form of the given xpath string, which will be suitable

+     * for queries on documents that use the same navigator as this one.

+     *

+     * @param xpath the XPath expression

+     * @return Returns a new XPath expression object.

+     * @throws SAXPathException if the string is not a syntactically

+     *                          correct XPath expression

+     * @see XPath

+     */

+    public XPath parseXPath(String xpath) throws SAXPathException {

+        return new BaseXPath(xpath, this);

+    }

+

+    /**

+     * Retrieves the namespace URI of the given element node.

+     *

+     * @param object the context element node

+     * @return Returns the namespace URI of the element node.

+     */

+    public String getElementNamespaceUri(Object object) {

+        OMElement attr = (OMElement) object;

+        return attr.getQName().getNamespaceURI();

+    }

+

+    /**

+     * Retrieves the name of the given element node.

+     *

+     * @param object the context element node

+     * @return Returns the name of the element node.

+     */

+    public String getElementName(Object object) {

+        OMElement attr = (OMElement) object;

+        return attr.getQName().getLocalPart();

+    }

+

+    /**

+     * Retrieves the QName of the given element node.

+     *

+     * @param object the context element node

+     * @return Returns the QName of the element node.

+     */

+    public String getElementQName(Object object) {

+        OMElement attr = (OMElement) object;

+        String prefix = null;

+        if (attr.getNamespace() != null) {

+            prefix = attr.getNamespace().getPrefix();

+        }

+        if (prefix == null || "".equals(prefix)) {

+            return attr.getQName().getLocalPart();

+        }

+        return prefix + ":" + attr.getNamespace().getName();

+    }

+

+    /**

+     * Retrieves the namespace URI of the given attribute node.

+     *

+     * @param object the context attribute node

+     * @return Returns the namespace URI of the attribute node.

+     */

+    public String getAttributeNamespaceUri(Object object) {

+        OMAttribute attr = (OMAttribute) object;

+        return attr.getQName().getNamespaceURI();

+    }

+

+    /**

+     * Retrieves the name of the given attribute node.

+     *

+     * @param object the context attribute node

+     * @return Returns the name of the attribute node.

+     */

+    public String getAttributeName(Object object) {

+        OMAttribute attr = (OMAttribute) object;

+        return attr.getQName().getLocalPart();

+    }

+

+    /**

+     * Retrieves the QName of the given attribute node.

+     *

+     * @param object the context attribute node

+     * @return Returns the qualified name of the attribute node.

+     */

+    public String getAttributeQName(Object object) {

+        OMAttribute attr = (OMAttribute) object;

+        String prefix = attr.getNamespace().getPrefix();

+        if (prefix == null || "".equals(prefix)) {

+            return attr.getQName().getLocalPart();

+        }

+        return prefix + ":" + attr.getNamespace().getName();

+    }

+

+    /**

+     * Returns whether the given object is a document node. A document node

+     * is the node that is selected by the xpath expression <code>/</code>.

+     *

+     * @param object the object to test

+     * @return Returns <code>true</code> if the object is a document node,

+     *         else <code>false</code> .

+     */

+    public boolean isDocument(Object object) {

+        return object instanceof OMDocument;

+    }

+

+    /**

+     * Returns whether the given object is an element node.

+     *

+     * @param object the object to test

+     * @return Returns <code>true</code> if the object is an element node,

+     *         else <code>false</code> .

+     */

+    public boolean isElement(Object object) {

+        return object instanceof OMElement;

+    }

+

+    /**

+     * Returns whether the given object is an attribute node.

+     *

+     * @param object the object to test

+     * @return Returns <code>true</code> if the object is an attribute node,

+     *         else <code>false</code> .

+     */

+    public boolean isAttribute(Object object) {

+        return object instanceof OMAttribute;

+    }

+

+    /**

+     * Returns whether the given object is a namespace node.

+     *

+     * @param object the object to test

+     * @return Returns <code>true</code> if the object is a namespace node,

+     *         else <code>false</code> .

+     */

+    public boolean isNamespace(Object object) {

+        return object instanceof OMNamespace;

+    }

+

+    /**

+     * Returns whether the given object is a comment node.

+     *

+     * @param object the object to test

+     * @return Returns <code>true</code> if the object is a comment node,

+     *         else <code>false</code> .

+     */

+    public boolean isComment(Object object) {

+        return (object instanceof OMComment);

+    }

+

+    /**

+     * Returns whether the given object is a text node.

+     *

+     * @param object the object to test

+     * @return Returns <code>true</code> if the object is a text node,

+     *         else <code>false</code> .

+     */

+    public boolean isText(Object object) {

+        return (object instanceof OMText);

+    }

+

+    /**

+     * Returns whether the given object is a processing-instruction node.

+     *

+     * @param object the object to test

+     * @return Returns <code>true</code> if the object is a processing-instruction node,

+     *         else <code>false</code> .

+     */

+    public boolean isProcessingInstruction(Object object) {

+        return (object instanceof OMProcessingInstruction);

+    }

+

+    /**

+     * Retrieves the string-value of a comment node.

+     * This may be the empty string if the comment is empty,

+     * but must not be null.

+     *

+     * @param object the comment node

+     * @return Returns the string-value of the node.

+     */

+    public String getCommentStringValue(Object object) {

+        return ((OMComment) object).getValue();

+    }

+

+    /**

+     * Retrieves the string-value of an element node.

+     * This may be the empty string if the element is empty,

+     * but must not be null.

+     *

+     * @param object the comment node.

+     * @return Returns the string-value of the node.

+     */

+    public String getElementStringValue(Object object) {

+        if (isElement(object)) {

+            return getStringValue((OMElement) object, new StringBuffer())

+                    .toString();

+        }

+        return null;

+    }

+

+    private StringBuffer getStringValue(OMNode node, StringBuffer buffer) {

+        if (isText(node)) {

+            buffer.append(((OMText) node).getText());

+        } else if (node instanceof OMElement) {

+            Iterator children = ((OMElement) node).getChildren();

+            while (children.hasNext()) {

+                getStringValue((OMNode) children.next(), buffer);

+            }

+        }

+        return buffer;

+    }

+

+    /**

+     * Retrieves the string-value of an attribute node.

+     * This should be the XML 1.0 normalized attribute value.

+     * This may be the empty string but must not be null.

+     *

+     * @param object the attribute node

+     * @return Returns the string-value of the node.

+     */

+    public String getAttributeStringValue(Object object) {

+        return ((OMAttribute) object).getAttributeValue();

+    }

+

+    /**

+     * Retrieves the string-value of a namespace node.

+     * This is generally the namespace URI.

+     * This may be the empty string but must not be null.

+     *

+     * @param object the namespace node

+     * @return Returns the string-value of the node.

+     */

+    public String getNamespaceStringValue(Object object) {

+        return ((OMNamespace) object).getName();

+    }

+

+    /**

+     * Retrieve the string-value of a text node.

+     * This must not be null and should not be the empty string.

+     * The XPath data model does not allow empty text nodes.

+     *

+     * @param object the text node

+     * @return Returns the string-value of the node.

+     */

+    public String getTextStringValue(Object object) {

+        return ((OMText) object).getText();

+    }

+

+    /**

+     * Retrieves the namespace prefix of a namespace node.

+     *

+     * @param object the namespace node

+     * @return Returns the prefix associated with the node.

+     */

+    public String getNamespacePrefix(Object object) {

+        return ((OMNamespace) object).getPrefix();

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the <code>child</code>

+     * XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the child axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        if (contextNode instanceof OMContainer) {

+            return ((OMContainer) contextNode).getChildren();

+        }

+        return JaxenConstants.EMPTY_ITERATOR;

+    }

+

+    public Iterator getDescendantAxisIterator(Object object) throws UnsupportedAxisException {

+        //TODO: Fix this better?

+        return super.getDescendantAxisIterator(object);

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the <code>attribute</code>

+     * XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the attribute axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        if (isElement(contextNode)) {

+            ArrayList attributes = new ArrayList();

+            Iterator i = ((OMElement) contextNode).getAllAttributes();

+            while (i != null && i.hasNext()) {

+                attributes.add(

+                        new OMAttributeEx((OMAttribute) i.next(),

+                                (OMContainer) contextNode));

+            }

+            return attributes.iterator();

+        }

+        return JaxenConstants.EMPTY_ITERATOR;

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the <code>namespace</code>

+     * XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the namespace axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        if (!(contextNode instanceof OMContainer &&

+                contextNode instanceof OMElement)) {

+            return JaxenConstants.EMPTY_ITERATOR;

+        }

+        List nsList = new ArrayList();

+        HashSet prefixes = new HashSet();

+        for (OMContainer context = (OMContainer) contextNode;

+             context != null && !(context instanceof OMDocument);

+             context = ((OMElement) context).getParent()) {

+            OMElement element = (OMElement) context;

+            ArrayList declaredNS = new ArrayList();

+            Iterator i = element.getAllDeclaredNamespaces();

+            while (i != null && i.hasNext()) {

+                declaredNS.add(i.next());

+            }

+            declaredNS.add(element.getNamespace());

+            for (Iterator iter = element.getAllAttributes();

+                 iter != null && iter.hasNext();) {

+                OMAttribute attr = (OMAttribute) iter.next();

+                declaredNS.add(attr.getNamespace());

+            }

+            for (Iterator iter = declaredNS.iterator();

+                 iter != null && iter.hasNext();) {

+                OMNamespace namespace = (OMNamespace) iter.next();

+                if (namespace != null) {

+                    String prefix = namespace.getPrefix();

+                    if (prefix != null && !prefixes.contains(prefix)) {

+                        prefixes.add(prefix);

+                        nsList.add(new OMNamespaceEx(namespace, context));

+                    }

+                }

+            }

+        }

+        nsList.add(

+                new OMNamespaceEx(

+                        new OMNamespaceImpl(

+                                "http://www.w3.org/XML/1998/namespace", "xml"),

+                        (OMContainer) contextNode));

+        return nsList.iterator();

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the <code>self</code> xpath

+     * axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the self axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getSelfAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        //TODO: Fix this better?

+        return super.getSelfAxisIterator(contextNode);

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the

+     * <code>descendant-or-self</code> XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the descendant-or-self axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getDescendantOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        //TODO: Fix this better?

+        return super.getDescendantOrSelfAxisIterator(contextNode);

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the

+     * <code>ancestor-or-self</code> XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the ancestor-or-self axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getAncestorOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        //TODO: Fix this better?

+        return super.getAncestorOrSelfAxisIterator(contextNode);

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the <code>parent</code> XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the parent axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        if (contextNode instanceof OMNode) {

+            return new SingleObjectIterator(((OMNode) contextNode).getParent());

+        } else if (contextNode instanceof OMNamespaceEx) {

+            return new SingleObjectIterator(

+                    ((OMNamespaceEx) contextNode).getParent());

+        } else if (contextNode instanceof OMAttributeEx) {

+            return new SingleObjectIterator(

+                    ((OMAttributeEx) contextNode).getParent());

+        }

+        return JaxenConstants.EMPTY_ITERATOR;

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the <code>ancestor</code>

+     * XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the ancestor axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getAncestorAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        //TODO: Fix this better?

+        return super.getAncestorAxisIterator(contextNode);

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the

+     * <code>following-sibling</code> XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the following-sibling axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getFollowingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        ArrayList list = new ArrayList();

+        if (contextNode != null && contextNode instanceof OMNode) {

+            while (contextNode != null && contextNode instanceof OMNode) {

+                contextNode = ((OMNode) contextNode).getNextOMSibling();

+                if (contextNode != null)

+                    list.add(contextNode);

+            }

+        }

+        return list.iterator();

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the

+     * <code>preceding-sibling</code> XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the preceding-sibling axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getPrecedingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        ArrayList list = new ArrayList();

+        if (contextNode != null && contextNode instanceof OMNode) {

+            while (contextNode != null && contextNode instanceof OMNode) {

+                contextNode = ((OMNode) contextNode).getPreviousOMSibling();

+                if (contextNode != null)

+                    list.add(contextNode);

+            }

+        }

+        return list.iterator();

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the <code>following</code>

+     * XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the following axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getFollowingAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        //TODO: Fix this better?

+        return super.getFollowingAxisIterator(contextNode);

+    }

+

+    /**

+     * Retrieves an <code>Iterator</code> matching the <code>preceding</code> XPath axis.

+     *

+     * @param contextNode the original context node

+     * @return Returns an Iterator capable of traversing the axis, not null.

+     * @throws UnsupportedAxisException if the semantics of the preceding axis are

+     *                                  not supported by this object model

+     */

+    public Iterator getPrecedingAxisIterator(Object contextNode) throws UnsupportedAxisException {

+        //TODO: Fix this better?

+        return super.getPrecedingAxisIterator(contextNode);

+    }

+

+    /**

+     * Loads a document from the given URI.

+     *

+     * @param uri the URI of the document to load

+     * @return Returns the document.

+     * @throws FunctionCallException if the document could not be loaded

+     */

+    public Object getDocument(String uri)

+            throws FunctionCallException {

+        try {

+            XMLStreamReader parser;

+            XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();

+            xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);

+            if (uri.indexOf(':') == -1) {

+                parser = xmlInputFactory.createXMLStreamReader(

+                                new FileInputStream(uri));

+            } else {

+                URL url = new URL(uri);

+                parser = xmlInputFactory.createXMLStreamReader(

+                                url.openStream());

+            }

+            StAXOMBuilder builder =

+                    new StAXOMBuilder(parser);

+            return builder.getDocumentElement().getParent();

+        } catch (Exception e) {

+            throw new FunctionCallException(e);

+        }

+    }

+

+    /**

+     * Returns the element whose ID is given by elementId.

+     * If no such element exists, returns null.

+     * Attributes with the name "ID" are not of type ID unless so defined.

+     * Implementations that do not know whether attributes are of type ID or

+     * not are expected to return null.

+     *

+     * @param contextNode a node from the document in which to look for the

+     *                    id

+     * @param elementId   id to look for

+     * @return Returns element whose ID is given by elementId, or null if no such

+     *         element exists in the document or if the implementation

+     *         does not know about attribute types.

+     */

+    public Object getElementById(Object contextNode, String elementId) {

+        //TODO: Fix this better?

+        return super.getElementById(contextNode, elementId);

+    }

+

+    /**

+     * Returns the document node that contains the given context node.

+     *

+     * @param contextNode the context node

+     * @return Returns the document of the context node.

+     * @see #isDocument(Object)

+     */

+    public Object getDocumentNode(Object contextNode) {

+        if (contextNode instanceof OMDocument) {

+            return contextNode;

+        }

+        return getDocumentNode(((OMNode) contextNode).getParent());

+    }

+

+    /**

+     * Translates a namespace prefix to a namespace URI, <b>possibly</b>

+     * considering a particular element node.

+     * <p/>

+     * Strictly speaking, prefix-to-URI translation should occur

+     * irrespective of any element in the document.  This method

+     * is provided to allow a non-conforming ease-of-use enhancement.

+     * </p>

+     *

+     * @param prefix  the prefix to translate

+     * @param element the element to consider during translation

+     * @return Returns the namespace URI associated with the prefix.

+     */

+    public String translateNamespacePrefixToUri(String prefix, Object element) {

+        //TODO: Fix this better?

+        return super.translateNamespacePrefixToUri(prefix, element);

+    }

+

+    /**

+     * Retrieves the target of a processing-instruction.

+     *

+     * @param object the context processing-instruction node

+     * @return Returns the target of the processing-instruction node.

+     */

+    public String getProcessingInstructionTarget(Object object) {

+        return ((OMProcessingInstruction)object).getTarget();

+    }

+

+    /**

+     * Retrieves the data of a processing-instruction.

+     *

+     * @param object the context processing-instruction node

+     * @return Returns the data of the processing-instruction node.

+     */

+    public String getProcessingInstructionData(Object object) {

+        return ((OMProcessingInstruction)object).getValue();

+    }

+

+    /**

+     * Returns a number that identifies the type of node that the given

+     * object represents in this navigator. See org.jaxen.pattern.Pattern

+     *

+     * @param node ????

+     * @return Returns short.

+     */

+    public short getNodeType(Object node) {

+        //TODO: Fix this better?

+        return super.getNodeType(node);

+    }

+

+    /**

+     * Returns the parent of the given context node.

+     * <p/>

+     * The parent of any node must either be a document

+     * node or an element node.

+     *

+     * @param contextNode the context node

+     * @return Returns the parent of the context node, or null if this is a document node.

+     * @throws UnsupportedAxisException if the parent axis is not

+     *                                  supported by the model

+     * @see #isDocument

+     * @see #isElement

+     */

+    public Object getParentNode(Object contextNode) throws UnsupportedAxisException {

+        if (contextNode == null ||

+                contextNode instanceof OMDocument) {

+            return null;

+        } else if (contextNode instanceof OMAttributeEx) {

+            return ((OMAttributeEx) contextNode).getParent();

+        } else if (contextNode instanceof OMNamespaceEx) {

+            return ((OMNamespaceEx) contextNode).getParent();

+        }

+        return ((OMNode) contextNode).getParent();

+    }

+

+    class OMNamespaceEx implements OMNamespace {

+        OMNamespace originalNsp = null;

+        OMContainer parent = null;

+

+        OMNamespaceEx(OMNamespace nsp, OMContainer parent) {

+            originalNsp = nsp;

+            this.parent = parent;

+        }

+

+        public boolean equals(String uri, String prefix) {

+            return originalNsp.equals(uri, prefix);

+        }

+

+        public String getPrefix() {

+            return originalNsp.getPrefix();

+        }

+

+        public String getName() {

+            return originalNsp.getName();

+        }

+

+        public OMContainer getParent() {

+            return parent;

+        }

+    }

+

+    class OMAttributeEx implements OMAttribute {

+        OMAttribute attribute = null;

+        OMContainer parent = null;

+

+        OMAttributeEx(OMAttribute attribute, OMContainer parent) {

+            this.attribute = attribute;

+            this.parent = parent;

+        }

+

+        public String getLocalName() {

+            return attribute.getLocalName();

+        }

+

+        public void setLocalName(String localName) {

+            attribute.setLocalName(localName);

+        }

+

+        public String getAttributeValue() {

+            return attribute.getAttributeValue();

+        }

+

+        public void setAttributeValue(String value) {

+            attribute.setAttributeValue(value);

+        }

+

+        public void setOMNamespace(OMNamespace omNamespace) {

+            attribute.setOMNamespace(omNamespace);

+        }

+

+        public OMNamespace getNamespace() {

+            return attribute.getNamespace();

+        }

+

+        public QName getQName() {

+            return attribute.getQName();

+        }

+

+        public OMContainer getParent() {

+            return parent;

+        }

+    }

+}

+

diff --git a/src/org/apache/ws/commons/soap/SOAP11Constants.java b/src/org/apache/ws/commons/soap/SOAP11Constants.java
new file mode 100644
index 0000000..7477ebb
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAP11Constants.java
@@ -0,0 +1,54 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+

+public interface SOAP11Constants extends SOAPConstants {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    public static final String SOAP_ENVELOPE_NAMESPACE_URI = "http://schemas.xmlsoap.org/soap/envelope/";

+

+    /**

+     * Field ATTR_ACTOR

+     */

+    public static final String ATTR_ACTOR = "actor";

+

+    /**

+     * Field SOAP_FAULT_CODE_LOCAL_NAME

+     */

+    public static final String SOAP_FAULT_CODE_LOCAL_NAME = "faultcode";

+    /**

+     * Field SOAP_FAULT_STRING_LOCAL_NAME

+     */

+    public static final String SOAP_FAULT_STRING_LOCAL_NAME = "faultstring";

+    /**

+     * Field SOAP_FAULT_ACTOR_LOCAL_NAME

+     */

+    public static final String SOAP_FAULT_ACTOR_LOCAL_NAME = "faultactor";

+

+    public static final String SOAP_FAULT_DETAIL_LOCAL_NAME = "detail";

+

+    //SOAP 1.2 Content Type

+    public static final String SOAP_11_CONTENT_TYPE = "text/xml";

+

+     // -------- SOAP Fault Codes ------------------------------

+    public static final String FAULT_CODE_SENDER = "Client";

+    public static final String FAULT_CODE_RECEIVER = "Server";

+

+    public static final String SOAP_ACTOR_NEXT = "http://schemas.xmlsoap.org/soap/actor/next";

+}

diff --git a/src/org/apache/ws/commons/soap/SOAP12Constants.java b/src/org/apache/ws/commons/soap/SOAP12Constants.java
new file mode 100644
index 0000000..22494e9
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAP12Constants.java
@@ -0,0 +1,70 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+

+public interface SOAP12Constants extends SOAPConstants {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public String SOAP_ENVELOPE_NAMESPACE_URI =

+            "http://www.w3.org/2003/05/soap-envelope";

+

+    public static final String SOAP_ROLE = "role";

+    public static final String SOAP_RELAY = "relay";

+

+    // SOAP Fault Code

+    public static final String SOAP_FAULT_CODE_LOCAL_NAME = "Code";

+    public static final String SOAP_FAULT_SUB_CODE_LOCAL_NAME = "Subcode";

+    public static final String SOAP_FAULT_VALUE_LOCAL_NAME = "Value";

+

+    // SOAP Fault Codes

+    public static final String SOAP_FAULT_VALUE_VERSION_MISMATCH = "VersionMismatch";

+    public static final String SOAP_FAULT_VALUE_MUST_UNDERSTAND = "MustUnderstand";

+    public static final String SOAP_FAULT_VALUE_DATA_ENCODING_UKNOWN = "DataEncodingUnknown";

+    public static final String SOAP_FAULT_VALUE_SENDER = "Sender";

+    public static final String SOAP_FAULT_VALUE_RECEIVER = "Receiver";

+

+    // SOAP Fault Reason

+    public static final String SOAP_FAULT_REASON_LOCAL_NAME = "Reason";

+    public static final String SOAP_FAULT_TEXT_LOCAL_NAME = "Text";

+    public static final String SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME = "lang";

+    public static final String SOAP_FAULT_TEXT_LANG_ATTR_NS_URI = "http://www.w3.org/XML/1998/namespace";

+    public static final String SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX = "xml";

+

+    // SOAP Fault Node

+    public static final String SOAP_FAULT_NODE_LOCAL_NAME = "Node";

+

+    // SOAP Fault Detail

+    public static final String SOAP_FAULT_DETAIL_LOCAL_NAME = "Detail";

+

+    // SOAP Fault Role

+    public static final String SOAP_FAULT_ROLE_LOCAL_NAME = "Role";

+

+    //SOAP 1.2 Content Type

+    public static final String SOAP_12_CONTENT_TYPE = "application/soap+xml";

+

+    // -------- SOAP Fault Codes ------------------------------

+    public static final String FAULT_CODE_SENDER = "Sender";

+    public static final String FAULT_CODE_RECEIVER = "Receiver";

+

+    public static final String SOAP_ROLE_NEXT = "http://www.w3.org/2003/05/soap-envelope/role/next";

+    public static final String SOAP_ROLE_NONE = "http://www.w3.org/2003/05/soap-envelope/role/next";

+    public static final String SOAP_ROLE_ULTIMATE_RECEIVER = "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver";

+    

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPBody.java b/src/org/apache/ws/commons/soap/SOAPBody.java
new file mode 100644
index 0000000..f3e7dea
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPBody.java
@@ -0,0 +1,72 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+

+/**

+ * An object that represents the contents of the SOAP body

+ * element in a SOAP message. B SOAP body element consists of XML data

+ * that affects the way the application-specific content is processed.

+ * <P>

+ * B <code>SOAPBody</code> object contains <code>OMBodyBlock</code>

+ * objects, which have the content for the SOAP body.

+ * B <code>SOAPFault</code> object, which carries status and/or

+ * error information, is an example of a <code>OMBodyBlock</code> object.

+ */

+public interface SOAPBody extends OMElement {

+    /**

+     * Creates a new <code>SOAPFault</code> object and adds it to

+     * this <code>SOAPBody</code> object.

+     *

+     * @param e

+     * @return the new <code>SOAPFault</code> object

+     * @throws org.apache.ws.commons.om.OMException

+     *          if there is a SOAP error

+     * @throws org.apache.ws.commons.om.OMException

+     *

+     */

+    public abstract SOAPFault addFault(Exception e) throws OMException;

+

+    /**

+     * Indicates whether a <code>SOAPFault</code> object exists in

+     * this <code>SOAPBody</code> object.

+     *

+     * @return <code>true</code> if a <code>SOAPFault</code> object exists in

+     *         this <code>SOAPBody</code> object; <code>false</code>

+     *         otherwise

+     */

+    public abstract boolean hasFault();

+

+    /**

+     * Returns the <code>SOAPFault</code> object in this <code>SOAPBody</code>

+     * object.

+     *

+     * @return the <code>SOAPFault</code> object in this <code>SOAPBody</code>

+     *         object

+     */

+    public abstract SOAPFault getFault();

+

+    /**

+     * @param soapFault

+     * @throws OMException

+     */

+    public abstract void addFault(SOAPFault soapFault) throws OMException;

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPConstants.java b/src/org/apache/ws/commons/soap/SOAPConstants.java
new file mode 100644
index 0000000..b9a59dc
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPConstants.java
@@ -0,0 +1,85 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public interface SOAPConstants {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    /**

+     * Field SOAP_DEFAULT_NAMESPACE_PREFIX

+     */

+    public static final String SOAP_DEFAULT_NAMESPACE_PREFIX = "soapenv";

+    /**

+     * Field SOAPENVELOPE_LOCAL_NAME

+     */

+    public static final String SOAPENVELOPE_LOCAL_NAME = "Envelope";

+

+    /**

+     * Field HEADER_LOCAL_NAME

+     */

+    public static final String HEADER_LOCAL_NAME = "Header";

+

+    /**

+     * Field BODY_LOCAL_NAME

+     */

+    public static final String BODY_LOCAL_NAME = "Body";

+    /**

+     * Field BODY_NAMESPACE_PREFIX

+     */

+    public static final String BODY_NAMESPACE_PREFIX =

+            SOAP_DEFAULT_NAMESPACE_PREFIX;

+    /**

+     * Field BODY_FAULT_LOCAL_NAME

+     */

+    public static final String BODY_FAULT_LOCAL_NAME = "Fault";

+

+    /**

+     * Field ATTR_MUSTUNDERSTAND

+     */

+    public static final String ATTR_MUSTUNDERSTAND = "mustUnderstand";

+    public static final String ATTR_MUSTUNDERSTAND_TRUE = "true";

+    public static final String ATTR_MUSTUNDERSTAND_FALSE = "false";

+    public static final String ATTR_MUSTUNDERSTAND_0 = "0";

+    public static final String ATTR_MUSTUNDERSTAND_1 = "1";

+    /**

+     * Field SOAPFAULT_LOCAL_NAME

+     */

+    public static final String SOAPFAULT_LOCAL_NAME = "Fault";

+    /**

+     * Field SOAPFAULT_DETAIL_LOCAL_NAME

+     */

+    public static final String SOAPFAULT_DETAIL_LOCAL_NAME = "detail";

+

+    /**

+     * Field SOAPFAULT_NAMESPACE_PREFIX

+     */

+    public static final String SOAPFAULT_NAMESPACE_PREFIX =

+            SOAP_DEFAULT_NAMESPACE_PREFIX;

+

+    public static final String SOAP_FAULT_DETAIL_EXCEPTION_ENTRY = "Exception";

+

+    // -------- SOAP Fault Codes ------------------------------

+    public static final String FAULT_CODE_VERSION_MISMATCH = "env:VersionMismatch";

+    public static final String FAULT_CODE_MUST_UNDERSTAND  = "env:MustUnderstand";

+    public static final String FAULT_CODE_DATA_ENCODING_UNKNOWN = "env:DataEncodingUnknown";

+

+    // Followings are different in SOAP 1.1 and 1.2 specifications

+    public static final String FAULT_CODE_SENDER = "";

+    public static final String FAULT_CODE_RECEIVER = "";

+

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPEnvelope.java b/src/org/apache/ws/commons/soap/SOAPEnvelope.java
new file mode 100644
index 0000000..1f6182f
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPEnvelope.java
@@ -0,0 +1,55 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+

+/**

+ * Interface SOAPEnvelope

+ */

+public interface SOAPEnvelope extends OMElement {

+    /**

+     * Returns the <CODE>SOAPHeader</CODE> object for this <CODE>

+     * SOAPEnvelope</CODE> object.

+     * <P> This SOAPHeader will just be a container for all the headers in the

+     * <CODE>OMMessage</CODE>

+     * </P>

+     *

+     * @return the <CODE>SOAPHeader</CODE> object or <CODE>

+     *         null</CODE> if there is none

+     * @throws org.apache.ws.commons.om.OMException

+     *          if there is a problem

+     *          obtaining the <CODE>SOAPHeader</CODE> object

+     */

+    public abstract SOAPHeader getHeader() throws OMException;

+

+    /**

+     * Returns the <CODE>SOAPBody</CODE> object associated with

+     * this <CODE>SOAPEnvelope</CODE> object.

+     * <P> This SOAPBody will just be a container for all the BodyElements in the

+     * <CODE>OMMessage</CODE>

+     * </P>

+     *

+     * @return the <CODE>SOAPBody</CODE> object for this <CODE>

+     *         SOAPEnvelope</CODE> object or <CODE>null</CODE> if there

+     *         is none

+     * @throws OMException if there is a problem

+     *                     obtaining the <CODE>SOAPBody</CODE> object

+     */

+    public abstract SOAPBody getBody() throws OMException;

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFactory.java b/src/org/apache/ws/commons/soap/SOAPFactory.java
new file mode 100644
index 0000000..89c2b96
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFactory.java
@@ -0,0 +1,328 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+

+

+public interface SOAPFactory extends OMFactory {

+    

+    public String getSoapVersionURI();

+    

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public SOAPMessage createSOAPMessage(OMXMLParserWrapper builder);

+    public SOAPMessage createSOAPMessage(SOAPEnvelope envelope, OMXMLParserWrapper parserWrapper);

+

+    /**

+     * @param builder

+     * @return Returns SOAPEnvelope.

+     */

+    public SOAPEnvelope createSOAPEnvelope(OMXMLParserWrapper builder);

+

+    /**

+     * @return Returns SOAPEnvelope.

+     */

+    public SOAPEnvelope createSOAPEnvelope() throws SOAPProcessingException;

+

+    /**

+     * @param envelope

+     * @return Returns SOAPHeader.

+     */

+    public SOAPHeader createSOAPHeader(SOAPEnvelope envelope) throws SOAPProcessingException;

+

+    /**

+     * @param envelope

+     * @param builder

+     * @return Returns SOAPHeader.

+     */

+    public SOAPHeader createSOAPHeader(SOAPEnvelope envelope,

+                                       OMXMLParserWrapper builder);

+

+    /**

+     * @param localName

+     * @param ns

+     * @return Returns SOAPHeaderBlock.

+     */

+    public SOAPHeaderBlock createSOAPHeaderBlock(String localName,

+                                                 OMNamespace ns,

+                                                 SOAPHeader parent) throws SOAPProcessingException;

+

+    /**

+     * @param localName

+     * @param ns

+     * @param parent

+     * @param builder

+     * @return Returns SOAPHeaderBlock.

+     */

+    public SOAPHeaderBlock createSOAPHeaderBlock(String localName,

+                                                 OMNamespace ns,

+                                                 SOAPHeader parent,

+                                                 OMXMLParserWrapper builder) throws SOAPProcessingException;

+

+    /**

+     * @param parent

+     * @param e

+     * @return Returns SOAPFault.

+     */

+    public SOAPFault createSOAPFault(SOAPBody parent, Exception e) throws SOAPProcessingException;

+

+    public SOAPFault createSOAPFault(SOAPBody parent) throws SOAPProcessingException;

+

+    /**

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFault.

+     */

+    public SOAPFault createSOAPFault(SOAPBody parent,

+                                     OMXMLParserWrapper builder);

+

+    /**

+     * @param envelope

+     * @return Returns SOAPBody.

+     */

+    public SOAPBody createSOAPBody(SOAPEnvelope envelope) throws SOAPProcessingException;

+

+    /**

+     * @param envelope

+     * @param builder

+     * @return Returns SOAPBody.

+     */

+    public SOAPBody createSOAPBody(SOAPEnvelope envelope,

+                                   OMXMLParserWrapper builder);

+

+    /* ========================

+       =  SOAPFaultCode       =

+       ======================== */

+

+    /**

+     * Code eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultCode.

+     */

+    public SOAPFaultCode createSOAPFaultCode(SOAPFault parent) throws SOAPProcessingException;

+

+    /**

+     * Code eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultCode.

+     */

+    public SOAPFaultCode createSOAPFaultCode(SOAPFault parent,

+                                             OMXMLParserWrapper builder);

+

+

+    /*========================

+      =  SOAPFaultCodeValue  =

+      ======================== */

+    /**

+     * Value eii under Code (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultValue.

+     */

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultCode parent) throws SOAPProcessingException;

+

+    /**

+     * Value eii under Code (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultValue.

+     */

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultCode parent,

+                                               OMXMLParserWrapper builder);

+

+    /*========================

+      =  SOAPFaultSubCode    =

+      ======================== */

+

+    /**

+     * SubCode eii under Value (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultValue.

+     */

+

+    //added

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultSubCode parent) throws SOAPProcessingException;

+

+    //added

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultSubCode parent,

+                                               OMXMLParserWrapper builder);

+

+    //changed

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultCode parent) throws SOAPProcessingException;

+

+    /**

+     * SubCode eii under Value (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultSubCode.

+     */

+    //changed

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultCode parent,

+                                                   OMXMLParserWrapper builder);

+

+    /**

+     * SubCode eii under SubCode (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultSubCode.

+     */

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultSubCode parent) throws SOAPProcessingException;

+

+    /**

+     * SubCode eii under SubCode (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultSubCode.

+     */

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultSubCode parent,

+                                                   OMXMLParserWrapper builder);

+

+

+    /*========================

+      =  SOAPFaultReason     =

+      ======================== */

+

+    /**

+     * Reason eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultReason.

+     */

+    public SOAPFaultReason createSOAPFaultReason(SOAPFault parent) throws SOAPProcessingException;

+

+    /**

+     * Reason eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultReason.

+     */

+    public SOAPFaultReason createSOAPFaultReason(SOAPFault parent,

+                                                 OMXMLParserWrapper builder);

+

+    /*========================

+      =  SOAPFaultReasonText     =

+      ======================== */

+

+    /**

+     * SubCode eii under SubCode (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultText.

+     */

+    public SOAPFaultText createSOAPFaultText(SOAPFaultReason parent) throws SOAPProcessingException;

+

+    /**

+     * SubCode eii under SubCode (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultText.

+     */

+    public SOAPFaultText createSOAPFaultText(SOAPFaultReason parent,

+                                             OMXMLParserWrapper builder);

+

+

+    /*========================

+      =  SOAPFaultNode       =

+      ======================== */

+

+    /**

+     * Node eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultNode.

+     */

+    public SOAPFaultNode createSOAPFaultNode(SOAPFault parent) throws SOAPProcessingException;

+

+    /**

+     * Node eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultNode.

+     */

+    public SOAPFaultNode createSOAPFaultNode(SOAPFault parent,

+                                             OMXMLParserWrapper builder);

+

+    /*========================

+      =  SOAPFaultRole       =

+      ======================== */

+

+    /**

+     * Role eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultRole.

+     */

+    public SOAPFaultRole createSOAPFaultRole(SOAPFault parent) throws SOAPProcessingException;

+

+    /**

+     * Role eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultRole.

+     */

+    public SOAPFaultRole createSOAPFaultRole(SOAPFault parent,

+                                             OMXMLParserWrapper builder);

+

+    /*========================

+      =  SOAPFaultDetail     =

+      ======================== */

+

+    /**

+     * Detail eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @return Returns SOAPFaultDetail.

+     */

+    public SOAPFaultDetail createSOAPFaultDetail(SOAPFault parent) throws SOAPProcessingException;

+

+    /**

+     * Role eii under SOAPFault (parent)

+     *

+     * @param parent

+     * @param builder

+     * @return Returns SOAPFaultDetail.

+     */

+    public SOAPFaultDetail createSOAPFaultDetail(SOAPFault parent,

+                                                 OMXMLParserWrapper builder);

+

+

+    /**

+     * Method getDefaultEnvelope

+     *

+     * @return Returns SOAPEnvelope.

+     */

+    public SOAPEnvelope getDefaultEnvelope() throws SOAPProcessingException;

+

+    public SOAPEnvelope getDefaultFaultEnvelope() throws SOAPProcessingException;

+    

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFault.java b/src/org/apache/ws/commons/soap/SOAPFault.java
new file mode 100644
index 0000000..9a3373c
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFault.java
@@ -0,0 +1,107 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+

+

+/**

+ * An element in the <CODE>SOAPBody</CODE> object that contains

+ * error and/or status information. This information may relate to

+ * errors in the <CODE>OMMessage</CODE> object or to problems

+ * that are not related to the content in the message itself.

+ * Problems not related to the message itself are generally errors

+ * in processing, such as the inability to communicate with an

+ * upstream server.

+ * <P>

+ * The <CODE>SOAPFault</CODE> interface provides methods for

+ * retrieving the information contained in a <CODE>

+ * SOAPFault</CODE> object and for setting the fault code, the

+ * fault actor, and a string describing the fault. B fault code is

+ * one of the codes defined in the SOAP 1.1 specification that

+ * describe the fault. An actor is an intermediate recipient to

+ * whom a message was routed. The message path may include one or

+ * more actors, or, if no actors are specified, the message goes

+ * only to the default actor, which is the final intended

+ * recipient.

+ */

+public interface SOAPFault extends OMElement {

+

+    /**

+     * SOAPFaultCode is a mandatory item in a Fault, in SOAP 1.2 specification

+     *

+     * @param soapFaultCode

+     */

+    public void setCode(SOAPFaultCode soapFaultCode) throws SOAPProcessingException;

+

+    public SOAPFaultCode getCode();

+

+    /**

+     * SOAPFaultReason is a mandatory item in a Fault, in SOAP 1.2 specification

+     *

+     * @param reason

+     */

+    public void setReason(SOAPFaultReason reason) throws SOAPProcessingException;

+

+    public SOAPFaultReason getReason();

+

+    /**

+     * SOAPFaultNode is an optional item in a Fault, in SOAP 1.2 specification

+     *

+     * @param node

+     */

+    public void setNode(SOAPFaultNode node) throws SOAPProcessingException;

+

+    public SOAPFaultNode getNode();

+

+    /**

+     * SOAPFaultRoleImpl is an optional item in a Fault, in SOAP 1.2 specification

+     *

+     * @param role

+     */

+    public void setRole(SOAPFaultRole role) throws SOAPProcessingException;

+

+    public SOAPFaultRole getRole();

+

+    /**

+     * SOAPFaultRoleImpl is an optional item in a Fault, in SOAP 1.2 specification

+     *

+     * @param detail

+     */

+    public void setDetail(SOAPFaultDetail detail) throws SOAPProcessingException;

+

+    public SOAPFaultDetail getDetail();

+

+    /**

+     * Returns Exception if there is one in the SOAP fault.

+     * <p/>

+     * If the exception is like;

+     * <SOAPFault>

+     * <Detail>

+     * <Exception> stack trace goes here </Exception>

+     * </Detail>

+     * </SOAPFault>

+     *

+     * @return Returns Exception.

+     * @throws org.apache.ws.commons.om.OMException

+     *

+     */

+    public Exception getException() throws OMException;

+

+    public void setException(Exception e) throws OMException;

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFaultCode.java b/src/org/apache/ws/commons/soap/SOAPFaultCode.java
new file mode 100644
index 0000000..de8508d
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFaultCode.java
@@ -0,0 +1,46 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+public interface SOAPFaultCode extends OMElement {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    /**

+     * @param value

+     */

+    public void setValue(SOAPFaultValue value) throws SOAPProcessingException;

+

+    /**

+     * @return Returns SOAPFaultValue.

+     */

+    public SOAPFaultValue getValue();

+

+    /**

+     * @param value

+     */

+    public void setSubCode(SOAPFaultSubCode value) throws SOAPProcessingException;

+

+    /**

+     * @return Returns SOAPFaultSubCode.

+     */

+    public SOAPFaultSubCode getSubCode();

+

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFaultDetail.java b/src/org/apache/ws/commons/soap/SOAPFaultDetail.java
new file mode 100644
index 0000000..c5a5ab1
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFaultDetail.java
@@ -0,0 +1,42 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+import java.util.Iterator;

+

+

+/**

+ * The Detail element information item is intended for carrying application

+ * specific error information related to the SOAP Body .

+ * <p/>

+ * The Detail element information item has:

+ * A [local name] of Detail .

+ * A [namespace name] of http://www.w3.org/2003/05/soap-envelope .

+ * Zero or more attribute information items in its [attributes] property.

+ * Zero or more child element information items in its [children] property.

+ */

+public interface SOAPFaultDetail extends OMElement {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    public void addDetailEntry(OMElement detailElement);

+

+    public Iterator getAllDetailEntries();

+

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFaultNode.java b/src/org/apache/ws/commons/soap/SOAPFaultNode.java
new file mode 100644
index 0000000..f00aaa3
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFaultNode.java
@@ -0,0 +1,39 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+public interface SOAPFaultNode extends OMElement {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    /**

+     * each SOAP node is identified by a URI. The value of the Node element

+     * information item is the URI that identifies the SOAP node that generated

+     * the fault. SOAP nodes that do not act as the ultimate SOAP receiver MUST

+     * include this element information item. An ultimate SOAP receiver MAY

+     * include this element information item to indicate explicitly that it

+     * generated the fault.

+     *

+     * @param uri

+     */

+    public void setNodeValue(String uri);

+

+    public String getNodeValue();

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFaultReason.java b/src/org/apache/ws/commons/soap/SOAPFaultReason.java
new file mode 100644
index 0000000..f0a1155
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFaultReason.java
@@ -0,0 +1,29 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+public interface SOAPFaultReason extends OMElement {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public void setSOAPText(SOAPFaultText soapFaultText) throws SOAPProcessingException;

+

+    public SOAPFaultText getSOAPText();

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFaultRole.java b/src/org/apache/ws/commons/soap/SOAPFaultRole.java
new file mode 100644
index 0000000..7eee7ef
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFaultRole.java
@@ -0,0 +1,44 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+

+/**

+ * The Role element information item identifies the role the node was operating

+ * in at the point the fault occurred.

+ * <p/>

+ * The Role element information item has:

+ * A [local name] of Role .

+ * A [namespace name] of http://www.w3.org/2003/05/soap-envelope .

+ */

+public interface SOAPFaultRole extends OMElement {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    

+    /**

+     * The value of the Role element information item MUST be one of the roles

+     * assumed by the node during processing of the message

+     *

+     * @param uri

+     */

+    public void setRoleValue(String uri);

+

+    public String getRoleValue();

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFaultSubCode.java b/src/org/apache/ws/commons/soap/SOAPFaultSubCode.java
new file mode 100644
index 0000000..c394b59
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFaultSubCode.java
@@ -0,0 +1,44 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+public interface SOAPFaultSubCode extends OMElement {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    /**

+     * Fault SubCode contain only one mandatory Value child. This value child contains a QName

+     *

+     * @param soapFaultSubCodeValue

+     */

+    public void setValue(SOAPFaultValue soapFaultSubCodeValue) throws SOAPProcessingException;

+

+    public SOAPFaultValue getValue();

+

+

+    /**

+     * Fault SubCode can contain an optional SubCode

+     *

+     * @param subCode

+     */

+    public void setSubCode(SOAPFaultSubCode subCode) throws SOAPProcessingException;

+

+    public SOAPFaultSubCode getSubCode();

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFaultText.java b/src/org/apache/ws/commons/soap/SOAPFaultText.java
new file mode 100644
index 0000000..4bfcec8
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFaultText.java
@@ -0,0 +1,38 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+public interface SOAPFaultText extends OMElement {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    /**

+     * lang is a mandatory attribute within the SOAPFaultText which must have

+     * SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_URI as the namespace URI and

+     * SOAP12constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX or a capitalization thereof as the prefix

+     *

+     * @param lang

+     */

+    public void setLang(String lang);

+

+    public String getLang();

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPFaultValue.java b/src/org/apache/ws/commons/soap/SOAPFaultValue.java
new file mode 100644
index 0000000..e769a61
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPFaultValue.java
@@ -0,0 +1,25 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+public interface SOAPFaultValue extends OMElement {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPHeader.java b/src/org/apache/ws/commons/soap/SOAPHeader.java
new file mode 100644
index 0000000..1ad45c0
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPHeader.java
@@ -0,0 +1,128 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNamespace;

+

+import java.util.ArrayList;

+import java.util.Iterator;

+

+/**

+ * Interface SOAPHeader

+ */

+public interface SOAPHeader extends OMElement {

+    /**

+     * Creates a new <CODE>SOAPHeaderBlock</CODE> object initialized with the

+     * specified name and adds it to this <CODE>SOAPHeader</CODE> object.

+     *

+     * @param localName

+     * @param ns

+     * @return the new <CODE>SOAPHeaderBlock</CODE> object that was inserted

+     *         into this <CODE>SOAPHeader</CODE> object

+     * @throws org.apache.ws.commons.om.OMException

+     *             if a SOAP error occurs

+     */

+    public abstract SOAPHeaderBlock addHeaderBlock(String localName,

+            OMNamespace ns) throws OMException;

+

+    /**

+     * Returns a list of all the <CODE>SOAPHeaderBlock</CODE> objects in this

+     * <CODE>SOAPHeader</CODE> object that have the the specified role. An

+     * role is a global attribute that indicates the intermediate parties to

+     * whom the message should be sent. An role receives the message and then

+     * sends it to the next role. The default role is the ultimate intended

+     * recipient for the message, so if no role attribute is included in a

+     * <CODE>SOAPHeader</CODE> object, the message is sent to its ultimate

+     * destination.

+     *

+     * @param role

+     *            a <CODE>String</CODE> giving the URI of the role for which

+     *            to search

+     * @return Returns an <CODE>Iterator</CODE> object over all the <CODE>

+     *         SOAPHeaderBlock</CODE> objects that contain the specified role

+     * @see #extractHeaderBlocks(java.lang.String)

+     *      extractHeaderBlocks(java.lang.String)

+     */

+    public abstract Iterator examineHeaderBlocks(String role);

+

+    /**

+     * Returns a list of all the <CODE>SOAPHeaderBlock</CODE> objects in this

+     * <CODE>SOAPHeader</CODE> object that have the the specified role and

+     * detaches them from this <CODE>SOAPHeader</CODE> object.

+     * <P>

+     * This method allows an role to process only the parts of the <CODE>

+     * SOAPHeader</CODE> object that apply to it and to remove them before

+     * passing the message on to the next role.

+     *

+     * @param role

+     *            a <CODE>String</CODE> giving the URI of the role for which

+     *            to search

+     * @return Returns an <CODE>Iterator</CODE> object over all the <CODE>

+     *         SOAPHeaderBlock</CODE> objects that contain the specified role

+     * @see #examineHeaderBlocks(java.lang.String)

+     *      examineHeaderBlocks(java.lang.String)

+     */

+    public abstract Iterator extractHeaderBlocks(String role);

+

+    /**

+     * Returns an <code>Iterator</code> over all the

+     * <code>SOAPHeaderBlock</code> objects in this <code>SOAPHeader</code>

+     * object that have the specified role and that have a MustUnderstand

+     * attribute whose value is equivalent to <code>true</code>.

+     *

+     * @param role

+     *            a <code>String</code> giving the URI of the role for which

+     *            to search

+     * @return Returns an <code>Iterator</code> object over all the

+     *         <code>SOAPHeaderBlock</code> objects that contain the specified

+     *         role and are marked as MustUnderstand.

+     */

+    public abstract Iterator examineMustUnderstandHeaderBlocks(String role);

+

+    /**

+     * Returns an <code>Iterator</code> over all the

+     * <code>SOAPHeaderBlock</code> objects in this <code>SOAPHeader</code>

+     * object.

+     *

+     * @return an <code>Iterator</code> object over all the

+     *         <code>SOAPHeaderBlock</code> objects contained by this

+     *         <code>SOAPHeader</code>. If there are no header blocks then an

+     *         empty iterator is returned.

+     */

+    public abstract Iterator examineAllHeaderBlocks();

+

+    /**

+     * Returns an <code>Iterator</code> over all the

+     * <code>SOAPHeaderBlock</code> objects in this <code>SOAPHeader </code>

+     * object and detaches them from this <code>SOAPHeader</code> object.

+     *

+     * @return Returns an <code>Iterator</code> object over all the

+     *         <code>SOAPHeaderBlock</code> objects contained by this

+     *         <code>SOAPHeader</code>

+     */

+    public abstract Iterator extractAllHeaderBlocks();

+

+    /**

+     * Return all the Headers that has the Namespace URI to given NS URI.

+     *

+     * @param nsURI

+     * @return Returns ArrayList.

+     */

+    public ArrayList getHeaderBlocksWithNSURI(String nsURI);

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPHeaderBlock.java b/src/org/apache/ws/commons/soap/SOAPHeaderBlock.java
new file mode 100644
index 0000000..e3368aa
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPHeaderBlock.java
@@ -0,0 +1,89 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+

+/**

+ * <P>An object representing the contents in the SOAP header part of the SOAP

+ * envelope. The immediate children of a <CODE> SOAPHeader</CODE> object can be

+ * represented only as <CODE> SOAPHeaderBlock</CODE> objects.</P> <P>B

+ * <CODE>SOAPHeaderBlock</CODE> object can have other <CODE>OMElement</CODE>

+ * objects as its children.</P>

+ */

+public interface SOAPHeaderBlock extends OMElement {

+    /**

+     * Sets the actor associated with this <CODE> SOAPHeaderBlock</CODE> object

+     * to the specified actor.

+     *

+     * @param roleURI a <CODE>String</CODE> giving the URI of the actor to set

+     * @throws java.lang.IllegalArgumentException

+     *          if there is a problem in setting the actor.

+     * @see #getRole() getRole()

+     */

+    public abstract void setRole(String roleURI);

+

+    /**

+     * Returns the uri of the actor associated with this <CODE>

+     * SOAPHeaderBlock</CODE> object.

+     *

+     * @return a <CODE>String</CODE> giving the URI of the actor

+     * @see #setRole(java.lang.String) setRole(java.lang.String)

+     */

+    public abstract String getRole();

+

+    /**

+     * Sets the mustUnderstand attribute for this <CODE> SOAPHeaderBlock</CODE>

+     * object to be on or off. <P>If the mustUnderstand attribute is on, the

+     * actor who receives the <CODE>SOAPHeaderBlock</CODE> must process it

+     * correctly. This ensures, for example, that if the <CODE>

+     * SOAPHeaderBlock</CODE> object modifies the message, that the message is

+     * being modified correctly.</P>

+     *

+     * @param mustUnderstand <CODE>true</CODE> to set the mustUnderstand

+     *                       attribute on; <CODE>false</CODE> to turn if off

+     * @throws java.lang.IllegalArgumentException

+     *          if there is a problem in setting the actor.

+     * @see #getMustUnderstand() getMustUnderstand()

+     */

+    public abstract void setMustUnderstand(boolean mustUnderstand);

+

+    public abstract void setMustUnderstand(String mustUnderstand) throws SOAPProcessingException;

+

+    /**

+     * Returns whether the mustUnderstand attribute for this

+     * <CODE>SOAPHeaderBlock</CODE> object is turned on.

+     *

+     * @return <CODE>true</CODE> if the mustUnderstand attribute of this

+     *         <CODE>SOAPHeaderBlock</CODE> object is turned on;

+     *         <CODE>false</CODE> otherwise

+     */

+    public abstract boolean getMustUnderstand() throws SOAPProcessingException;

+

+

+    public abstract boolean isProcessed();

+

+    /**

+     * We need to know whether all the mustUnderstand headers have been

+     * processed by the node. This will done by a specific validation handler at

+     * the end of the execution chain. For this all the handlers who process a

+     * particular header block must explicitly say that he processesd the header

+     * by calling setProcessed()

+     */

+    public abstract void setProcessed();

+

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPMessage.java b/src/org/apache/ws/commons/soap/SOAPMessage.java
new file mode 100644
index 0000000..ba1b1ee
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPMessage.java
@@ -0,0 +1,26 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMDocument;

+

+public interface SOAPMessage extends OMDocument {

+

+    public SOAPEnvelope getSOAPEnvelope() throws SOAPProcessingException;

+    public void setSOAPEnvelope(SOAPEnvelope envelope) throws SOAPProcessingException;

+

+}

diff --git a/src/org/apache/ws/commons/soap/SOAPProcessingException.java b/src/org/apache/ws/commons/soap/SOAPProcessingException.java
new file mode 100644
index 0000000..b7c06eb
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/SOAPProcessingException.java
@@ -0,0 +1,64 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMException;

+

+public class SOAPProcessingException extends OMException {

+

+    private String soapFaultCode;

+

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    public SOAPProcessingException(String message) {

+        super(message);

+    }

+

+    public SOAPProcessingException(Throwable cause) {

+        super(cause);

+    }

+

+    /**

+     *

+     * @param messageText - this will appear as the Text in the Reason information item of SOAP Fault

+     * @param faultCode - this will appear as the Value in the Code information item of SOAP Fault

+     * @param cause - this will appear under the Detail information item of SOAP Fault

+     */

+    public SOAPProcessingException(String messageText, String faultCode, Throwable cause) {

+        super(messageText, cause);

+        this.soapFaultCode = faultCode;

+    }

+

+    /**

+     *

+     * @param messageText - this will appear as the Text in the Reason information item of SOAP Fault

+     * @param faultCode - this will appear as the Value in the Code information item of SOAP Fault

+     */

+    public SOAPProcessingException(String messageText, String faultCode) {

+        super(messageText);

+        this.soapFaultCode = faultCode;

+    }

+

+    public String getFaultCode() {

+        return soapFaultCode;

+    }

+

+    public void setFaultCode(String soapFaultCode) {

+        this.soapFaultCode = soapFaultCode;

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPBodyImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPBodyImpl.java
new file mode 100644
index 0000000..3c249e0
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPBodyImpl.java
@@ -0,0 +1,157 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMConstants;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+/**

+ * Class SOAPBodyImpl

+ */

+public abstract class SOAPBodyImpl extends SOAPElement

+        implements SOAPBody, OMConstants {

+    /**

+     * Field hasSOAPFault

+     */

+    private boolean hasSOAPFault = false;

+

+    /**

+     * @param envelope

+     */

+    public SOAPBodyImpl(SOAPEnvelope envelope) throws SOAPProcessingException {

+        super(envelope, SOAPConstants.BODY_LOCAL_NAME, true);

+

+    }

+

+    /**

+     * Constructor SOAPBodyImpl

+     *

+     * @param envelope

+     * @param builder

+     */

+    public SOAPBodyImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) {

+        super(envelope, SOAPConstants.BODY_LOCAL_NAME, builder);

+    }

+

+    /**

+     * Creates a new <code>SOAPFault</code> object and adds it to

+     * this <code>SOAPBody</code> object.

+     *

+     * @param e

+     * @return the new <code>SOAPFault</code> object

+     * @throws org.apache.ws.commons.om.OMException

+     *                     if there is a SOAP error

+     * @throws OMException

+     */

+    public abstract SOAPFault addFault(Exception e) throws OMException;

+

+    /**

+     * Indicates whether a <code>SOAPFault</code> object exists in

+     * this <code>SOAPBody</code> object.

+     *

+     * @return <code>true</code> if a <code>SOAPFault</code> object exists in

+     *         this <code>SOAPBody</code> object; <code>false</code>

+     *         otherwise

+     */

+    public boolean hasFault() {

+        if (hasSOAPFault) {

+            return true;

+        } else {

+            OMElement element = getFirstElement();

+            if (element != null

+                    &&

+                    SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(

+                            element.getLocalName())

+                    &&

+                    (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(

+                            element.getNamespace().getName())

+                    ||

+                    SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(

+                            element.getNamespace().getName()))) {  //added this line

+                hasSOAPFault = true;

+                return true;

+            } else {

+                return false;

+            }

+        }

+    }

+

+    /**

+     * Returns the <code>SOAPFault</code> object in this <code>SOAPBody</code>

+     * object.

+     *

+     * @return the <code>SOAPFault</code> object in this <code>SOAPBody</code>

+     *         object

+     */

+    public SOAPFault getFault() {

+        OMElement element = getFirstElement();

+        if (hasSOAPFault) {

+            return (SOAPFault) element;

+        } else if (element != null

+                &&

+                SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(

+                        element.getLocalName())

+                &&

+                (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(

+                        element.getNamespace().getName())

+                ||

+                SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(

+                        element.getNamespace().getName()))) {     //added this line

+            hasSOAPFault = true;

+            return (SOAPFault) element;

+        } else {

+            return null;

+        }

+

+    }

+

+    /**

+     * @param soapFault

+     * @throws org.apache.ws.commons.om.OMException

+     *

+     * @throws OMException

+     */

+    public void addFault(SOAPFault soapFault) throws OMException {

+        if (hasSOAPFault) {

+            throw new OMException(

+                    "SOAP Body already has a SOAP Fault and there can not be more than one SOAP fault");

+        }

+        addChild(soapFault);

+        hasSOAPFault = true;

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAPEnvelopeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting an implementation of SOAP Envelope as the parent. But received some other implementation");

+        }

+    }

+

+    public OMNode detach() throws OMException {

+        throw new SOAPProcessingException("Can not detach SOAP Body, SOAP Envelope must have a Body !!");

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPElement.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPElement.java
new file mode 100644
index 0000000..0128018
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPElement.java
@@ -0,0 +1,79 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.OMElementImpl;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+public abstract class SOAPElement extends OMElementImpl {

+

+

+    /**

+     * @param parent

+     * @param localName

+     * @param extractNamespaceFromParent     

+     */

+    protected SOAPElement(OMElement parent,

+                          String localName,

+                          boolean extractNamespaceFromParent) throws SOAPProcessingException {

+        super(localName, null, parent);

+        if (parent == null) {

+            throw new SOAPProcessingException(

+                    " Can not create " + localName +

+                    " element without a parent !!");

+        }

+        checkParent(parent);

+

+        if (extractNamespaceFromParent) {

+            this.ns = parent.getNamespace();

+        }

+        this.localName = localName;

+    }

+

+

+    protected SOAPElement(OMElement parent,

+                          String localName,

+                          OMXMLParserWrapper builder) {

+        super(localName, null, parent, builder);

+    }

+

+    /**

+     * Caution : This Constructor is meant to be used only by the SOAPEnvelope.

+     * <p/>

+     * Reasons : This can be used to create a SOAP Element programmatically. But we need to make sure that the user

+     * always passes a parent for the element being created. But SOAP Envelope has no parent.

+     *

+     * @param localName

+     * @param ns

+     */

+    protected SOAPElement(String localName, OMNamespace ns) {

+        super(localName, ns);

+

+    }

+

+    /**

+     * This has to be implemented by all the derived classes to check for the correct parent.

+     */

+    protected abstract void checkParent(OMElement parent) throws SOAPProcessingException;

+

+

+    

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPEnvelopeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPEnvelopeImpl.java
new file mode 100644
index 0000000..b2ae015
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPEnvelopeImpl.java
@@ -0,0 +1,166 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMConstants;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.factory.SOAPLinkedListImplFactory;

+

+import javax.xml.namespace.QName;

+import javax.xml.stream.XMLStreamException;

+

+/**

+ * Class SOAPEnvelopeImpl

+ */

+public class SOAPEnvelopeImpl extends SOAPElement

+        implements SOAPEnvelope, OMConstants {

+    SOAPFactory factory;

+

+    /**

+     * @param builder

+     */

+    public SOAPEnvelopeImpl(OMXMLParserWrapper builder, SOAPFactory factory) {

+        super(null, SOAPConstants.SOAPENVELOPE_LOCAL_NAME, builder);

+        this.factory = factory;

+    }

+

+    /**

+     * @param ns

+     */

+    public SOAPEnvelopeImpl(OMNamespace ns, SOAPFactory factory) {

+        super(SOAPConstants.SOAPENVELOPE_LOCAL_NAME, ns);

+        this.factory = factory;

+    }

+

+    /**

+     * Returns the <CODE>SOAPHeader</CODE> object for this <CODE>

+     * SOAPEnvelope</CODE> object. <P> This SOAPHeader will just be a container

+     * for all the headers in the <CODE>OMMessage</CODE> </P>

+     *

+     * @return the <CODE>SOAPHeader</CODE> object or <CODE> null</CODE> if there

+     *         is none

+     * @throws org.apache.ws.commons.om.OMException

+     *                     if there is a problem obtaining

+     *                     the <CODE>SOAPHeader</CODE>

+     *                     object

+     * @throws OMException

+     */

+    public SOAPHeader getHeader() throws OMException {

+        SOAPHeader header =

+                (SOAPHeader) getFirstChildWithName(

+                        new QName(SOAPConstants.HEADER_LOCAL_NAME));

+        if (builder == null && header == null) {

+            inferFactory();

+            header = factory.createSOAPHeader(this);

+            addChild(header);

+        }

+        return header;

+    }

+

+    private void inferFactory() {

+        if (factory instanceof SOAPLinkedListImplFactory && ns != null) {

+            if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getName())) {

+                factory = OMAbstractFactory.getSOAP12Factory();

+            } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getName())) {

+                factory = OMAbstractFactory.getSOAP11Factory();

+            }

+        }

+    }

+

+    public void addChild(OMNode child) {

+        if ((child instanceof OMElement) && !(child instanceof SOAPHeader || child instanceof SOAPBody)) {

+            throw new SOAPProcessingException("SOAP Envelope can not have children other than SOAP Header and Body", SOAP12Constants.FAULT_CODE_SENDER);

+        } else {

+            super.addChild(child);

+        }

+    }

+

+    /**

+     * Returns the <CODE>SOAPBody</CODE> object associated with this

+     * <CODE>SOAPEnvelope</CODE> object. <P> This SOAPBody will just be a

+     * container for all the BodyElements in the <CODE>OMMessage</CODE> </P>

+     *

+     * @return the <CODE>SOAPBody</CODE> object for this <CODE>

+     *         SOAPEnvelope</CODE> object or <CODE>null</CODE> if there is none

+     * @throws org.apache.ws.commons.om.OMException

+     *                     if there is a problem obtaining

+     *                     the <CODE>SOAPBody</CODE> object

+     * @throws OMException

+     */

+    public SOAPBody getBody() throws OMException {

+        //check for the first element

+        OMElement element = getFirstElement();

+        if (element != null) {

+            if (SOAPConstants.BODY_LOCAL_NAME.equals(element.getLocalName())) {

+                return (SOAPBody) element;

+            } else {      // if not second element SHOULD be the body

+                OMNode node = element.getNextOMSibling();

+                while (node != null && node.getType() != OMNode.ELEMENT_NODE) {

+                    node = node.getNextOMSibling();

+                }

+                element = (OMElement) node;

+

+                if (node != null &&

+                        SOAPConstants.BODY_LOCAL_NAME.equals(element.getLocalName())) {

+                    return (SOAPBody) element;

+                } else {

+                    throw new OMException("SOAPEnvelope must contain a body element which is either first or second child element of the SOAPEnvelope.");

+                }

+            }

+        }

+        return null;

+    }

+

+    /**

+     * Method detach

+     *

+     * @throws OMException

+     */

+    public OMNode detach() throws OMException {

+        throw new OMException("Root Element can not be detached");

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        // here do nothing as SOAPEnvelope doesn't have a parent !!!

+    }

+

+    protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+

+        if (!omOutput.isIgnoreXMLDeclaration()) {

+            String charSetEncoding = omOutput.getCharSetEncoding();

+            String xmlVersion = omOutput.getXmlVersion();

+            omOutput.getXmlStreamWriter().writeStartDocument(charSetEncoding == null ?

+                    OMConstants.DEFAULT_CHAR_SET_ENCODING : charSetEncoding,

+                    xmlVersion == null ? OMConstants.DEFAULT_XML_VERSION : xmlVersion);

+        }

+        super.serialize(omOutput, cache);

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultCodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultCodeImpl.java
new file mode 100644
index 0000000..c2a77cc
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultCodeImpl.java
@@ -0,0 +1,121 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.om.util.ElementHelper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.stream.XMLStreamException;

+

+public abstract class SOAPFaultCodeImpl extends SOAPElement implements SOAPFaultCode {

+

+

+    /**

+     * Constructor OMElementImpl

+     *

+     * @param parent

+     * @param builder

+     */

+    public SOAPFaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, builder);

+    }

+

+    /**

+     * @param parent

+     */

+    public SOAPFaultCodeImpl(SOAPFault parent,

+                             boolean extractNamespaceFromParent) throws SOAPProcessingException {

+        super(parent,

+                SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME,

+                extractNamespaceFromParent);

+    }

+

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {

+        ElementHelper.setNewElement(this, value, value);

+    }

+

+    public SOAPFaultValue getValue() {

+        return (SOAPFaultValue) ElementHelper.getChildWithName(this,

+                SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME);

+    }

+

+    public void setSubCode(SOAPFaultSubCode value) throws SOAPProcessingException {

+        ElementHelper.setNewElement(this, getSubCode(), value);

+    }

+

+    public SOAPFaultSubCode getSubCode() {

+        return (SOAPFaultSubCode) ElementHelper.getChildWithName(this,

+                SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);

+    }

+

+    protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));

+        }

+

+

+        if (!cache) {

+            //No caching

+            if (this.firstChild != null) {

+                OMSerializerUtil.serializeStartpart(this, omOutput);

+                ((OMNodeEx)firstChild).serializeAndConsume(omOutput);

+                OMSerializerUtil.serializeEndpart(omOutput);

+            } else if (!this.done) {

+                if (builderType == PULL_TYPE_BUILDER) {

+                    OMSerializerUtil.serializeByPullStream(this, omOutput);

+                } else {

+                    OMSerializerUtil.serializeStartpart(this, omOutput);

+                    builder.setCache(cache);

+                    builder.next();

+                    OMSerializerUtil.serializeEndpart(omOutput);

+                }

+            } else {

+                OMSerializerUtil.serializeNormal(this, omOutput, cache);

+            }

+            // do not serialise the siblings

+

+

+        } else {

+            //Cached

+            OMSerializerUtil.serializeNormal(this, omOutput, cache);

+

+            // do not serialise the siblings

+        }

+

+

+    }

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultDetailImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultDetailImpl.java
new file mode 100644
index 0000000..9f273ac
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultDetailImpl.java
@@ -0,0 +1,97 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultDetail;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.stream.XMLStreamException;

+import java.util.Iterator;

+

+public abstract class SOAPFaultDetailImpl extends SOAPElement implements SOAPFaultDetail {

+

+    protected SOAPFaultDetailImpl(SOAPFault parent,

+                                  boolean extractNamespaceFromParent) throws SOAPProcessingException {

+        super(parent,

+                SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,

+                extractNamespaceFromParent);

+    }

+

+    protected SOAPFaultDetailImpl(SOAPFault parent,

+                                  OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, builder);

+    }

+

+    public void addDetailEntry(OMElement detailElement) {

+        this.addChild(detailElement);

+    }

+

+    public Iterator getAllDetailEntries() {

+        return this.getChildren();

+    }

+

+    protected void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));

+        }

+

+

+        if (!cache) {

+            //No caching

+            if (this.firstChild != null) {

+                OMSerializerUtil.serializeStartpart(this, omOutput);

+                ((OMNodeEx)firstChild).serializeAndConsume(omOutput);

+                OMSerializerUtil.serializeEndpart(omOutput);

+            } else if (!this.done) {

+                if (builderType == PULL_TYPE_BUILDER) {

+                    OMSerializerUtil.serializeByPullStream(this, omOutput);

+                } else {

+                    OMSerializerUtil.serializeStartpart(this, omOutput);

+                    builder.setCache(cache);

+                    builder.next();

+                    OMSerializerUtil.serializeEndpart(omOutput);

+                }

+            } else {

+                OMSerializerUtil.serializeNormal(this, omOutput, cache);

+            }

+            // do not serialise the siblings

+

+

+        } else {

+            //Cached

+            OMSerializerUtil.serializeNormal(this, omOutput, cache);

+

+            // do not serialise the siblings

+        }

+

+

+    }

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultImpl.java
new file mode 100644
index 0000000..5ee20ec
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultImpl.java
@@ -0,0 +1,236 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMConstants;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.OMElementImpl;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultDetail;

+import org.apache.ws.commons.soap.SOAPFaultNode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultRole;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+import javax.xml.namespace.QName;

+import javax.xml.stream.XMLStreamException;

+import java.io.PrintWriter;

+import java.io.StringWriter;

+import java.util.Iterator;

+

+/**

+ * Class SOAPFaultImpl

+ */

+public abstract class SOAPFaultImpl extends SOAPElement

+        implements SOAPFault, OMConstants {

+

+    protected Exception e;

+   private Log log = LogFactory.getLog(getClass());

+

+    /**

+     * Constructor SOAPFaultImpl

+     *

+     * @param parent

+     * @param e

+     */

+    public SOAPFaultImpl(SOAPBody parent, Exception e) throws SOAPProcessingException {

+        super(parent, SOAPConstants.SOAPFAULT_LOCAL_NAME, true);

+        setException(e);

+    }

+

+    public void setException(Exception e) {

+        this.e = e;

+        putExceptionToSOAPFault(e);

+    }

+

+    public SOAPFaultImpl(SOAPBody parent) throws SOAPProcessingException {

+        super(parent, SOAPConstants.SOAPFAULT_LOCAL_NAME, true);

+    }

+

+    /**

+     * Constructor SOAPFaultImpl

+     *

+     * @param parent

+     * @param builder

+     */

+    public SOAPFaultImpl(SOAPBody parent, OMXMLParserWrapper builder) {

+        super(parent, SOAPConstants.SOAPFAULT_LOCAL_NAME, builder);

+    }

+

+

+    protected abstract SOAPFaultDetail getNewSOAPFaultDetail(SOAPFault fault) throws SOAPProcessingException;

+

+    // --------------- Getters and Settors --------------------------- //

+

+    public void setCode(SOAPFaultCode soapFaultCode) throws SOAPProcessingException {

+        setNewElement(getCode(), soapFaultCode);

+    }

+

+    public SOAPFaultCode getCode() {

+        return (SOAPFaultCode) this.getChildWithName(

+                SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME);

+    }

+

+    public void setReason(SOAPFaultReason reason) throws SOAPProcessingException {

+        setNewElement(getReason(), reason);

+    }

+

+    public SOAPFaultReason getReason() {

+        return (SOAPFaultReason) this.getChildWithName(

+                SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME);

+    }

+

+    public void setNode(SOAPFaultNode node) throws SOAPProcessingException {

+        setNewElement(getNode(), node);

+    }

+

+    public SOAPFaultNode getNode() {

+        return (SOAPFaultNode) this.getChildWithName(

+                SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME);

+    }

+

+    public void setRole(SOAPFaultRole role) throws SOAPProcessingException {

+        setNewElement(getRole(), role);

+    }

+

+    public SOAPFaultRole getRole() {

+        return (SOAPFaultRoleImpl) this.getChildWithName(

+                SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME);

+    }

+

+    public void setDetail(SOAPFaultDetail detail) throws SOAPProcessingException {

+        setNewElement(getDetail(), detail);

+    }

+

+    public SOAPFaultDetail getDetail() {

+        return (SOAPFaultDetail) this.getChildWithName(

+                SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME);

+    }

+

+    /**

+     * If exception detailElement is not there we will return null

+     */

+    public Exception getException() throws OMException {

+        SOAPFaultDetail detail = getDetail();

+        if (detail == null) {

+            return null;

+        }

+

+        OMElement exceptionElement = getDetail().getFirstChildWithName(

+                new QName(SOAPConstants.SOAP_FAULT_DETAIL_EXCEPTION_ENTRY));

+        if (exceptionElement != null && exceptionElement.getText() != null) {

+            return new Exception(exceptionElement.getText());

+        }

+        return null;

+    }

+

+    protected void putExceptionToSOAPFault(Exception e) throws SOAPProcessingException {

+        StringWriter sw = new StringWriter();

+        e.printStackTrace(new PrintWriter(sw));

+        sw.flush();

+        getDetail();

+        if (getDetail() == null) {

+            setDetail(getNewSOAPFaultDetail(this));

+

+        }

+        OMElement faultDetailEnty = new OMElementImpl(

+                SOAPConstants.SOAP_FAULT_DETAIL_EXCEPTION_ENTRY,

+                this.getNamespace());

+        faultDetailEnty.setText(sw.getBuffer().toString());

+        getDetail().addChild(faultDetailEnty);

+    }

+

+    protected void setNewElement(OMElement myElement, OMElement newElement) {

+        if (myElement != null) {

+            myElement.discard();

+        }

+        if (newElement != null && newElement.getParent() != null) {

+            newElement.discard();

+        }

+        this.addChild(newElement);

+        myElement = newElement;

+    }

+

+    protected OMElement getChildWithName(String childName) {

+        Iterator childrenIter = getChildren();

+        while (childrenIter.hasNext()) {

+            OMNode node = (OMNode) childrenIter.next();

+            if (node.getType() == OMNode.ELEMENT_NODE &&

+                    childName.equals(((OMElement) node).getLocalName())) {

+                return (OMElement) node;

+            }

+        }

+        return null;

+    }

+

+    protected void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));

+        }

+

+

+        // this is a special case. This fault element may contain its children in any order. But spec mandates a specific order

+        // the overriding of the method will facilitate that. Not sure this is the best method to do this :(

+        build();

+

+        OMSerializerUtil.serializeStartpart(this, omOutput);

+        SOAPFaultCode faultCode = getCode();

+        if (faultCode != null) {

+            ((OMNodeEx)faultCode).serialize(omOutput);

+        }

+        SOAPFaultReason faultReason = getReason();

+        if (faultReason != null) {

+            ((OMNodeEx)faultReason).serialize(omOutput);

+        }

+

+        serializeFaultNode(omOutput);

+

+        SOAPFaultRole faultRole = getRole();

+        if (faultRole != null) {

+            ((OMNodeEx)faultRole).serialize(omOutput);

+        }

+

+        SOAPFaultDetail faultDetail = getDetail();

+        if (faultDetail != null) {

+            ((OMNodeEx)faultDetail).serialize(omOutput);

+        }

+

+        OMSerializerUtil.serializeEndpart(omOutput);

+    }

+

+    protected abstract void serializeFaultNode(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException;

+        

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultNodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultNodeImpl.java
new file mode 100644
index 0000000..554c2cd
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultNodeImpl.java
@@ -0,0 +1,91 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultNode;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.stream.XMLStreamException;

+

+public abstract class SOAPFaultNodeImpl extends SOAPElement implements SOAPFaultNode {

+

+    public SOAPFaultNodeImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME, true);

+    }

+

+    public SOAPFaultNodeImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME, builder);

+    }

+

+    public void setNodeValue(String uri) {

+        this.setText(uri);

+    }

+

+    public String getNodeValue() {

+        return this.getText();

+    }

+

+    protected void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+            // select the builder

+            short builderType = PULL_TYPE_BUILDER;    // default is pull type

+            if (builder != null) {

+                builderType = this.builder.getBuilderType();

+            }

+            if ((builderType == PUSH_TYPE_BUILDER)

+                    && (builder.getRegisteredContentHandler() == null)) {

+                builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));

+            }

+

+

+            if (!cache) {

+                //No caching

+                if (this.firstChild != null) {

+                    OMSerializerUtil.serializeStartpart(this, omOutput);

+                    ((OMNodeEx)firstChild).serializeAndConsume(omOutput);

+                    OMSerializerUtil.serializeEndpart(omOutput);

+                } else if (!this.done) {

+                    if (builderType == PULL_TYPE_BUILDER) {

+                        OMSerializerUtil.serializeByPullStream(this, omOutput);

+                    } else {

+                        OMSerializerUtil.serializeStartpart(this, omOutput);

+                        builder.setCache(cache);

+                        builder.next();

+                        OMSerializerUtil.serializeEndpart(omOutput);

+                    }

+                } else {

+                    OMSerializerUtil.serializeNormal(this, omOutput, cache);

+                }

+                // do not serialise the siblings

+

+

+            } else {

+                //Cached

+                OMSerializerUtil.serializeNormal(this, omOutput, cache);

+

+                // do not serialise the siblings

+            }

+

+

+        }

+    

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultReasonImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultReasonImpl.java
new file mode 100644
index 0000000..f429a6e
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultReasonImpl.java
@@ -0,0 +1,111 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.om.util.ElementHelper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.stream.XMLStreamException;

+

+public abstract class SOAPFaultReasonImpl extends SOAPElement implements SOAPFaultReason {

+    protected SOAPFaultText text;

+

+    /**

+     * Constructor OMElementImpl

+     *

+     * @param parent

+     * @param builder

+     */

+    public SOAPFaultReasonImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME, builder);

+    }

+

+    /**

+     * @param parent

+     */

+    public SOAPFaultReasonImpl(OMElement parent,

+                               boolean extractNamespaceFromParent) throws SOAPProcessingException {

+        super(parent,

+                SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME,

+                extractNamespaceFromParent);

+    }

+

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    public void setSOAPText(SOAPFaultText soapFaultText) throws SOAPProcessingException {

+        ElementHelper.setNewElement(this, text, soapFaultText);

+    }

+

+    public SOAPFaultText getSOAPText() {

+        return (SOAPFaultText) ElementHelper.getChildWithName(this,

+                SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME);

+    }

+

+    protected void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));

+        }

+

+

+        if (!cache) {

+            //No caching

+            if (this.firstChild != null) {

+                OMSerializerUtil.serializeStartpart(this, omOutput);

+                ((OMNodeEx)firstChild).serializeAndConsume(omOutput);

+                OMSerializerUtil.serializeEndpart(omOutput);

+            } else if (!this.done) {

+                if (builderType == PULL_TYPE_BUILDER) {

+                    OMSerializerUtil.serializeByPullStream(this, omOutput);

+                } else {

+                    OMSerializerUtil.serializeStartpart(this, omOutput);

+                    builder.setCache(cache);

+                    builder.next();

+                    OMSerializerUtil.serializeEndpart(omOutput);

+                }

+            } else {

+                OMSerializerUtil.serializeNormal(this, omOutput, cache);

+            }

+            // do not serialise the siblings

+

+

+        } else {

+            //Cached

+            OMSerializerUtil.serializeNormal(this, omOutput, cache);

+

+            // do not serialise the siblings

+        }

+

+

+    }

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultRoleImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultRoleImpl.java
new file mode 100644
index 0000000..38d7b60
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultRoleImpl.java
@@ -0,0 +1,94 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.stream.XMLStreamException;

+

+public abstract class SOAPFaultRoleImpl extends SOAPElement implements org.apache.ws.commons.soap.SOAPFaultRole {

+

+    public SOAPFaultRoleImpl(SOAPFault parent,

+                             boolean extractNamespaceFromParent) throws SOAPProcessingException {

+        super(parent,

+                SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME,

+                extractNamespaceFromParent);

+    }

+

+    public SOAPFaultRoleImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME, builder);

+    }

+

+    public void setRoleValue(String uri) {

+        this.setText(uri);

+    }

+

+    public String getRoleValue() {

+        return this.getText();

+    }

+

+    protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(omOutput));

+        }

+

+

+        if (!cache) {

+            //No caching

+            if (this.firstChild != null) {

+                OMSerializerUtil.serializeStartpart(this, omOutput);

+                ((OMNodeEx)firstChild).serializeAndConsume(omOutput);

+                OMSerializerUtil.serializeEndpart(omOutput);

+            } else if (!this.done) {

+                if (builderType == PULL_TYPE_BUILDER) {

+                    OMSerializerUtil.serializeByPullStream(this, omOutput);

+                } else {

+                    OMSerializerUtil.serializeStartpart(this, omOutput);

+                    builder.setCache(cache);

+                    builder.next();

+                    OMSerializerUtil.serializeEndpart(omOutput);

+                }

+            } else {

+                OMSerializerUtil.serializeNormal(this, omOutput, cache);

+            }

+            // do not serialise the siblings

+

+

+        } else {

+            //Cached

+            OMSerializerUtil.serializeNormal(this, omOutput, cache);

+

+            // do not serialise the siblings

+        }

+

+

+    }

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultSubCodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultSubCodeImpl.java
new file mode 100644
index 0000000..02bc336
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultSubCodeImpl.java
@@ -0,0 +1,69 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.util.ElementHelper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+public abstract class SOAPFaultSubCodeImpl extends SOAPElement implements SOAPFaultSubCode {

+

+    protected SOAPFaultValue value;

+    protected SOAPFaultSubCode subCode;

+

+

+    protected SOAPFaultSubCodeImpl(OMElement parent, String localName) throws SOAPProcessingException {

+        super(parent, localName, true);

+    }

+

+    protected SOAPFaultSubCodeImpl(OMElement parent,

+                                   String localName,

+                                   OMXMLParserWrapper builder) {

+        super(parent, localName, builder);

+    }

+

+    public void setValue(SOAPFaultValue soapFaultSubCodeValue) throws SOAPProcessingException {

+        ElementHelper.setNewElement(this, value, soapFaultSubCodeValue);

+    }

+

+    public SOAPFaultValue getValue() {

+        if (value == null) {

+            value =

+                    (SOAPFaultValue) ElementHelper.getChildWithName(this,

+                            SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME);

+        }

+        return value;

+    }

+

+    public void setSubCode(SOAPFaultSubCode subCode) throws SOAPProcessingException {

+        ElementHelper.setNewElement(this, this.subCode, subCode);

+

+    }

+

+    public SOAPFaultSubCode getSubCode() {

+        if (subCode == null) {

+            subCode =

+                    (SOAPFaultSubCode) ElementHelper.getChildWithName(this,

+                            SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);

+        }

+        return subCode;

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultTextImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultTextImpl.java
new file mode 100644
index 0000000..f5ad236
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultTextImpl.java
@@ -0,0 +1,70 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.OMAttributeImpl;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.namespace.QName;

+

+public abstract class SOAPFaultTextImpl extends SOAPElement implements SOAPFaultText {

+    protected OMAttribute langAttr;

+    protected OMNamespace langNamespace = OMAbstractFactory.getOMFactory()

+            .createOMNamespace(

+                    SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_URI,

+                    SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX);

+

+    protected SOAPFaultTextImpl(SOAPFaultReason parent) throws SOAPProcessingException {

+        super(parent, SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME, true);

+    }

+

+    protected SOAPFaultTextImpl(SOAPFaultReason parent,

+                                OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME, builder);

+    }

+

+

+    public void setLang(String lang) {

+        //langAttr = new OMAttributeImpl(SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME, parent.getNamespace(), lang);

+        langAttr =

+                new OMAttributeImpl(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME,

+                        langNamespace,

+                        lang);

+        this.addAttribute(langAttr);

+    }

+

+    public String getLang() {

+        if (langAttr == null) {

+            //langAttr = this.getFirstAttribute(new QName(SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME, parent.getNamespace().getName()));

+            langAttr =

+                    this.getAttribute(

+                            new QName(langNamespace.getName(),

+                                    SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME,

+                                    SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX));

+        }

+

+        return langAttr == null ? null : langAttr.getAttributeValue();

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultValueImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultValueImpl.java
new file mode 100644
index 0000000..7da4ee2
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPFaultValueImpl.java
@@ -0,0 +1,34 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+public abstract class SOAPFaultValueImpl extends SOAPElement implements SOAPFaultValue {

+

+    protected SOAPFaultValueImpl(OMElement parent) throws SOAPProcessingException {

+        super(parent, SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME, true);

+    }

+

+    protected SOAPFaultValueImpl(OMElement parent, OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME, builder);

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPHeaderBlockImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPHeaderBlockImpl.java
new file mode 100644
index 0000000..307c57c
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPHeaderBlockImpl.java
@@ -0,0 +1,111 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.OMAttributeImpl;

+import org.apache.ws.commons.om.impl.llom.OMElementImpl;

+import org.apache.ws.commons.om.impl.llom.OMNamespaceImpl;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.namespace.QName;

+

+/**

+ * Class SOAPHeaderBlockImpl

+ */

+public abstract class SOAPHeaderBlockImpl extends OMElementImpl

+        implements SOAPHeaderBlock {

+

+    private boolean processed = false;

+

+    /**

+     * @param localName

+     * @param ns

+     * @param parent     

+     */

+    public SOAPHeaderBlockImpl(String localName,

+                               OMNamespace ns,

+                               SOAPHeader parent) throws SOAPProcessingException {

+        super(localName, ns, parent);

+        this.setNamespace(ns);

+    }

+

+    /**

+     * Constructor SOAPHeaderBlockImpl.

+     *

+     * @param localName

+     * @param ns

+     * @param parent

+     * @param builder

+     */

+    public SOAPHeaderBlockImpl(String localName, OMNamespace ns,

+                               OMElement parent, OMXMLParserWrapper builder) {

+        super(localName, ns, parent, builder);

+        this.setNamespace(ns);

+    }

+

+    /**

+     * @param attributeName

+     * @param attrValue

+     * @param soapEnvelopeNamespaceURI     

+     */

+    protected void setAttribute(String attributeName,

+                                String attrValue,

+                                String soapEnvelopeNamespaceURI) {

+        OMAttribute omAttribute = this.getAttribute(

+                new QName(soapEnvelopeNamespaceURI, attributeName));

+        if (omAttribute != null) {

+            omAttribute.setAttributeValue(attrValue);

+        } else {

+            OMAttribute attribute = new OMAttributeImpl(attributeName,

+                    new OMNamespaceImpl(soapEnvelopeNamespaceURI,

+                            SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX),

+                    attrValue);

+            this.addAttribute(attribute);

+        }

+    }

+

+    /**

+     * Method getAttribute.

+     *

+     * @param attrName

+     * @param soapEnvelopeNamespaceURI     

+     * @return Returns String.

+     */

+    protected String getAttribute(String attrName,

+                                  String soapEnvelopeNamespaceURI) {

+        OMAttribute omAttribute = this.getAttribute(

+                new QName(soapEnvelopeNamespaceURI, attrName));

+        return (omAttribute != null)

+                ? omAttribute.getAttributeValue()

+                : null;

+    }

+

+    public boolean isProcessed() {

+        return processed;

+    }

+

+    public void setProcessed() {

+        processed = true;

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPHeaderImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPHeaderImpl.java
new file mode 100644
index 0000000..0cdb128
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPHeaderImpl.java
@@ -0,0 +1,226 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import java.util.ArrayList;

+import java.util.Iterator;

+

+/**

+ * Class SOAPHeaderImpl

+ */

+public abstract class SOAPHeaderImpl extends SOAPElement implements SOAPHeader {

+    /**

+     * @param envelope

+     */

+    public SOAPHeaderImpl(SOAPEnvelope envelope) throws SOAPProcessingException {

+        super(envelope, SOAPConstants.HEADER_LOCAL_NAME, true);

+

+    }

+

+    /**

+     * Constructor SOAPHeaderImpl

+     *

+     * @param envelope

+     * @param builder

+     */

+    public SOAPHeaderImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) {

+        super(envelope, SOAPConstants.HEADER_LOCAL_NAME, builder);

+    }

+

+    /**

+     * Creates a new <CODE>SOAPHeaderBlock</CODE> object initialized with the

+     * specified name and adds it to this <CODE>SOAPHeader</CODE> object.

+     *

+     * @param localName

+     * @param ns

+     * @return the new <CODE>SOAPHeaderBlock</CODE> object that was inserted

+     *         into this <CODE>SOAPHeader</CODE> object

+     * @throws org.apache.ws.commons.om.OMException

+     *                     if a SOAP error occurs

+     * @throws OMException

+     */

+    public abstract SOAPHeaderBlock addHeaderBlock(String localName,

+                                                   OMNamespace ns)

+            throws OMException;

+

+    /**

+     * Returns a list of all the <CODE>SOAPHeaderBlock</CODE> objects in this

+     * <CODE>SOAPHeader</CODE> object that have the the specified actor. An

+     * actor is a global attribute that indicates the intermediate parties to

+     * whom the message should be sent. An actor receives the message and then

+     * sends it to the next actor. The default actor is the ultimate intended

+     * recipient for the message, so if no actor attribute is included in a

+     * <CODE>SOAPHeader</CODE> object, the message is sent to its ultimate

+     * destination.

+     *

+     * @param paramRole a <CODE>String</CODE> giving the URI of the actor for

+     *                  which to search

+     * @return an <CODE>Iterator</CODE> object over all the <CODE>

+     *         SOAPHeaderBlock</CODE> objects that contain the specified actor

+     * @see #extractHeaderBlocks(String) extractHeaderBlocks(java.lang.String)

+     */

+    public Iterator examineHeaderBlocks(String paramRole) {

+        Iterator headerBlocksIter = this.getChildren();

+        ArrayList headersWithGivenActor = new ArrayList();

+        

+        if(paramRole == null || "".equals(paramRole)){

+    		return returnAllSOAPHeaders(this.getChildren());

+    	}

+        

+        while (headerBlocksIter.hasNext()) {

+            Object o = headerBlocksIter.next();

+            if (o instanceof SOAPHeaderBlock) {

+                SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) o;

+                String role = soapHeaderBlock.getRole();

+                if ((role != null) && role.equalsIgnoreCase(paramRole)) {

+                    headersWithGivenActor.add(soapHeaderBlock);

+                }

+            }

+        }

+        return headersWithGivenActor.iterator();

+    }

+

+    private Iterator returnAllSOAPHeaders(Iterator children) {

+    	ArrayList headers = new ArrayList();

+    	while (children.hasNext()) {

+            Object o = children.next();

+            if (o instanceof SOAPHeaderBlock) {

+                headers.add(o);

+            }

+        }

+    	

+    	return headers.iterator();

+		

+	}

+

+	/**

+     * Returns a list of all the <CODE>SOAPHeaderBlock</CODE> objects in this

+     * <CODE>SOAPHeader</CODE> object that have the the specified role and

+     * detaches them from this <CODE> SOAPHeader</CODE> object. <P>This method

+     * allows an role to process only the parts of the <CODE>SOAPHeader</CODE>

+     * object that apply to it and to remove them before passing the message on

+     * to the next role.

+     *

+     * @param role a <CODE>String</CODE> giving the URI of the role for which to

+     *             search

+     * @return an <CODE>Iterator</CODE> object over all the <CODE>

+     *         SOAPHeaderBlock</CODE> objects that contain the specified role

+     * @see #examineHeaderBlocks(String) examineHeaderBlocks(java.lang.String)

+     */

+    public abstract Iterator extractHeaderBlocks(String role);

+

+    /**

+     * Returns an <code>Iterator</code> over all the <code>SOAPHeaderBlock</code>

+     * objects in this <code>SOAPHeader</code> object that have the specified

+     * actor and that have a MustUnderstand attribute whose value is equivalent

+     * to <code>true</code>.

+     *

+     * @param actor a <code>String</code> giving the URI of the actor for which

+     *              to search

+     * @return an <code>Iterator</code> object over all the

+     *         <code>SOAPHeaderBlock</code> objects that contain the specified

+     *         actor and are marked as MustUnderstand

+     */

+    public Iterator examineMustUnderstandHeaderBlocks(String actor) {

+        Iterator headerBlocksIter = this.getChildren();

+        ArrayList mustUnderstandHeadersWithGivenActor = new ArrayList();

+        while (headerBlocksIter.hasNext()) {

+            Object o = headerBlocksIter.next();

+            if (o instanceof SOAPHeaderBlock) {

+                SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock) o;

+                String role = soapHeaderBlock.getRole();

+                boolean mustUnderstand = soapHeaderBlock.getMustUnderstand();

+                if ((role != null) && role.equalsIgnoreCase(actor) &&

+                        mustUnderstand) {

+                    mustUnderstandHeadersWithGivenActor.add(soapHeaderBlock);

+                }

+            }

+        }

+        return mustUnderstandHeadersWithGivenActor.iterator();

+    }

+

+    /**

+     * Returns an <code>Iterator</code> over all the <code>SOAPHeaderBlock</code>

+     * objects in this <code>SOAPHeader</code> object. Not that this will return

+     * elements containing the QName (http://schemas.xmlsoap.org/soap/envelope/,

+     * Header)

+     *

+     * @return an <code>Iterator</code> object over all the

+     *         <code>SOAPHeaderBlock</code> objects contained by this

+     *         <code>SOAPHeader</code>

+     */

+    public Iterator examineAllHeaderBlocks() {

+        return this.getChildrenWithName(null);

+    }

+

+    /**

+     * Returns an <code>Iterator</code> over all the <code>SOAPHeaderBlock</code>

+     * objects in this <code>SOAPHeader </code> object and detaches them from

+     * this <code>SOAPHeader</code> object.

+     *

+     * @return an <code>Iterator</code> object over all the

+     *         <code>SOAPHeaderBlock</code> objects contained by this

+     *         <code>SOAPHeader</code>

+     */

+    public Iterator extractAllHeaderBlocks() {

+        throw new UnsupportedOperationException(); // TODO implement this

+    }

+

+    public ArrayList getHeaderBlocksWithNSURI(String nsURI) {

+        ArrayList headers = null;

+        OMNode node = null;

+        OMElement header = this.getFirstElement();

+

+        if (header != null) {

+            headers = new ArrayList();

+        }

+

+        node = header;

+

+        while (node != null) {

+            if (node.getType() == OMNode.ELEMENT_NODE) {

+                header = (OMElement) node;

+                if (nsURI.equals(header.getNamespace().getName())) {

+                    headers.add(header);

+                }

+            }

+            node = node.getNextOMSibling();

+

+        }

+        return headers;

+

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAPEnvelopeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting an implementation of SOAP Envelope as the parent. But received some other implementation");

+        }

+    }

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPMessageImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPMessageImpl.java
new file mode 100644
index 0000000..e793376
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPMessageImpl.java
@@ -0,0 +1,70 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.om.impl.llom.OMDocumentImpl;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPMessage;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.stream.XMLStreamException;

+

+public class SOAPMessageImpl extends OMDocumentImpl implements SOAPMessage {

+

+

+    public SOAPMessageImpl() {

+    }

+

+    public SOAPMessageImpl(SOAPEnvelope envelope, OMXMLParserWrapper parserWrapper) {

+        super(envelope, parserWrapper);

+    }

+

+    public SOAPMessageImpl(OMXMLParserWrapper parserWrapper) {

+        super(parserWrapper);

+    }

+

+

+    public SOAPEnvelope getSOAPEnvelope() throws SOAPProcessingException {

+        return (SOAPEnvelope) getOMDocumentElement();

+    }

+

+    public void setSOAPEnvelope(SOAPEnvelope envelope) throws SOAPProcessingException {

+        super.addChild(envelope);

+        this.documentElement = envelope;

+    }

+

+    public void setOMDocumentElement(OMElement rootElement) {

+        throw new UnsupportedOperationException("This is not allowed. Use set SOAPEnvelope instead");

+    }

+

+    public void setFirstChild(OMNode firstChild) {

+        throw new UnsupportedOperationException("This is not allowed. Use set SOAPEnvelope instead");

+    }

+

+    protected void serialize(OMOutputImpl omOutput, boolean cache, boolean includeXMLDeclaration) throws XMLStreamException {

+        if (cache) {

+            ((OMNodeEx)this.documentElement).serialize(omOutput);

+        } else {

+            ((OMNodeEx)this.documentElement).serializeAndConsume(omOutput);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/SOAPTextImpl.java b/src/org/apache/ws/commons/soap/impl/llom/SOAPTextImpl.java
new file mode 100644
index 0000000..8a13736
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/SOAPTextImpl.java
@@ -0,0 +1,46 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+public class SOAPTextImpl extends SOAPElement {

+

+    protected SOAPTextImpl(OMElement parent) throws SOAPProcessingException {

+        super(parent, SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME, true);

+    }

+

+    protected SOAPTextImpl(OMElement parent, OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME, builder);

+    }

+

+    public void setLang(String lang) {

+        // TODO : Chinthaka fix me

+    }

+

+    public String getLang() {

+        // TODO Chinthaka fix me

+        return null;

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        // do nothing

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/builder/SOAP11BuilderHelper.java b/src/org/apache/ws/commons/soap/impl/llom/builder/SOAP11BuilderHelper.java
new file mode 100644
index 0000000..9eb96fd
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/builder/SOAP11BuilderHelper.java
@@ -0,0 +1,174 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.builder;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.exception.OMBuilderException;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.w3c.dom.Element;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+

+public class SOAP11BuilderHelper extends SOAPBuilderHelper implements SOAP11Constants {

+    private SOAPFactory factory;

+    private boolean faultcodePresent = false;

+    private boolean faultstringPresent = false;

+

+    private OMElement lastProcessedSOAPElement;

+

+    public SOAP11BuilderHelper(StAXSOAPModelBuilder builder) {

+        super(builder);

+        factory = builder.getSoapFactory();

+    }

+

+    public OMElement handleEvent(XMLStreamReader parser,

+                                 OMElement parent,

+                                 int elementLevel) throws SOAPProcessingException {

+        this.parser = parser;

+

+        OMElement element = null;

+        String localName = parser.getLocalName();

+

+        if (elementLevel == 4) {

+

+            if (SOAP_FAULT_CODE_LOCAL_NAME.equals(localName)) {

+                if (faultstringPresent) {

+                    builder.setBooleanProcessingMandatoryFaultElements(false);

+                }

+                SOAPFaultCode code = factory.createSOAPFaultCode(

+                        (SOAPFault) parent, builder);

+                SOAPFaultValue value = factory.createSOAPFaultValue(code);

+                processNamespaceData(code, true);

+                processAttributes(code);

+

+                processText(parser, value);

+                ((OMNodeEx)code).setComplete(true);

+                element = code;

+                builder.elementLevel--;

+

+                faultcodePresent = true;

+            } else if (SOAP_FAULT_STRING_LOCAL_NAME.equals(localName)) {

+                if (faultcodePresent) {

+                    builder.setBooleanProcessingMandatoryFaultElements(false);

+                }

+

+

+                SOAPFaultReason reason = factory.createSOAPFaultReason(

+                        (SOAPFault) parent, builder);

+                SOAPFaultText faultText = factory.createSOAPFaultText(reason);

+                processNamespaceData(reason, true);

+                processAttributes(reason);

+

+                processText(parser, faultText);

+                ((OMNodeEx)reason).setComplete(true);

+                element = reason;

+                builder.elementLevel--;

+

+

+                faultstringPresent = true;

+            } else if (SOAP_FAULT_ACTOR_LOCAL_NAME.equals(localName)) {

+                element =

+                        factory.createSOAPFaultRole((SOAPFault) parent,

+                                builder);

+                processNamespaceData(element, true);

+                processAttributes(element);

+            } else if (SOAP_FAULT_DETAIL_LOCAL_NAME.equals(localName)) {

+                element =

+                        factory.createSOAPFaultDetail((SOAPFault) parent,

+                                builder);

+                processNamespaceData(element, true);

+                processAttributes(element);

+            } else {

+                element =

+                        factory.createOMElement(

+                                localName, null, parent, builder);

+                processNamespaceData(element, false);

+                processAttributes(element);

+            }

+

+        } else if (elementLevel == 5) {

+

+        	String parentTagName = "";

+        	if(parent instanceof Element) {

+        		parentTagName = ((Element)parent).getTagName();

+        	} else {

+        		parentTagName = parent.getLocalName();

+        	}

+        	

+            if (parentTagName.equals(SOAP_FAULT_CODE_LOCAL_NAME)) {

+                throw new OMBuilderException(

+                        "faultcode element should not have children");

+            } else if (parentTagName.equals(

+                    SOAP_FAULT_STRING_LOCAL_NAME)) {

+                throw new OMBuilderException(

+                        "faultstring element should not have children");

+            } else if (parentTagName.equals(

+                    SOAP_FAULT_ACTOR_LOCAL_NAME)) {

+                throw new OMBuilderException(

+                        "faultactor element should not have children");

+            } else {

+                element =

+                        this.factory.createOMElement(

+                                localName, null, parent, builder);

+                processNamespaceData(element, false);

+                processAttributes(element);

+            }

+

+        } else if (elementLevel > 5) {

+            element =

+                    this.factory.createOMElement(localName,

+                            null,

+                            parent,

+                            builder);

+            processNamespaceData(element, false);

+            processAttributes(element);

+        }

+

+        return element;

+    }

+

+    private void processText(XMLStreamReader parser, OMElement value) {

+        try {

+            int token = parser.next();

+            while (token != XMLStreamReader.END_ELEMENT) {

+                if (token == XMLStreamReader.CHARACTERS) {

+                    OMText text = factory.createText(value, parser.getText());

+                    value.addChild(text);

+                } else {

+                    throw new SOAPProcessingException(

+                            "Only Characters are allowed here");

+                }

+                token = parser.next();

+            }

+

+

+        } catch (XMLStreamException e) {

+            throw new SOAPProcessingException(e);

+        }

+    }

+

+}
\ No newline at end of file
diff --git a/src/org/apache/ws/commons/soap/impl/llom/builder/SOAP12BuilderHelper.java b/src/org/apache/ws/commons/soap/impl/llom/builder/SOAP12BuilderHelper.java
new file mode 100644
index 0000000..c2c1724
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/builder/SOAP12BuilderHelper.java
@@ -0,0 +1,321 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.builder;

+

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.exception.OMBuilderException;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.stream.XMLStreamReader;

+import java.util.Vector;

+

+public class SOAP12BuilderHelper extends SOAPBuilderHelper {

+

+    private SOAPFactory factory;

+    private boolean codePresent = false;

+    private boolean reasonPresent = false;

+    private boolean nodePresent = false;

+    private boolean rolePresent = false;

+    private boolean detailPresent = false;

+    private boolean subcodeValuePresent = false;

+    private boolean subSubcodePresent = false;

+    private boolean valuePresent = false;

+    private boolean subcodePresent = false;

+    private boolean codeprocessing = false;

+    private boolean subCodeProcessing = false;

+    private boolean reasonProcessing = false;

+    private Vector detailElementNames;

+

+    public SOAP12BuilderHelper(StAXSOAPModelBuilder builder) {

+        super(builder);

+        factory = builder.getSoapFactory();

+    }

+

+    public OMElement handleEvent(XMLStreamReader parser,

+                                 OMElement parent,

+                                 int elementLevel) throws SOAPProcessingException {

+

+        this.parser = parser;

+        OMElement element = null;

+

+        if (elementLevel == 4) {

+            if (parser.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {

+                if (codePresent) {

+                    throw new OMBuilderException(

+                            "Multiple Code element encountered");

+                } else {

+                    element =

+                            factory.createSOAPFaultCode((SOAPFault) parent,

+                                    builder);

+                    codePresent = true;

+                    codeprocessing = true;

+                }

+            } else if (parser.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {

+                if (!codeprocessing && !subCodeProcessing) {

+                    if (codePresent) {

+                        if (reasonPresent) {

+                            throw new OMBuilderException(

+                                    "Multiple Reason Element encountered");

+                        } else {

+                            element =

+                                    factory.createSOAPFaultReason(

+                                            (SOAPFault) parent, builder);

+                            reasonPresent = true;

+                            reasonProcessing = true;

+                        }

+                    } else {

+                        throw new OMBuilderException(

+                                "Wrong element order encountred at " +

+                                parser.getLocalName());

+                    }

+                } else {

+                    if (codeprocessing) {

+                        throw new OMBuilderException(

+                                "Code doesn't have a value");

+                    } else {

+                        throw new OMBuilderException(

+                                "A subcode doesn't have a Value");

+                    }

+                }

+

+            } else if (parser.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME)) {

+                if (!reasonProcessing) {

+                    if (reasonPresent && !rolePresent && !detailPresent) {

+                        if (nodePresent) {

+                            throw new OMBuilderException(

+                                    "Multiple Node element encountered");

+                        } else {

+                            element =

+                                    factory.createSOAPFaultNode(

+                                            (SOAPFault) parent, builder);

+                            nodePresent = true;

+                        }

+                    } else {

+                        throw new OMBuilderException(

+                                "wrong element order encountered at " +

+                                parser.getLocalName());

+                    }

+                } else {

+                    throw new OMBuilderException(

+                            "Reason element Should have a text");

+                }

+            } else if (parser.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME)) {

+                if (!reasonProcessing) {

+                    if (reasonPresent && !detailPresent) {

+                        if (rolePresent) {

+                            throw new OMBuilderException(

+                                    "Multiple Role element encountered");

+                        } else {

+                            element =

+                                    factory.createSOAPFaultRole(

+                                            (SOAPFault) parent, builder);

+                            rolePresent = true;

+                        }

+                    } else {

+                        throw new OMBuilderException(

+                                "Wrong element order encountered at " +

+                                parser.getLocalName());

+                    }

+                } else {

+                    throw new OMBuilderException(

+                            "Reason element should have a text");

+                }

+            } else if (parser.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {

+                if (!reasonProcessing) {

+                    if (reasonPresent) {

+                        if (detailPresent) {

+                            throw new OMBuilderException(

+                                    "Multiple detail element encountered");

+                        } else {

+                            element =

+                                    factory.createSOAPFaultDetail(

+                                            (SOAPFault) parent, builder);

+                            detailPresent = true;

+                        }

+                    } else {

+                        throw new OMBuilderException(

+                                "wrong element order encountered at " +

+                                parser.getLocalName());

+                    }

+                } else {

+                    throw new OMBuilderException(

+                            "Reason element should have a text");

+                }

+            } else {

+                throw new OMBuilderException(

+                        parser.getLocalName() +

+                        " unsupported element in SOAPFault element");

+            }

+

+        } else if (elementLevel == 5) {

+            if (parent.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {

+                if (parser.getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME)) {

+                    if (!valuePresent) {

+                        element =

+                                factory.createSOAPFaultValue(

+                                        (SOAPFaultCode) parent, builder);

+                        valuePresent = true;

+                        codeprocessing = false;

+                    } else {

+                        throw new OMBuilderException(

+                                "Multiple value Encountered in code element");

+                    }

+

+                } else if (parser.getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {

+                    if (!subcodePresent) {

+                        if (valuePresent) {

+                            element =

+                                    factory.createSOAPFaultSubCode(

+                                            (SOAPFaultCode) parent, builder);

+                            subcodePresent = true;

+                            subCodeProcessing = true;

+                        } else {

+                            throw new OMBuilderException(

+                                    "Value should present before the subcode");

+                        }

+

+                    } else {

+                        throw new OMBuilderException(

+                                "multiple subcode Encountered in code element");

+                    }

+                } else {

+                    throw new OMBuilderException(

+                            parser.getLocalName() +

+                            " is not supported inside the code element");

+                }

+

+            } else if (parent.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {

+                if (parser.getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME)) {

+                    element =

+                            factory.createSOAPFaultText(

+                                    (SOAPFaultReason) parent, builder);

+                    ((OMNodeEx)element).setComplete(false);

+                    reasonProcessing = false;

+                    builder.setBooleanProcessingMandatoryFaultElements(false);

+                } else {

+                    throw new OMBuilderException(

+                            parser.getLocalName() +

+                            " is not supported inside the reason");

+                }

+            } else if (parent.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {

+                element =

+                        this.factory.createOMElement(

+                                parser.getLocalName(), null, parent, builder);

+                builder.setProcessingDetailElements(true);

+                detailElementNames = new Vector();

+                detailElementNames.add(parser.getLocalName());

+

+            } else {

+                throw new OMBuilderException(

+                        parent.getLocalName() +

+                        " should not have child element");

+            }

+

+

+        } else if (elementLevel > 5) {

+            if (parent.getLocalName().equals(

+                    SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {

+                if (parser.getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME)) {

+                    if (subcodeValuePresent) {

+                        throw new OMBuilderException(

+                                "multiple subCode value encountered");

+                    } else {

+                        element =

+                                factory.createSOAPFaultValue(

+                                        (SOAPFaultSubCode) parent, builder);

+                        subcodeValuePresent = true;

+                        subSubcodePresent = false;

+                        subCodeProcessing = false;

+                    }

+                } else if (parser.getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {

+                    if (subcodeValuePresent) {

+                        if (!subSubcodePresent) {

+                            element =

+                                    factory.createSOAPFaultSubCode(

+                                            (SOAPFaultSubCode) parent,

+                                            builder);

+                            subcodeValuePresent = false;

+                            subSubcodePresent = true;

+                            subCodeProcessing = true;

+                        } else {

+                            throw new OMBuilderException(

+                                    "multiple subcode encountered");

+                        }

+                    } else {

+                        throw new OMBuilderException(

+                                "Value should present before the subcode");

+                    }

+                } else {

+                    throw new OMBuilderException(

+                            parser.getLocalName() +

+                            " is not supported inside the subCode element");

+                }

+            } else if (builder.isProcessingDetailElements()) {

+                int detailElementLevel = 0;

+                boolean localNameExist = false;

+                for (int i = 0; i < detailElementNames.size(); i++) {

+                    if (parent.getLocalName().equals(

+                            detailElementNames.get(i))) {

+                        localNameExist = true;

+                        detailElementLevel = i + 1;

+                    }

+                }

+                if (localNameExist) {

+                    detailElementNames.setSize(detailElementLevel);

+                    element =

+                            this.factory.createOMElement(

+                                    parser.getLocalName(),

+                                    null,

+                                    parent,

+                                    builder);

+                    detailElementNames.add(parser.getLocalName());

+                }

+

+            } else {

+                throw new OMBuilderException(

+                        parent.getLocalName() +

+                        " should not have child at element level " +

+                        elementLevel);

+            }

+        }

+

+        processNamespaceData(element, false);

+        processAttributes(element);

+        return element;

+    }

+}
\ No newline at end of file
diff --git a/src/org/apache/ws/commons/soap/impl/llom/builder/SOAPBuilderHelper.java b/src/org/apache/ws/commons/soap/impl/llom/builder/SOAPBuilderHelper.java
new file mode 100644
index 0000000..040ba25
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/builder/SOAPBuilderHelper.java
@@ -0,0 +1,101 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.builder;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.impl.llom.exception.OMBuilderException;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+

+import javax.xml.stream.XMLStreamReader;

+

+public abstract class SOAPBuilderHelper {

+    protected StAXSOAPModelBuilder builder;

+    protected XMLStreamReader parser;

+

+    protected SOAPBuilderHelper(StAXSOAPModelBuilder builder) {

+        this.builder = builder;

+    }

+

+    public abstract OMElement handleEvent(XMLStreamReader parser,

+                                          OMElement element,

+                                          int elementLevel) throws SOAPProcessingException;

+

+    protected void processNamespaceData(OMElement node, boolean isSOAPElement) {

+        int namespaceCount = parser.getNamespaceCount();

+        for (int i = 0; i < namespaceCount; i++) {

+            node.declareNamespace(parser.getNamespaceURI(i),

+                    parser.getNamespacePrefix(i));

+        }

+

+        // set the own namespace

+        String namespaceURI = parser.getNamespaceURI();

+        String prefix = parser.getPrefix();

+        OMNamespace namespace = null;

+        if (namespaceURI != null && namespaceURI.length() > 0) {

+            if (prefix == null) {

+                // this means, this elements has a default namespace or it has inherited a default namespace from its parent

+                namespace = node.findNamespace(namespaceURI, "");

+                if (namespace == null) {

+                    namespace = node.declareNamespace(namespaceURI, "");

+                }

+            } else {

+                namespace = node.findNamespace(namespaceURI, prefix);

+            }

+            node.setNamespace(namespace);

+        } else {

+

+        }

+

+

+

+        // TODO we got to have this to make sure OM reject mesagess that are not name space qualified

+        // But got to comment this to interop with Axis.1.x

+        // if (namespace == null) {

+        // throw new OMException("All elements must be namespace qualified!");

+        // }

+        if (isSOAPElement) {

+            if (node.getNamespace() != null &&

+                    !node.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI) &&

+                    !node.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {

+                throw new OMBuilderException("invalid SOAP namespace URI");

+            }

+        }

+

+    }

+

+    protected void processAttributes(OMElement node) {

+        int attribCount = parser.getAttributeCount();

+        for (int i = 0; i < attribCount; i++) {

+            OMNamespace ns = null;

+            String uri = parser.getAttributeNamespace(i);

+            if (uri.hashCode() != 0) {

+                ns = node.findNamespace(uri,

+                        parser.getAttributePrefix(i));

+            }

+

+            // todo if the attributes are supposed to namespace qualified all the time

+            // todo then this should throw an exception here

+            node.addAttribute(parser.getAttributeLocalName(i),

+                    parser.getAttributeValue(i), ns);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/builder/StAXSOAPModelBuilder.java b/src/org/apache/ws/commons/soap/impl/llom/builder/StAXSOAPModelBuilder.java
new file mode 100644
index 0000000..fbefe39
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/builder/StAXSOAPModelBuilder.java
@@ -0,0 +1,427 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.builder;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMDocument;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPMessage;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+import javax.xml.stream.XMLStreamReader;

+

+/**

+ * Class StAXSOAPModelBuilder

+ */

+public class StAXSOAPModelBuilder extends StAXOMBuilder {

+

+    SOAPMessage soapMessage;

+    /**

+     * Field envelope

+     */

+    private SOAPEnvelope envelope;

+    private OMNamespace envelopeNamespace;

+

+

+    private SOAPFactory soapFactory;

+

+    /**

+     * Field headerPresent

+     */

+    private boolean headerPresent = false;

+

+    /**

+     * Field bodyPresent

+     */

+    private boolean bodyPresent = false;

+

+    /**

+     * Field log

+     */

+    private Log log = LogFactory.getLog(getClass());

+

+    /**

+     * element level 1 = envelope level element level 2 = Header or Body level

+     * element level 3 = HeaderElement or BodyElement level

+     */

+    protected int elementLevel = 0;

+

+    private boolean processingFault = false;

+

+

+    //added

+    /* This is used to indicate whether detail element is processing in soap 1.2 builderhelper

+    */

+    private boolean processingDetailElements = false;

+

+    private SOAPBuilderHelper builderHelper;

+    private String senderfaultCode;

+    private String receiverfaultCode;

+    private boolean processingMandatoryFaultElements;

+    

+    // We need to have soap factory, temporary, until we find out the correct SOAP version. If user has not provided

+    // a SOAP factory, internally we are creating a default one. This flag will be set if we create one internally, to

+    // warn that this should be replaced later.

+    private boolean isTempSOAPFactory = true;

+

+    /**

+     * Constructor StAXSOAPModelBuilder

+     * soapVersion parameter is to give the soap version from the transport. For example, in HTTP case

+     * you can identify the version of the soap message u have recd by looking at the HTTP headers. 

+     * It is used to check whether the actual soap message contained is of that version.

+     * If one is creates the builder from the transport, then can just pass null for version.

+     *

+     * @param parser

+     * @param soapVersion   parameter is to give the soap version for the transport.  

+     */

+    public StAXSOAPModelBuilder(XMLStreamReader parser, String soapVersion) {

+        super(parser);

+        soapFactory = OMAbstractFactory.getDefaultSOAPFactory();

+        isTempSOAPFactory = true;

+        soapMessage = soapFactory.createSOAPMessage(this);

+        this.document = soapMessage;

+        if(parser.getCharacterEncodingScheme() != null) {

+            document.setCharsetEncoding(parser.getCharacterEncodingScheme());

+        }

+        identifySOAPVersion(soapVersion);

+    }

+

+    /**

+     * @param parser

+     * @param factory

+     * @param soapVersion parameter is to give the soap version from the transport. For example, in

+     *                    HTTP case you can identify the version of the soap message u have recd by looking at

+     *                    the HTTP headers. It is used to check whether the actual soap message 

+     *                    contained is of that version.If one is creates the builder from the transport, 

+     *                    then can just pass null for version.

+     */

+    public StAXSOAPModelBuilder(XMLStreamReader parser, SOAPFactory factory, String soapVersion) {

+        super(factory, parser);

+        soapFactory = factory;

+        isTempSOAPFactory = false;

+        soapMessage = soapFactory.createSOAPMessage(this);

+        this.document = soapMessage;

+        identifySOAPVersion(soapVersion);

+    }

+

+    protected void identifySOAPVersion(String soapVersionURIFromTransport) {

+

+        SOAPEnvelope soapEnvelope = getSOAPEnvelope();

+        if (soapEnvelope == null) {

+            throw new SOAPProcessingException("SOAP Message does not contain an Envelope",

+                    SOAPConstants.FAULT_CODE_VERSION_MISMATCH);

+        }

+

+        envelopeNamespace = soapEnvelope.getNamespace();

+        String namespaceName = envelopeNamespace.getName();

+        if ((soapVersionURIFromTransport != null) && !(soapVersionURIFromTransport.equals(namespaceName))) {

+            throw new SOAPProcessingException("Transport level information does not match with SOAP" +

+                    " Message namespace URI", SOAPConstants.FAULT_CODE_VERSION_MISMATCH);

+

+        }

+        if(isTempSOAPFactory) {

+	        if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceName)) {

+	            soapFactory = OMAbstractFactory.getSOAP12Factory();

+	            log.debug("Starting to process SOAP 1.2 message");

+	        } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceName)) {

+	            soapFactory = OMAbstractFactory.getSOAP11Factory();

+	            log.debug("Starting to process SOAP 1.1 message");

+	

+	        } else {

+	            throw new SOAPProcessingException("Only SOAP 1.1 or SOAP 1.2 messages are supported in the" +

+	                    " system", SOAPConstants.FAULT_CODE_VERSION_MISMATCH);

+	        }

+        }

+    }

+

+    /**

+     * Method getSOAPEnvelope.

+     *

+     * @return Returns SOAPEnvelope.

+     * @throws OMException

+     */

+    public SOAPEnvelope getSOAPEnvelope() throws OMException {

+        while ((envelope == null) && !done) {

+            next();

+        }

+        return envelope;

+    }

+

+    /**

+     * Method createOMElement.

+     *

+     * @return Returns OMNode.

+     * @throws OMException

+     */

+    protected OMNode createOMElement() throws OMException {

+        elementLevel++;

+        OMElement node;

+        String elementName = parser.getLocalName();

+        if (lastNode == null) {

+            node = constructNode(null, elementName, true);

+            setSOAPEnvelope(node);

+        } else if (lastNode.isComplete()) {

+            node =

+                    constructNode((OMElement) lastNode.getParent(),

+                            elementName,

+                            false);

+            ((OMNodeEx) lastNode).setNextOMSibling(node);

+            ((OMNodeEx) node).setPreviousOMSibling(lastNode);

+        } else {

+            OMElement e = (OMElement) lastNode;

+            node = constructNode((OMElement) lastNode, elementName, false);

+            e.setFirstChild(node);

+        }

+

+

+        log.debug("Build the OMElelment " + node.getLocalName() +

+                "By the StaxSOAPModelBuilder");

+        return node;

+    }

+

+    protected void setSOAPEnvelope(OMElement node) {

+        soapMessage.setSOAPEnvelope((SOAPEnvelope) node);

+        soapMessage.setXMLVersion(parser.getVersion());

+        soapMessage.setCharsetEncoding(parser.getCharacterEncodingScheme());

+    }

+

+    /**

+     * Method constructNode

+     *

+     * @param parent

+     * @param elementName

+     * @param isEnvelope

+     */

+    protected OMElement constructNode(OMElement parent, String elementName,

+                                      boolean isEnvelope) {

+        OMElement element = null;

+        if (parent == null) {

+            if (!elementName.equalsIgnoreCase(SOAPConstants.SOAPENVELOPE_LOCAL_NAME)) {

+                throw new SOAPProcessingException("First Element must contain the local name, "

+                        + SOAPConstants.SOAPENVELOPE_LOCAL_NAME, SOAPConstants.FAULT_CODE_VERSION_MISMATCH);

+            }

+            envelope = soapFactory.createSOAPEnvelope(this);

+            element = envelope;

+            processNamespaceData(element, true);

+            // fill in the attributes

+            processAttributes(element);

+

+        } else if (elementLevel == 2) {

+

+            // this is either a header or a body

+            if (elementName.equals(SOAPConstants.HEADER_LOCAL_NAME)) {

+                if (headerPresent) {

+                    throw new SOAPProcessingException("Multiple headers encountered!", getSenderFaultCode());

+                }

+                if (bodyPresent) {

+                    throw new SOAPProcessingException("Header Body wrong order!", getSenderFaultCode());

+                }

+                headerPresent = true;

+                element =

+                        soapFactory.createSOAPHeader((SOAPEnvelope) parent,

+                                this);

+

+                processNamespaceData(element, true);

+                processAttributes(element);

+

+            } else if (elementName.equals(SOAPConstants.BODY_LOCAL_NAME)) {

+                if (bodyPresent) {

+                    throw new SOAPProcessingException("Multiple body elements encountered", getSenderFaultCode());

+                }

+                bodyPresent = true;

+                element =

+                        soapFactory.createSOAPBody((SOAPEnvelope) parent,

+                                this);

+

+                processNamespaceData(element, true);

+                processAttributes(element);

+

+            } else {

+                throw new SOAPProcessingException(elementName

+                        +

+                        " is not supported here. Envelope can not have elements other than Header and Body.", getSenderFaultCode());

+            }

+        } else if ((elementLevel == 3)

+                &&

+                parent.getLocalName().equalsIgnoreCase(SOAPConstants.HEADER_LOCAL_NAME)) {

+

+            // this is a headerblock

+            try {

+                element =

+                        soapFactory.createSOAPHeaderBlock(elementName, null,

+                                (SOAPHeader) parent, this);

+            } catch (SOAPProcessingException e) {

+                throw new SOAPProcessingException("Can not create SOAPHeader block", getReceiverFaultCode(), e);

+            }

+            processNamespaceData(element, false);

+            processAttributes(element);

+

+        } else if ((elementLevel == 3) &&

+                parent.getLocalName().equalsIgnoreCase(SOAPConstants.BODY_LOCAL_NAME) &&

+                elementName.equalsIgnoreCase(SOAPConstants.BODY_FAULT_LOCAL_NAME)) {

+

+            // this is a headerblock

+            element = soapFactory.createSOAPFault((SOAPBody) parent, this);

+            processNamespaceData(element, false);

+            processAttributes(element);

+

+

+            processingFault = true;

+            processingMandatoryFaultElements = true;

+            if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelopeNamespace.getName())) {

+                builderHelper = new SOAP12BuilderHelper(this);

+            } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelopeNamespace.getName())) {

+                builderHelper = new SOAP11BuilderHelper(this);

+            }

+

+        } else if (elementLevel > 3 && processingFault) {

+            element = builderHelper.handleEvent(parser, parent, elementLevel);

+        } else {

+

+            // this is neither of above. Just create an element

+            element = soapFactory.createOMElement(elementName, null,

+                    parent, this);

+            processNamespaceData(element, false);

+            processAttributes(element);

+

+        }

+        return element;

+    }

+

+    private String getSenderFaultCode() {

+        if (senderfaultCode == null) {

+            senderfaultCode = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelopeNamespace.getName()) ? SOAP12Constants.FAULT_CODE_SENDER : SOAP11Constants.FAULT_CODE_SENDER;

+        }

+        return senderfaultCode;

+    }

+

+    private String getReceiverFaultCode() {

+        if (receiverfaultCode == null) {

+            receiverfaultCode = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelopeNamespace.getName()) ? SOAP12Constants.FAULT_CODE_RECEIVER : SOAP11Constants.FAULT_CODE_RECEIVER;

+        }

+        return receiverfaultCode;

+    }

+

+    public void endElement() {

+        if (lastNode.isComplete()) {

+            OMElement parent = (OMElement) lastNode.getParent();

+            ((OMNodeEx) parent).setComplete(true);

+            lastNode = parent;

+        } else {

+            OMNode e = lastNode;

+            ((OMNodeEx) e).setComplete(true);

+        }

+        elementLevel--;

+    }

+

+    /**

+     * Method createDTD.

+     * Overriding the default behaviour as a SOAPMessage should not have a DTD.

+     */

+    protected OMNode createDTD() throws OMException {

+        throw new OMException("SOAP message MUST NOT contain a Document Type Declaration(DTD)");

+    }

+

+    /**

+     * Method createPI.

+     * Overriding the default behaviour as a SOAP Message should not have a PI.

+     */

+    protected OMNode createPI() throws OMException {

+        throw new OMException("SOAP message MUST NOT contain Processing Instructions(PI)");

+    }

+

+    /**

+     * Method getDocumentElement.

+     *

+     * @return Returns OMElement.

+     */

+    public OMElement getDocumentElement() {

+        return getSOAPEnvelope();

+    }

+

+    /**

+     * Method processNamespaceData.

+     *

+     * @param node

+     * @param isSOAPElement

+     */

+    protected void processNamespaceData(OMElement node, boolean isSOAPElement) {

+

+        super.processNamespaceData(node, isSOAPElement);

+

+        if (isSOAPElement) {

+            if (node.getNamespace() != null &&

+                    !node.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI) &&

+                    !node.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {

+                throw new SOAPProcessingException("invalid SOAP namespace URI. " +

+                        "Only " + SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI +

+                        " and " + SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI +

+                        " are supported.", SOAP12Constants.FAULT_CODE_SENDER);

+            }

+        }

+

+    }

+

+/*these three methods to set and check detail element processing or mandatory fault element are present

+*/

+

+    public OMNamespace getEnvelopeNamespace() {

+        return envelopeNamespace;

+    }

+

+    public void setBooleanProcessingMandatoryFaultElements(boolean value) {

+        this.processingMandatoryFaultElements = value;

+    }

+

+    public boolean isProcessingDetailElements() {

+        return processingDetailElements;

+    }

+

+    public void setProcessingDetailElements(boolean value) {

+        processingDetailElements = value;

+    }

+

+    public SOAPMessage getSoapMessage() {

+        return soapMessage;

+    }

+

+    public OMDocument getDocument() {

+        return (OMDocument) this.soapMessage;

+    }

+

+	/**

+	 * @return Returns the soapFactory.

+	 */

+	protected SOAPFactory getSoapFactory() {

+		return soapFactory;

+	}

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/factory/SOAPLinkedListImplFactory.java b/src/org/apache/ws/commons/soap/impl/llom/factory/SOAPLinkedListImplFactory.java
new file mode 100644
index 0000000..42ae89e
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/factory/SOAPLinkedListImplFactory.java
@@ -0,0 +1,235 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.factory;

+

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.factory.OMLinkedListImplFactory;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultDetail;

+import org.apache.ws.commons.soap.SOAPFaultNode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultRole;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.ws.commons.soap.SOAPMessage;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPEnvelopeImpl;

+import org.apache.ws.commons.soap.impl.llom.SOAPMessageImpl;

+

+public class SOAPLinkedListImplFactory extends OMLinkedListImplFactory implements SOAPFactory {

+    public String getSoapVersionURI() {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPMessage createSOAPMessage(OMXMLParserWrapper builder) {

+        return new SOAPMessageImpl(builder);

+    }

+

+    

+    public SOAPMessage createSOAPMessage(SOAPEnvelope envelope, OMXMLParserWrapper parserWrapper) {

+        return new SOAPMessageImpl(envelope, parserWrapper);

+    }

+

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public SOAPEnvelope createSOAPEnvelope(OMXMLParserWrapper builder) {

+        return new SOAPEnvelopeImpl(builder, this);

+    }

+

+    public SOAPEnvelope createSOAPEnvelope() {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPHeader createSOAPHeader(SOAPEnvelope envelope) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPHeader createSOAPHeader(SOAPEnvelope envelope,

+                                       OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+

+    }

+

+    public SOAPHeaderBlock createSOAPHeaderBlock(String localName,

+                                                 OMNamespace ns,

+                                                 SOAPHeader parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+

+    }

+

+    public SOAPHeaderBlock createSOAPHeaderBlock(String localName,

+                                                 OMNamespace ns,

+                                                 SOAPHeader parent,

+                                                 OMXMLParserWrapper builder) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+

+    }

+

+

+    public SOAPFault createSOAPFault(SOAPBody parent, Exception e) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFault createSOAPFault(SOAPBody parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFault createSOAPFault(SOAPBody parent,

+                                     OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPBody createSOAPBody(SOAPEnvelope envelope) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPBody createSOAPBody(SOAPEnvelope envelope,

+                                   OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultCode createSOAPFaultCode(SOAPFault parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultCode createSOAPFaultCode(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultCode parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultCode parent,

+                                               OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    //added

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultSubCode parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    //added

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultSubCode parent,

+                                               OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    //changed

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultCode parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    //changed

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultCode parent,

+                                                   OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultSubCode parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultSubCode parent,

+                                                   OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultReason createSOAPFaultReason(SOAPFault parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultReason createSOAPFaultReason(SOAPFault parent,

+                                                 OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultText createSOAPFaultText(SOAPFaultReason parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultText createSOAPFaultText(SOAPFaultReason parent,

+                                             OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultNode createSOAPFaultNode(SOAPFault parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultNode createSOAPFaultNode(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultRole createSOAPFaultRole(SOAPFault parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultRole createSOAPFaultRole(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultDetail createSOAPFaultDetail(SOAPFault parent) throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPFaultDetail createSOAPFaultDetail(SOAPFault parent,

+                                                 OMXMLParserWrapper builder) {

+        throw new UnsupportedOperationException();

+    }

+

+

+    /**

+     * Method getDefaultEnvelope

+     *

+     * @return Returns SOAPEnvelope.

+     */

+    public SOAPEnvelope getDefaultEnvelope() throws SOAPProcessingException {

+        throw new UnsupportedOperationException();

+    }

+

+    public SOAPEnvelope getDefaultFaultEnvelope() throws SOAPProcessingException {

+        SOAPEnvelope defaultEnvelope = getDefaultEnvelope();

+        SOAPFault fault = createSOAPFault(defaultEnvelope.getBody());

+

+        SOAPFaultCode faultCode = createSOAPFaultCode(fault);

+        SOAPFaultValue value = createSOAPFaultValue(faultCode);

+

+        SOAPFaultReason reason = createSOAPFaultReason(fault);

+        SOAPFaultText faultText = createSOAPFaultText(reason);

+

+        SOAPFaultNode faultNode = createSOAPFaultNode(fault);

+        SOAPFaultRole faultRole = createSOAPFaultRole(fault);

+        SOAPFaultDetail faultDetail = createSOAPFaultDetail(fault);

+

+        return defaultEnvelope;

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11BodyImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11BodyImpl.java
new file mode 100644
index 0000000..bfa4db7
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11BodyImpl.java
@@ -0,0 +1,47 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPBodyImpl;

+

+public class SOAP11BodyImpl extends SOAPBodyImpl {

+    /**

+     * @param envelope

+     */

+    public SOAP11BodyImpl(SOAPEnvelope envelope) throws SOAPProcessingException {

+        super(envelope);

+    }

+

+    /**

+     * Constructor SOAPBodyImpl

+     *

+     * @param envelope

+     * @param builder

+     */

+    public SOAP11BodyImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) {

+        super(envelope, builder);

+    }

+

+    public SOAPFault addFault(Exception e) throws OMException {

+        return new SOAP11Factory().createSOAPFault(this, e);

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11Factory.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11Factory.java
new file mode 100644
index 0000000..64850aa
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11Factory.java
@@ -0,0 +1,207 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.OMNamespaceImpl;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultDetail;

+import org.apache.ws.commons.soap.SOAPFaultNode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultRole;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPEnvelopeImpl;

+import org.apache.ws.commons.soap.impl.llom.factory.SOAPLinkedListImplFactory;

+

+public class SOAP11Factory extends SOAPLinkedListImplFactory {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public String getSoapVersionURI() {

+        return SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;

+    }

+

+    public SOAPEnvelope createSOAPEnvelope() {

+        return new SOAPEnvelopeImpl(

+                new OMNamespaceImpl(

+                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,

+                        SOAP11Constants.SOAP_DEFAULT_NAMESPACE_PREFIX),

+                this);

+    }

+

+    public SOAPHeader createSOAPHeader(SOAPEnvelope envelope) throws SOAPProcessingException {

+        return new SOAP11HeaderImpl(envelope);

+    }

+

+    public SOAPHeader createSOAPHeader(SOAPEnvelope envelope,

+                                       OMXMLParserWrapper builder) {

+        return new SOAP11HeaderImpl(envelope, builder);

+    }

+

+    public SOAPHeaderBlock createSOAPHeaderBlock(String localName,

+                                                 OMNamespace ns,

+                                                 SOAPHeader parent) throws SOAPProcessingException {

+        return new SOAP11HeaderBlockImpl(localName, ns, parent);

+    }

+

+    public SOAPHeaderBlock createSOAPHeaderBlock(String localName,

+                                                 OMNamespace ns,

+                                                 SOAPHeader parent,

+                                                 OMXMLParserWrapper builder) throws SOAPProcessingException {

+        return new SOAP11HeaderBlockImpl(localName, ns, parent, builder);

+    }

+

+    public SOAPFault createSOAPFault(SOAPBody parent, Exception e) throws SOAPProcessingException {

+        return new SOAP11FaultImpl(parent, e);

+    }

+

+    public SOAPFault createSOAPFault(SOAPBody parent) throws SOAPProcessingException {

+        return new SOAP11FaultImpl(parent);

+    }

+

+    public SOAPFault createSOAPFault(SOAPBody parent,

+                                     OMXMLParserWrapper builder) {

+        return new SOAP11FaultImpl(parent, builder);

+    }

+

+    public SOAPBody createSOAPBody(SOAPEnvelope envelope) throws SOAPProcessingException {

+        return new SOAP11BodyImpl(envelope);

+    }

+

+    public SOAPBody createSOAPBody(SOAPEnvelope envelope,

+                                   OMXMLParserWrapper builder) {

+        return new SOAP11BodyImpl(envelope, builder);

+    }

+

+    public SOAPFaultCode createSOAPFaultCode(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP11FaultCodeImpl(parent);

+    }

+

+    public SOAPFaultCode createSOAPFaultCode(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        return new SOAP11FaultCodeImpl(parent, builder);

+    }

+

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultCode parent) throws SOAPProcessingException {

+        return new SOAP11FaultValueImpl(parent);

+    }

+

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultCode parent,

+                                               OMXMLParserWrapper builder) {

+        return new SOAP11FaultValueImpl(parent, builder);

+    }

+

+    //added

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultSubCode parent) throws SOAPProcessingException {

+        return new SOAP11FaultValueImpl(parent);

+    }

+

+    //added

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultSubCode parent,

+                                               OMXMLParserWrapper builder) {

+        return new SOAP11FaultValueImpl(parent, builder);

+    }

+

+    //changed

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultCode parent) throws SOAPProcessingException {

+        return new SOAP11FaultSubCodeImpl(parent);

+    }

+

+    //changed

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultCode parent,

+                                                   OMXMLParserWrapper builder) {

+        return new SOAP11FaultSubCodeImpl(parent, builder);

+    }

+

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultSubCode parent) throws SOAPProcessingException {

+        return new SOAP11FaultSubCodeImpl(parent);

+    }

+

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultSubCode parent,

+                                                   OMXMLParserWrapper builder) {

+        return new SOAP11FaultSubCodeImpl(parent, builder);

+    }

+

+    public SOAPFaultReason createSOAPFaultReason(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP11FaultReasonImpl(parent);

+    }

+

+    public SOAPFaultReason createSOAPFaultReason(SOAPFault parent,

+                                                 OMXMLParserWrapper builder) {

+        return new SOAP11FaultReasonImpl(parent, builder);

+    }

+

+    public SOAPFaultText createSOAPFaultText(SOAPFaultReason parent) throws SOAPProcessingException {

+        return new SOAP11FaultTextImpl(parent);

+    }

+

+    public SOAPFaultText createSOAPFaultText(SOAPFaultReason parent,

+                                             OMXMLParserWrapper builder) {

+        return new SOAP11FaultTextImpl(parent, builder);

+    }

+

+    public SOAPFaultNode createSOAPFaultNode(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP11FaultNodeImpl(parent);

+    }

+

+    public SOAPFaultNode createSOAPFaultNode(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        return new SOAP11FaultNodeImpl(parent, builder);

+    }

+

+    public SOAPFaultRole createSOAPFaultRole(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP11FaultRoleImpl(parent);

+    }

+

+    public SOAPFaultRole createSOAPFaultRole(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        return new SOAP11FaultRoleImpl(parent, builder);

+    }

+

+    public SOAPFaultDetail createSOAPFaultDetail(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP11FaultDetailImpl(parent);

+    }

+

+    public SOAPFaultDetail createSOAPFaultDetail(SOAPFault parent,

+                                                 OMXMLParserWrapper builder) {

+        return new SOAP11FaultDetailImpl(parent, builder);

+    }

+

+    public SOAPEnvelope getDefaultEnvelope() throws SOAPProcessingException {

+        OMNamespace ns =

+                new OMNamespaceImpl(

+                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,

+                        SOAP11Constants.SOAP_DEFAULT_NAMESPACE_PREFIX);

+        SOAPEnvelopeImpl env = new SOAPEnvelopeImpl(ns, this);

+        createSOAPHeader(env);

+        createSOAPBody(env);

+        return env;

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultCodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultCodeImpl.java
new file mode 100644
index 0000000..d26572a
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultCodeImpl.java
@@ -0,0 +1,109 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultCodeImpl;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+

+public class SOAP11FaultCodeImpl extends SOAPFaultCodeImpl {

+    /**

+     * Constructor OMElementImpl

+     *

+     * @param parent

+     * @param builder

+     */

+    public SOAP11FaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    /**

+     * @param parent

+     */

+    public SOAP11FaultCodeImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, false);

+    }

+

+

+    public void setSubCode(SOAPFaultSubCode subCode) throws SOAPProcessingException {

+        if (!(subCode instanceof SOAP11FaultSubCodeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault Sub Code. But received some other implementation");

+        }

+        super.setSubCode(subCode);

+    }

+

+    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {

+        if (!(value instanceof SOAP11FaultValueImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault Value. But received some other implementation");

+        }

+        super.setValue(value);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+

+    protected void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(

+                    new StreamWriterToContentHandlerConverter(omOutput));

+        }

+

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        if (this.getNamespace() != null) {

+            String prefix = this.getNamespace().getPrefix();

+            String nameSpaceName = this.getNamespace().getName();

+            writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME,

+                    nameSpaceName);

+        } else {

+            writer.writeStartElement(

+                    SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME);

+        }

+

+        OMSerializerUtil.serializeAttributes(this, omOutput);

+        OMSerializerUtil.serializeNamespaces(this, omOutput);

+

+

+        String text = this.getValue().getText();

+        writer.writeCharacters(text);

+        writer.writeEndElement();

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultDetailImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultDetailImpl.java
new file mode 100644
index 0000000..a59c728
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultDetailImpl.java
@@ -0,0 +1,85 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultDetailImpl;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+

+public class SOAP11FaultDetailImpl extends SOAPFaultDetailImpl {

+    public SOAP11FaultDetailImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, false);

+    }

+

+    public SOAP11FaultDetailImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+

+    public void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(

+                    new StreamWriterToContentHandlerConverter(omOutput));

+        }

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        if (this.getNamespace() != null) {

+            String prefix = this.getNamespace().getPrefix();

+            String nameSpaceName = this.getNamespace().getName();

+            writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,

+                    nameSpaceName);

+        } else {

+            writer.writeStartElement(

+                    SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME);

+        }

+        OMSerializerUtil.serializeAttributes(this, omOutput);

+        OMSerializerUtil.serializeNamespaces(this, omOutput);

+

+

+        String text = this.getText();

+        writer.writeCharacters(text);

+

+

+        if (firstChild != null) {

+            ((OMNodeEx)firstChild).serializeAndConsume(omOutput);

+        }

+        writer.writeEndElement();

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultImpl.java
new file mode 100644
index 0000000..6011736
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultImpl.java
@@ -0,0 +1,120 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultDetail;

+import org.apache.ws.commons.soap.SOAPFaultNode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultRole;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultImpl;

+

+import javax.xml.stream.XMLStreamException;

+

+

+public class SOAP11FaultImpl extends SOAPFaultImpl {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public SOAP11FaultImpl(SOAPBody parent, Exception e) throws SOAPProcessingException {

+        super(parent, e);

+    }

+

+    public SOAP11FaultImpl(SOAPBody parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    /**

+     * This is a convenience method for the SOAP Fault Impl.

+     *

+     * @param parent

+     */

+    public SOAP11FaultImpl(SOAPBody parent) throws SOAPProcessingException {

+        super(parent);

+

+    }

+

+    protected SOAPFaultDetail getNewSOAPFaultDetail(SOAPFault fault) throws SOAPProcessingException {

+        return new SOAP11FaultDetailImpl(fault);

+    }

+

+    public void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        super.serialize(omOutput);

+    }

+

+    public void serializeAndConsume(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        super.serializeAndConsume(omOutput);

+    }

+

+    public void setCode(SOAPFaultCode soapFaultCode) throws SOAPProcessingException {

+        if (!(soapFaultCode instanceof SOAP11FaultCodeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault Code. But received some other implementation");

+        }

+        super.setCode(soapFaultCode);

+    }

+

+    public void setReason(SOAPFaultReason reason) throws SOAPProcessingException {

+        if (!(reason instanceof SOAP11FaultReasonImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault Reason. But received some other implementation");

+        }

+        super.setReason(reason);

+    }

+

+    public void setNode(SOAPFaultNode node) throws SOAPProcessingException {

+        if (!(node instanceof SOAP11FaultNodeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault Node. But received some other implementation");

+        }

+        super.setNode(node);

+    }

+

+    public void setRole(SOAPFaultRole role) throws SOAPProcessingException {

+        if (!(role instanceof SOAP11FaultRoleImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault Role. But received some other implementation");

+        }

+        super.setRole(role);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11BodyImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Body as the parent. But received some other implementation");

+        }

+    }

+

+    public void setDetail(SOAPFaultDetail detail) throws SOAPProcessingException {

+        if (!(detail instanceof SOAP11FaultDetailImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault Detail. But received some other implementation");

+        }

+        super.setDetail(detail);

+    }

+

+    protected void serializeFaultNode(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        

+    }

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultNodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultNodeImpl.java
new file mode 100644
index 0000000..2d01dc6
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultNodeImpl.java
@@ -0,0 +1,42 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultNodeImpl;

+

+

+public class SOAP11FaultNodeImpl extends SOAPFaultNodeImpl {

+

+    public SOAP11FaultNodeImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent);

+    }

+

+    public SOAP11FaultNodeImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultReasonImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultReasonImpl.java
new file mode 100644
index 0000000..06beef6
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultReasonImpl.java
@@ -0,0 +1,96 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMOutputImpl;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultReasonImpl;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+

+public class SOAP11FaultReasonImpl extends SOAPFaultReasonImpl {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public SOAP11FaultReasonImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    /**

+     * @param parent

+     */

+    public SOAP11FaultReasonImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, false);

+    }

+

+    public void setSOAPText(SOAPFaultText soapFaultText) throws SOAPProcessingException {

+        if (!(soapFaultText instanceof SOAP11FaultTextImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault Text. But received some other implementation");

+        }

+        super.setSOAPText(soapFaultText);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+

+    protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(

+                    new StreamWriterToContentHandlerConverter(omOutput));

+        }

+

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        if (this.getNamespace() != null) {

+            String prefix = this.getNamespace().getPrefix();

+            String nameSpaceName = this.getNamespace().getName();

+            writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME,

+                    nameSpaceName);

+        } else {

+            writer.writeStartElement(

+                    SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME);

+        }

+        OMSerializerUtil.serializeAttributes(this, omOutput);

+        OMSerializerUtil.serializeNamespaces(this, omOutput);

+

+        String text = this.getSOAPText().getText();

+        writer.writeCharacters(text);

+        writer.writeEndElement();

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultRoleImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultRoleImpl.java
new file mode 100644
index 0000000..e987305
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultRoleImpl.java
@@ -0,0 +1,79 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.OMSerializerUtil;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultRoleImpl;

+

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamWriter;

+

+public class SOAP11FaultRoleImpl extends SOAPFaultRoleImpl {

+    public SOAP11FaultRoleImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, false);

+    }

+

+    public SOAP11FaultRoleImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+

+    protected void serialize(org.apache.ws.commons.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {

+

+        // select the builder

+        short builderType = PULL_TYPE_BUILDER;    // default is pull type

+        if (builder != null) {

+            builderType = this.builder.getBuilderType();

+        }

+        if ((builderType == PUSH_TYPE_BUILDER)

+                && (builder.getRegisteredContentHandler() == null)) {

+            builder.registerExternalContentHandler(

+                    new StreamWriterToContentHandlerConverter(omOutput));

+        }

+

+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();

+        if (this.getNamespace() != null) {

+            String prefix = this.getNamespace().getPrefix();

+            String nameSpaceName = this.getNamespace().getName();

+            writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME,

+                    nameSpaceName);

+        } else {

+            writer.writeStartElement(

+                    SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME);

+        }

+        OMSerializerUtil.serializeAttributes(this, omOutput);

+        OMSerializerUtil.serializeNamespaces(this, omOutput);

+

+        String text = this.getText();

+        writer.writeCharacters(text);

+        writer.writeEndElement();

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultSubCodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultSubCodeImpl.java
new file mode 100644
index 0000000..1285e0d
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultSubCodeImpl.java
@@ -0,0 +1,71 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultSubCodeImpl;

+

+public class SOAP11FaultSubCodeImpl extends SOAPFaultSubCodeImpl {

+    //changed

+    public SOAP11FaultSubCodeImpl(SOAPFaultCode parent) throws SOAPProcessingException {

+        super(parent, SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);

+    }

+

+    //changed

+    public SOAP11FaultSubCodeImpl(SOAPFaultCode parent,

+                                  OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME, builder);

+    }

+

+    public SOAP11FaultSubCodeImpl(SOAPFaultSubCode parent) throws SOAPProcessingException {

+        super(parent, SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);

+    }

+

+    public SOAP11FaultSubCodeImpl(SOAPFaultSubCode parent,

+                                  OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11FaultSubCodeImpl) ||

+                (parent instanceof SOAP11FaultCodeImpl)) {

+            throw new SOAPProcessingException("Expecting SOAP 1.1 implementation of SOAP FaultSubCode or SOAP FaultCode as the parent. But received some other implementation");

+        }

+    }

+

+    public void setSubCode(SOAPFaultSubCode subCode) throws SOAPProcessingException {

+        if (!((parent instanceof SOAP11FaultSubCodeImpl) || (parent instanceof SOAP11FaultCodeImpl))) {

+            throw new SOAPProcessingException("Expecting SOAP 1.1 implementation of SOAP Fault Sub Code. But received some other implementation");

+        }

+        super.setSubCode(subCode);

+    }

+

+    public void setValue(SOAPFaultValue soapFaultSubCodeValue) throws SOAPProcessingException {

+        if (!(soapFaultSubCodeValue instanceof SOAP11FaultValueImpl)) {

+            throw new SOAPProcessingException("Expecting SOAP 1.1 implementation of SOAP Fault Value. But received some other implementation");

+        }

+        super.setValue(soapFaultSubCodeValue);

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultTextImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultTextImpl.java
new file mode 100644
index 0000000..f76efc8
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultTextImpl.java
@@ -0,0 +1,41 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultTextImpl;

+

+public class SOAP11FaultTextImpl extends SOAPFaultTextImpl {

+    public SOAP11FaultTextImpl(SOAPFaultReason parent) throws SOAPProcessingException {

+        super(parent);

+    }

+

+    public SOAP11FaultTextImpl(SOAPFaultReason parent,

+                               OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11FaultReasonImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP FaultReason as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultValueImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultValueImpl.java
new file mode 100644
index 0000000..96bf6fa
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11FaultValueImpl.java
@@ -0,0 +1,42 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultValueImpl;

+

+public class SOAP11FaultValueImpl extends SOAPFaultValueImpl {

+    public SOAP11FaultValueImpl(OMElement parent) throws SOAPProcessingException {

+        super(parent);

+    }

+

+    public SOAP11FaultValueImpl(OMElement parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!((parent instanceof SOAP11FaultSubCodeImpl) ||

+                (parent instanceof SOAP11FaultCodeImpl))) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP FaultSubCode or SOAP FaultCode as the parent. But received some other implementation." +

+                    parent.getClass());

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11HeaderBlockImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11HeaderBlockImpl.java
new file mode 100644
index 0000000..572eff0
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11HeaderBlockImpl.java
@@ -0,0 +1,129 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPHeaderBlockImpl;

+

+public class SOAP11HeaderBlockImpl extends SOAPHeaderBlockImpl {

+    /**

+     * @param localName

+     * @param ns

+     */

+    public SOAP11HeaderBlockImpl(String localName,

+                                 OMNamespace ns,

+                                 SOAPHeader parent) throws SOAPProcessingException {

+        super(localName, ns, parent);

+        checkParent(parent);

+    }

+

+    /**

+     * Constructor SOAPHeaderBlockImpl

+     *

+     * @param localName

+     * @param ns

+     * @param parent

+     * @param builder

+     */

+    public SOAP11HeaderBlockImpl(String localName,

+                                 OMNamespace ns,

+                                 OMElement parent,

+                                 OMXMLParserWrapper builder) {

+        super(localName, ns, parent, builder);

+    }

+

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP11HeaderImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.1 implementation of SOAP Body as the parent. But received some other implementation");

+        }

+    }

+

+    public void setRole(String roleURI) {

+        setAttribute(SOAP11Constants.ATTR_ACTOR,

+                roleURI,

+                SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+

+    }

+

+    public String getRole() {

+        return getAttribute(SOAP11Constants.ATTR_ACTOR,

+                SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+    }

+

+    public void setMustUnderstand(boolean mustUnderstand) {

+        setAttribute(SOAPConstants.ATTR_MUSTUNDERSTAND,

+                mustUnderstand ? "1" : "0",

+                SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+    }

+

+    public void setMustUnderstand(String mustUnderstand) throws SOAPProcessingException {

+        if (SOAPConstants.ATTR_MUSTUNDERSTAND_TRUE.equals(mustUnderstand) ||

+                SOAPConstants.ATTR_MUSTUNDERSTAND_FALSE.equals(mustUnderstand) ||

+                SOAPConstants.ATTR_MUSTUNDERSTAND_0.equals(mustUnderstand) ||

+                SOAPConstants.ATTR_MUSTUNDERSTAND_1.equals(mustUnderstand)) {

+            setAttribute(SOAPConstants.ATTR_MUSTUNDERSTAND,

+                    mustUnderstand,

+                    SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+        } else {

+            throw new SOAPProcessingException(

+                    "mustUndertand should be one of \"true\", \"false\", \"0\" or \"1\" ");

+        }

+    }

+

+    /**

+     * Returns whether the mustUnderstand attribute for this

+     * <CODE>SOAPHeaderBlock</CODE> object is turned on.

+     *

+     * @return <CODE>true</CODE> if the mustUnderstand attribute of

+     *         this <CODE>SOAPHeaderBlock</CODE> object is turned on;

+     *         <CODE>false</CODE> otherwise

+     */

+    public boolean getMustUnderstand() throws SOAPProcessingException {

+        String mustUnderstand = "";

+        if ((mustUnderstand =

+                getAttribute(SOAPConstants.ATTR_MUSTUNDERSTAND,

+                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI))

+                != null) {

+            if (SOAPConstants.ATTR_MUSTUNDERSTAND_TRUE.equalsIgnoreCase(

+                    mustUnderstand) ||

+                    SOAPConstants.ATTR_MUSTUNDERSTAND_1.equalsIgnoreCase(

+                            mustUnderstand)) {

+                return true;

+            } else if (SOAPConstants.ATTR_MUSTUNDERSTAND_FALSE.equalsIgnoreCase(

+                    mustUnderstand) ||

+                    SOAPConstants.ATTR_MUSTUNDERSTAND_0.equalsIgnoreCase(

+                            mustUnderstand)) {

+                return false;

+            } else {

+                throw new SOAPProcessingException(

+                        "Invalid value found in mustUnderstand value of " +

+                        this.getLocalName() +

+                        " header block");

+            }

+        }

+        return false;

+

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11HeaderImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11HeaderImpl.java
new file mode 100644
index 0000000..dcf03bb
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11HeaderImpl.java
@@ -0,0 +1,82 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.traverse.OMChildrenWithSpecificAttributeIterator;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPHeaderImpl;

+

+import javax.xml.namespace.QName;

+import java.util.Iterator;

+

+public class SOAP11HeaderImpl extends SOAPHeaderImpl {

+    /**

+     * @param envelope

+     */

+    public SOAP11HeaderImpl(SOAPEnvelope envelope) throws SOAPProcessingException {

+        super(envelope);

+    }

+

+    /**

+     * Constructor SOAPHeaderImpl

+     *

+     * @param envelope

+     * @param builder

+     */

+    public SOAP11HeaderImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) {

+        super(envelope, builder);

+    }

+

+    public SOAPHeaderBlock addHeaderBlock(String localName, OMNamespace ns) throws OMException {

+        if (ns == null || ns.getName() == null || "".equals(ns.getName())) {

+            throw new OMException(

+                    "All the SOAP Header blocks should be namespace qualified");

+        }

+

+        OMNamespace namespace = findNamespace(ns.getName(), ns.getPrefix());

+        if (namespace != null) {

+            ns = namespace;

+        }

+

+        SOAPHeaderBlock soapHeaderBlock = null;

+        try {

+            soapHeaderBlock = new SOAP11HeaderBlockImpl(localName, ns, this);

+        } catch (SOAPProcessingException e) {

+            throw new OMException(e);

+        }

+        ((OMNodeEx)soapHeaderBlock).setComplete(true);

+        return soapHeaderBlock;

+    }

+

+    public Iterator extractHeaderBlocks(String role) {

+        return new OMChildrenWithSpecificAttributeIterator(getFirstOMChild(),

+                new QName(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,

+                        SOAP11Constants.ATTR_ACTOR),

+                role,

+                true);

+

+    }

+

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12BodyImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12BodyImpl.java
new file mode 100644
index 0000000..0b3cbba
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12BodyImpl.java
@@ -0,0 +1,48 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPBodyImpl;

+

+public class SOAP12BodyImpl extends SOAPBodyImpl {

+    /**

+     * @param envelope

+     */

+    public SOAP12BodyImpl(SOAPEnvelope envelope) throws SOAPProcessingException {

+        super(envelope);

+    }

+

+    /**

+     * Constructor SOAPBodyImpl

+     *

+     * @param envelope

+     * @param builder

+     */

+    public SOAP12BodyImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) {

+        super(envelope, builder);

+    }

+

+    public SOAPFault addFault(Exception e) throws OMException {

+        SOAPFault soapFault = new SOAP12FaultImpl(this, e);

+        return soapFault;

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12Factory.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12Factory.java
new file mode 100644
index 0000000..2ebaffc
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12Factory.java
@@ -0,0 +1,207 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.OMNamespaceImpl;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultDetail;

+import org.apache.ws.commons.soap.SOAPFaultNode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultRole;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPEnvelopeImpl;

+import org.apache.ws.commons.soap.impl.llom.factory.SOAPLinkedListImplFactory;

+

+public class SOAP12Factory extends SOAPLinkedListImplFactory {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public String getSoapVersionURI() {

+        return SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;

+    }

+

+    public SOAPEnvelope createSOAPEnvelope() {

+        return new SOAPEnvelopeImpl(

+                new OMNamespaceImpl(

+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI,

+                        SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX),

+                this);

+    }

+

+    public SOAPHeader createSOAPHeader(SOAPEnvelope envelope) throws SOAPProcessingException {

+        return new SOAP12HeaderImpl(envelope);

+    }

+

+    public SOAPHeader createSOAPHeader(SOAPEnvelope envelope,

+                                       OMXMLParserWrapper builder) {

+        return new SOAP12HeaderImpl(envelope, builder);

+    }

+

+    public SOAPHeaderBlock createSOAPHeaderBlock(String localName,

+                                                 OMNamespace ns,

+                                                 SOAPHeader parent) throws SOAPProcessingException {

+        return new SOAP12HeaderBlockImpl(localName, ns, parent);

+    }

+

+    public SOAPHeaderBlock createSOAPHeaderBlock(String localName,

+                                                 OMNamespace ns,

+                                                 SOAPHeader parent,

+                                                 OMXMLParserWrapper builder) throws SOAPProcessingException {

+        return new SOAP12HeaderBlockImpl(localName, ns, parent, builder);

+    }

+

+    public SOAPFault createSOAPFault(SOAPBody parent, Exception e) throws SOAPProcessingException {

+        return new SOAP12FaultImpl(parent, e);

+    }

+

+    public SOAPFault createSOAPFault(SOAPBody parent) throws SOAPProcessingException {

+        return new SOAP12FaultImpl(parent);

+    }

+

+    public SOAPFault createSOAPFault(SOAPBody parent,

+                                     OMXMLParserWrapper builder) {

+        return new SOAP12FaultImpl(parent, builder);

+    }

+

+    public SOAPBody createSOAPBody(SOAPEnvelope envelope) throws SOAPProcessingException {

+        return new SOAP12BodyImpl(envelope);

+    }

+

+    public SOAPBody createSOAPBody(SOAPEnvelope envelope,

+                                   OMXMLParserWrapper builder) {

+        return new SOAP12BodyImpl(envelope, builder);

+    }

+

+    public SOAPFaultCode createSOAPFaultCode(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP12FaultCodeImpl(parent);

+    }

+

+    public SOAPFaultCode createSOAPFaultCode(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        return new SOAP12FaultCodeImpl(parent, builder);

+    }

+

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultCode parent) throws SOAPProcessingException {

+        return new SOAP12FaultValueImpl(parent);

+    }

+

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultCode parent,

+                                               OMXMLParserWrapper builder) {

+        return new SOAP12FaultValueImpl(parent, builder);

+    }

+

+    //added

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultSubCode parent) throws SOAPProcessingException {

+        return new SOAP12FaultValueImpl(parent);

+    }

+

+    //added

+    public SOAPFaultValue createSOAPFaultValue(SOAPFaultSubCode parent,

+                                               OMXMLParserWrapper builder) {

+        return new SOAP12FaultValueImpl(parent, builder);

+    }

+

+    //changed

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultCode parent) throws SOAPProcessingException {

+        return new SOAP12FaultSubCodeImpl(parent);

+    }

+

+    //changed

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultCode parent,

+                                                   OMXMLParserWrapper builder) {

+        return new SOAP12FaultSubCodeImpl(parent, builder);

+    }

+

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultSubCode parent) throws SOAPProcessingException {

+        return new SOAP12FaultSubCodeImpl(parent);

+    }

+

+    public SOAPFaultSubCode createSOAPFaultSubCode(SOAPFaultSubCode parent,

+                                                   OMXMLParserWrapper builder) {

+        return new SOAP12FaultSubCodeImpl(parent, builder);

+    }

+

+    public SOAPFaultReason createSOAPFaultReason(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP12FaultReasonImpl(parent);

+    }

+

+    public SOAPFaultReason createSOAPFaultReason(SOAPFault parent,

+                                                 OMXMLParserWrapper builder) {

+        return new SOAP12FaultReasonImpl(parent, builder);

+    }

+

+    public SOAPFaultText createSOAPFaultText(SOAPFaultReason parent) throws SOAPProcessingException {

+        return new SOAP12FaultTextImpl(parent);

+    }

+

+    public SOAPFaultText createSOAPFaultText(SOAPFaultReason parent,

+                                             OMXMLParserWrapper builder) {

+        return new SOAP12FaultTextImpl(parent, builder);

+    }

+

+    public SOAPFaultNode createSOAPFaultNode(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP12FaultNodeImpl(parent);

+    }

+

+    public SOAPFaultNode createSOAPFaultNode(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        return new SOAP12FaultNodeImpl(parent, builder);

+    }

+

+    public SOAPFaultRole createSOAPFaultRole(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP12FaultRoleImpl(parent);

+    }

+

+    public SOAPFaultRole createSOAPFaultRole(SOAPFault parent,

+                                             OMXMLParserWrapper builder) {

+        return new SOAP12FaultRoleImpl(parent, builder);

+    }

+

+    public SOAPFaultDetail createSOAPFaultDetail(SOAPFault parent) throws SOAPProcessingException {

+        return new SOAP12FaultDetailImpl(parent);

+    }

+

+    public SOAPFaultDetail createSOAPFaultDetail(SOAPFault parent,

+                                                 OMXMLParserWrapper builder) {

+        return new SOAP12FaultDetailImpl(parent, builder);

+    }

+

+    public SOAPEnvelope getDefaultEnvelope() throws SOAPProcessingException {

+        OMNamespace ns =

+                new OMNamespaceImpl(

+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI,

+                        SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX);

+        SOAPEnvelopeImpl env = new SOAPEnvelopeImpl(ns, this);

+        createSOAPHeader(env);

+        createSOAPBody(env);

+

+        return env;

+    }

+

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultCodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultCodeImpl.java
new file mode 100644
index 0000000..a150291
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultCodeImpl.java
@@ -0,0 +1,71 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultCodeImpl;

+

+public class SOAP12FaultCodeImpl extends SOAPFaultCodeImpl {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    /**

+     * Constructor OMElementImpl

+     *

+     * @param parent

+     * @param builder

+     */

+    public SOAP12FaultCodeImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    /**

+     * @param parent

+     */

+    public SOAP12FaultCodeImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, true);

+    }

+

+

+    public void setSubCode(SOAPFaultSubCode subCode) throws SOAPProcessingException {

+        if (!(subCode instanceof SOAP12FaultSubCodeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Sub Code. But received some other implementation");

+        }

+        super.setSubCode(subCode);

+    }

+

+    public void setValue(SOAPFaultValue value) throws SOAPProcessingException {

+        if (!(value instanceof SOAP12FaultValueImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Value. But received some other implementation");

+        }

+        super.setValue(value);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP12FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultDetailImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultDetailImpl.java
new file mode 100644
index 0000000..d3a8576
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultDetailImpl.java
@@ -0,0 +1,41 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultDetailImpl;

+

+

+public class SOAP12FaultDetailImpl extends SOAPFaultDetailImpl {

+    public SOAP12FaultDetailImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, true);

+    }

+

+    public SOAP12FaultDetailImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP12FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultImpl.java
new file mode 100644
index 0000000..f1fe461
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultImpl.java
@@ -0,0 +1,116 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultDetail;

+import org.apache.ws.commons.soap.SOAPFaultNode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultRole;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultImpl;

+

+import javax.xml.stream.XMLStreamException;

+

+

+public class SOAP12FaultImpl extends SOAPFaultImpl {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    public SOAP12FaultImpl(SOAPBody parent, Exception e) throws SOAPProcessingException {

+        super(parent, e);

+    }

+

+    public SOAP12FaultImpl(SOAPBody parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    /**

+     * This is a convenience method for the SOAP Fault Impl.

+     *

+     * @param parent

+     */

+    public SOAP12FaultImpl(SOAPBody parent) throws SOAPProcessingException {

+        super(parent);

+    }

+

+    protected SOAPFaultDetail getNewSOAPFaultDetail(SOAPFault fault) {

+        return new SOAP12FaultDetailImpl(fault);

+

+    }

+

+    public void setCode(SOAPFaultCode soapFaultCode) throws SOAPProcessingException {

+        if (!(soapFaultCode instanceof SOAP12FaultCodeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Code. But received some other implementation");

+        }

+        super.setCode(soapFaultCode);

+    }

+

+

+    public void setReason(SOAPFaultReason reason) throws SOAPProcessingException {

+        if (!(reason instanceof SOAP12FaultReasonImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Reason. But received some other implementation");

+        }

+        super.setReason(reason);

+    }

+

+    public void setNode(SOAPFaultNode node) throws SOAPProcessingException {

+        if (!(node instanceof SOAP12FaultNodeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Node. But received some other implementation");

+        }

+        super.setNode(node);

+    }

+

+    public void setRole(SOAPFaultRole role) throws SOAPProcessingException {

+        if (!(role instanceof SOAP12FaultRoleImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Role. But received some other implementation");

+        }

+        super.setRole(role);

+    }

+

+    public void setDetail(SOAPFaultDetail detail) throws SOAPProcessingException {

+        if (!(detail instanceof SOAP12FaultDetailImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Detail. But received some other implementation");

+        }

+        super.setDetail(detail);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP12BodyImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Body as the parent. But received some other implementation");

+        }

+    }

+

+    protected void serializeFaultNode(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) throws XMLStreamException {

+        SOAPFaultNode faultNode = getNode();

+        if (faultNode != null) {

+            ((OMNodeEx)faultNode).serialize(omOutput);

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultNodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultNodeImpl.java
new file mode 100644
index 0000000..180c250
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultNodeImpl.java
@@ -0,0 +1,41 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultNodeImpl;

+

+

+public class SOAP12FaultNodeImpl extends SOAPFaultNodeImpl {

+    public SOAP12FaultNodeImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent);

+    }

+

+    public SOAP12FaultNodeImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP12FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultReasonImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultReasonImpl.java
new file mode 100644
index 0000000..0304a27
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultReasonImpl.java
@@ -0,0 +1,55 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultReasonImpl;

+

+public class SOAP12FaultReasonImpl extends SOAPFaultReasonImpl {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    public SOAP12FaultReasonImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    /**

+     * @param parent

+     */

+    public SOAP12FaultReasonImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, true);

+    }

+

+    public void setSOAPText(SOAPFaultText soapFaultText) throws SOAPProcessingException {

+        if (!(soapFaultText instanceof SOAP12FaultTextImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Text. But received some other implementation");

+        }

+        super.setSOAPText(soapFaultText);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP12FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultRoleImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultRoleImpl.java
new file mode 100644
index 0000000..31b799b
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultRoleImpl.java
@@ -0,0 +1,40 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultRoleImpl;

+

+public class SOAP12FaultRoleImpl extends SOAPFaultRoleImpl {

+    public SOAP12FaultRoleImpl(SOAPFault parent) throws SOAPProcessingException {

+        super(parent, true);

+    }

+

+    public SOAP12FaultRoleImpl(SOAPFault parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP12FaultImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultSubCodeImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultSubCodeImpl.java
new file mode 100644
index 0000000..69184d8
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultSubCodeImpl.java
@@ -0,0 +1,72 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultSubCodeImpl;

+

+public class SOAP12FaultSubCodeImpl extends SOAPFaultSubCodeImpl {

+    //changed

+    public SOAP12FaultSubCodeImpl(SOAPFaultCode parent) throws SOAPProcessingException {

+        super(parent, SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);

+    }

+

+    //changed

+    public SOAP12FaultSubCodeImpl(SOAPFaultCode parent,

+                                  OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME, builder);

+    }

+

+    public SOAP12FaultSubCodeImpl(SOAPFaultSubCode parent) throws SOAPProcessingException {

+        super(parent, SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME);

+    }

+

+    public SOAP12FaultSubCodeImpl(SOAPFaultSubCode parent,

+                                  OMXMLParserWrapper builder) {

+        super(parent, SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!((parent instanceof SOAP12FaultSubCodeImpl) ||

+                (parent instanceof SOAP12FaultCodeImpl))) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP FaultSubCode or SOAP FaultCodeValue as the parent. But received some other implementation");

+        }

+    }

+

+    public void setSubCode(SOAPFaultSubCode subCode) throws SOAPProcessingException {

+        if (!(subCode instanceof SOAP12FaultSubCodeImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Sub Code. But received some other implementation");

+        }

+        super.setSubCode(subCode);

+    }

+

+    public void setValue(SOAPFaultValue soapFaultSubCodeValue) throws SOAPProcessingException {

+        if (!(soapFaultSubCodeValue instanceof SOAP12FaultValueImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Fault Value. But received some other implementation");

+        }

+        super.setValue(soapFaultSubCodeValue);

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultTextImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultTextImpl.java
new file mode 100644
index 0000000..e235165
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultTextImpl.java
@@ -0,0 +1,41 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultTextImpl;

+

+public class SOAP12FaultTextImpl extends SOAPFaultTextImpl {

+    public SOAP12FaultTextImpl(SOAPFaultReason parent) throws SOAPProcessingException {

+        super(parent);

+    }

+

+    public SOAP12FaultTextImpl(SOAPFaultReason parent,

+                               OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP12FaultReasonImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP FaultReason as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultValueImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultValueImpl.java
new file mode 100644
index 0000000..ed042ba
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12FaultValueImpl.java
@@ -0,0 +1,41 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPFaultValueImpl;

+

+

+public class SOAP12FaultValueImpl extends SOAPFaultValueImpl {

+    public SOAP12FaultValueImpl(OMElement parent) throws SOAPProcessingException {

+        super(parent);

+    }

+

+    public SOAP12FaultValueImpl(OMElement parent, OMXMLParserWrapper builder) {

+        super(parent, builder);

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!((parent instanceof SOAP12FaultSubCodeImpl) ||

+                (parent instanceof SOAP12FaultCodeImpl))) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP FaultSubCode or SOAP FaultCode as the parent. But received some other implementation");

+        }

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12HeaderBlockImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12HeaderBlockImpl.java
new file mode 100644
index 0000000..4cd3502
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12HeaderBlockImpl.java
@@ -0,0 +1,125 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPHeaderBlockImpl;

+

+public class SOAP12HeaderBlockImpl extends SOAPHeaderBlockImpl {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+    /**

+     * @param localName

+     * @param ns

+     */

+    public SOAP12HeaderBlockImpl(String localName,

+                                 OMNamespace ns,

+                                 SOAPHeader parent) throws SOAPProcessingException {

+        super(localName, ns, parent);

+        checkParent(parent);

+    }

+

+    /**

+     * Constructor SOAPHeaderBlockImpl

+     *

+     * @param localName

+     * @param ns

+     * @param parent

+     * @param builder

+     */

+    public SOAP12HeaderBlockImpl(String localName,

+                                 OMNamespace ns,

+                                 SOAPHeader parent,

+                                 OMXMLParserWrapper builder) {

+        super(localName, ns, parent, builder);

+

+    }

+

+    protected void checkParent(OMElement parent) throws SOAPProcessingException {

+        if (!(parent instanceof SOAP12HeaderImpl)) {

+            throw new SOAPProcessingException(

+                    "Expecting SOAP 1.2 implementation of SOAP Body as the parent. But received some other implementation");

+        }

+    }

+

+    public void setRole(String roleURI) {

+        setAttribute(SOAP12Constants.SOAP_ROLE,

+                roleURI,

+                SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+    }

+

+    public String getRole() {

+        return getAttribute(SOAP12Constants.SOAP_ROLE,

+                SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+

+    }

+

+    public void setMustUnderstand(boolean mustUnderstand) {

+        setAttribute(SOAPConstants.ATTR_MUSTUNDERSTAND,

+                mustUnderstand ? "1" : "0",

+                SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+

+    }

+

+    public void setMustUnderstand(String mustUnderstand) throws SOAPProcessingException {

+        if (SOAPConstants.ATTR_MUSTUNDERSTAND_TRUE.equals(mustUnderstand) ||

+                SOAPConstants.ATTR_MUSTUNDERSTAND_FALSE.equals(mustUnderstand) ||

+                SOAPConstants.ATTR_MUSTUNDERSTAND_0.equals(mustUnderstand) ||

+                SOAPConstants.ATTR_MUSTUNDERSTAND_1.equals(mustUnderstand)) {

+            setAttribute(SOAPConstants.ATTR_MUSTUNDERSTAND,

+                    mustUnderstand,

+                    SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+        } else {

+            throw new SOAPProcessingException(

+                    "mustUndertand should be one of \"true\", \"false\", \"0\" or \"1\" ");

+        }

+    }

+

+    public boolean getMustUnderstand() throws SOAPProcessingException {

+        String mustUnderstand = "";

+        if ((mustUnderstand =

+                getAttribute(SOAPConstants.ATTR_MUSTUNDERSTAND,

+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI))

+                != null) {

+            if (SOAPConstants.ATTR_MUSTUNDERSTAND_TRUE.equalsIgnoreCase(

+                    mustUnderstand) ||

+                    SOAPConstants.ATTR_MUSTUNDERSTAND_1.equalsIgnoreCase(

+                            mustUnderstand)) {

+                return true;

+            } else if (SOAPConstants.ATTR_MUSTUNDERSTAND_FALSE.equalsIgnoreCase(

+                    mustUnderstand) ||

+                    SOAPConstants.ATTR_MUSTUNDERSTAND_0.equalsIgnoreCase(

+                            mustUnderstand)) {

+                return false;

+            } else {

+                throw new SOAPProcessingException(

+                        "Invalid value found in mustUnderstand value of " +

+                        this.getLocalName() +

+                        " header block");

+            }

+        }

+        return false;

+

+    }

+}

diff --git a/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12HeaderImpl.java b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12HeaderImpl.java
new file mode 100644
index 0000000..0f6be40
--- /dev/null
+++ b/src/org/apache/ws/commons/soap/impl/llom/soap12/SOAP12HeaderImpl.java
@@ -0,0 +1,85 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap12;

+

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.OMNodeEx;

+import org.apache.ws.commons.om.impl.llom.traverse.OMChildrenWithSpecificAttributeIterator;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.ws.commons.soap.impl.llom.SOAPHeaderImpl;

+

+import javax.xml.namespace.QName;

+import java.util.Iterator;

+

+public class SOAP12HeaderImpl extends SOAPHeaderImpl {

+    /**

+     * Eran Chinthaka (chinthaka@apache.org)

+     */

+

+    /**

+     * @param envelope

+     */

+    public SOAP12HeaderImpl(SOAPEnvelope envelope) throws SOAPProcessingException {

+        super(envelope);

+    }

+

+    /**

+     * Constructor SOAPHeaderImpl

+     *

+     * @param envelope

+     * @param builder

+     */

+    public SOAP12HeaderImpl(SOAPEnvelope envelope, OMXMLParserWrapper builder) {

+        super(envelope, builder);

+    }

+

+    public SOAPHeaderBlock addHeaderBlock(String localName, OMNamespace ns) throws OMException {

+        if (ns == null || ns.getName() == null || "".equals(ns.getName())) {

+            throw new OMException(

+                    "All the SOAP Header blocks should be namespace qualified");

+        }

+

+        OMNamespace namespace = findNamespace(ns.getName(), ns.getPrefix());

+        if (namespace != null) {

+            ns = namespace;

+        }

+

+        SOAPHeaderBlock soapHeaderBlock = null;

+        try {

+            soapHeaderBlock = new SOAP12HeaderBlockImpl(localName, ns, this);

+        } catch (SOAPProcessingException e) {

+            throw new OMException(e);

+        }

+        ((OMNodeEx)soapHeaderBlock).setComplete(true);

+        return soapHeaderBlock;

+    }

+

+

+    public Iterator extractHeaderBlocks(String role) {

+        return new OMChildrenWithSpecificAttributeIterator(getFirstOMChild(),

+                new QName(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI,

+                        SOAP12Constants.SOAP_ROLE),

+                role,

+                true);

+    }

+

+}

diff --git a/test/org/apache/ws/commons/attachments/Base64Test.java b/test/org/apache/ws/commons/attachments/Base64Test.java
new file mode 100644
index 0000000..b44acf4
--- /dev/null
+++ b/test/org/apache/ws/commons/attachments/Base64Test.java
@@ -0,0 +1,52 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import junit.framework.TestCase;

+

+import java.io.ByteArrayInputStream;

+import java.io.ByteArrayOutputStream;

+import java.io.ObjectInputStream;

+import java.io.ObjectOutputStream;

+

+import org.apache.ws.commons.om.util.Base64;

+

+public class Base64Test extends TestCase {

+

+    Object expectedObject;

+

+    ByteArrayInputStream byteStream;

+

+    /*

+     * Class under test for String encode(byte[])

+     */

+

+    public void testEncodebyteArray() throws Exception {

+        Object actualObject;

+        String expectedBase64;

+        expectedObject = new String("Lanka Software Foundation");

+        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();

+        ObjectOutputStream objectOutStream = new ObjectOutputStream(byteStream);

+        objectOutStream.writeObject(expectedObject);

+        expectedBase64 = Base64.encode(byteStream.toByteArray());

+        byte[] tempa = Base64.decode(expectedBase64);

+        ObjectInputStream objectInStream = new ObjectInputStream(

+                new ByteArrayInputStream(tempa));

+        actualObject = objectInStream.readObject();

+        assertEquals("Base64 Encoding Check", expectedObject, actualObject);

+    }

+}
\ No newline at end of file
diff --git a/test/org/apache/ws/commons/attachments/ImageSampleTest.java b/test/org/apache/ws/commons/attachments/ImageSampleTest.java
new file mode 100644
index 0000000..2c6adaa
--- /dev/null
+++ b/test/org/apache/ws/commons/attachments/ImageSampleTest.java
@@ -0,0 +1,141 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import org.apache.ws.commons.attachments.utils.ImageDataSource;

+import org.apache.ws.commons.attachments.utils.ImageIO;

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMOutputFormat;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.impl.llom.OMElementImpl;

+import org.apache.ws.commons.om.impl.llom.OMNamespaceImpl;

+import org.apache.ws.commons.om.impl.llom.OMTextImpl;

+import org.apache.ws.commons.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;

+

+import javax.activation.DataHandler;

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.awt.*;

+import java.io.BufferedReader;

+import java.io.File;

+import java.io.FileInputStream;

+import java.io.FileOutputStream;

+import java.io.InputStream;

+import java.io.InputStreamReader;

+

+public class ImageSampleTest extends AbstractTestCase {

+

+    public ImageSampleTest(String testName) {

+        super(testName);

+    }

+

+    /*

+     * @see TestCase#setUp()

+     */

+    Image expectedImage;

+

+    MTOMStAXSOAPModelBuilder builder;

+

+    DataHandler expectedDH;

+

+    File outMTOMFile;

+

+    File outBase64File;

+

+    String outFileName = "target/ActualImageMTOMOut.bin";

+

+    String outBase64FileName = "target/OMSerializeBase64Out.xml";

+

+    String imageInFileName = "mtom/img/test.jpg";

+

+    String imageOutFileName = "target/testOut.jpg";

+

+    String inMimeFileName = "mtom/ImageMTOMOut.bin";

+

+    String contentTypeString = "multipart/Related; type=\"application/xop+xml\";start=\"<SOAPPart>\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"";

+

+

+

+    public void testImageSampleSerialize() throws Exception {

+

+        outMTOMFile = new File(outFileName);

+        outBase64File = new File(outBase64FileName);

+        OMOutputFormat mtomOutputFormat = new OMOutputFormat();

+        mtomOutputFormat.setDoOptimize(true); 

+        OMOutputFormat baseOutputFormat = new OMOutputFormat();

+        baseOutputFormat.setDoOptimize(false);

+

+        OMNamespaceImpl soap = new OMNamespaceImpl(

+                "http://schemas.xmlsoap.org/soap/envelope/", "soap");

+        OMElement envelope = new OMElementImpl("Envelope", soap);

+        OMElement body = new OMElementImpl("Body", soap);

+

+        OMNamespaceImpl dataName = new OMNamespaceImpl(

+                "http://www.example.org/stuff", "m");

+        OMElement data = new OMElementImpl("data", dataName);

+

+        expectedImage =

+                new ImageIO().loadImage(

+                        new FileInputStream(

+                                getTestResourceFile(imageInFileName)));

+        ImageDataSource dataSource = new ImageDataSource("WaterLilies.jpg",

+                expectedImage);

+        expectedDH = new DataHandler(dataSource);

+        OMText binaryNode = new OMTextImpl(expectedDH, true);

+

+        envelope.addChild(body);

+        body.addChild(data);

+        data.addChild(binaryNode);

+

+        envelope.serializeAndConsume(new FileOutputStream(outBase64File), baseOutputFormat);

+        envelope.serializeAndConsume(new FileOutputStream(outMTOMFile), mtomOutputFormat);

+    }

+

+    public void testImageSampleDeserialize() throws Exception {

+        InputStream inStream = new FileInputStream(

+                getTestResourceFile(inMimeFileName));

+        MIMEHelper mimeHelper = new MIMEHelper(inStream, contentTypeString);

+        XMLStreamReader reader = XMLInputFactory.newInstance()

+                .createXMLStreamReader(

+                        new BufferedReader(

+                                new InputStreamReader(

+                                        mimeHelper

+                .getSOAPPartInputStream())));

+        builder = new MTOMStAXSOAPModelBuilder(reader, mimeHelper, null);

+        OMElement root = builder.getDocumentElement();

+        OMElement body = (OMElement) root.getFirstOMChild();

+        OMElement data = (OMElement) body.getFirstOMChild();

+        OMText blob = (OMText) data.getFirstOMChild();

+        /*

+         * Following is the procedure the user has to follow to read objects in

+         * OBBlob User has to know the object type & whether it is serializable.

+         * If it is not he has to use a Custom Defined DataSource to get the

+         * Object.

+         */

+

+        DataHandler actualDH;

+        actualDH = (DataHandler)blob.getDataHandler();

+        Image actualObject = new ImageIO().loadImage(actualDH.getDataSource()

+                .getInputStream());

+        FileOutputStream imageOutStream = new FileOutputStream(

+                new File(imageOutFileName));

+        new ImageIO().saveImage("image/jpeg", actualObject, imageOutStream);

+

+    }

+

+}
\ No newline at end of file
diff --git a/test/org/apache/ws/commons/attachments/MIMEHelperTest.java b/test/org/apache/ws/commons/attachments/MIMEHelperTest.java
new file mode 100644
index 0000000..fde7e94
--- /dev/null
+++ b/test/org/apache/ws/commons/attachments/MIMEHelperTest.java
@@ -0,0 +1,36 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.attachments;

+

+import junit.framework.TestCase;

+

+public class MIMEHelperTest extends TestCase {

+

+

+    public void testMIMEHelper() {

+    }

+

+    public void testGetAttachmentSpecType() {

+    }

+

+    public void testGetSOAPPartInputStream() {

+    }

+

+    public void testGetDataHandler() {

+    }

+

+}
\ No newline at end of file
diff --git a/test/org/apache/ws/commons/om/AbstractOMSerializationTest.java b/test/org/apache/ws/commons/om/AbstractOMSerializationTest.java
new file mode 100644
index 0000000..32d7d07
--- /dev/null
+++ b/test/org/apache/ws/commons/om/AbstractOMSerializationTest.java
@@ -0,0 +1,178 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+import org.custommonkey.xmlunit.Diff;

+import org.custommonkey.xmlunit.XMLTestCase;

+import org.w3c.dom.Document;

+import org.xml.sax.InputSource;

+import org.xml.sax.SAXException;

+

+import javax.xml.parsers.DocumentBuilder;

+import javax.xml.parsers.DocumentBuilderFactory;

+import javax.xml.parsers.ParserConfigurationException;

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.transform.Result;

+import javax.xml.transform.Source;

+import javax.xml.transform.Transformer;

+import javax.xml.transform.TransformerConfigurationException;

+import javax.xml.transform.TransformerException;

+import javax.xml.transform.TransformerFactory;

+import javax.xml.transform.dom.DOMSource;

+import javax.xml.transform.stream.StreamResult;

+import java.io.ByteArrayInputStream;

+import java.io.ByteArrayOutputStream;

+import java.io.File;

+import java.io.FileInputStream;

+import java.io.IOException;

+import java.io.InputStream;

+import java.io.InputStreamReader;

+

+public class AbstractOMSerializationTest extends XMLTestCase {

+

+    protected boolean ignoreXMLDeclaration = true;

+    protected boolean ignoreDocument = false;

+    protected Log log = LogFactory.getLog(getClass());

+

+

+    /**

+     * @param xmlString - remember this is not the file path. this is the xml string

+     */

+    public Diff getDiffForComparison(String xmlString) throws Exception {

+        return getDiffForComparison(new ByteArrayInputStream(xmlString.getBytes()));

+    }

+

+    public Diff getDiffForComparison(File xmlFile) throws Exception {

+        return getDiffForComparison(new FileInputStream(xmlFile));

+    }

+

+    public String getSerializedOM(String xmlString) throws Exception {

+        try {

+            XMLInputFactory factory = XMLInputFactory.newInstance();

+

+            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xmlString.getBytes());

+            StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.

+                    createStAXOMBuilder(OMAbstractFactory.getOMFactory(),

+                            factory.createXMLStreamReader(byteArrayInputStream));

+            staxOMBuilder.setDoDebug(true);

+            OMElement rootElement = staxOMBuilder.getDocumentElement();

+

+            ByteArrayOutputStream baos = new ByteArrayOutputStream();

+

+            OMOutputFormat format = new OMOutputFormat();

+            format.setIgnoreXMLDeclaration(ignoreXMLDeclaration);

+

+            ((OMDocument) rootElement.getParent()).serialize(baos, format);

+

+            return new String(baos.toByteArray());

+        } catch (Exception e) {

+            throw e;

+        }

+    }

+

+    public Diff getDiffForComparison(InputStream inStream) throws Exception {

+

+        try {

+            XMLInputFactory factory = XMLInputFactory.newInstance();

+

+            StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.

+                    createStAXOMBuilder(OMAbstractFactory.getOMFactory(),

+                            factory.createXMLStreamReader(inStream));

+            staxOMBuilder.setDoDebug(true);

+            OMElement rootElement = staxOMBuilder.getDocumentElement();

+

+            ByteArrayOutputStream baos = new ByteArrayOutputStream();

+

+            if (ignoreDocument) {

+                rootElement.serialize(baos);

+            } else {

+                ((OMDocument) rootElement.getParent()).serialize(baos);

+            }

+

+            InputSource resultXML = new InputSource(new InputStreamReader(

+                    new ByteArrayInputStream(baos.toByteArray())));

+

+            Document dom2 = newDocument(resultXML);

+            Document dom1 = newDocument(inStream);

+

+            return compareXML(dom1, dom2);

+        } catch (XMLStreamException e) {

+            fail(e.getMessage());

+            throw new Exception(e);

+        } catch (ParserConfigurationException e) {

+            fail(e.getMessage());

+            throw new Exception(e);

+        } catch (SAXException e) {

+            fail(e.getMessage());

+            throw new Exception(e);

+        } catch (IOException e) {

+            fail(e.getMessage());

+            throw new Exception(e);

+        }

+    }

+

+    public Document newDocument(InputSource in)

+            throws ParserConfigurationException, SAXException, IOException {

+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

+        dbf.setNamespaceAware(true);

+        DocumentBuilder db = dbf.newDocumentBuilder();

+        return db.parse(in);

+    }

+

+    public Document newDocument(InputStream in)

+            throws ParserConfigurationException, SAXException, IOException {

+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

+        dbf.setNamespaceAware(true);

+        DocumentBuilder db = dbf.newDocumentBuilder();

+        return db.parse(in);

+    }

+

+    public Document newDocument(String xml)

+            throws ParserConfigurationException, SAXException, IOException {

+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

+        dbf.setNamespaceAware(true);

+        DocumentBuilder db = dbf.newDocumentBuilder();

+        return db.parse(new ByteArrayInputStream(xml.getBytes()));

+    }

+

+    public String writeXmlFile(Document doc) {

+        try {

+            // Prepare the DOM document for writing

+            Source source = new DOMSource(doc);

+

+            ByteArrayOutputStream baos = new ByteArrayOutputStream();

+            Result result = new StreamResult(baos);

+

+            // Write the DOM document to the file

+            Transformer xformer = TransformerFactory.newInstance().newTransformer();

+            xformer.transform(source, result);

+            return new String(baos.toByteArray());

+        } catch (TransformerConfigurationException e) {

+            log.error(e.getMessage(), e);

+        } catch (TransformerException e) {

+            log.error(e.getMessage(), e);

+        }

+        return null;

+

+    }

+

+}

diff --git a/test/org/apache/ws/commons/om/AbstractTestCase.java b/test/org/apache/ws/commons/om/AbstractTestCase.java
new file mode 100644
index 0000000..e9eafc5
--- /dev/null
+++ b/test/org/apache/ws/commons/om/AbstractTestCase.java
@@ -0,0 +1,71 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import junit.framework.TestCase;

+

+import java.io.File;

+

+/**

+ * Abstract base class for test cases.

+ */

+public abstract class AbstractTestCase

+        extends TestCase {

+    protected String testDir = "test" + File.separator;

+    protected String sampleDir = "samples" + File.separator;

+    protected String outDir = "target" + File.separator + "generated" +

+            File.separator +

+            "samples" +

+            File.separator;

+    protected String tempDir = "target" + File.separator + "generated" +

+            File.separator +

+            "temp";

+    protected String testResourceDir = "test-resources";

+

+    /**

+     * Basedir for all file I/O. Important when running tests from

+     * the reactor.

+     */

+    public String basedir = System.getProperty("basedir");

+

+    /**

+     * @param testName

+     */

+    public AbstractTestCase(String testName) {

+        super(testName);

+        if (basedir == null) {

+            basedir = new File(".").getAbsolutePath();

+        }

+        testDir = new File(basedir, testDir).getAbsolutePath();

+        sampleDir = new File(basedir, sampleDir).getAbsolutePath();

+        outDir = new File(basedir, outDir).getAbsolutePath();

+        tempDir = new File(basedir, tempDir).getAbsolutePath();

+    }

+

+    public File getTestResourceFile(String relativePath) {

+        return new File(testResourceDir, relativePath);

+    }

+

+    public File getTempOutputFile(String filename) {

+        File f = new File(tempDir);

+        if(!f.exists()) {

+            f.mkdirs();

+        }

+        return new File(f, filename);

+    }

+}

+

diff --git a/test/org/apache/ws/commons/om/AttrNsTest.java b/test/org/apache/ws/commons/om/AttrNsTest.java
new file mode 100644
index 0000000..3c8abb0
--- /dev/null
+++ b/test/org/apache/ws/commons/om/AttrNsTest.java
@@ -0,0 +1,86 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.custommonkey.xmlunit.Diff;

+import org.w3c.dom.Document;

+

+import javax.xml.namespace.QName;

+import java.io.ByteArrayInputStream;

+

+public class AttrNsTest extends AbstractOMSerializationTest {

+

+    private String attrNamespaceTestXML = "<?xml version='1.0' encoding='UTF-8'?>\n" +

+            "<foo xmlns:a=\"http://opensource.lk\">" +

+            "    <bar1 b:attr=\"test attr value1\" xmlns:b=\"http://opensource.lk/ns1\">test1</bar1>" +

+            "    <bar2 b:attr=\"test attr value2\" xmlns:b=\"http://opensource.lk/ns1\">test2</bar2>" +

+            "</foo>";

+

+    public void testAttributeNamespaces() throws Exception {

+        ignoreXMLDeclaration = true;

+        ignoreDocument = true;

+

+        Document document1 = newDocument(attrNamespaceTestXML);

+        String serializedOM = getSerializedOM(attrNamespaceTestXML);

+        Document document2 = newDocument(serializedOM);

+

+        Diff diff = compareXML(document1, document2);

+        assertXMLEqual(diff, true);

+    }

+    

+

+    /**

+     * Test method to test the XML namespace

+     * @throws Exception

+     */

+	public void testAttr() throws Exception{

+		String xml = "<wsp:Policy xml:base=\"uri:thisBase\" " +

+			"xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">" + 

+		"</wsp:Policy>";

+		

+		ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());

+		StAXOMBuilder builder = new StAXOMBuilder(bais);

+		OMElement elem = builder.getDocumentElement();

+		elem.build();

+		assertEquals("Attribute value mismatch", "uri:thisBase", elem.getAttributeValue(new QName(OMConstants.XMLNS_URI,"base")));

+		

+		OMAttribute attr = elem.getAttribute(new QName(OMConstants.XMLNS_URI,"base"));

+		

+		assertEquals("Attribute namespace mismatch", OMConstants.XMLNS_URI, attr.getNamespace().getName());

+	}

+

+    /**

+     * Test method to test the XML namespace of an attr without

+     * any other ns declarations in the element

+     * @throws Exception

+     */

+	public void testAttrWithoutElementNS() throws Exception{

+		String xml = "<Policy xml:base=\"uri:thisBase\"></Policy>";

+		

+		ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());

+		StAXOMBuilder builder = new StAXOMBuilder(bais);

+		OMElement elem = builder.getDocumentElement();

+		elem.build();

+		assertEquals("Attribute value mismatch", "uri:thisBase", elem.getAttributeValue(new QName(OMConstants.XMLNS_URI,"base")));

+		

+		OMAttribute attr = elem.getAttribute(new QName(OMConstants.XMLNS_URI,"base"));

+		

+		assertEquals("Attribute namespace mismatch", OMConstants.XMLNS_URI, attr.getNamespace().getName());

+	}

+

+}

diff --git a/test/org/apache/ws/commons/om/BadInputTest.java b/test/org/apache/ws/commons/om/BadInputTest.java
new file mode 100644
index 0000000..eda38eb
--- /dev/null
+++ b/test/org/apache/ws/commons/om/BadInputTest.java
@@ -0,0 +1,136 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.soap.SOAPEnvelope;

+

+public class BadInputTest extends OMTestCase {

+

+    public BadInputTest(String testName) {

+        super(testName);

+    }

+

+

+    //done

+    public void testEnvelopeMissing() throws Exception {

+        try {

+            SOAPEnvelope soapEnvelope =

+                    (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                            getTestResourceFile(TestConstants.BAD_ENVELOPE_MISSING))

+                    .getDocumentElement();

+            OMTestUtils.walkThrough(soapEnvelope);

+            fail("this must failed gracefully with OMException or AxisFault");

+        } catch (OMException e) {

+            return;

+        }

+

+    }

+

+    //done

+    public void testHeaderBodyWrongOrder() throws Exception {

+        try {

+            SOAPEnvelope soapEnvelope =

+                    (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                            getTestResourceFile(TestConstants.BAD_HEADER_BODY_WRONG_ORDER))

+                    .getDocumentElement();

+            OMTestUtils.walkThrough(soapEnvelope);

+            fail("this must failed gracefully with OMException or AxisFault");

+        } catch (OMException e) {

+            return;

+        }

+    }

+

+    //done

+    //    public void testNotnamespaceQualified() throws Exception {

+    //        try {

+    //            SOAPEnvelope soapEnvelope =

+    //                    (SOAPEnvelope) OMTestUtils.getOMBuilder(new File(dir, "notnamespaceQualified.xml")).getDocumentElement();

+    //            OMTestUtils.walkThrough(soapEnvelope);

+    //            fail("this must failed gracefully with OMException or AxisFault");

+    //        } catch (OMException e) {

+    //            return;

+    //        } catch (AxisFault e) {

+    //            return;

+    //        }

+    //

+    //    }

+    //done

+    //    public void testBodyNotQualified() throws Exception {

+    //        try {

+    //            SOAPEnvelope soapEnvelope =

+    //                    (SOAPEnvelope) OMTestUtils.getOMBuilder(new File(dir, "bodyNotQualified.xml")).getDocumentElement();

+    //            OMTestUtils.walkThrough(soapEnvelope);

+    //            fail("this must failed gracefully with OMException or AxisFault");

+    //        } catch (OMException e) {

+    //            //we are OK!

+    //            return;

+    //        } catch (AxisFault e) {

+    //            //we are OK here too!

+    //            return;

+    //        }

+    //

+    //    }

+

+    //done

+    public void testTwoBodymessage() throws Exception {

+        try {

+            SOAPEnvelope soapEnvelope =

+                    (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                            getTestResourceFile(TestConstants.BAD_TWO_BODY))

+                    .getDocumentElement();

+            OMTestUtils.walkThrough(soapEnvelope);

+            fail("this must failed gracefully with OMException or AxisFault");

+        } catch (OMException e) {

+            return;

+        }

+

+    }

+

+    //done

+    public void testTwoheaders() throws Exception {

+        try {

+            SOAPEnvelope soapEnvelope =

+                    (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                            getTestResourceFile(TestConstants.BAD_TWO_HEADERS))

+                    .getDocumentElement();

+            OMTestUtils.walkThrough(soapEnvelope);

+            fail("this must failed gracefully with OMException or AxisFault");

+        } catch (OMException e) {

+            return;

+        }

+

+    }

+

+    //done

+    public void testWrongSoapNs() throws Exception {

+        try {

+            SOAPEnvelope soapEnvelope =

+                    (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                            getTestResourceFile(TestConstants.BAD_WRONG_SOAP_NS))

+                    .getDocumentElement();

+            OMTestUtils.walkThrough(soapEnvelope);

+            fail("this must failed gracefully with OMException or AxisFault");

+        } catch (OMException e) {

+            return;

+        }

+

+    }

+

+

+

+

+}

diff --git a/test/org/apache/ws/commons/om/CompareOMWithDOMTest.java b/test/org/apache/ws/commons/om/CompareOMWithDOMTest.java
new file mode 100644
index 0000000..0a35403
--- /dev/null
+++ b/test/org/apache/ws/commons/om/CompareOMWithDOMTest.java
@@ -0,0 +1,57 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.w3c.dom.Document;

+

+import javax.xml.parsers.DocumentBuilder;

+import javax.xml.parsers.DocumentBuilderFactory;

+import java.io.File;

+

+/**

+ * @version $Rev: $ $Date: $

+ */

+public class CompareOMWithDOMTest extends AbstractTestCase {

+    /**

+     * @param testName

+     */

+    public CompareOMWithDOMTest(String testName) {

+        super(testName);

+    }

+

+    public void testAllMessagesInSOAP() throws OMException, Exception {

+        File dir = new File(testResourceDir, "soap");

+        File[] files = dir.listFiles();

+        if (files != null) {

+            for (int i = 0; i < files.length; i++) {

+                if (files[i].isFile() && files[i].getName().endsWith(".xml") && !files[i].getName().startsWith("wrong")) {

+                    SOAPEnvelope soapEnvelope = (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                            files[i])

+                            .getDocumentElement();

+                    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

+                    dbf.setNamespaceAware(true);

+                    DocumentBuilder builder = dbf.newDocumentBuilder();

+                    Document doc = builder.parse(files[i].getAbsolutePath());

+                    OMTestUtils.compare(doc.getDocumentElement(),

+                            soapEnvelope);

+                }

+            }

+

+        }

+    }

+}

diff --git a/test/org/apache/ws/commons/om/DefaultNamespaceTest.java b/test/org/apache/ws/commons/om/DefaultNamespaceTest.java
new file mode 100644
index 0000000..1a090a6
--- /dev/null
+++ b/test/org/apache/ws/commons/om/DefaultNamespaceTest.java
@@ -0,0 +1,52 @@
+package org.apache.ws.commons.om;

+

+import org.custommonkey.xmlunit.XMLTestCase;

+

+import javax.xml.namespace.QName;

+

+/*

+ * Copyright 2001-2004 The Apache Software Foundation.

+ *

+ * Licensed 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.

+ *

+ */

+

+public class DefaultNamespaceTest extends XMLTestCase {

+

+    public void testDefaultNamespace() throws Exception {

+

+        String expectedXML = "<Foo xmlns=\"http://defaultNsUri.org\"><Bar xmlns=\"\"></Bar><Baz></Baz></Foo>";

+

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+        OMElement foo = factory.createOMElement(new QName("http://defaultNsUri.org", "Foo"), null);

+        factory.createOMElement("Bar", null, foo);

+        factory.createOMElement(new QName("http://defaultNsUri.org", "Baz"), foo);

+        assertXMLEqual(expectedXML, foo.toString());

+    }

+

+    public void test() {

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+

+        String nsURI = "http://test.org";

+        String nsPrefix = "testPrefix";

+        OMElement element = factory.createOMElement("DocElement", null);

+

+        OMElement foo = factory.createOMElement(new QName(nsURI, "Foo", nsPrefix), element);

+        factory.createOMElement(new QName(nsURI+1, "Bar", nsPrefix), element);

+

+        factory.createOMElement(new QName(nsURI+2, "Baz", nsPrefix), foo);

+        factory.createOMElement(new QName(nsURI, "Baz", nsPrefix), foo);

+

+    }

+

+}

diff --git a/test/org/apache/ws/commons/om/IteratorTest.java b/test/org/apache/ws/commons/om/IteratorTest.java
new file mode 100644
index 0000000..0540c18
--- /dev/null
+++ b/test/org/apache/ws/commons/om/IteratorTest.java
@@ -0,0 +1,184 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.om.impl.llom.factory.OMLinkedListImplFactory;

+

+import javax.xml.namespace.QName;

+import javax.xml.stream.XMLInputFactory;

+import java.io.FileReader;

+import java.util.Iterator;

+

+public class IteratorTest extends AbstractTestCase {

+    private OMElement envelope = null;

+

+    public IteratorTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        //lets use a plain OM factory

+        envelope =

+                new StAXOMBuilder(new OMLinkedListImplFactory(),

+                        XMLInputFactory.newInstance().createXMLStreamReader(

+                                new FileReader(

+                                        getTestResourceFile(

+                                                "soap/soapmessage1.xml")))).getDocumentElement();

+    }

+

+    protected void tearDown() throws Exception {

+        envelope = null;

+    }

+

+    /**

+     * Test the plain iterator which includes all the

+     * children (including the texts)

+     */

+    public void testIterator() {

+        OMElement elt = envelope;

+        Iterator iter = elt.getChildren();

+        int counter = 0;

+        while (iter.hasNext()) {

+            counter ++;

+            assertNotNull("Must return not null objects!",iter.next());

+        }

+        assertEquals("This element should contain only five children including the text ",5,counter);

+    }

+

+    /**

+     * Test the element iterator

+     */

+    public void testElementIterator() {

+        OMElement elt = envelope;

+        Iterator iter = elt.getChildElements();

+        int counter = 0;

+        while (iter.hasNext()) {

+            counter ++;

+            Object o = iter.next();

+            assertNotNull("Must return not null objects!",o);

+            assertTrue("All these should be elements!",((OMNode)o).getType()==OMNode.ELEMENT_NODE);

+        }

+        assertEquals("This element should contain only two elements ",2,counter);

+    }

+

+    /**

+     * Test the element iterator

+     */

+    public void testElementQNameIterator() {

+        OMElement elt = envelope;

+        QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/","body");

+        Iterator iter = elt.getChildrenWithName(qname);

+        int counter = 0;

+        while (iter.hasNext()) {

+            counter ++;

+            Object o = iter.next();

+            assertNotNull("Must return not null objects!",o);

+            assertTrue("All these should be elements!",((OMNode)o).getType()==OMNode.ELEMENT_NODE);

+        }

+        assertEquals("This element should contain only one element with the given QName ",1,counter);

+    }

+

+    /**

+     * test the remove exception behavior

+     */

+    public void testIteratorRemove1() {

+        OMElement elt = envelope;

+        Iterator iter = elt.getChildren();

+

+        //this is supposed to throw an illegal state exception

+        try {

+            iter.remove();

+            fail("remove should throw an exception");

+        } catch (IllegalStateException e) {

+            //ok. this is what should happen

+        }

+

+    }

+

+    /**

+     * test the remove exception behavior, consecutive remove calls

+     */

+    public void testIteratorRemove2() {

+        OMElement elt = envelope;

+        Iterator iter = elt.getChildren();

+        if (iter.hasNext()) {

+            iter.next();

+        }

+        iter.remove();

+

+        //this call must generate an exception

+        try {

+            iter.remove();

+            fail("calling remove twice without a call to next is prohibited");

+        } catch (IllegalStateException e) {

+            //ok if we come here :)

+        }

+

+    }

+

+    /**

+     * Remove all!

+     */

+    public void testIteratorRemove3() {

+        OMElement elt = envelope;

+        Iterator iter = elt.getChildren();

+        while (iter.hasNext()) {

+            iter.next();

+            iter.remove();

+        }

+        iter = elt.getChildren();

+        if (iter.hasNext()) {

+            //we shouldn't reach here!

+            fail("No children should remain after removing all!");

+        }

+

+

+    }

+

+    /**

+     * test whether the children count reduces.

+     */

+    public void testIteratorRemove4() {

+        OMElement elt = envelope;

+        Iterator iter = elt.getChildren();

+        int firstChildrenCount = 0;

+        int secondChildrenCount = 0;

+        while (iter.hasNext()) {

+            assertNotNull(iter.next());

+            firstChildrenCount++;

+        }

+

+        //remove the last node

+        iter.remove();

+

+        //reloop and check the count

+        //Note- here we should get a fresh iterator since there is no method to

+        //reset the iterator

+        iter = elt.getChildren(); //reset the iterator

+        while (iter.hasNext()) {

+            assertNotNull(iter.next());

+            secondChildrenCount++;

+        }

+        assertEquals("children count must reduce from 1",

+                firstChildrenCount - 1,

+                secondChildrenCount);

+

+    }

+

+

+}

diff --git a/test/org/apache/ws/commons/om/MIMEOutputUtilsTest.java b/test/org/apache/ws/commons/om/MIMEOutputUtilsTest.java
new file mode 100644
index 0000000..9986b2c
--- /dev/null
+++ b/test/org/apache/ws/commons/om/MIMEOutputUtilsTest.java
@@ -0,0 +1,91 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.attachments.ByteArrayDataSource;

+import org.apache.ws.commons.om.impl.MIMEOutputUtils;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPFactory;

+

+import javax.activation.DataHandler;

+import javax.mail.MessagingException;

+import javax.mail.internet.MimeBodyPart;

+import javax.mail.internet.MimeMessage;

+import javax.mail.internet.MimeMultipart;

+import java.io.ByteArrayInputStream;

+import java.io.ByteArrayOutputStream;

+import java.io.IOException;

+import java.util.Properties;

+

+public class MIMEOutputUtilsTest extends TestCase {

+    byte[] buffer;

+    byte[] byteArray = new byte[]{13, 56, 65, 32, 12, 12, 7, -3, -2, -1,

+                                  98};

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();

+        ByteArrayOutputStream outStream;

+        String boundary;

+        

+        OMOutputFormat omOutput = new OMOutputFormat();

+        boundary = omOutput.getMimeBoundary();

+

+        String contentType = org.apache.ws.commons.om.impl.MIMEOutputUtils

+				.getContentTypeForMime(boundary, omOutput.getRootContentId(),

+						omOutput.getCharSetEncoding(),SOAP12Constants.SOAP_12_CONTENT_TYPE);

+        DataHandler dataHandler;

+        dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));

+        OMText textData = factory.createText(dataHandler, true);

+        assertNotNull(textData.getContentID());

+

+        DataHandler dataHandler2 = new DataHandler(

+                "Apache Software Foundation", "text/plain");

+        OMText text = factory.createText(dataHandler2, true);

+        assertNotNull(text.getContentID());

+        outStream = new ByteArrayOutputStream();

+        outStream.write(("Content-Type: " + contentType).getBytes());

+        outStream.write(new byte[]{13,10});

+        outStream.write(new byte[]{13,10});

+

+        MIMEOutputUtils.startWritingMime(outStream, boundary);

+        MimeBodyPart part1 = MIMEOutputUtils.createMimeBodyPart(textData);

+        MIMEOutputUtils.writeBodyPart(outStream, part1, boundary);

+        MimeBodyPart part2 = MIMEOutputUtils.createMimeBodyPart(text);

+        MIMEOutputUtils.writeBodyPart(outStream, part2, boundary);

+        MIMEOutputUtils.finishWritingMime(outStream);

+        buffer = outStream.toByteArray();

+    }

+

+    public void testMIMEWriting() throws IOException, MessagingException {

+        ByteArrayInputStream inStream = new ByteArrayInputStream(buffer);

+        Properties props = new Properties();

+        javax.mail.Session session = javax.mail.Session

+                .getInstance(props, null);

+        MimeMessage mimeMessage = new MimeMessage(session, inStream);

+        DataHandler dh = mimeMessage.getDataHandler();

+        MimeMultipart multiPart = new MimeMultipart(dh.getDataSource());

+        MimeBodyPart mimeBodyPart0 = (MimeBodyPart) multiPart.getBodyPart(0);

+        Object object0 = mimeBodyPart0.getContent();

+        assertNotNull(object0);

+        MimeBodyPart mimeBodyPart1 = (MimeBodyPart) multiPart.getBodyPart(1);

+        Object object1 = mimeBodyPart1.getContent();

+        assertNotNull(object1);

+        assertEquals(multiPart.getCount(),2);

+    }

+}
\ No newline at end of file
diff --git a/test/org/apache/ws/commons/om/MessagesTest.java b/test/org/apache/ws/commons/om/MessagesTest.java
new file mode 100644
index 0000000..7f11a09
--- /dev/null
+++ b/test/org/apache/ws/commons/om/MessagesTest.java
@@ -0,0 +1,62 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.soap.SOAPEnvelope;

+

+public class MessagesTest extends OMTestCase {

+    SOAPEnvelope soapEnvelope;

+

+    public MessagesTest(String testName) {

+        super(testName);

+    }

+

+    public void testMessageWithLotOfWhiteSpaces() throws OMException,

+            Exception {

+        soapEnvelope =

+                (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                        getTestResourceFile(TestConstants.WHITESPACE_MESSAGE))

+                .getDocumentElement();

+        OMTestUtils.walkThrough(soapEnvelope);

+    }

+

+    public void testMinimalMessage() throws OMException, Exception {

+        soapEnvelope =

+                (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                        getTestResourceFile(TestConstants.MINIMAL_MESSAGE))

+                .getDocumentElement();

+        OMTestUtils.walkThrough(soapEnvelope);

+    }

+

+    public void testReallyBigMessage() throws OMException, Exception {

+        soapEnvelope =

+                (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                        getTestResourceFile(TestConstants.REALLY_BIG_MESSAGE))

+                .getDocumentElement();

+        OMTestUtils.walkThrough(soapEnvelope);

+    }

+

+    public void testEmptyBodiedMessage() throws OMException, Exception {

+        soapEnvelope =

+                (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                        getTestResourceFile(TestConstants.EMPTY_BODY_MESSAGE))

+                .getDocumentElement();

+        OMTestUtils.walkThrough(soapEnvelope);

+    }

+

+

+}

diff --git a/test/org/apache/ws/commons/om/OMBlankElementTest.java b/test/org/apache/ws/commons/om/OMBlankElementTest.java
new file mode 100644
index 0000000..003ff24
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMBlankElementTest.java
@@ -0,0 +1,56 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import junit.framework.TestCase;

+

+import javax.xml.stream.XMLStreamException;

+import java.io.StringWriter;

+

+

+public class OMBlankElementTest extends TestCase {

+

+

+	public OMBlankElementTest(String name) {

+		super(name);

+	}

+

+	public void testBlankOMElem() {

+		try {

+			//We should not get anything as the return value here: the output of the serialization

+			String value = buildBlankOMElem();

+			assertNull("There's a serialized output for a blank XML element that cannot exist", value);

+		} catch (Exception e) {

+			//An exception is thrown trying to serializeAndConsume a blank element

+			assertTrue(true);

+		}

+	}

+

+

+

+	String buildBlankOMElem() throws XMLStreamException {

+		OMFactory factory = OMAbstractFactory.getOMFactory();

+		OMNamespace namespace1 = factory.createOMNamespace("","");

+		OMElement elem1 = factory.createOMElement("",namespace1);

+

+		StringWriter writer = new StringWriter();

+		elem1.build();

+		elem1.serialize(writer);

+		writer.flush();

+		return writer.toString();

+	}

+}

diff --git a/test/org/apache/ws/commons/om/OMBodyTest.java b/test/org/apache/ws/commons/om/OMBodyTest.java
new file mode 100644
index 0000000..8318115
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMBodyTest.java
@@ -0,0 +1,62 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+public class OMBodyTest extends OMTestCase implements OMConstants {

+    SOAPBody soapBody;

+    private Log log = LogFactory.getLog(getClass());

+

+    public OMBodyTest(String testName) {

+        super(testName);

+    }

+

+    /*

+     * @see TestCase#setUp()

+     */

+    protected void setUp() throws Exception {

+        super.setUp();

+        soapBody = soapEnvelope.getBody();

+    }

+

+    /*

+     * Class under test for SOAPFault addFault()

+     */

+    public void testAddFault() {

+        log.info("Adding SOAP fault to body ....");

+        try {

+            soapBody.addChild(

+                    soapFactory.createSOAPFault(soapBody,

+                            new Exception("Testing soap fault")));

+        } catch (SOAPProcessingException e) {

+            log.info(e.getMessage());

+            fail(e.getMessage());

+        }

+        log.info("\t checking for SOAP Fault ...");

+        assertTrue("SOAP body has no SOAP fault", soapBody.hasFault());

+        log.info("\t checking for not-nullity ...");

+        assertTrue("SOAP body has no SOAP fault", soapBody.getFault() != null);

+

+        //SimpleOMSerializer simpleOMSerializer = new SimpleOMSerializer();

+        //simpleOMSerializer.serializeAndConsume(soapBody, System.out);

+    }

+

+}

diff --git a/test/org/apache/ws/commons/om/OMDocumentTest.java b/test/org/apache/ws/commons/om/OMDocumentTest.java
new file mode 100644
index 0000000..b84546e
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMDocumentTest.java
@@ -0,0 +1,95 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import java.io.ByteArrayOutputStream;

+import java.io.StringReader;

+import java.util.Iterator;

+

+public class OMDocumentTest extends TestCase {

+    private String sampleXML = "<?xml version='1.0' encoding='utf-8'?>" +

+            "<!--This is some comments at the start of the document-->" +

+            "<?PITarget PIData?>" +

+            "<Axis2>" +

+            "    <ProjectName>The Apache Web Sevices Project</ProjectName>" +

+            "</Axis2>";

+

+    public void testOMDocument() throws XMLStreamException {

+        // read the string in to the builder

+        OMDocument omDocument = getSampleOMDocument(sampleXML);

+

+        // serialise it to a string

+        String outXML = "";

+        ByteArrayOutputStream outStream = new ByteArrayOutputStream();

+        omDocument.serializeAndConsume(outStream);

+        outXML = new String(outStream.toByteArray());

+

+        // again load that to another builder

+        OMDocument secondDocument = getSampleOMDocument(outXML);

+

+        // check for the comment and the PI

+        boolean commentFound = false;

+        boolean piFound = false;

+        Iterator children = secondDocument.getChildren();

+        while (children.hasNext()) {

+            OMNode omNode = (OMNode) children.next();

+            if (omNode instanceof OMComment) {

+                commentFound = true;

+            } else if (omNode instanceof OMProcessingInstruction) {

+                piFound = true;

+            } else if (omNode instanceof OMElement && !commentFound && !piFound) {

+               fail("OMElement should come after Comment and PI");

+

+            }

+        }

+        assertTrue(commentFound && piFound);

+

+

+    }

+

+    private OMDocument getSampleOMDocument(String xml) {

+        try {

+            XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));

+            StAXOMBuilder builder = new StAXOMBuilder(xmlStreamReader);

+            return builder.getDocument();

+        } catch (XMLStreamException e) {

+            throw new UnsupportedOperationException();

+        }

+    }

+

+//    private OMDocument getSampleOMDocument() {

+//        OMFactory omFactory = OMAbstractFactory.getOMFactory();

+//        OMDocument omDocument = omFactory.createOMDocument();

+//        omFactory.createOMComment(omDocument, "This is some comments at the start of the document");

+//        omDocument.setCharsetEncoding("utf-8");

+//        omFactory.createOMProcessingInstruction(omDocument, "PITarget", "PIData");

+//

+//        OMElement documentElement = omFactory.createOMElement("Axis2", null, omDocument);

+//        omDocument.setDocumentElement(documentElement);

+//        omFactory.createOMElement("ProjectName", null, documentElement);

+//        documentElement.getFirstElement().setText("The Apache Web Sevices Project");

+//

+//        return omDocument;

+//    }

+

+}

diff --git a/test/org/apache/ws/commons/om/OMElementCloneTest.java b/test/org/apache/ws/commons/om/OMElementCloneTest.java
new file mode 100644
index 0000000..2b8f5d0
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMElementCloneTest.java
@@ -0,0 +1,89 @@
+package org.apache.ws.commons.om;

+

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.custommonkey.xmlunit.XMLTestCase;

+import org.w3c.dom.Document;

+import org.xml.sax.SAXException;

+

+import javax.xml.parsers.DocumentBuilder;

+import javax.xml.parsers.DocumentBuilderFactory;

+import javax.xml.parsers.ParserConfigurationException;

+import java.io.ByteArrayInputStream;

+import java.io.File;

+import java.io.IOException;

+

+/*

+ * Copyright 2001-2004 The Apache Software Foundation.

+ *

+ * Licensed 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.

+ *

+ */

+

+public class OMElementCloneTest extends XMLTestCase {

+

+    File dir = new File(TestConstants.TEST_RESOURCES, TestConstants.SOAP_DIR);

+

+    public void testElementCloningWithoutUsingOMElementMethod() throws Exception {

+        SOAPEnvelope soapEnvelope =

+                (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                        new File(dir, TestConstants.SOAPMESSAGE))

+                        .getDocumentElement();

+        SOAPBody body = soapEnvelope.getBody();

+

+        OMElement firstClonedBodyElement = new StAXOMBuilder(body.getXMLStreamReader()).getDocumentElement();

+        OMElement secondClonedBodyElement = new StAXOMBuilder(body.getXMLStreamReader()).getDocumentElement();

+

+        // first check whether both have the same information

+        assertXMLEqual(newDocument(body.toString()), newDocument(firstClonedBodyElement.toString()));

+        assertXMLEqual(newDocument(body.toString()), newDocument(secondClonedBodyElement.toString()));

+        assertXMLEqual(newDocument(firstClonedBodyElement.toString()), newDocument(secondClonedBodyElement.toString()));

+

+        // lets check some links. They must not be equal

+        assertNotSame(body.getParent(), firstClonedBodyElement.getParent());

+        assertNotSame(body.getParent(), secondClonedBodyElement.getParent());

+        assertNotSame(firstClonedBodyElement.getParent(), secondClonedBodyElement.getParent());

+

+    }

+

+    public void testElementCloningUsingOMElementMethod() throws Exception {

+        SOAPEnvelope soapEnvelope =

+                (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                        new File(dir, TestConstants.SOAPMESSAGE))

+                        .getDocumentElement();

+        SOAPBody body = soapEnvelope.getBody();

+

+        OMElement firstClonedBodyElement = body.cloneOMElement();

+        OMElement secondClonedBodyElement = body.cloneOMElement();

+

+        // first check whether both have the same information

+        assertXMLEqual(newDocument(body.toString()), newDocument(firstClonedBodyElement.toString()));

+        assertXMLEqual(newDocument(body.toString()), newDocument(secondClonedBodyElement.toString()));

+        assertXMLEqual(newDocument(firstClonedBodyElement.toString()), newDocument(secondClonedBodyElement.toString()));

+

+        // lets check some links. They must not be equal

+        assertNotSame(body.getParent(), firstClonedBodyElement.getParent());

+        assertNotSame(body.getParent(), secondClonedBodyElement.getParent());

+        assertNotSame(firstClonedBodyElement.getParent(), secondClonedBodyElement.getParent());

+

+    }

+

+    public Document newDocument(String xml)

+            throws ParserConfigurationException, SAXException, IOException {

+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

+        dbf.setNamespaceAware(true);

+        DocumentBuilder db = dbf.newDocumentBuilder();

+        return db.parse(new ByteArrayInputStream(xml.getBytes()));

+    }

+}

diff --git a/test/org/apache/ws/commons/om/OMElementQNameTest.java b/test/org/apache/ws/commons/om/OMElementQNameTest.java
new file mode 100644
index 0000000..ca1a813
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMElementQNameTest.java
@@ -0,0 +1,88 @@
+/** (C) Copyright 2005 Hewlett-Packard Development Company, LP
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+ For more information: www.smartfrog.org
+
+ */
+package org.apache.ws.commons.om;
+
+import org.apache.ws.commons.om.util.ElementHelper;
+
+import javax.xml.namespace.QName;
+
+/**
+ * created 03-Nov-2005 11:46:32
+ */
+
+public class OMElementQNameTest extends OMTestCase {
+
+    OMElement element;
+
+    private static final String WSA= "http://schemas.xmlsoap.org/ws/2004/03/addressing";
+    private static final String SOAPENV = "http://schemas.xmlsoap.org/soap/envelope/";
+
+    public OMElementQNameTest(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        element = OMTestUtils.getOMBuilder(
+                        getTestResourceFile(TestConstants.SOAP_SOAPMESSAGE1))
+                        .getDocumentElement();
+    }
+
+    public void testSimpleQName() throws Exception {
+        QName result = element.resolveQName("wsa:To");
+        assertEquals(WSA,result.getNamespaceURI());
+        assertEquals("wsa", result.getPrefix());
+        assertEquals("To", result.getLocalPart());
+    }
+
+    public void testDefaultQName() throws Exception {
+        QName result = element.resolveQName("localonly");
+        assertEquals(SOAPENV, result.getNamespaceURI());
+        assertEquals("soapenv", result.getPrefix());
+        assertEquals("localonly", result.getLocalPart());
+    }
+
+    public void testDefaultQNameCanBeLocal() throws Exception {
+        ElementHelper helper=new ElementHelper(element);
+        QName result = helper.resolveQName("localonly",false);
+        assertEquals("", result.getNamespaceURI());
+        assertEquals("localonly", result.getLocalPart());
+    }
+
+    public void testNoLocal() throws Exception {
+        assertResolvesToNull("wsa:");
+    }
+
+    public void testNoMatch() throws Exception {
+        assertResolvesToNull("wsa2005:To");
+    }
+
+    public void testNothing() throws Exception {
+        assertResolvesToNull(":");
+    }
+
+
+
+    private void assertResolvesToNull(String qname) {
+        QName result = element.resolveQName(qname);
+        assertNull("Expected "+qname+" to resolve to null",result);
+    }
+
+}
diff --git a/test/org/apache/ws/commons/om/OMNavigatorTest.java b/test/org/apache/ws/commons/om/OMNavigatorTest.java
new file mode 100644
index 0000000..12070e0
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMNavigatorTest.java
@@ -0,0 +1,103 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.om.impl.llom.OMNavigator;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.File;

+import java.io.FileOutputStream;

+import java.io.FileReader;

+

+public class OMNavigatorTest extends AbstractTestCase {

+    private SOAPEnvelope envelope = null;

+    private OMXMLParserWrapper builder;

+    private File tempFile;

+    private XMLStreamWriter output;

+

+    public OMNavigatorTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().

+                createXMLStreamReader(

+                        new FileReader(

+                                getTestResourceFile(TestConstants.SOAP_SOAPMESSAGE1)));

+        builder = new StAXSOAPModelBuilder(xmlStreamReader, null);

+        envelope = (SOAPEnvelope) builder.getDocumentElement();

+        tempFile = File.createTempFile("temp", "xml");

+        output =

+                XMLOutputFactory.newInstance().createXMLStreamWriter(

+                        new FileOutputStream(tempFile));

+    }

+

+    public void testnavigatorFullyBuilt() throws Exception {

+        assertNotNull(envelope);

+        //dump the out put to a  temporary file

+        envelope.serialize(output);

+

+        //now the OM is fully created -> test the navigation

+        OMNavigator navigator = new OMNavigator(envelope);

+        OMNode node = null;

+        while (navigator.isNavigable()) {

+            node = navigator.next();

+            assertNotNull(node);

+        }

+    }

+

+    public void testnavigatorHalfBuilt() {

+        assertNotNull(envelope);

+        //now the OM is not fully created. Try to navigate it

+        OMNavigator navigator = new OMNavigator(envelope);

+        OMNode node = null;

+        while (navigator.isNavigable()) {

+            node = navigator.next();

+            assertNotNull(node);

+        }

+    }

+

+    public void testnavigatorHalfBuiltStep() {

+        assertNotNull(envelope);

+

+        //now the OM is not fully created

+        OMNavigator navigator = new OMNavigator(envelope);

+        OMNode node = null;

+        while (!navigator.isCompleted()) {

+            if (navigator.isNavigable()) {

+                node = navigator.next();

+            } else {

+                builder.next();

+                navigator.step();

+                node = navigator.next();

+            }

+            assertNotNull(node);

+

+        }

+

+    }

+

+    protected void tearDown() throws Exception {

+        tempFile.delete();

+    }

+

+}

diff --git a/test/org/apache/ws/commons/om/OMTest.java b/test/org/apache/ws/commons/om/OMTest.java
new file mode 100644
index 0000000..64617bf
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMTest.java
@@ -0,0 +1,142 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.io.File;

+import java.io.FileReader;

+import java.util.Iterator;

+

+/**

+ * This test case tests the basic expectations of the engine from the OM.

+ */

+public class OMTest extends AbstractTestCase {

+    private SOAPEnvelope envelope;

+

+    /**

+     * Constructor.

+     */

+    public OMTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        File file = getTestResourceFile(TestConstants.SAMPLE1);

+        XMLStreamReader parser = XMLInputFactory.newInstance()

+                .createXMLStreamReader(new FileReader(file));

+        OMXMLParserWrapper builder = new StAXSOAPModelBuilder(parser, null);

+        envelope = (SOAPEnvelope) builder.getDocumentElement();

+    }

+

+    /**

+     * Sometime the hasNext() in the childeren iterator is true yet the next() is null

+     */

+    public void testNullInChilderen() {

+        isNullChildrenThere(envelope);

+    }

+

+    /**

+     * the envelope is completly namesapce qulified so all the OMElements got to have namespace values not null

+     */

+    public void test4MissingNamespaces() {

+        isNameSpacesMissing(envelope);

+    }

+

+    public void isNullChildrenThere(OMElement omeleent) {

+        Iterator it = omeleent.getChildren();

+        while (it.hasNext()) {

+            OMNode node = (OMNode) it.next();

+            assertNotNull(node);

+            if (node.getType() == OMNode.ELEMENT_NODE) {

+                isNullChildrenThere((OMElement) node);

+            }

+        }

+    }

+

+    public void isNameSpacesMissing(OMElement omeleent) {

+        OMNamespace omns = omeleent.getNamespace();

+        assertNotNull(omns);

+        assertNotNull(omns.getName());

+        Iterator it = omeleent.getChildren();

+        while (it.hasNext()) {

+            OMNode node = (OMNode) it.next();

+            if (node != null && node.getType() == OMNode.ELEMENT_NODE) {

+                isNameSpacesMissing((OMElement) node);

+            }

+        }

+    }

+

+    public void testRootNotCompleteInPartialBuild() throws Exception {

+        assertFalse("Root should not be complete", envelope.isComplete());

+    }

+

+    /**

+     * Assumption - The fed XML has at least two children under the root element

+     *

+     * @throws Exception

+     */

+    public void testFirstChildDetach() throws Exception {

+        OMElement root = envelope;

+        assertFalse("Root should not be complete", root.isComplete());

+        OMNode oldFirstChild = root.getFirstOMChild();

+        assertNotNull(oldFirstChild);

+        oldFirstChild.detach();

+        OMNode newFirstChild = root.getFirstOMChild();

+        assertNotNull(newFirstChild);

+        assertNotSame(oldFirstChild, newFirstChild);

+    }

+

+    //todo this is wrong correct this

+    public void testAdditionOfaCompletelyNewElement() throws Exception {

+

+        //        OMElement root= envelope;

+        //

+        //        OMNamespace soapenv= root.findNamespace("http://schemas.xmlsoap.org/soap/envelope/", "soapenv");

+        //        OMNamespace wsa= root.findNamespace("http://schemas.xmlsoap.org/ws/2004/03/addressing", "wsa");

+        //        if (wsa==null)

+        //            wsa= root.declareNamespace("http://schemas.xmlsoap.org/ws/2004/03/addressing", "wsa");

+        //

+        //        //Assumption - A RelatesTo Element does not exist in the input document

+        //        OMElement relatesTo= fac.createOMElement ("RelatesTo", wsa);

+        //        relatesTo.addAttribute(fac.createOMAttribute("RelationshipType", null, "wsa:Reply", relatesTo));

+        //        relatesTo.addAttribute(fac.createOMAttribute("mustUnderstand", soapenv, "0", relatesTo));

+        //        relatesTo.addChild(fac.createText(relatesTo, "uuid:3821F4F0-D020-11D8-A10A-E4EE6425FCB0"));

+        //        relatesTo.setComplete(true);

+        //

+        //        root.addChild(relatesTo);

+        //

+        //        QName name = new QName(wsa.getName(),"RelatesTo",wsa.getPrefix());

+        //

+        //        Iterator children = root.getChildrenWithName(name);

+        //        //this should contain only one child!

+        //        if (children.hasNext()){

+        //            OMElement newlyAddedElement = (OMElement)children.next();

+        //

+        //            assertNotNull(newlyAddedElement);

+        //

+        //            assertEquals(newlyAddedElement.getLocalName(),"RelatesTo");

+        //            //todo put the other assert statements here

+        //        }else{

+        //            assertFalse("New child not added",true);

+        //        }

+

+    }

+}

diff --git a/test/org/apache/ws/commons/om/OMTestCase.java b/test/org/apache/ws/commons/om/OMTestCase.java
new file mode 100644
index 0000000..4348755
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMTestCase.java
@@ -0,0 +1,73 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.FileReader;

+import java.io.InputStream;

+import java.io.OutputStream;

+

+public abstract class OMTestCase extends AbstractTestCase {

+    protected StAXSOAPModelBuilder builder;

+    protected OMFactory ombuilderFactory;

+    protected SOAPFactory soapFactory;

+

+    protected SOAPEnvelope soapEnvelope;

+

+    public OMTestCase(String testName) {

+        super(testName);

+        ombuilderFactory = OMAbstractFactory.getOMFactory();

+        soapFactory = OMAbstractFactory.getSOAP11Factory();

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soapEnvelope = (SOAPEnvelope) getOMBuilder("").getDocumentElement();

+    }

+

+    protected StAXSOAPModelBuilder getOMBuilder(String fileName) throws Exception {

+        if ("".equals(fileName) || fileName == null) {

+            fileName = TestConstants.SOAP_SOAPMESSAGE;

+        }

+        XMLStreamReader parser = XMLInputFactory.newInstance()

+                .createXMLStreamReader(

+                        new FileReader(getTestResourceFile(fileName)));

+        builder = new StAXSOAPModelBuilder(parser, null);

+        return builder;

+    }

+

+    protected StAXSOAPModelBuilder getOMBuilder(InputStream in) throws Exception {

+        XMLStreamReader parser = XMLInputFactory.newInstance()

+                .createXMLStreamReader(in);

+        builder = new StAXSOAPModelBuilder(parser, null);

+        return builder;

+    }

+

+    protected XMLStreamWriter getStAXStreamWriter(OutputStream out) throws XMLStreamException {

+        return XMLOutputFactory.newInstance().createXMLStreamWriter(out);

+    }

+

+

+}

diff --git a/test/org/apache/ws/commons/om/OMTestUtils.java b/test/org/apache/ws/commons/om/OMTestUtils.java
new file mode 100644
index 0000000..a69e419
--- /dev/null
+++ b/test/org/apache/ws/commons/om/OMTestUtils.java
@@ -0,0 +1,121 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.w3c.dom.Attr;

+import org.w3c.dom.Element;

+import org.w3c.dom.NamedNodeMap;

+import org.w3c.dom.Node;

+import org.w3c.dom.NodeList;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.io.File;

+import java.io.FileReader;

+import java.util.Iterator;

+

+public class OMTestUtils {

+    public static OMXMLParserWrapper getOMBuilder(File file) throws Exception {

+        XMLStreamReader parser = XMLInputFactory.newInstance()

+                .createXMLStreamReader(new FileReader(file));

+        return OMXMLBuilderFactory.createStAXSOAPModelBuilder(

+                OMAbstractFactory.getSOAP11Factory(), parser);

+    }

+

+    public static void walkThrough(OMElement omEle) {

+        Iterator attibIt = omEle.getAllAttributes();

+        if (attibIt != null) {

+            while (attibIt.hasNext()) {

+                TestCase.assertNotNull("once the has next is not null, the " +

+                        "element should not be null",

+                        attibIt.next());

+            }

+        }

+        Iterator it = omEle.getChildren();

+        if (it != null) {

+            while (it.hasNext()) {

+                OMNode ele = (OMNode) it.next();

+                TestCase.assertNotNull("once the has next is not null, the " +

+                        "element should not be null", ele);

+                if (ele instanceof OMElement) {

+                    walkThrough((OMElement) ele);

+                }

+            }

+        }

+    }

+

+    public static void compare(Element ele, OMElement omele) throws Exception {

+        if (ele == null && omele == null) {

+            return;

+        } else if (ele != null && omele != null) {

+            TestCase.assertEquals("Element name not correct",

+                    ele.getLocalName(),

+                    omele.getLocalName());

+            if (omele.getNamespace() != null) {

+                TestCase.assertEquals("Namespace URI not correct",

+                        ele.getNamespaceURI(),

+                        omele.getNamespace().getName());

+

+            }

+

+            //go through the attributes

+            NamedNodeMap map = ele.getAttributes();

+            Iterator attIterator = omele.getAllAttributes();

+            OMAttribute omattribute;

+            while (attIterator != null && attIterator.hasNext() && map == null) {

+                omattribute = (OMAttribute) attIterator.next();

+                Node node = map.getNamedItemNS(

+                        omattribute.getNamespace().getName(),

+                        omattribute.getLocalName());

+                if (node.getNodeType() == Node.ATTRIBUTE_NODE) {

+                    Attr attr = (Attr) node;

+                    TestCase.assertEquals(attr.getValue(),

+                            omattribute.getAttributeValue());

+                } else {

+                    throw new OMException("return type is not a Attribute");

+                }

+

+            }

+            Iterator it = omele.getChildren();

+            NodeList list = ele.getChildNodes();

+            for (int i = 0; i < list.getLength(); i++) {

+                Node node = list.item(i);

+                if (node.getNodeType() == Node.ELEMENT_NODE) {

+                    TestCase.assertTrue(it.hasNext());

+                    OMNode tempOmNode = (OMNode) it.next();

+                    while (tempOmNode.getType() != OMNode.ELEMENT_NODE) {

+                        TestCase.assertTrue(it.hasNext());

+                        tempOmNode = (OMNode) it.next();

+                    }

+                    compare((Element) node, (OMElement) tempOmNode);

+                }

+            }

+

+

+        } else {

+            throw new Exception("One is null");

+        }

+    }

+

+    public static SOAPEnvelope createOM(File file) throws Exception {

+        return (SOAPEnvelope) getOMBuilder(file).getDocumentElement();

+    }

+

+}

diff --git a/test/org/apache/ws/commons/om/SpacesTest.java b/test/org/apache/ws/commons/om/SpacesTest.java
new file mode 100644
index 0000000..8df59ed
--- /dev/null
+++ b/test/org/apache/ws/commons/om/SpacesTest.java
@@ -0,0 +1,98 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.custommonkey.xmlunit.Diff;

+import org.custommonkey.xmlunit.XMLTestCase;

+import org.w3c.dom.Document;

+import org.xml.sax.InputSource;

+import org.xml.sax.SAXException;

+

+import javax.xml.parsers.DocumentBuilder;

+import javax.xml.parsers.DocumentBuilderFactory;

+import javax.xml.parsers.ParserConfigurationException;

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamException;

+import java.io.ByteArrayInputStream;

+import java.io.ByteArrayOutputStream;

+import java.io.FileInputStream;

+import java.io.IOException;

+import java.io.InputStream;

+import java.io.InputStreamReader;

+

+public class SpacesTest extends XMLTestCase {

+    private String filePath = "test-resources/xml/spaces.xml";

+

+

+    private OMElement rootElement;

+

+    protected void setUp() throws Exception {

+    }

+

+    public void testCData() throws Exception {

+        checkOMConformance(new FileInputStream(filePath));

+    }

+

+    private void checkOMConformance(InputStream iStream) throws Exception {

+        try {

+            XMLInputFactory factory = XMLInputFactory.newInstance();

+

+            StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.

+                    createStAXOMBuilder(OMAbstractFactory.getOMFactory(),

+                            factory.createXMLStreamReader(

+                                    iStream));

+            staxOMBuilder.setDoDebug(true);

+            rootElement = staxOMBuilder.getDocumentElement();

+

+            ByteArrayOutputStream baos = new ByteArrayOutputStream();

+            ((OMDocument) rootElement.getParent()).serialize(baos);

+

+            InputSource resultXML = new InputSource(new InputStreamReader(

+                    new ByteArrayInputStream(baos.toByteArray())));

+

+            Document dom1 = newDocument(new InputSource(new FileInputStream(filePath)));

+            Document dom2 = newDocument(resultXML);

+

+            Diff diff = compareXML(dom1, dom2);

+            assertXMLEqual(diff, true);

+        } catch (XMLStreamException e) {

+            fail(e.getMessage());

+            throw new Exception(e);

+        } catch (ParserConfigurationException e) {

+            fail(e.getMessage());

+            throw new Exception(e);

+        } catch (SAXException e) {

+            fail(e.getMessage());

+            throw new Exception(e);

+        } catch (IOException e) {

+            fail(e.getMessage());

+            throw new Exception(e);

+        }

+    }

+

+    public Document newDocument(InputSource in)

+            throws ParserConfigurationException, SAXException, IOException {

+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

+        dbf.setNamespaceAware(true);

+        DocumentBuilder db = dbf.newDocumentBuilder();

+        return db.parse(in);

+    }

+

+

+}

diff --git a/test/org/apache/ws/commons/om/StaxParserTest.java b/test/org/apache/ws/commons/om/StaxParserTest.java
new file mode 100644
index 0000000..d445ac9
--- /dev/null
+++ b/test/org/apache/ws/commons/om/StaxParserTest.java
@@ -0,0 +1,221 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om;

+

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.ByteArrayInputStream;

+import java.util.Iterator;

+

+public class StaxParserTest extends AbstractTestCase {

+

+    XMLStreamReader parser1;

+    XMLStreamReader parser2;

+    XMLStreamReader parser3;

+    XMLStreamReader parser4;

+    String xmlDocument = "<purchase-order xmlns=\"http://openuri.org/easypo\">" +

+            "<customer>" +

+            "    <name>Gladys Kravitz</name>" +

+            "    <address>Anytown, PA</address>" +

+            "  </customer>" +

+            "  <date>2005-03-06T14:06:12.697+06:00</date>" +

+            "</purchase-order>";

+

+    public StaxParserTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        //make the parsers

+        //Parser 1 is a plain parser from the stax implementation

+        parser1 =

+                XMLInputFactory.newInstance().createXMLStreamReader(

+                        new ByteArrayInputStream(xmlDocument.getBytes()));

+

+        //parser 2 is one of our parsers taken with cache. i.e. when the parser

+        //proceeds the object model will be built

+        OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(

+                OMAbstractFactory.getSOAP11Factory(),

+                XMLInputFactory.newInstance().createXMLStreamReader(

+                        new ByteArrayInputStream(xmlDocument.getBytes())));

+        parser2 = builder.getDocumentElement().getXMLStreamReader();

+

+        //same as parser2 but this time the parser is not a caching parser. Once the

+        //parser proceeds, it's gone forever.

+        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(

+                OMAbstractFactory.getSOAP11Factory(),

+                XMLInputFactory.newInstance().createXMLStreamReader(

+                        new ByteArrayInputStream(xmlDocument.getBytes())));

+        parser3 =

+                builder2.getDocumentElement().getXMLStreamReaderWithoutCaching();

+

+        //parser4 is another instance of our parser accessing the same stream as parser3.

+        // Note - The implementation returns a *new* instance but with reference to

+        //the same underlying stream!

+        parser4 = builder2.getDocumentElement().getXMLStreamReaderWithoutCaching();

+

+    }

+

+    public void testParserEventsWithCache() throws Exception {

+

+        //check the initial event

+        assertEquals(parser1.getEventType(), parser2.getEventType());

+

+        //check the other events

+        while (parser1.hasNext()) {

+

+            int parser1Event = parser1.next();

+            int parser2Event = parser2.next();

+            assertEquals(parser1Event, parser2Event);

+

+        }

+

+

+    }

+

+    public void testParserEventsWithoutCache() throws Exception {

+

+        assertEquals(parser1.getEventType(), parser3.getEventType());

+

+        while (parser1.hasNext()) {

+            int parser1Event = parser1.next();

+            int parser2Event = parser3.next();

+            assertEquals(parser1Event, parser2Event);

+        }

+

+

+    }

+

+    public void testParserEvents2WithCache() throws Exception {

+        while (parser1.hasNext()) {

+            int parser1Event = parser1.getEventType();

+            int parser2Event = parser2.getEventType();

+            parser1.next();

+            parser2.next();

+            assertEquals(parser1Event, parser2Event);

+        }

+

+

+    }

+

+

+    public void testParserBehaviornonCaching() throws Exception{

+

+        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(

+                OMAbstractFactory.getOMFactory(),

+                XMLInputFactory.newInstance().createXMLStreamReader(

+                        new ByteArrayInputStream(xmlDocument.getBytes())));

+

+        OMElement documentElement = builder2.getDocumentElement();

+        XMLStreamReader originalParser =

+                documentElement.getXMLStreamReaderWithoutCaching();

+

+        //consume the parser. this should force the xml stream to be exhausted without

+        //building the tree

+        while(originalParser.hasNext()){

+            originalParser.next();

+        }

+

+        //try to find the children of the document element. This should produce an

+        //error since the underlying stream is fully consumed without building the object tree

+        Iterator childElements = documentElement.getChildElements();

+        try {

+            while (childElements.hasNext()) {

+                childElements.next();

+                fail("The stream should've been consumed by now!");

+            }

+        } catch (Exception e) {

+            //if we are here without failing, then we are successful

+        }

+    }

+

+

+    public void testParserBehaviorCaching() throws Exception{

+

+        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(

+                OMAbstractFactory.getSOAP11Factory(),

+                XMLInputFactory.newInstance().createXMLStreamReader(

+                        new ByteArrayInputStream(xmlDocument.getBytes())));

+

+        OMElement documentElement = builder2.getDocumentElement();

+        XMLStreamReader originalParser =

+                documentElement.getXMLStreamReader();

+

+        //consume the parser. this should force the xml stream to be exhausted but the

+        //tree to be fully built

+        while(originalParser.hasNext()){

+            originalParser.next();

+        }

+

+        //try to find the children of the document element. This should *NOT* produce an

+        //error even when the underlying stream is fully consumed , the object tree is already complete

+        Iterator childElements = documentElement.getChildElements();

+        int count = 0;

+        try {

+            while (childElements.hasNext()) {

+                childElements.next();

+                count++;

+            }

+        } catch (Exception e) {

+            fail("The object tree needs to be built and traversing the children is to be a success!");

+        }

+

+        assertEquals("Number of elements need to be 2",count,2);

+    }

+

+

+    public void testParserBehaviorNonCaching2() throws Exception{

+

+        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(

+                OMAbstractFactory.getSOAP11Factory(),

+                XMLInputFactory.newInstance().createXMLStreamReader(

+                        new ByteArrayInputStream(xmlDocument.getBytes())));

+

+        OMElement documentElement = builder2.getDocumentElement();

+

+        XMLStreamReader originalParser =

+                documentElement.getXMLStreamReaderWithoutCaching();

+

+        //consume the parser. this should force the xml stream to be exhausted without

+        //building the tree

+        while(originalParser.hasNext()){

+            originalParser.next();

+        }

+

+        //try to find the children of the document element. This should produce an

+        //error since the underlying stream is fully consumed without building the object tree

+        Iterator childElements = documentElement.getChildElements();

+        try {

+            XMLStreamWriter writer =

+                    XMLOutputFactory.newInstance().

+                            createXMLStreamWriter(System.out);

+            documentElement.serializeAndConsume(writer);

+            fail("Stream should be consumed by now");

+        }catch(XMLStreamException e){

+           //wea re cool

+        } catch (Exception e) {

+           fail("This should throw an XMLStreamException");

+        }

+    }

+

+}

+

diff --git a/test/org/apache/ws/commons/om/TestConstants.java b/test/org/apache/ws/commons/om/TestConstants.java
new file mode 100644
index 0000000..3943193
--- /dev/null
+++ b/test/org/apache/ws/commons/om/TestConstants.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.ws.commons.om;
+
+/**
+ * All the various files
+ * created 03-Nov-2005 12:02:12
+ */
+
+public class TestConstants {
+    public static final String TEST_RESOURCES = "test-resources";
+    public static final String SOAP_DIR = "soap";
+    public static final String SOAPMESSAGE = "soapmessage.xml";
+    public static final String SOAP_SOAPMESSAGE = "soap/soapmessage.xml";
+    public static final String SOAP_SOAPMESSAGE1 = "soap/soapmessage1.xml";
+    public static final String SAMPLE1 = "soap/sample1.xml";
+    public static final String WHITESPACE_MESSAGE = "soap/whitespacedMessage.xml";
+    public static final String MINIMAL_MESSAGE = "soap/minimalMessage.xml";
+    public static final String REALLY_BIG_MESSAGE = "soap/reallyReallyBigMessage.xml";
+    public static final String EMPTY_BODY_MESSAGE = "soap/emtyBodymessage.xml";
+    public static final String BAD_WRONG_SOAP_NS = "badsoap/wrongSoapNs.xml";
+    public static final String BAD_TWO_HEADERS = "badsoap/twoheaders.xml";
+    public static final String BAD_TWO_BODY = "badsoap/twoBodymessage.xml";
+    public static final String BAD_ENVELOPE_MISSING = "badsoap/envelopeMissing.xml";
+    public static final String BAD_HEADER_BODY_WRONG_ORDER = "badsoap/haederBodyWrongOrder.xml";
+
+    private TestConstants() {
+    }
+
+
+}
diff --git a/test/org/apache/ws/commons/om/factory/OMLinkedListImplFactoryTest.java b/test/org/apache/ws/commons/om/factory/OMLinkedListImplFactoryTest.java
new file mode 100644
index 0000000..3bead0c
--- /dev/null
+++ b/test/org/apache/ws/commons/om/factory/OMLinkedListImplFactoryTest.java
@@ -0,0 +1,235 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.factory;

+

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMTestUtils;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+/**

+ * User: Eran Chinthaka (eran.chinthaka@gmail.com)

+ * Date: Feb 8, 2005

+ * Time: 11:06:09 AM

+ * All Rights Reserved.

+ */

+public class OMLinkedListImplFactoryTest extends AbstractTestCase {

+

+    private Log log = LogFactory.getLog(getClass());

+

+    public OMLinkedListImplFactoryTest(String testName) {

+        super(testName);

+    }

+

+    SOAPFactory omFactory;

+    OMNamespace namespace;

+    String nsUri = "http://www.apache.org/~chinthaka";

+    String nsPrefix = "myhome";

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        omFactory = OMAbstractFactory.getSOAP11Factory();

+        namespace = omFactory.createOMNamespace(nsUri, nsPrefix);

+    }

+

+    public void testCreateOMElementWithNoBuilder() {

+        OMElement omElement = omFactory.createOMElement("chinthaka",

+                namespace);

+        assertTrue(

+                "Programatically created OMElement should have done = true ",

+                omElement.isComplete());

+

+    }

+

+    public void testCreateOMElement() {

+        try {

+            OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(

+                    getTestResourceFile("soap/whitespacedMessage.xml"));

+            OMElement documentElement = omBuilder.getDocumentElement();

+            OMElement child = omFactory.createOMElement("child",

+                    namespace,

+                    documentElement,

+                    omBuilder);

+            assertTrue(

+                    "OMElement with a builder should start with done = false ",

+                    !child.isComplete());

+            assertTrue("This OMElement must have a builder ",

+                    child.getBuilder() instanceof OMXMLParserWrapper);

+

+        } catch (Exception e) {

+            log.info(e.getMessage());

+        }

+    }

+

+    public void testCreateOMNamespace() {

+        assertTrue("OMNamespace uri not correct",

+                nsUri.equals(namespace.getName()));   // here equalsIgnoreCase should not be used as case does matter

+        assertTrue("OMNamespace prefix not correct",

+                nsPrefix.equals(namespace.getPrefix()));  // here equalsIgnoreCase should not be used as case does matter

+    }

+

+    public void testCreateText() {

+        OMElement omElement = omFactory.createOMElement("chinthaka",

+                namespace);

+        String text = "sampleText";

+        OMText omText = omFactory.createText(omElement, text);

+        assertTrue("Programatically created OMText should have done = true ",

+                omText.isComplete());

+        assertTrue(

+                "Programatically created OMText should have correct text value ",

+                text.equals(omText.getText()));

+

+    }

+

+    public void testCreateSOAPBody() {

+        try {

+            OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(

+                    getTestResourceFile("soap/minimalMessage.xml"));

+            SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();

+            SOAPBody soapBodyOne = omFactory.createSOAPBody(soapEnvelope);

+            assertTrue(

+                    "Programatically created SOAPBody should have done = true ",

+                    soapBodyOne.isComplete());

+            soapBodyOne.detach();

+            SOAPBody soapBodyTwo = omFactory.createSOAPBody(soapEnvelope,

+                    omBuilder);

+            assertTrue(

+                    "SOAPBody with a builder should start with done = false ",

+                    !soapBodyTwo.isComplete());

+            assertTrue("This SOAPBody must have a builder ",

+                    soapBodyTwo.getBuilder() instanceof OMXMLParserWrapper);

+

+

+        } catch (Exception e) {

+            log.info(e.getMessage());

+        }

+    }

+

+    public void testCreateSOAPEnvelope() {

+        try {

+            omFactory.createOMNamespace(

+                    SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,

+                    SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX);

+            SOAPEnvelope soapEnvelopeTwo = omFactory.createSOAPEnvelope();

+            assertTrue(

+                    "Programatically created SOAPEnvelope should have done = true ",

+                    soapEnvelopeTwo.isComplete());

+            SOAPEnvelope soapEnvelope = omFactory.createSOAPEnvelope(

+                    OMTestUtils.getOMBuilder(

+                            getTestResourceFile("soap/minimalMessage.xml")));

+            assertTrue(

+                    "SOAPEnvelope with a builder should start with done = false ",

+                    !soapEnvelope.isComplete());

+            assertTrue("This SOAPEnvelope must have a builder ",

+                    soapEnvelope.getBuilder() instanceof OMXMLParserWrapper);

+

+

+        } catch (Exception e) {

+            log.info(e.getMessage());

+        }

+    }

+

+    public void testCreateSOAPHeader() {

+        try {

+            OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(

+                    getTestResourceFile("soap/minimalMessage.xml"));

+            SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();

+            SOAPHeader soapHeader = omFactory.createSOAPHeader(soapEnvelope);

+            assertTrue(

+                    "Programatically created SOAPHeader should have done = true ",

+                    soapHeader.isComplete());

+            soapHeader.detach();

+            SOAPHeader soapHeaderTwo = omFactory.createSOAPHeader(soapEnvelope,

+                    omBuilder);

+            assertTrue(

+                    "SOAPHeader with a builder should start with done = false ",

+                    !soapHeaderTwo.isComplete());

+            assertTrue("This SOAPHeader must have a builder ",

+                    soapHeaderTwo.getBuilder() instanceof OMXMLParserWrapper);

+

+

+        } catch (Exception e) {

+            log.info(e.getMessage());

+        }

+    }

+

+    public void testCreateSOAPHeaderBlock() {

+        try {

+            OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(

+                    getTestResourceFile("soap/soapmessage.xml"));

+            SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();

+            SOAPHeader soapHeader = soapEnvelope.getHeader();

+            SOAPHeaderBlock soapHeaderBlock = omFactory.createSOAPHeaderBlock(

+                    "soapHeaderBlockOne", namespace, soapHeader);

+            assertTrue(

+                    "Programatically created SOAPHeaderBlock should have done = true ",

+                    soapHeaderBlock.isComplete());

+            SOAPHeaderBlock soapHeaderBlockTwo = omFactory.createSOAPHeaderBlock(

+                    "soapHeaderBlockOne", namespace, soapHeader, omBuilder);

+            assertTrue(

+                    "SOAPHeaderBlock with a builder should start with done = false ",

+                    !soapHeaderBlockTwo.isComplete());

+            assertTrue("This SOAPHeaderBlock must have a builder ",

+                    soapHeaderBlockTwo.getBuilder() instanceof OMXMLParserWrapper);

+

+

+        } catch (Exception e) {

+            log.info(e.getMessage());

+        }

+    }

+

+    public void testCreateSOAPFault() {

+        try {

+            OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(

+                    getTestResourceFile("soap/soapmessage.xml"));

+            SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();

+            SOAPBody soapBody = soapEnvelope.getBody();

+            SOAPFault soapFault = omFactory.createSOAPFault(soapBody,

+                    new Exception(" this is just a test "));

+            assertTrue(

+                    "Programatically created SOAPFault should have done = true ",

+                    soapFault.isComplete());

+            soapFault.detach();

+            SOAPFault soapFaultTwo = omFactory.createSOAPFault(soapBody,

+                    omBuilder);

+            assertTrue(

+                    "SOAPFault with a builder should start with done = false ",

+                    !soapFaultTwo.isComplete());

+            assertTrue("This SOAPFault must have a builder ",

+                    soapFaultTwo.getBuilder() instanceof OMXMLParserWrapper);

+

+

+        } catch (Exception e) {

+            log.info(e.getMessage());

+        }

+    }

+

+

+}

diff --git a/test/org/apache/ws/commons/om/impl/OMBlankElementTest.java b/test/org/apache/ws/commons/om/impl/OMBlankElementTest.java
new file mode 100644
index 0000000..c14e4a8
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/OMBlankElementTest.java
@@ -0,0 +1,64 @@
+package org.apache.ws.commons.om.impl;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMException;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+

+import javax.xml.stream.XMLStreamException;

+import java.io.StringWriter;

+

+public class OMBlankElementTest extends TestCase {

+

+    public OMBlankElementTest(String name) {

+        super(name);

+    }

+

+    public void testBlankOMElem() throws XMLStreamException {

+        try {

+            //We should not get anything as the return value here: the output of the serialization

+            String value = buildBlankOMElem();

+            assertNull(

+                "There's a serialized output for a blank XML element that cannot exist",

+                value);

+        } catch (OMException e) {

+        }

+    }

+

+    String buildBlankOMElem() throws XMLStreamException {

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+        OMNamespace namespace1 = factory.createOMNamespace("", "");

+        OMElement elem1 = factory.createOMElement("", namespace1);

+

+        StringWriter writer = new StringWriter();

+        elem1.build();

+        elem1.serialize(writer);

+        writer.flush();

+        return writer.toString();

+    }

+

+    public void testOMElemWithWhiteSpace() throws XMLStreamException {

+        try {

+            //We should not get anything as the return value here: the output of the serialization

+            String value = buildWithWhiteSpaceOMElem();

+            assertNull(

+                "There's a serialized output for a blank XML element that cannot exist",

+                value);

+        } catch (OMException e) {

+        }

+    }

+

+    String buildWithWhiteSpaceOMElem() throws XMLStreamException {

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+        OMNamespace namespace1 = factory.createOMNamespace("  ", "");

+        OMElement elem1 = factory.createOMElement("  ", namespace1);

+

+        StringWriter writer = new StringWriter();

+        elem1.build();

+        elem1.serialize(writer);

+        writer.flush();

+        return writer.toString();

+    }

+}

diff --git a/test/org/apache/ws/commons/om/impl/builder/StAXOMBuilderTest.java b/test/org/apache/ws/commons/om/impl/builder/StAXOMBuilderTest.java
new file mode 100644
index 0000000..cfa76ab
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/builder/StAXOMBuilderTest.java
@@ -0,0 +1,71 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.builder;

+

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+

+import javax.xml.stream.XMLInputFactory;

+import java.io.FileReader;

+import java.util.Iterator;

+

+public class StAXOMBuilderTest extends AbstractTestCase {

+    StAXOMBuilder stAXOMBuilder;

+    FileReader testFile;

+    private OMElement rootElement;

+

+    /**

+     * Constructor.

+     */

+    public StAXOMBuilderTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        testFile = new FileReader(getTestResourceFile("non_soap.xml"));

+        stAXOMBuilder =

+                OMXMLBuilderFactory.createStAXOMBuilder(

+                        OMAbstractFactory.getSOAP11Factory(),

+                        XMLInputFactory.newInstance().createXMLStreamReader(

+                                testFile));

+    }

+

+    public void testGetRootElement() throws Exception {

+        rootElement = stAXOMBuilder.getDocumentElement();

+        assertTrue("Root element can not be null", rootElement != null);

+        assertTrue(" Name of the root element is wrong",

+                rootElement.getLocalName().equalsIgnoreCase("Root"));

+        // get the first OMElement child

+        OMNode omnode = rootElement.getFirstOMChild();

+        while (omnode instanceof OMText) {

+            omnode = omnode.getNextOMSibling();

+        }

+        Iterator children = ((OMElement) omnode).getChildren();

+        int childrenCount = 0;

+        while (children.hasNext()) {

+            OMNode node = (OMNode) children.next();

+            if (node instanceof OMElement)

+                childrenCount++;

+        }

+        assertTrue(childrenCount == 5);

+    }

+}
\ No newline at end of file
diff --git a/test/org/apache/ws/commons/om/impl/llom/OMDocumentSerilizationTest.java b/test/org/apache/ws/commons/om/impl/llom/OMDocumentSerilizationTest.java
new file mode 100644
index 0000000..94d858f
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/llom/OMDocumentSerilizationTest.java
@@ -0,0 +1,131 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMDocument;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMOutputFormat;

+

+import javax.xml.stream.XMLStreamException;

+import java.io.ByteArrayOutputStream;

+import java.io.UnsupportedEncodingException;

+

+/**

+ * This tests the serializeAndConsume method

+ */

+public class OMDocumentSerilizationTest extends TestCase {

+

+    private OMDocument document;

+    private String xmlDeclStart = "<?xml";

+    private String encoding = "encoding='UTF-8'";

+    private String encoding_UTF16 = "encoding='UTF-16'";

+    private String encoding2 = "encoding=\"UTF-8\"";

+    private String encoding2_UTF16 = "encoding=\"UTF-16\"";

+    private String version = "version='1.0'";

+    private String version_11 = "version='1.1'";

+    private String version2 = "version=\"1.0\"";

+    private String version2_11 = "version=\"1.1\"";

+

+    public void setUp() {

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+

+        OMNamespace namespace = factory.createOMNamespace("http://testuri.org","test");

+        OMElement documentElement = factory.createOMElement("DocumentElement",namespace);

+

+        OMElement child1 = factory.createOMElement("Child1",namespace);

+        child1.setText("TestText");

+        documentElement.addChild(child1);

+

+        document = factory.createOMDocument();

+        document.setOMDocumentElement(documentElement);

+

+    }

+

+    public OMDocumentSerilizationTest(String name) {

+        super(name);

+    }

+

+

+    public void testXMLDecleration() throws XMLStreamException {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        document.serializeAndConsume(baos);

+

+        String xmlDocument = new String(baos.toByteArray());

+

+        assertTrue("XML Declaration missing",-1<xmlDocument.indexOf(xmlDeclStart));

+    }

+

+    public void testExcludeXMLDeclaration() throws XMLStreamException {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        OMOutputFormat format = new OMOutputFormat();

+        format.setIgnoreXMLDeclaration(true);

+        document.serializeAndConsume(baos, format);

+

+        String xmlDocument = new String(baos.toByteArray());

+

+        assertTrue(

+                "XML Declaration is included when serilizing without the declaration",

+                -1 == xmlDocument.indexOf(xmlDeclStart));

+    }

+

+    public void testCharsetEncoding() throws XMLStreamException {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        document.serializeAndConsume(baos);

+

+        String xmlDocument = new String(baos.toByteArray());

+

+        assertTrue("Charset declaration missing",-1 < xmlDocument.indexOf(encoding) ||

+                                                 -1 < xmlDocument.indexOf(encoding.toLowerCase()) ||

+                                                 -1 < xmlDocument.indexOf(encoding2.toLowerCase()) ||

+                                                 -1 < xmlDocument.indexOf(encoding2));

+    }

+

+    public void testCharsetEncodingUTF_16() throws XMLStreamException, UnsupportedEncodingException {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        OMOutputFormat format = new OMOutputFormat();

+        format.setCharSetEncoding("UTF-16");

+        document.serializeAndConsume(baos, format);

+

+        String xmlDocument = new String(baos.toByteArray(),"UTF-16");

+        assertTrue("Charset declaration missing",-1<xmlDocument.indexOf(encoding_UTF16) ||

+                                                 -1<xmlDocument.indexOf(encoding2_UTF16));

+    }

+

+

+    public void testXMLVersion() throws XMLStreamException {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        document.serializeAndConsume(baos);

+

+        String xmlDocument = new String(baos.toByteArray());

+        assertTrue("Charset declaration missing",-1<xmlDocument.indexOf(version) ||

+                                                 -1<xmlDocument.indexOf(version2));

+    }

+

+    public void testXMLVersion_11() throws XMLStreamException {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        document.setXMLVersion("1.1");

+        document.serializeAndConsume(baos);

+

+        String xmlDocument = new String(baos.toByteArray());

+        assertTrue("Charset declaration missing",-1<xmlDocument.indexOf(version_11) ||

+                                                 -1<xmlDocument.indexOf(version2_11));

+    }

+}

diff --git a/test/org/apache/ws/commons/om/impl/llom/OMOutputTest.java b/test/org/apache/ws/commons/om/impl/llom/OMOutputTest.java
new file mode 100644
index 0000000..df0894c
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/llom/OMOutputTest.java
@@ -0,0 +1,109 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom;

+

+import org.apache.ws.commons.attachments.ByteArrayDataSource;

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMOutputFormat;

+

+import javax.activation.DataHandler;

+import java.io.File;

+import java.io.FileOutputStream;

+

+public class OMOutputTest extends AbstractTestCase {

+

+    /**

+     * @param testName

+     */

+    public OMOutputTest(String testName) {

+        super(testName);

+    }

+

+    String outFileName;

+

+    String outBase64FileName;

+

+    OMElement envelope;

+

+    File outMTOMFile;

+

+    File outBase64File;

+

+    /*

+     * @see TestCase#setUp()

+     */

+    protected void setUp() throws Exception {

+        super.setUp();

+        DataHandler dataHandler;

+

+        outFileName = "OMSerializeMTOMOut.txt";

+        outBase64FileName = "OMSerializeBase64Out.xml";

+        outMTOMFile = getTempOutputFile(outFileName);

+        outBase64File = getTempOutputFile(outBase64FileName);

+

+        OMNamespaceImpl soap = new OMNamespaceImpl(

+                "http://schemas.xmlsoap.org/soap/envelope/", "soap");

+        envelope = new OMElementImpl("Envelope", soap);

+        OMElement body = new OMElementImpl("Body", soap);

+

+        OMNamespaceImpl dataName = new OMNamespaceImpl(

+                "http://www.example.org/stuff", "m");

+        OMElement data = new OMElementImpl("data", dataName);

+

+        OMNamespaceImpl mime = new OMNamespaceImpl(

+                "http://www.w3.org/2003/06/xmlmime", "m");

+

+        OMElement text = new OMElementImpl("name", dataName);

+        OMAttribute cType1 = new OMAttributeImpl("contentType", mime,

+                "text/plain");

+        text.addAttribute(cType1);

+        byte[] byteArray = new byte[]{13, 56, 65, 32, 12, 12, 7, -3, -2, -1,

+                                      98};

+        dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));

+        OMTextImpl textData = new OMTextImpl(dataHandler, false);

+

+        envelope.addChild(body);

+        body.addChild(data);

+        data.addChild(text);

+        text.addChild(textData);

+    }

+

+    /*

+     * @see TestCase#tearDown()

+     */

+    protected void tearDown() throws Exception {

+        super.tearDown();

+        if (this.outMTOMFile.exists()) {

+            this.outMTOMFile.delete();

+        }

+        if (this.outBase64File.exists()) {

+            this.outBase64File.delete();

+        }

+    }

+

+    public void testComplete() throws Exception {

+        OMOutputFormat mtomOutputFormat = new OMOutputFormat();

+        mtomOutputFormat.setDoOptimize(true);

+        OMOutputFormat baseOutputFormat = new OMOutputFormat();

+        baseOutputFormat.setDoOptimize(false);

+        

+        envelope.serializeAndConsume(new FileOutputStream(outBase64File), baseOutputFormat);

+        envelope.serializeAndConsume(new FileOutputStream(outMTOMFile), mtomOutputFormat);

+    }

+}
\ No newline at end of file
diff --git a/test/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilderTest.java b/test/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilderTest.java
new file mode 100644
index 0000000..3fe795f
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilderTest.java
@@ -0,0 +1,98 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.llom.mtom;

+

+import org.apache.ws.commons.attachments.MIMEHelper;

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP12Constants;

+

+import javax.activation.DataHandler;

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.io.BufferedReader;

+import java.io.FileInputStream;

+import java.io.InputStream;

+import java.io.InputStreamReader;

+import java.util.Iterator;

+

+public class MTOMStAXSOAPModelBuilderTest extends AbstractTestCase {

+    MIMEHelper mimeHelper;

+

+    String inFileName;

+

+    OMXMLParserWrapper builder;

+

+    /**

+     * @param testName

+     */

+    public MTOMStAXSOAPModelBuilderTest(String testName) {

+        super(testName);

+    }

+

+    String contentTypeString = "multipart/Related; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"";

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        inFileName = "mtom/MTOMBuilderTestIn.txt";

+        InputStream inStream = new FileInputStream(getTestResourceFile(inFileName));

+        mimeHelper = new MIMEHelper(inStream, contentTypeString);

+        XMLStreamReader reader = XMLInputFactory.newInstance()

+                .createXMLStreamReader(new BufferedReader(new InputStreamReader(mimeHelper

+                .getSOAPPartInputStream())));

+        builder = new MTOMStAXSOAPModelBuilder(reader, mimeHelper, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);

+    }

+

+    public void testCreateOMElement() throws Exception {

+        OMElement root = builder.getDocumentElement();

+//        System.out.println(root.getLocalName() + " : "

+//                + root.getNamespace().getName());

+        OMElement body = (OMElement) root.getFirstOMChild();

+//        System.out.println(body.getLocalName() + " : "

+//                + body.getNamespace().getName());

+

+        OMElement data = (OMElement) body.getFirstOMChild();

+//        System.out.println(data.getLocalName() + " : "

+//                + data.getNamespace().getName());

+        Iterator childIt = data.getChildren();

+        //while (childIt.hasNext()) {

+        OMElement child = (OMElement) childIt.next();

+        OMText blob = (OMText) child.getFirstOMChild();

+        /*

+         * Following is the procedure the user has to follow to read objects in

+         * OBBlob User has to know the object type & whether it is serializable.

+         * If it is not he has to use a Custom Defined DataSource to get the

+         * Object.

+         */

+        byte[] expectedObject = new byte[]{13, 56, 65, 32, 12, 12, 7, -3, -2,

+                                           -1, 98};

+        DataHandler actualDH;

+        actualDH = (DataHandler)blob.getDataHandler();

+        //ByteArrayInputStream object = (ByteArrayInputStream) actualDH

+        //.getContent();

+        //byte[] actualObject= null;

+        //  object.read(actualObject,0,10);

+

+        //  assertEquals("Object check", expectedObject[5],actualObject[5] );

+    }

+

+    public void testGetDataHandler() {

+    }

+

+}
\ No newline at end of file
diff --git a/test/org/apache/ws/commons/om/impl/serializer/ElementSerializerTest.java b/test/org/apache/ws/commons/om/impl/serializer/ElementSerializerTest.java
new file mode 100644
index 0000000..95fd306
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/serializer/ElementSerializerTest.java
@@ -0,0 +1,132 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.serializer;

+

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMNode;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.File;

+import java.io.FileOutputStream;

+import java.io.FileReader;

+

+public class ElementSerializerTest extends AbstractTestCase {

+    private XMLStreamReader reader;

+    private XMLStreamWriter writer;

+    private OMXMLParserWrapper builder;

+    private File tempFile;

+

+    public ElementSerializerTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        reader =

+                XMLInputFactory.newInstance().

+                createXMLStreamReader(

+                        new FileReader(

+                                getTestResourceFile("soap/soapmessage.xml")));

+        tempFile = File.createTempFile("temp", "xml");

+        writer = XMLOutputFactory.newInstance().

+                createXMLStreamWriter(new FileOutputStream(tempFile));

+        builder =

+                OMXMLBuilderFactory.createStAXSOAPModelBuilder(

+                        OMAbstractFactory.getSOAP11Factory(), reader);

+    }

+

+    public void testElementSerilization() throws Exception {

+        OMElement elt = builder.getDocumentElement();

+        elt.serialize(writer);

+

+    }

+

+    public void testElementSerilizationCacheOff() throws Exception {

+        OMElement elt = builder.getDocumentElement();

+        elt.serialize(writer);

+

+    }

+

+    public void testElementSerilizationChild() throws Exception {

+        OMElement elt = builder.getDocumentElement();

+        OMNode node = elt.getFirstOMChild().getNextOMSibling();

+        node.serialize(writer);

+

+    }

+

+    public void testElementSerilizationSOAPBodyCacheOff() throws Exception {

+        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();

+        OMNode node = env.getBody();

+        node.serialize(writer);

+    }

+

+    public void testElement() throws Exception {

+        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();

+        SOAPBody body = env.getBody();

+        body.serialize(writer);

+    }

+

+    public void testCompleteElement() throws Exception {

+        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();

+        env.serialize(writer);

+    }

+

+    public void testDualNamespaces1() throws Exception {

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+        OMNamespace ns1 = factory.createOMNamespace("bar", "x");

+        OMNamespace ns2 = factory.createOMNamespace("bar", "y");

+        OMElement root = factory.createOMElement("root", ns1);

+        OMElement elt11 = factory.createOMElement("foo1", ns1);

+        OMElement elt12 = factory.createOMElement("foo2", ns1);

+        OMElement elt21 = factory.createOMElement("yuck", ns2);

+        OMElement elt22 = factory.createOMElement("yuck", ns2);

+        elt11.addChild(elt21);

+        elt12.addChild(elt22);

+        root.addChild(elt11);

+        root.addChild(elt12);

+        root.serialize(writer);

+    }

+

+    public void testDualNamespaces2() throws Exception {

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+        OMNamespace ns1 = factory.createOMNamespace("bar", "x");

+        OMElement root = factory.createOMElement("root", ns1);

+        OMNamespace ns2 = root.declareNamespace("bar", "y");

+        OMElement elt1 = factory.createOMElement("foo", ns1);

+        OMElement elt2 = factory.createOMElement("yuck", ns2);

+        OMText txt1 = factory.createText(elt2, "blah");

+        elt2.addChild(txt1);

+        elt1.addChild(elt2);

+        root.addChild(elt1);

+        root.serialize(writer);

+    }

+

+    protected void tearDown() throws Exception {

+        tempFile.delete();

+    }

+}

diff --git a/test/org/apache/ws/commons/om/impl/serializer/NoNamespaceSerializerTest.java b/test/org/apache/ws/commons/om/impl/serializer/NoNamespaceSerializerTest.java
new file mode 100644
index 0000000..aa67091
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/serializer/NoNamespaceSerializerTest.java
@@ -0,0 +1,150 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.serializer;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFactory;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.ByteArrayInputStream;

+import java.io.InputStreamReader;

+

+public class NoNamespaceSerializerTest extends TestCase {

+

+    private String xmlTextOne = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +

+            "<soapenv:Body>\n" +

+            "   <ns1:getBalance xmlns:ns1=\"http://localhost:8081/axis/services/BankPort/\">\n" +

+            "      <accountNo href=\"#id0\"/>\n" +

+            "   </ns1:getBalance>\n" +

+            " </soapenv:Body></soapenv:Envelope>";

+

+    private String xmlText2 = "<purchase-order xmlns=\"http://openuri.org/easypo\">\n" +

+            "  <customer>\n" +

+            "    <name>Gladys Kravitz</name>\n" +

+            "    <address>Anytown, PA</address>\n" +

+            "  </customer>\n" +

+            "  <date>2005-03-06T14:06:12.697+06:00</date>\n" +

+            "</purchase-order>";

+

+    private String xmlTextTwo = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +

+            "<soapenv:Body>\n" +

+            "   <getBalance xmlns=\"http://localhost:8081/axis/services/BankPort/\">\n" +

+            "      <accountNo href=\"#id0\"/>\n" +

+            "   </getBalance>\n" +

+            " </soapenv:Body></soapenv:Envelope>";

+

+    private XMLStreamReader readerOne;

+    private XMLStreamReader readerTwo;

+    private XMLStreamWriter writer;

+

+    // private OMXMLParserWrapper builder;

+    // private File tempFile;

+

+    private OMXMLParserWrapper builderOne;

+    private OMXMLParserWrapper builderTwo;

+    // private File tempFile;

+

+

+

+    protected void setUp() throws Exception {

+        readerOne =

+                XMLInputFactory.newInstance().

+                createXMLStreamReader(

+                        new InputStreamReader(

+                                new ByteArrayInputStream(xmlTextOne.getBytes())));

+        readerTwo =

+                XMLInputFactory.newInstance().

+                createXMLStreamReader(

+                        new InputStreamReader(

+                                new ByteArrayInputStream(xmlTextTwo.getBytes())));

+        writer = XMLOutputFactory.newInstance().

+                createXMLStreamWriter(System.out);

+        builderOne =

+                OMXMLBuilderFactory.createStAXSOAPModelBuilder(

+                        OMAbstractFactory.getSOAP11Factory(), readerOne);

+        builderTwo =

+                OMXMLBuilderFactory.createStAXSOAPModelBuilder(

+                        OMAbstractFactory.getSOAP11Factory(), readerTwo);

+    }

+

+

+//    public void testSerilizationWithCacheOff() throws Exception {

+//        SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement();

+//        env.serializeAndConsume(writer, false);

+//        writer.flush();

+//

+//

+//    }

+//

+//    public void testSerilizationWithCacheOn() throws Exception {

+//        SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement();

+//        env.serializeAndConsume(writer, true);

+//        writer.flush();

+//    }

+

+

+    public void testSerilizationWithDefaultNamespaces() throws Exception {

+        SOAPEnvelope env = (SOAPEnvelope) builderTwo.getDocumentElement();

+        env.serialize(writer);

+        OMElement balanceElement = env.getBody().getFirstElement();

+        assertEquals("Deafualt namespace has not been set properly",

+                balanceElement.getNamespace().getName(),

+                "http://localhost:8081/axis/services/BankPort/");

+

+        OMElement accountNo = balanceElement.getFirstElement();

+        assertEquals(

+                "Deafualt namespace of children has not been set properly",

+                accountNo.getNamespace().getName(),

+                "http://localhost:8081/axis/services/BankPort/");

+

+    }

+

+    public void submitPurchaseOrderTest()

+            throws Exception {

+        SOAPFactory omFactory = OMAbstractFactory.getSOAP11Factory();

+        SOAPEnvelope env = omFactory.getDefaultEnvelope();

+        OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(

+                omFactory,

+                XMLInputFactory.newInstance().

+                createXMLStreamReader(

+                        new InputStreamReader(

+                                new ByteArrayInputStream(xmlText2.getBytes()))));

+        env.getBody().addChild(builder.getDocumentElement());

+

+        env.serialize(System.out);

+    }

+

+    public void testSerilizationWithCacheOn() throws Exception {

+        SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement();

+        env.serialize(writer);

+        writer.flush();

+    }

+

+    public void testSerilizationWithCacheOff() throws Exception {

+        SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement();

+        env.serialize(writer);

+        writer.flush();

+    }

+}

diff --git a/test/org/apache/ws/commons/om/impl/serializer/OMSerializerTest.java b/test/org/apache/ws/commons/om/impl/serializer/OMSerializerTest.java
new file mode 100644
index 0000000..b2d95ba
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/serializer/OMSerializerTest.java
@@ -0,0 +1,114 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.serializer;

+

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.apache.ws.commons.om.impl.llom.serialize.StreamingOMSerializer;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import javax.xml.stream.XMLStreamWriter;

+import java.io.File;

+import java.io.FileReader;

+

+public class OMSerializerTest extends AbstractTestCase {

+    private XMLStreamReader reader;

+    private XMLStreamWriter writer;

+    private File tempFile;

+

+    public OMSerializerTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        reader =

+                XMLInputFactory.newInstance().

+                        createXMLStreamReader(

+                                new FileReader(

+                                        getTestResourceFile("soap/soapmessage.xml")));

+        tempFile = File.createTempFile("temp", "xml");

+//        writer =

+//                XMLOutputFactory.newInstance().

+//                        createXMLStreamWriter(new FileOutputStream(tempFile));

+        writer =

+                XMLOutputFactory.newInstance().

+                        createXMLStreamWriter(System.out);

+    }

+

+    public void testRawSerializer() throws Exception {

+        StreamingOMSerializer serializer = new StreamingOMSerializer();

+        //serializer.setNamespacePrefixStack(new Stack());

+        serializer.serialize(reader, writer);

+        writer.flush();

+

+

+    }

+

+    public void testElementPullStream1() throws Exception {

+        OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(

+                OMAbstractFactory.getSOAP11Factory(),

+                reader);

+        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();

+        StreamingOMSerializer serializer = new StreamingOMSerializer();

+        serializer.serialize(env.getXMLStreamReaderWithoutCaching(), writer);

+        writer.flush();

+    }

+

+    public void testElementPullStream1WithCacheOff() throws Exception {

+        OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(

+                OMAbstractFactory.getSOAP11Factory(),

+                reader);

+

+        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();

+        env.serializeAndConsume(writer);

+        writer.flush();

+

+        //now we should not be able to serilaize anything ! this should throw

+        //an error

+        try {

+           env.serializeAndConsume(writer);

+           fail();

+        } catch (XMLStreamException e) {

+           assertTrue(true);

+        } catch (Exception e) {

+           assertTrue(true);

+        }

+    }

+

+    public void testElementPullStream2() throws Exception {

+        OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(

+                OMAbstractFactory.getSOAP11Factory(),

+                reader);

+        SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();

+        SOAPBody body = env.getBody();

+        StreamingOMSerializer serializer = new StreamingOMSerializer();

+        serializer.serialize(body.getXMLStreamReaderWithoutCaching(),

+                writer);

+        writer.flush();

+    }

+

+    protected void tearDown() throws Exception {

+        tempFile.delete();

+    }

+}

diff --git a/test/org/apache/ws/commons/om/impl/serializer/PreserveEnvelopeTest.java b/test/org/apache/ws/commons/om/impl/serializer/PreserveEnvelopeTest.java
new file mode 100644
index 0000000..3c34d41
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/serializer/PreserveEnvelopeTest.java
@@ -0,0 +1,97 @@
+package org.apache.ws.commons.om.impl.serializer;
+
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;
+import org.custommonkey.xmlunit.XMLTestCase;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayInputStream;
+
+	public class PreserveEnvelopeTest extends XMLTestCase{
+
+		
+		 private String originalXML = "<Assertion xmlns=\"urn:oasis:names:tc:SAML:1.0:assertion\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" AssertionID=\"ef98507718ea606c6ae1e89d2c0865ee\" IssueInstant=\"2006-01-03T15:09:35.164Z\" Issuer=\"C=US,O=National Center for Supercomputing Applications,CN=Hemapani Srinath Perera\" MajorVersion=\"1\" MinorVersion=\"1\"><Conditions NotBefore=\"2006-01-03T15:09:35.164Z\" NotOnOrAfter=\"2006-01-03T15:39:35.164Z\"><AudienceRestrictionCondition><Audience>http://www.extreme.indiana.edu/lead/TestCMD_Simple_Tue_Jan_03_10_09_27_EST_2006_142825</Audience></AudienceRestrictionCondition></Conditions><AuthorizationDecisionStatement Decision=\"Permit\" Resource=\"http://www.extreme.indiana.edu/lead/TestCMD_Simple_Tue_Jan_03_10_09_27_EST_2006_142825\"><Subject><NameIdentifier>/C=US/O=Indiana University/OU=Computer Science/CN=Hemapani Srinath Perera</NameIdentifier><SubjectConfirmation><ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</ConfirmationMethod></SubjectConfirmation></Subject><Action Namespace=\"http://www.extreme.indiana.edu/lead\">Run</Action></AuthorizationDecisionStatement><ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">\n" +
+	     "<ds:SignedInfo>\n" +
+	     "<ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></ds:CanonicalizationMethod>\n" +
+	     "<ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"></ds:SignatureMethod>\n" +
+	     "<ds:Reference URI=\"#ef98507718ea606c6ae1e89d2c0865ee\">\n" +
+	     "<ds:Transforms>\n" +
+	     "<ds:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"></ds:Transform>\n" +
+	     "<ds:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"><ec:InclusiveNamespaces xmlns:ec=\"http://www.w3.org/2001/10/xml-exc-c14n#\" PrefixList=\"code ds kind rw saml samlp typens #default\"></ec:InclusiveNamespaces></ds:Transform>\n" +
+	     "</ds:Transforms>\n" +
+	     "<ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></ds:DigestMethod>\n" +
+	     "<ds:DigestValue>0bqebD+zkADcbXleyxpFUySp7cY=</ds:DigestValue>\n" +
+	     "</ds:Reference>\n" +
+	     "</ds:SignedInfo>\n" +
+	     "<ds:SignatureValue>\n" +
+	     "HVZDR4InypCICJxbCSrZJsikcpSACZRTt5Ly2gfLBUpdVeq6koHAKo8WGrGHbZVzNFAmxj3i52jQ\n" +
+	     "aYeO0J6LIA==\n" +
+	     "</ds:SignatureValue>\n" +
+	     "<ds:KeyInfo>\n" +
+	     "<ds:X509Data>\n" +
+	     "<ds:X509Certificate>\n" +
+	     "MIIClDCCAXygAwIBAwICBEkwDQYJKoZIhvcNAQEEBQAwaTELMAkGA1UEBhMCVVMxODA2BgNVBAoT\n" +
+	     "L05hdGlvbmFsIENlbnRlciBmb3IgU3VwZXJjb21wdXRpbmcgQXBwbGljYXRpb25zMSAwHgYDVQQD\n" +
+	     "ExdIZW1hcGFuaSBTcmluYXRoIFBlcmVyYTAeFw0wNjAxMDMxNDM2MTFaFw0wNjAxMDQwMjQxMTFa\n" +
+	     "MHkxCzAJBgNVBAYTAlVTMTgwNgYDVQQKEy9OYXRpb25hbCBDZW50ZXIgZm9yIFN1cGVyY29tcHV0\n" +
+	     "aW5nIEFwcGxpY2F0aW9uczEgMB4GA1UEAxMXSGVtYXBhbmkgU3JpbmF0aCBQZXJlcmExDjAMBgNV\n" +
+	     "BAMTBXByb3h5MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALyBo53oJTrVjs/RCFLJaMKektAqeNCi\n" +
+	     "IAhEx+pE0BxL23WV8mhxUNDJevO7lkRuwuDWchbobq8S1WNRYrbOqRkCAwEAATANBgkqhkiG9w0B\n" +
+	     "AQQFAAOCAQEAEZRsxz1izBa8SNw7x1nCttjTDnRM102CTad/uq3vihKmOauBo8lFqklT2xoFv+Nx\n" +
+	     "WX1FXT5AAqedITtUn99zk3Sr5c/SgdO59NxSaWgqxTOd7koZUmz8Sta9IK7d1fDFhDie2W2EtUMk\n" +
+	     "QX0Rr7KHReF6a0knQ+kGlhDuA2YN27CpNg+gBTq0+p1yaVA79qf2BVDYBklPG2N5tWn2GekHoUMs\n" +
+	     "7nlU9WlUI0tRUKuGGdQ+2WLTW0w2UuqsJuHvDaquZRnTOjhdiRw5/Mg62LqkSwo99Dc3JiJusqoY\n" +
+	     "16Unq8wp5gVJbj36UoVvqnVOyBltseIaU5bLS5LIrv11hXA6fg==\n" +
+	     "</ds:X509Certificate>\n" +
+	     "<ds:X509Certificate>\n" +
+	     "MIIEVzCCAz+gAwIBAgICBEkwDQYJKoZIhvcNAQEEBQAwaTELMAkGA1UEBhMCVVMxODA2BgNVBAoT\n" +
+	     "L05hdGlvbmFsIENlbnRlciBmb3IgU3VwZXJjb21wdXRpbmcgQXBwbGljYXRpb25zMSAwHgYDVQQD\n" +
+	     "ExdDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNTEwMjUxOTMxMzRaFw0wNzEwMjUxOTMxMzRa\n" +
+	     "MGkxCzAJBgNVBAYTAlVTMTgwNgYDVQQKEy9OYXRpb25hbCBDZW50ZXIgZm9yIFN1cGVyY29tcHV0\n" +
+	     "aW5nIEFwcGxpY2F0aW9uczEgMB4GA1UEAxMXSGVtYXBhbmkgU3JpbmF0aCBQZXJlcmEwggEiMA0G\n" +
+	     "CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC/pkVn4ZUEM5BjfocwiiQVF4ivFpJJ8u1m8vq0WNlc\n" +
+	     "bw4rjMOet1YArC46fZ1Gg652A1dF92+8hHNeBa6chll5HRZkx5FLN7XEGY4EcHhXA6lHmjklpf8N\n" +
+	     "Iy6/91ElOT1pVoLRpOeJ1TFT/nQxMBMJbMyhycrUV49M8oL3O/CYAm1YVQjCtdieK/ibFXzgP2iX\n" +
+	     "R8oOrAX/Ogp+FilUkdrZlhhhzV/NdGdQrPQxxpWbXsLOgiyEU4W1BWSHHI1E1cs0KUoYvaboAYaq\n" +
+	     "E+0WZlhqDxQy3SKOZVPYk9fJu9+qAb0gaDIgtN4FrZFYvTrlNMcrmyaC2ozr43nxwVMlq9dnAgMB\n" +
+	     "AAGjggEHMIIBAzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE8DAdBgNVHQ4EFgQU90FgTLg4k1yN3yJu\n" +
+	     "d4TZIbxUGigwgZMGA1UdIwSBizCBiIAU8r6NqmFJES25W3IkKhjSwoXGmIGhbaRrMGkxCzAJBgNV\n" +
+	     "BAYTAlVTMTgwNgYDVQQKEy9OYXRpb25hbCBDZW50ZXIgZm9yIFN1cGVyY29tcHV0aW5nIEFwcGxp\n" +
+	     "Y2F0aW9uczEgMB4GA1UEAxMXQ2VydGlmaWNhdGlvbiBBdXRob3JpdHmCAQAwNAYDVR0fBC0wKzAp\n" +
+	     "oCegJYYjaHR0cDovL2NhLm5jc2EudWl1Yy5lZHUvNGE2Y2Q4YjEucjAwDQYJKoZIhvcNAQEEBQAD\n" +
+	     "ggEBAHnFMFeZTHjuq/juH3qw1jDrr4IuKnljuLHWSi8GuMt1mxOs/vR7rMg0OAs16gMJP3X2uSK5\n" +
+	     "0miXqsbZ4AQuBJqo5Pm8UaSzeJlBle02SUvt2Fxhze9odLgoUXHp/1hKm9blHbp5cZqlbsmckk8y\n" +
+	     "4xOPgNYh1G3oxdv2OcadmJBMlYwcBK+TkO8GbemqXqdFt6itGkkhLGQdspw9c1r38bXd9lhLbVR8\n" +
+	     "7yif8ffqIgouVe/wj3NIjSbxgjff88Hz6CCuOWiafvfpgmrU906yOZqe6jBDBTKF5xmqyCNKKFAJ\n" +
+	     "UbmPCX2vMKCpWrLU+MotR2HSbljslSUhfKCjHvFb/AA=\n" +
+	     "</ds:X509Certificate>\n" +
+	     "</ds:X509Data>\n" +
+	     "</ds:KeyInfo></ds:Signature></Assertion>";
+
+
+		 
+		 public void testOMNS() {
+		        try {
+		        	StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(originalXML.getBytes()));
+		            OMElement documentElement = builder.getDocumentElement();
+		            //assertXMLEqual(originalXML, documentElement.toString());
+		            
+		            String outstr  = documentElement.toString();
+		            System.out.println(outstr);
+		            assertTrue(outstr.indexOf("xmlns:saml=") > 0);
+		            assertTrue(outstr.indexOf("<Assertion") == 0);
+		            
+		        } catch (XMLStreamException e) {
+		            e.printStackTrace();
+
+		        }
+		    }
+		 
+
+
+	}
+
+
+
+
+
diff --git a/test/org/apache/ws/commons/om/impl/streamwrapper/OMStaxStreamingWrapperTest.java b/test/org/apache/ws/commons/om/impl/streamwrapper/OMStaxStreamingWrapperTest.java
new file mode 100644
index 0000000..aa61273
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/streamwrapper/OMStaxStreamingWrapperTest.java
@@ -0,0 +1,229 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.streamwrapper;

+

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.io.File;

+import java.io.FileReader;

+

+public class OMStaxStreamingWrapperTest extends AbstractTestCase {

+    private SOAPEnvelope envelope = null;

+    private File tempFile;

+    private XMLStreamReader parser;

+

+    public OMStaxStreamingWrapperTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().

+                createXMLStreamReader(

+                        new FileReader(

+                                getTestResourceFile("soap/soapmessage1.xml")));

+        OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(

+                OMAbstractFactory.getSOAP11Factory(), xmlStreamReader);

+        envelope = (SOAPEnvelope) builder.getDocumentElement();

+        tempFile = File.createTempFile("temp", "xml");

+

+    }

+

+

+    //    public void testWrapperFullOM() throws Exception {

+    //        assertNotNull(envelope);

+    //        //this serializing will cause the OM to fully build!

+    //        XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(tempFile));

+    //        envelope.serializeAndConsume(writer,true);

+    //        parser = envelope.getXMLStreamReader(false);

+    //        while (parser.hasNext()) {

+    //            int event = parser.next();

+    //            assertTrue(event > 0);

+    //        }

+    //

+    //    }

+

+    public void testWrapperHalfOM() throws Exception {

+        assertNotNull(envelope);

+        parser = envelope.getXMLStreamReaderWithoutCaching();

+        while (parser.hasNext()) {

+            int event = parser.next();

+            assertTrue(event > 0);

+        }

+    }

+

+    //    public void testWrapperHalfOMWithCacheOff() throws Exception {

+    //        assertNotNull(envelope);

+    //        parser = envelope.getXMLStreamReader(true);

+    //        while (parser.hasNext()) {

+    //            int event = parser.next();

+    //            assertTrue(event > 0);

+    //        }

+    //    }

+    //

+    //    public void testWrapperElementEventGenerationWithHalfOMWithCacheOff() throws XMLStreamException {

+    //        assertNotNull(envelope);

+    //        parser = envelope.getXMLStreamReader(true);

+    //        while (parser.hasNext()) {

+    //            int event = parser.next();

+    //            assertTrue(event > 0);

+    //            if (event == XMLStreamConstants.START_ELEMENT) {

+    //                checkStartElement(parser);

+    //            } else if (event == XMLStreamConstants.CHARACTERS) {

+    //                checkCharacters(parser);

+    //            }

+    //        }

+    //

+    //

+    //    }

+    //

+    //    public void testWrapperElementEventGenerationWithHalfOM() throws Exception {

+    //        assertNotNull(envelope);

+    //        parser = envelope.getXMLStreamReader(false);

+    //        while (parser.hasNext()) {

+    //            int event = parser.next();

+    //            assertTrue(event > 0);

+    //            if (event == XMLStreamConstants.START_ELEMENT) {

+    //                checkStartElement(parser);

+    //            } else if (event == XMLStreamConstants.CHARACTERS) {

+    //                checkCharacters(parser);

+    //            }

+    //        }

+    //

+    //

+    //    }

+    //

+    //    private void checkCharacters(XMLStreamReader wrapper) {

+    //        assertFalse(wrapper.isStartElement());

+    //        assertFalse(wrapper.isEndElement());

+    //        assertFalse(wrapper.isWhiteSpace());

+    //        assertFalse(wrapper.hasName());

+    //        assertTrue(wrapper.isCharacters());

+    //

+    //        assertNotNull(wrapper.getText());

+    //        assertTrue(wrapper.getTextLength() > 0);

+    //    }

+    //

+    //    private void checkStartElement(XMLStreamReader wrapper) {

+    //        assertTrue(wrapper.isStartElement());

+    //        assertTrue(wrapper.hasName());

+    //        assertFalse(wrapper.isEndElement());

+    //        assertFalse(wrapper.isCharacters());

+    //        assertFalse(wrapper.isWhiteSpace());

+    //

+    //        //at the start element event these need to be supplied

+    //        assertNotNull(wrapper.getLocalName());

+    //        assertNotNull(wrapper.getName());

+    //        assertNotNull(wrapper.getNamespaceURI());

+    //        //prefix may be null

+    //        wrapper.getPrefix();

+    //

+    //        //todo add the other checks here

+    //        int attribCount = wrapper.getAttributeCount();

+    //        for (int i = 0; i < attribCount; i++) {

+    //            assertNotNull(wrapper.getAttributeLocalName(i));

+    //            assertNotNull(wrapper.getAttributeValue(i));

+    //            assertNotNull(wrapper.getAttributeName(i));

+    //            wrapper.getAttributePrefix(i);

+    //            wrapper.getAttributeNamespace(i);

+    //            //todo add the other checks here

+    //        }

+    //

+    //

+    //    }

+    //

+    //    public void testWrapperElementEventGenerationWithHalfOMWithCacheOff() throws XMLStreamException {

+    //        assertNotNull(envelope);

+    //        parser = envelope.getXMLStreamReader(true);

+    //        while (parser.hasNext()) {

+    //            int event = parser.next();

+    //            assertTrue(event > 0);

+    //            if (event == XMLStreamConstants.START_ELEMENT) {

+    //                checkStartElement(parser);

+    //            } else if (event == XMLStreamConstants.CHARACTERS) {

+    //                checkCharacters(parser);

+    //            }

+    //        }

+    //

+    //

+    //    }

+    //

+    //    public void testWrapperElementEventGenerationWithHalfOM() throws Exception {

+    //        assertNotNull(envelope);

+    //        parser = envelope.getXMLStreamReader(false);

+    //        while (parser.hasNext()) {

+    //            int event = parser.next();

+    //            assertTrue(event > 0);

+    //            if (event == XMLStreamConstants.START_ELEMENT) {

+    //                checkStartElement(parser);

+    //            } else if (event == XMLStreamConstants.CHARACTERS) {

+    //                checkCharacters(parser);

+    //            }

+    //        }

+    //

+    //

+    //    }

+    //

+    //    private void checkCharacters(XMLStreamReader wrapper) {

+    //        assertFalse(wrapper.isStartElement());

+    //        assertFalse(wrapper.isEndElement());

+    //        assertFalse(wrapper.isWhiteSpace());

+    //        assertFalse(wrapper.hasName());

+    //        assertTrue(wrapper.isCharacters());

+    //

+    //        assertNotNull(wrapper.getText());

+    //        assertTrue(wrapper.getTextLength() > 0);

+    //    }

+    //

+    //    private void checkStartElement(XMLStreamReader wrapper) {

+    //        assertTrue(wrapper.isStartElement());

+    //        assertTrue(wrapper.hasName());

+    //        assertFalse(wrapper.isEndElement());

+    //        assertFalse(wrapper.isCharacters());

+    //        assertFalse(wrapper.isWhiteSpace());

+    //

+    //        //at the start element event these need to be supplied

+    //        assertNotNull(wrapper.getLocalName());

+    //        assertNotNull(wrapper.getName());

+    //        assertNotNull(wrapper.getNamespaceURI());

+    //        //prefix may be null

+    //        wrapper.getPrefix();

+    //

+    //        //todo add the other checks here

+    //        int attribCount = wrapper.getAttributeCount();

+    //        for (int i = 0; i < attribCount; i++) {

+    //            assertNotNull(wrapper.getAttributeLocalName(i));

+    //            assertNotNull(wrapper.getAttributeValue(i));

+    //            assertNotNull(wrapper.getAttributeName(i));

+    //            wrapper.getAttributePrefix(i);

+    //            wrapper.getAttributeNamespace(i);

+    //            //todo add the other checks here

+    //        }

+    //

+    //

+    //    }

+

+

+    protected void tearDown() throws Exception {

+        tempFile.delete();

+    }

+}

diff --git a/test/org/apache/ws/commons/om/impl/streamwrapper/OmStAXBuilderTest.java b/test/org/apache/ws/commons/om/impl/streamwrapper/OmStAXBuilderTest.java
new file mode 100644
index 0000000..75754df
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/streamwrapper/OmStAXBuilderTest.java
@@ -0,0 +1,66 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.streamwrapper;

+

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFactory;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.io.File;

+import java.io.FileOutputStream;

+import java.io.FileReader;

+

+public class OmStAXBuilderTest extends AbstractTestCase {

+    private SOAPFactory factory = null;

+    private OMXMLParserWrapper builder;

+    private File tempFile;

+

+    public OmStAXBuilderTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        factory = OMAbstractFactory.getSOAP11Factory();

+        XMLStreamReader reader = XMLInputFactory.newInstance().

+                createXMLStreamReader(

+                        new FileReader(

+                                getTestResourceFile("soap/soapmessage.xml")));

+        builder =

+                OMXMLBuilderFactory.createStAXSOAPModelBuilder(factory,

+                        reader);

+        tempFile = File.createTempFile("temp", "xml");

+    }

+

+    public void testStaxBuilder() throws Exception {

+        SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();

+        assertNotNull(envelope);

+        envelope.serialize(new FileOutputStream(tempFile));

+

+

+    }

+

+    protected void tearDown() throws Exception {

+        tempFile.delete();

+    }

+

+

+}

diff --git a/test/org/apache/ws/commons/om/impl/traverse/OMChildrenWithSpecificAttributeIteratorTest.java b/test/org/apache/ws/commons/om/impl/traverse/OMChildrenWithSpecificAttributeIteratorTest.java
new file mode 100644
index 0000000..fbd7050
--- /dev/null
+++ b/test/org/apache/ws/commons/om/impl/traverse/OMChildrenWithSpecificAttributeIteratorTest.java
@@ -0,0 +1,109 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.impl.traverse;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.impl.llom.traverse.OMChildrenWithSpecificAttributeIterator;

+

+import javax.xml.namespace.QName;

+import java.util.Iterator;

+

+public class OMChildrenWithSpecificAttributeIteratorTest extends TestCase {

+

+    public OMChildrenWithSpecificAttributeIteratorTest(String testName) {

+        super(testName);

+    }

+

+    public void testChildrenRetrievalWithDetaching() {

+

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+        OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");

+        OMElement documentElement = getSampleDocumentElement(testNamespace);

+

+        Iterator childrenIter = new OMChildrenWithSpecificAttributeIterator(

+                documentElement.getFirstOMChild(), new QName(testNamespace.getName(), "myAttr",

+                testNamespace.getPrefix()), "Axis2", true);

+

+        int childCount = getChidrenCount(childrenIter);

+        assertEquals("Iterator must return 5 children with the given attribute", childCount, 5);

+

+        Iterator children = documentElement.getChildren();

+        childCount = getChidrenCount(children);

+        assertEquals("Iterator must return only one child, having detached the other children", childCount, 1);

+

+    }

+

+    public void testChildrenRetrievalWithNoDetaching() {

+

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+        OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");

+        OMElement documentElement = getSampleDocumentElement(testNamespace);

+

+        Iterator childrenIter = new OMChildrenWithSpecificAttributeIterator(

+                documentElement.getFirstOMChild(), new QName(testNamespace.getName(), "myAttr",

+                testNamespace.getPrefix()), "Axis2", false);

+

+        int childCount = getChidrenCount(childrenIter);

+        assertEquals("Iterator must return 5 children with the given attribute", childCount, 5);

+

+        Iterator children = documentElement.getChildren();

+        childCount = getChidrenCount(children);

+        assertEquals("Iterator must return 6 children, having not detached the children", childCount, 6);

+

+    }

+

+    private OMElement getSampleDocumentElement(OMNamespace testNamespace){

+        OMFactory factory = OMAbstractFactory.getOMFactory();

+

+        OMElement documentElement = factory.createOMElement("Employees", testNamespace);

+        documentElement.declareNamespace(testNamespace);

+

+        OMElement employee;

+        OMElement name;

+

+        for (int i = 0; i < 5; i++) {

+            employee = factory.createOMElement("Employee", testNamespace, documentElement);

+            name = factory.createOMElement("Name"+i, testNamespace);

+            employee.addAttribute("myAttr", "Axis2", testNamespace);

+            name.setText("Apache Developer");

+            employee.addChild(name);

+        }

+

+        //adding one more child with the given attr

+        employee = factory.createOMElement("Employee", testNamespace, documentElement);

+        name = factory.createOMElement("Name", testNamespace);

+        name.addAttribute("myAttr", "Un-Related Value", testNamespace);

+        name.setText("Apache Developer");

+        employee.addChild(name);

+

+        return documentElement;

+    }

+

+    private int getChidrenCount(Iterator childrenIter) {

+        int childCount = 0;

+        while (childrenIter.hasNext()) {

+        	childrenIter.next();

+            childCount++;

+        }

+

+        return childCount;

+    }

+}

diff --git a/test/org/apache/ws/commons/om/infoset/XMLConformanceTest.java b/test/org/apache/ws/commons/om/infoset/XMLConformanceTest.java
new file mode 100644
index 0000000..91e979d
--- /dev/null
+++ b/test/org/apache/ws/commons/om/infoset/XMLConformanceTest.java
@@ -0,0 +1,53 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.infoset;

+

+import junit.framework.Test;

+import junit.framework.TestCase;

+import junit.framework.TestSuite;

+

+import java.io.File;

+

+public class XMLConformanceTest extends TestCase {

+

+    public static Test suite() throws Exception {

+        TestSuite suite = new TestSuite();

+

+        File testSuiteDirectory = new File("test-resources/XMLSuite/xmlconf");

+        if (testSuiteDirectory.exists()) {

+            ProcessDir(testSuiteDirectory, suite);

+        }

+        return suite;

+    }

+

+    private static void ProcessDir(File dir, TestSuite suite) throws Exception {

+        if (dir.isDirectory()) {

+            //process all children

+            String[] children = dir.list();

+            for (int i = 0; i < children.length; i++) {

+                File child = (new File(dir, children[i]));

+                ProcessDir(child, suite);

+            }

+        } else {

+            //check if it's xml file

+            String absPath = dir.getAbsolutePath();

+            if (absPath.endsWith(".xml")) {

+                suite.addTest(new XMLConformanceUnit(absPath, "testSingleFileConformance"));

+            }

+        }

+    }

+}

diff --git a/test/org/apache/ws/commons/om/infoset/XMLConformanceUnit.java b/test/org/apache/ws/commons/om/infoset/XMLConformanceUnit.java
new file mode 100644
index 0000000..a1d9b08
--- /dev/null
+++ b/test/org/apache/ws/commons/om/infoset/XMLConformanceUnit.java
@@ -0,0 +1,110 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.om.infoset;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMDocument;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.om.impl.llom.factory.OMXMLBuilderFactory;

+import org.custommonkey.xmlunit.Diff;

+import org.custommonkey.xmlunit.XMLTestCase;

+import org.w3c.dom.Document;

+import org.xml.sax.EntityResolver;

+import org.xml.sax.InputSource;

+import org.xml.sax.SAXException;

+

+import javax.xml.parsers.DocumentBuilder;

+import javax.xml.parsers.DocumentBuilderFactory;

+import javax.xml.parsers.ParserConfigurationException;

+import javax.xml.stream.XMLInputFactory;

+import java.io.ByteArrayInputStream;

+import java.io.ByteArrayOutputStream;

+import java.io.File;

+import java.io.FileInputStream;

+import java.io.FileReader;

+import java.io.IOException;

+import java.io.InputStreamReader;

+

+public class XMLConformanceUnit extends XMLTestCase implements EntityResolver {

+

+    private String filePath;

+    private File directory;

+

+    public XMLConformanceUnit(String filePath, String testName) {

+        super(testName);

+        this.filePath = filePath;

+        this.directory = new File(filePath).getParentFile();

+    }

+

+    public void testSingleFileConformance()

+            throws Exception {

+        OMElement rootElement;

+

+        System.out.println("XML File:" + filePath);

+        XMLInputFactory factory = XMLInputFactory.newInstance();

+//        factory.setProperty("report-cdata-event", Boolean.TRUE);

+        StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.

+                createStAXOMBuilder(OMAbstractFactory.getOMFactory(),

+                        factory.createXMLStreamReader(

+                                new FileInputStream(filePath)));

+        rootElement = staxOMBuilder.getDocumentElement();

+

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        ((OMDocument)rootElement.getParent()).serialize(baos);

+

+        InputSource resultXML = new InputSource(new InputStreamReader(

+                new ByteArrayInputStream(baos.toByteArray())));

+

+        Document dom1 = newDocument(new InputSource(new FileReader(filePath)));

+        Document dom2 = newDocument(resultXML);

+

+        Diff diff = compareXML(dom1, dom2);

+        assertXMLEqual(diff, true);

+    }

+

+    /**

+     * Method newDocument

+     *

+     * @param in

+     * @return

+     * @throws javax.xml.parsers.ParserConfigurationException

+     *

+     * @throws org.xml.sax.SAXException

+     * @throws java.io.IOException

+     */

+    public Document newDocument(InputSource in)

+            throws ParserConfigurationException, SAXException, IOException {

+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

+        dbf.setNamespaceAware(true);

+        DocumentBuilder db = dbf.newDocumentBuilder();

+        db.setEntityResolver(this);

+        return db.parse(in);

+    }

+

+    public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

+        File f = new File(directory, systemId.substring(systemId.lastIndexOf('/')));

+        return new InputSource(new FileInputStream(f));

+    }

+

+    public String getName() {

+        String name = filePath;

+        if(name.lastIndexOf("xmlconf")!=-1)

+            name = name.substring(name.lastIndexOf("xmlconf"));

+        return name.replace('\\','/');

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPBodyTest.java b/test/org/apache/ws/commons/soap/SOAPBodyTest.java
new file mode 100644
index 0000000..823c636
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPBodyTest.java
@@ -0,0 +1,154 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMException;

+

+public class SOAPBodyTest extends SOAPBodyTestCase {

+

+    public SOAPBodyTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+    }

+

+    //SOAP 1.1 Body Test (Programaticaly created)----------------------------------------------------------------------------------

+    public void testSOAP11AddFault1() {

+        soap11Body.addFault(new Exception("This an exception for testing"));

+        assertTrue(

+                "SOAP 1.1 Body Test:- After calling addFault method, SOAP body has no fault",

+                soap11Body.hasFault());

+

+    }

+

+    public void testSOAP11addFault2() {

+        soap11Body.addFault(soap11Factory.createSOAPFault(soap11Body));

+        assertTrue(

+                "SOAP 1.1 Body Test:- After calling addFault method, SOAP body has no fault",

+                soap11Body.hasFault());

+

+

+    }

+

+    public void testSOAP11HasFault() {

+        assertFalse(

+                "SOAP 1.1 Body Test:- After creating a soap body it has a fault",

+                soap11Body.hasFault());

+        soap11Body.addFault(new Exception("This an exception for testing"));

+        assertTrue(

+                "SOAP 1.1 Body Test:- After calling addFault method, hasFault method returns false",

+                soap11Body.hasFault());

+    }

+

+    public void testSOAP11GetFault() {

+        assertTrue(

+                "SOAP 1.1 Body Test:- After creating a soap body it has a fault",

+                soap11Body.getFault() == null);

+        soap11Body.addFault(new Exception("This an exception for testing"));

+        assertFalse(

+                "SOAP 1.1 Body Test:- After calling addFault method, getFault method returns null",

+                soap11Body.getFault() == null);

+    }

+

+    //SOAP 1.2 Body Test (Programaticaly Created)----------------------------------------------------------------------------------

+    public void testSOAP12AddFault1() {

+        soap12Body.addFault(new Exception("This an exception for testing"));

+        assertTrue(

+                "SOAP 1.2 Body Test:- After calling addFault method, SOAP body has no fault",

+                soap12Body.hasFault());

+

+    }

+

+    public void testSOAP12AddFault2() {

+        soap12Body.addFault(soap12Factory.createSOAPFault(soap12Body));

+        assertTrue(

+                "SOAP 1.2 Body Test:- After calling addFault method, SOAP body has no fault",

+                soap12Body.hasFault());

+    }

+

+    public void testSOAP12HasFault() {

+        assertFalse(

+                "SOAP 1.2 Body Test:- After creating a soap body it has a fault",

+                soap12Body.hasFault());

+        soap12Body.addFault(new Exception("This an exception for testing"));

+        assertTrue(

+                "SOAP 1.2 Body Test:- After calling addFault method, hasFault method returns false",

+                soap12Body.hasFault());

+    }

+

+    public void testSOAP12GetFault() {

+        assertTrue(

+                "SOAP 1.2 Body Test:- After creating a soap body it has a fault",

+                soap12Body.getFault() == null);

+        soap12Body.addFault(new Exception("This an exception for testing"));

+        assertFalse(

+                "SOAP 1.2 Body Test:- After calling addFault method, getFault method returns null",

+                soap12Body.getFault() == null);

+    }

+

+    //SOAP 1.1 Body Test (With Parser)-------------------------------------------------------------------------------------------

+    public void testSOAP11HasFaultWithParser() {

+        assertTrue(

+                "SOAP 1.1 Body Test With parser :- hasFault method returns false",

+                soap11BodyWithParser.hasFault());

+    }

+

+    public void testSOAP11GetFaultWithParser() {

+        assertFalse(

+                "SOAP 1.1 Body Test With parser :- getFault method returns null",

+                soap11BodyWithParser.getFault() == null);

+        assertTrue(

+                "SOAP 1.1 Body Test With parser : - SOAP fault name mismatch",

+                soap11BodyWithParser.getFault().getLocalName().equals(

+                        SOAPConstants.SOAPFAULT_LOCAL_NAME));

+    }

+

+    //SOAP 1.2 Body Test (With Parser)-------------------------------------------------------------------------------------------------

+    public void testSOAP12HasFaultWithParser() {

+        assertTrue(

+                "SOAP 1.2 Body Test With parser :- hasFault method returns false",

+                soap12BodyWithParser.hasFault());

+    }

+

+    public void testSOAP12GetFaultWithParser() {

+        assertFalse(

+                "SOAP 1.2 Body Test With parser :- getFault method returns null",

+                soap12BodyWithParser.getFault() == null);

+        assertTrue(

+                "SOAP 1.2 Body Test With parser : - SOAP fault name mismatch",

+                soap12BodyWithParser.getFault().getLocalName().equals(

+                        SOAPConstants.SOAPFAULT_LOCAL_NAME));

+    }

+

+    public void testSOAPBodyDetachment(){

+        try {

+            soap11Body.detach();

+            fail("Detachment of SOAP Body is not allowed !!");

+        } catch (OMException e) {

+            assertTrue(true);

+        }

+

+        try {

+            soap12Body.detach();

+            fail("Detachment of SOAP Body is not allowed !!");

+        } catch (OMException e) {

+            assertTrue(true);

+        }

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPBodyTestCase.java b/test/org/apache/ws/commons/soap/SOAPBodyTestCase.java
new file mode 100644
index 0000000..a8771fc
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPBodyTestCase.java
@@ -0,0 +1,40 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public class SOAPBodyTestCase extends SOAPTestCase {

+    protected SOAPBody soap11Body;

+    protected SOAPBody soap12Body;

+

+    protected SOAPBody soap11BodyWithParser;

+    protected SOAPBody soap12BodyWithParser;

+

+    public SOAPBodyTestCase(String testName) {

+        super(testName);

+

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11Body = soap11Factory.createSOAPBody(soap11Envelope);

+        soap12Body = soap12Factory.createSOAPBody(soap12Envelope);

+

+        soap11BodyWithParser = soap11EnvelopeWithParser.getBody();

+        soap12BodyWithParser = soap12EnvelopeWithParser.getBody();

+    }

+

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPEnvelopeTest.java b/test/org/apache/ws/commons/soap/SOAPEnvelopeTest.java
new file mode 100644
index 0000000..38cb408
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPEnvelopeTest.java
@@ -0,0 +1,105 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+

+public class SOAPEnvelopeTest extends SOAPTestCase {

+    protected SOAPEnvelope soap11Envelope;

+    protected SOAPEnvelope soap12Envelope;

+

+    public SOAPEnvelopeTest(String testName) {

+        super(testName);

+        soap11Envelope = soap11Factory.getDefaultEnvelope();

+        soap12Envelope = soap12Factory.getDefaultEnvelope();

+    }

+

+    //SOAP 1.1 Envelope Test (Programaticaly Created)-----------------------------------------------

+    public void testSOAP11GetHeader() {

+        SOAPHeader header = soap11Envelope.getHeader();

+        assertTrue("SOAP 1.1 Header Test : - Header local name mismatch",

+                header.getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME));

+        assertTrue("SOAP 1.1 Header Test : - Header namespace mismatch",

+                header.getNamespace().getName().equals(

+                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+    }

+

+    public void testSOAP11GetBody() {

+        SOAPBody body = soap11Envelope.getBody();

+        assertTrue("SOAP 1.1 Body Test : - Body local name mismatch",

+                body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));

+        assertTrue("SOAP 1.1 Body Test : - Body namespace mismatch",

+                body.getNamespace().getName().equals(

+                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+    }

+

+    //SOAP 1.2 Envelope Test (Programaticaly Created)-------------------------------------------------

+    public void testSOAP12GetHeader() {

+        SOAPHeader header = soap12Envelope.getHeader();

+        assertTrue("SOAP 1.2 Header Test : - Header local name mismatch",

+                header.getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME));

+        assertTrue("SOAP 1.2 Header Test : - Header namespace mismatch",

+                header.getNamespace().getName().equals(

+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+    }

+

+    public void testSOAP12GetBody() {

+        SOAPBody body = soap12Envelope.getBody();

+        assertTrue("SOAP 1.2 Body Test : - Body local name mismatch",

+                body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));

+        assertTrue("SOAP 1.2 Body Test : - Body namespace mismatch",

+                body.getNamespace().getName().equals(

+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+    }

+

+    //SOAP 1.1 Envelope Test (With Parser)-----------------------------------------------------------------

+    public void testSOAP11GetHeaderWithParser() {

+        SOAPHeader header = soap11EnvelopeWithParser.getHeader();

+        assertTrue("SOAP 1.1 Header Test : - Header local name mismatch",

+                header.getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME));

+        assertTrue("SOAP 1.1 Header Test : - Header namespace mismatch",

+                header.getNamespace().getName().equals(

+                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+    }

+

+    public void testSOAP11GetBodyWithParser() {

+        SOAPBody body = soap11EnvelopeWithParser.getBody();

+        assertTrue("SOAP 1.1 Body Test : - Body local name mismatch",

+                body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));

+        assertTrue("SOAP 1.1 Body Test : - Body namespace mismatch",

+                body.getNamespace().getName().equals(

+                        SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+    }

+

+    //SOAP 1.2 Envelope Test (With Parser)--------------------------------------------------------------------

+    public void testSOAP12GetHeaderWithParser() {

+        SOAPHeader header = soap12EnvelopeWithParser.getHeader();

+        assertTrue("SOAP 1.2 Header Test : - Header local name mismatch",

+                header.getLocalName().equals(SOAPConstants.HEADER_LOCAL_NAME));

+        assertTrue("SOAP 1.2 Header Test : - Header namespace mismatch",

+                header.getNamespace().getName().equals(

+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+    }

+

+    public void testSOAP12GetBodyWithParser() {

+        SOAPBody body = soap12EnvelopeWithParser.getBody();

+        assertTrue("SOAP 1.2 Body Test : - Body local name mismatch",

+                body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));

+        assertTrue("SOAP 1.2 Body Test : - Body namespace mismatch",

+                body.getNamespace().getName().equals(

+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultCodeTest.java b/test/org/apache/ws/commons/soap/SOAPFaultCodeTest.java
new file mode 100644
index 0000000..681c9c5
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultCodeTest.java
@@ -0,0 +1,163 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+

+public class SOAPFaultCodeTest extends SOAPFaultCodeTestCase {

+

+    public SOAPFaultCodeTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+    }

+

+    //SOAP 1.1 Fault Code Test (Programaticaly Created)

+    public void testSOAP11SetValue() {

+        soap11FaultCode.setValue(

+                soap11Factory.createSOAPFaultValue(soap11FaultCode));

+        assertFalse(

+                "SOAP 1.1 Fault Code Test :- After calling setValue method, getValue method returns null",

+                soap11FaultCode.getValue() == null);

+        try {

+            soap11FaultCode.setValue(

+                    soap12Factory.createSOAPFaultValue(soap12FaultCode));

+            fail("SOAP12FaultValue should not be inserted to SOAP11FaultCode");

+        } catch (SOAPProcessingException e) {

+            assertTrue(true);

+        }

+

+    }

+

+    public void testSOAP11GetValue() {

+        assertTrue(

+                "SOAP 1.1 Fault Code Test :- After creating soapfaultcode, it has a value",

+                soap11FaultCode.getValue() == null);

+        soap11FaultCode.setValue(

+                soap11Factory.createSOAPFaultValue(soap11FaultCode));

+        assertFalse(

+                "SOAP 1.1 Fault Code Test :- After calling setValue method, getValue method returns null",

+                soap11FaultCode.getValue() == null);

+    }

+

+    //SOAP 1.2 Fault Code Test (Programaticaly Created)

+    public void testSOAP12SetValue() {

+        soap12FaultCode.setValue(

+                soap12Factory.createSOAPFaultValue(soap12FaultCode));

+        assertFalse(

+                "SOAP 1.2 Fault Code Test :- After calling setValue method, getValue method returns null",

+                soap12FaultCode.getValue() == null);

+        try {

+            soap12FaultCode.setValue(

+                    soap11Factory.createSOAPFaultValue(soap11FaultCode));

+            fail("SOAP11FaultValue should not be inserted to SOAP12FaultCode");

+        } catch (SOAPProcessingException e) {

+            assertTrue(true);

+        }

+

+        try {

+            soap12FaultCode.setValue(

+                    soap12Factory.createSOAPFaultValue(

+                            soap12Factory.createSOAPFaultSubCode(

+                                    soap12FaultCode)));

+        } catch (Exception e) {

+            fail(

+                    "SOAP 1.2 Fault Code Test :- When calling setValue method, parent of value element mismatch");

+        }

+    }

+

+    public void testSOAP12GetValue() {

+        assertTrue(

+                "SOAP 1.2 Fault Code Test :- After creating soapfaultcode, it has a value",

+                soap12FaultCode.getValue() == null);

+        soap12FaultCode.setValue(

+                soap12Factory.createSOAPFaultValue(soap12FaultCode));

+        assertFalse(

+                "SOAP 1.2 Fault Code Test :- After calling setValue method, getValue method returns null",

+                soap12FaultCode.getValue() == null);

+    }

+

+    public void testSOAP12SetSubCode() {

+        soap12FaultCode.setSubCode(

+                soap12Factory.createSOAPFaultSubCode(soap12FaultCode));

+        assertFalse(

+                "SOAP 1.2 Fault Code Test :- After calling setSubCode method, getSubCode method returns null",

+                soap12FaultCode.getSubCode() == null);

+        try {

+            soap12FaultCode.setSubCode(

+                    soap11Factory.createSOAPFaultSubCode(soap11FaultCode));

+            fail(

+                    "SOAP11FaultSubCode should not be inserted to SOAP12FaultCode");

+        } catch (SOAPProcessingException e) {

+            assertTrue(true);

+        }

+

+        try {

+            soap12FaultCode.setSubCode(

+                    soap12Factory.createSOAPFaultSubCode(

+                            soap12Factory.createSOAPFaultSubCode(

+                                    soap12FaultCode)));

+        } catch (Exception e) {

+            fail(

+                    "SOAP 1.2 Fault Code Test :- When calling setSubCode method, parent of subcode element mismatch");

+        }

+    }

+

+    public void testSOAP12GetSubCode() {

+        assertTrue(

+                "SOAP 1.2 Fault Code Test :- After creating soapfaultcode, it has a subcode",

+                soap12FaultCode.getSubCode() == null);

+        soap12FaultCode.setSubCode(

+                soap12Factory.createSOAPFaultSubCode(soap12FaultCode));

+        assertFalse(

+                "SOAP 1.2 Fault Code Test :- After calling setSubCode method, getSubCode method returns null",

+                soap12FaultCode.getSubCode() == null);

+    }

+

+    //SOAP 1.1 Fault Code Test (With Parser)

+    public void testSOAP11GetValueWithParser() {

+        assertFalse(

+                "SOAP 1.1 Fault Code Test with parser : - getValue method returns null",

+                soap11FaultCodeWithParser.getValue() == null);

+        assertTrue(

+                "SOAP 1.1 Fault Code Test with parser : - Value local name mismatch",

+                soap11FaultCodeWithParser.getValue().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));

+    }

+

+    //SOAP 1.2 Fault Code Test (With Parser)

+    public void testSOAP12GetValueWithParser() {

+        assertFalse(

+                "SOAP 1.2 Fault Code Test with parser : - getValue method returns null",

+                soap12FaultCodeWithParser.getValue() == null);

+        assertTrue(

+                "SOAP 1.2 Fault Code Test with parser : - Value local name mismatch",

+                soap12FaultCodeWithParser.getValue().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));

+    }

+

+    public void testSOAP12GetSubCodeWithParser() {

+        assertFalse(

+                "SOAP 1.2 Fault Code Test with parser :- getSubCode method returns null",

+                soap12FaultCodeWithParser.getSubCode() == null);

+        assertTrue(

+                "SOAP 1.2 Fault Code Test with parser : - subcode local name mismatch",

+                soap12FaultCodeWithParser.getSubCode().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultCodeTestCase.java b/test/org/apache/ws/commons/soap/SOAPFaultCodeTestCase.java
new file mode 100644
index 0000000..270f65d
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultCodeTestCase.java
@@ -0,0 +1,41 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public class SOAPFaultCodeTestCase extends SOAPFaultTestCase {

+

+    protected SOAPFaultCode soap11FaultCode;

+    protected SOAPFaultCode soap12FaultCode;

+

+    protected SOAPFaultCode soap11FaultCodeWithParser;

+    protected SOAPFaultCode soap12FaultCodeWithParser;

+

+    public SOAPFaultCodeTestCase(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+

+        soap11FaultCode = soap11Factory.createSOAPFaultCode(soap11Fault);

+        soap12FaultCode = soap12Factory.createSOAPFaultCode(soap12Fault);

+

+        soap11FaultCodeWithParser = soap11FaultWithParser.getCode();

+        soap12FaultCodeWithParser = soap12FaultWithParser.getCode();

+    }

+

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultDetailTest.java b/test/org/apache/ws/commons/soap/SOAPFaultDetailTest.java
new file mode 100644
index 0000000..75b0d7f
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultDetailTest.java
@@ -0,0 +1,223 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMText;

+

+import java.util.Iterator;

+

+public class SOAPFaultDetailTest extends SOAPFaultTestCase {

+    protected SOAPFaultDetail soap11FaultDetail;

+    protected SOAPFaultDetail soap12FaultDetail;

+    protected SOAPFaultDetail soap11FaultDetailWithParser;

+    protected SOAPFaultDetail soap12FaultDetailWithParser;

+    protected OMNamespace omNamespace;

+

+    public SOAPFaultDetailTest(String testName) {

+        super(testName);

+        omNamespace =

+                omFactory.createOMNamespace("http://www.test.org", "test");

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11FaultDetail = soap11Factory.createSOAPFaultDetail(soap11Fault);

+        soap12FaultDetail = soap12Factory.createSOAPFaultDetail(soap12Fault);

+        soap11FaultDetailWithParser = soap11FaultWithParser.getDetail();

+        soap12FaultDetailWithParser = soap12FaultWithParser.getDetail();

+    }

+

+    //SOAP 1.1 Fault Detail Test (Programaticaly Created)

+    public void testSOAP11AddDetailEntry() {

+        soap11FaultDetail.addDetailEntry(

+                omFactory.createOMElement("DetailEntry1", omNamespace));

+        soap11FaultDetail.addDetailEntry(

+                omFactory.createOMElement("DetailEntry2", omNamespace));

+        Iterator iterator = soap11FaultDetail.getAllDetailEntries();

+        OMElement detailEntry1 = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns empty iterator",

+                detailEntry1 == null);

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - detailEntry1 local name mismatch",

+                detailEntry1.getLocalName().equals("DetailEntry1"));

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - detailEntry1 namespace uri mismatch",

+                detailEntry1.getNamespace().getName().equals(

+                        "http://www.test.org"));

+        OMElement detailEntry2 = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns an iterator with only one object",

+                detailEntry2 == null);

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - detailEntry2 local name mismatch",

+                detailEntry2.getLocalName().equals("DetailEntry2"));

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - detailEntry2 namespace uri mismatch",

+                detailEntry2.getNamespace().getName().equals(

+                        "http://www.test.org"));

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns an iterator with three objects",

+                iterator.next() == null);

+    }

+

+    public void testSOAP11GetAllDetailEntries() {

+        Iterator iterator = soap11FaultDetail.getAllDetailEntries();

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - After creating SOAP11FaultDetail element, it has DetailEntries",

+                iterator.next() == null);

+        soap11FaultDetail.addDetailEntry(

+                omFactory.createOMElement("DetailEntry", omNamespace));

+        iterator = soap11FaultDetail.getAllDetailEntries();

+        OMElement detailEntry = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Fault Detail Test : - After calling addDetailEntry method, getAllDetailEntries method returns empty iterator",

+                detailEntry == null);

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - detailEntry local name mismatch",

+                detailEntry.getLocalName().equals("DetailEntry"));

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - detailEntry namespace uri mismatch",

+                detailEntry.getNamespace().getName().equals(

+                        "http://www.test.org"));

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test : - After calling addDetailEntry method once, getAllDetailEntries method returns an iterator with two objects",

+                iterator.next() == null);

+    }

+

+    //SOAP 1.2 Fault Detail Test (Programaticaly Created)

+    public void testSOAP12AddDetailEntry() {

+        soap12FaultDetail.addDetailEntry(

+                omFactory.createOMElement("DetailEntry1", omNamespace));

+        soap12FaultDetail.addDetailEntry(

+                omFactory.createOMElement("DetailEntry2", omNamespace));

+        Iterator iterator = soap12FaultDetail.getAllDetailEntries();

+        OMElement detailEntry1 = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns empty iterator",

+                detailEntry1 == null);

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - detailEntry1 local name mismatch",

+                detailEntry1.getLocalName().equals("DetailEntry1"));

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - detailEntry1 namespace uri mismatch",

+                detailEntry1.getNamespace().getName().equals(

+                        "http://www.test.org"));

+        OMElement detailEntry2 = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns an iterator with only one object",

+                detailEntry2 == null);

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - detailEntry2 local name mismatch",

+                detailEntry2.getLocalName().equals("DetailEntry2"));

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - detailEntry2 namespace uri mismatch",

+                detailEntry2.getNamespace().getName().equals(

+                        "http://www.test.org"));

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - After calling addDetailEntry method twice, getAllDetailEntries method returns an iterator with three objects",

+                iterator.next() == null);

+    }

+

+    public void testSOAP12GetAllDetailEntries() {

+        Iterator iterator = soap12FaultDetail.getAllDetailEntries();

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - After creating SOAP11FaultDetail element, it has DetailEntries",

+                iterator.next() == null);

+        soap12FaultDetail.addDetailEntry(

+                omFactory.createOMElement("DetailEntry", omNamespace));

+        iterator = soap12FaultDetail.getAllDetailEntries();

+        OMElement detailEntry = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Fault Detail Test : - After calling addDetailEntry method, getAllDetailEntries method returns empty iterator",

+                detailEntry == null);

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - detailEntry local name mismatch",

+                detailEntry.getLocalName().equals("DetailEntry"));

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - detailEntry namespace uri mismatch",

+                detailEntry.getNamespace().getName().equals(

+                        "http://www.test.org"));

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test : - After calling addDetailEntry method once, getAllDetailEntries method returns an iterator with two objects",

+                iterator.next() == null);

+    }

+

+    //SOAP 1.1 Fault Detail Test (With Parser)

+    public void testSOAP11GetAllDetailEntriesWithParser() {

+        Iterator iterator = soap11FaultDetailWithParser.getAllDetailEntries();

+        OMText textEntry = (OMText) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Fault Detail Test With Parser : - getAllDetailEntries method returns empty iterator",

+                textEntry == null);

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test With Parser : - text value mismatch",

+                textEntry.getText().trim().equals("Details of error"));

+        OMElement detailEntry1 = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Fault Detail Test With Parser : - getAllDetailEntries method returns an itrator without detail entries",

+                detailEntry1 == null);

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test With Parser : - detailEntry1 localname mismatch",

+                detailEntry1.getLocalName().equals("MaxTime"));

+        iterator.next();

+        OMElement detailEntry2 = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Fault Detail Test With Parser : - getAllDetailEntries method returns an itrator with only one detail entries",

+                detailEntry2 == null);

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test With Parser : - detailEntry2 localname mismatch",

+                detailEntry2.getLocalName().equals("AveTime"));

+        iterator.next();

+        assertTrue(

+                "SOAP 1.1 Fault Detail Test With Parser : - getAllDetailEntries method returns an itrator with more than two detail entries",

+                iterator.next() == null);

+    }

+

+    //SOAP 1.2 Fault Detail Test (With Parser)

+    public void testSOAP12GetAllDetailEntriesWithParser() {

+        Iterator iterator = soap12FaultDetailWithParser.getAllDetailEntries();

+        OMText textEntry = (OMText) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Fault Detail Test With Parser : - getAllDetailEntries method returns empty iterator",

+                textEntry == null);

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test With Parser : - text value mismatch",

+                textEntry.getText().trim().equals("Details of error"));

+        OMElement detailEntry1 = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Fault Detail Test With Parser : - getAllDetailEntries method returns an itrator without detail entries",

+                detailEntry1 == null);

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test With Parser : - detailEntry1 localname mismatch",

+                detailEntry1.getLocalName().equals("MaxTime"));

+        iterator.next();

+        OMElement detailEntry2 = (OMElement) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Fault Detail Test With Parser : - getAllDetailEntries method returns an itrator with only one detail entries",

+                detailEntry2 == null);

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test With Parser : - detailEntry2 localname mismatch",

+                detailEntry2.getLocalName().equals("AveTime"));

+        iterator.next();

+        assertTrue(

+                "SOAP 1.2 Fault Detail Test With Parser : - getAllDetailEntries method returns an itrator with more than two detail entries",

+                iterator.next() == null);

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultNodeTest.java b/test/org/apache/ws/commons/soap/SOAPFaultNodeTest.java
new file mode 100644
index 0000000..b8d6420
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultNodeTest.java
@@ -0,0 +1,78 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public class SOAPFaultNodeTest extends SOAPFaultTestCase {

+    protected SOAPFaultNode soap11FaultNode;

+    protected SOAPFaultNode soap12FaultNode;

+    protected SOAPFaultNode soap12FaultNodeWithParser;

+

+    public SOAPFaultNodeTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11FaultNode = soap11Factory.createSOAPFaultNode(soap11Fault);

+        soap12FaultNode = soap12Factory.createSOAPFaultNode(soap12Fault);

+        soap12FaultNodeWithParser = soap12FaultWithParser.getNode();

+    }

+

+    //SOAP 1.1 Fault Node Test (Programaticaly Created)

+    public void testSOAP11SetNodeValue() {

+        soap11FaultNode.setNodeValue("This is only a test");

+        assertTrue(

+                "SOAP 1.1 Fault Node Test : - After calling setNodeValue method, getNodeValue method returns incorrect value",

+                soap11FaultNode.getNodeValue().equals("This is only a test"));

+    }

+

+    public void testSOAP11GetNodeValue() {

+        assertTrue(

+                "SOAP 1.1 Fault Node Test : - After creating SOAPFaultNode, it has a value",

+                soap11FaultNode.getNodeValue().equals(""));

+        soap11FaultNode.setNodeValue("This is only a test");

+        assertTrue(

+                "SOAP 1.1 Fault Node Test : - After calling setNodeValue method, getNodeValue method returns incorrect value",

+                soap11FaultNode.getNodeValue().equals("This is only a test"));

+    }

+

+    //SOAP 1.2 Fault Node Test (Programaticaly Created)

+    public void testSOAP12SetNodeValue() {

+        soap12FaultNode.setNodeValue("This is only a test");

+        assertTrue(

+                "SOAP 1.2 Fault Node Test : - After calling setNodeValue method, getNodeValue method returns incorrect value",

+                soap12FaultNode.getNodeValue().equals("This is only a test"));

+    }

+

+    public void testSOAP12GetNodeValue() {

+        assertTrue(

+                "SOAP 1.2 Fault Node Test : - After creating SOAPFaultNode, it has a value",

+                soap12FaultNode.getNodeValue().equals(""));

+        soap12FaultNode.setNodeValue("This is only a test");

+        assertTrue(

+                "SOAP 1.2 Fault Node Test : - After calling setNodeValue method, getNodeValue method returns incorrect value",

+                soap12FaultNode.getNodeValue().equals("This is only a test"));

+    }

+

+    //SOAP 1.2 Fault Node Test (With Parser)

+    public void testSOAP12GetNodeValueWithParser() {

+        assertTrue(

+                "SOAP 1.2 Fault Node Test With Parser : - getNodeValue method returns incorrect value",

+                soap12FaultNodeWithParser.getNodeValue().trim().equals(

+                        "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultReasonTest.java b/test/org/apache/ws/commons/soap/SOAPFaultReasonTest.java
new file mode 100644
index 0000000..22f3ef8
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultReasonTest.java
@@ -0,0 +1,97 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public class SOAPFaultReasonTest extends SOAPFaultReasonTestCase {

+

+    public SOAPFaultReasonTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+    }

+

+    //SOAP 1.1 Fault Reason Test (Programaticaly Created)

+    public void testSOAP11SetSOAPText() {

+        soap11FaultReason.setSOAPText(

+                soap11Factory.createSOAPFaultText(soap11FaultReason));

+        assertFalse(

+                "SOAP 1.1 FaultReason Test : - After calling setSOAPText, getSOAPText returns null",

+                soap11FaultReason.getSOAPText() == null);

+        try {

+            soap11FaultReason.setSOAPText(

+                    soap12Factory.createSOAPFaultText(soap12FaultReason));

+            fail("SOAP12FaultText should not be added to SOAP11FaultReason");

+

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP11GetSOAPText() {

+        assertTrue(

+                "SOAP 1.1 FaultReason Test : - After creating SOAP11FaultReason, it has a SOAPFaultText",

+                soap11FaultReason.getSOAPText() == null);

+        soap11FaultReason.setSOAPText(

+                soap11Factory.createSOAPFaultText(soap11FaultReason));

+        assertFalse(

+                "SOAP 1.1 FaultReason Test : - After calling setSOAPText, getSOAPText returns null",

+                soap11FaultReason.getSOAPText() == null);

+    }

+

+    //SOAP 1.2 Fault Reason Test (Programaticaly Created)

+    public void testSOAP12SetSOAPText() {

+        soap12FaultReason.setSOAPText(

+                soap12Factory.createSOAPFaultText(soap12FaultReason));

+        assertFalse(

+                "SOAP 1.2 FaultReason Test : - After calling setSOAPText, getSOAPText returns null",

+                soap12FaultReason.getSOAPText() == null);

+        try {

+            soap12FaultReason.setSOAPText(

+                    soap11Factory.createSOAPFaultText(soap11FaultReason));

+            fail("SOAP11FaultText should not be added to SOAP12FaultReason");

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP12GetSOAPText() {

+        assertTrue(

+                "SOAP 1.2 FaultReason Test : - After creating SOAP12FaultReason, it has a SOAPFaultText",

+                soap12FaultReason.getSOAPText() == null);

+        soap12FaultReason.setSOAPText(

+                soap12Factory.createSOAPFaultText(soap12FaultReason));

+        assertFalse(

+                "SOAP 1.2 FaultReason Test : - After calling setSOAPText, getSOAPText returns null",

+                soap12FaultReason.getSOAPText() == null);

+    }

+

+    //SOAP 1.1 Fault Reason Test (With Parser)

+    public void testSOAP11GetSOAPTextWithParser() {

+        assertFalse(

+                "SOAP 1.1 FaultReason Test With Parser : - getSOAPText method returns null",

+                soap11FaultReasonWithParser.getSOAPText() == null);

+    }

+

+    //SOAP 1.2 Fault Reason Test (With Parser)

+    public void testSOAP12GetSOAPTextWithParser() {

+        assertFalse(

+                "SOAP 1.2 FaultReason Test With Parser : - getSOAPText method returns null",

+                soap12FaultReasonWithParser.getSOAPText() == null);

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultReasonTestCase.java b/test/org/apache/ws/commons/soap/SOAPFaultReasonTestCase.java
new file mode 100644
index 0000000..c0f57c9
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultReasonTestCase.java
@@ -0,0 +1,38 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public class SOAPFaultReasonTestCase extends SOAPFaultTestCase {

+

+    protected SOAPFaultReason soap11FaultReason;

+    protected SOAPFaultReason soap12FaultReason;

+    protected SOAPFaultReason soap11FaultReasonWithParser;

+    protected SOAPFaultReason soap12FaultReasonWithParser;

+

+    public SOAPFaultReasonTestCase(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11FaultReason = soap11Factory.createSOAPFaultReason(soap11Fault);

+        soap12FaultReason = soap12Factory.createSOAPFaultReason(soap12Fault);

+        soap11FaultReasonWithParser = soap11FaultWithParser.getReason();

+        soap12FaultReasonWithParser = soap12FaultWithParser.getReason();

+    }

+

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultRoleTest.java b/test/org/apache/ws/commons/soap/SOAPFaultRoleTest.java
new file mode 100644
index 0000000..38ff478
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultRoleTest.java
@@ -0,0 +1,89 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public class SOAPFaultRoleTest extends SOAPFaultTestCase {

+

+    protected SOAPFaultRole soap11FaultRole;

+    protected SOAPFaultRole soap12FaultRole;

+    protected SOAPFaultRole soap11FaultRoleWithParser;

+    protected SOAPFaultRole soap12FaultRoleWithParser;

+

+    public SOAPFaultRoleTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11FaultRole = soap11Factory.createSOAPFaultRole(soap11Fault);

+        soap12FaultRole = soap12Factory.createSOAPFaultRole(soap12Fault);

+        soap11FaultRoleWithParser = soap11FaultWithParser.getRole();

+        soap12FaultRoleWithParser = soap12FaultWithParser.getRole();

+    }

+

+    //SOAP 1.1 Fault Role Test (Programaticaly Created)

+    public void testSOAP11SetRoleValue() {

+        soap11FaultRole.setRoleValue("This is only a test");

+        assertTrue(

+                "SOAP 1.1 Fault Role Test : - After calling setRoleValue method, getRoleValue method returns incorrect value",

+                soap11FaultRole.getRoleValue().trim().equals("This is only a test"));

+    }

+

+    public void testSOAP11GetRoleValue() {

+        assertTrue(

+                "SOAP 1.1 Fault Role Test : - After creating SOAPFaultRole, it has a value",

+                soap11FaultRole.getRoleValue().equals(""));

+        soap11FaultRole.setRoleValue("This is only a test");

+        assertTrue(

+                "SOAP 1.1 Fault Role Test : - After calling setRoleValue method, getRoleValue method returns incorrect value",

+                soap11FaultRole.getRoleValue().trim().equals("This is only a test"));

+    }

+

+    //SOAP 1.2 Fault Role Test (Programaticaly Created)

+    public void testSOAP12SetRoleValue() {

+        soap12FaultRole.setRoleValue("This is only a test");

+        assertTrue(

+                "SOAP 1.2 Fault Role Test : - After calling setRoleValue method, getRoleValue method returns incorrect value",

+                soap12FaultRole.getRoleValue().trim().equals("This is only a test"));

+    }

+

+    public void testSOAP12GetRoleValue() {

+        assertTrue(

+                "SOAP 1.2 Fault Role Test : - After creating SOAPFaultRole, it has a value",

+                soap12FaultRole.getRoleValue().trim().equals(""));

+        soap12FaultRole.setRoleValue("This is only a test");

+        assertTrue(

+                "SOAP 1.2 Fault Role Test : - After calling setRoleValue method, getRoleValue method returns incorrect value",

+                soap12FaultRole.getRoleValue().trim().equals("This is only a test"));

+    }

+

+    //SOAP 1.1 Fault Role Test (With Parser)

+    public void testSOAP11GetRoleValueWithParser() {

+        assertTrue(

+                "SOAP 1.1 Fault Role Test With Parser : - getRoleValue method returns incorrect value",

+                soap11FaultRoleWithParser.getRoleValue().trim().equals(

+                        "http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver"));

+    }

+

+    //SOAP 1.2 Fault Role Test (With Parser)

+    public void testSOAP12GetRoleValueWithParser() {

+        assertTrue(

+                "SOAP 1.2 Fault Role Test With Parser : - getRoleValue method returns incorrect value",

+                soap12FaultRoleWithParser.getRoleValue().trim().equals(

+                        "ultimateReceiver"));

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultSubCodeTest.java b/test/org/apache/ws/commons/soap/SOAPFaultSubCodeTest.java
new file mode 100644
index 0000000..22bab48
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultSubCodeTest.java
@@ -0,0 +1,180 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+

+public class SOAPFaultSubCodeTest extends SOAPFaultSubCodeTestCase {

+

+    public SOAPFaultSubCodeTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+    }

+

+    //SOAP Fault SubCode(In Fault Code) Test (Programaticaly Created)

+    public void testSetValueInFaultCode() {

+        soap12FaultSubCodeInCode.setValue(

+                soap12Factory.createSOAPFaultValue(soap12FaultSubCodeInCode));

+        assertFalse(

+                "SOAP 1.2 Subcode Test In Fault Code : - After calling setValue method, getValue method returns null",

+                soap12FaultSubCodeInCode.getValue() == null);

+        try {

+            soap12FaultSubCodeInCode.setValue(

+                    soap12Factory.createSOAPFaultValue(soap12FaultCode));

+        } catch (SOAPProcessingException e) {

+            fail(

+                    "SOAP 1.2 SOAPFaultSubCode Test In FaultCode : - FaultValue whose parent is FaultCode should not be set in to FaultSubCode, as a child");

+        }

+    }

+

+    public void testGetValueInFaultCode() {

+        assertTrue(

+                "After creating SOAP12FaultSubCode In Fault Code, it has a FaultValue",

+                soap12FaultSubCodeInCode.getValue() == null);

+        soap12FaultSubCodeInCode.setValue(

+                soap12Factory.createSOAPFaultValue(soap12FaultSubCodeInCode));

+        assertFalse(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultCode : - After calling setValue method, getValue method returns null",

+                soap12FaultSubCodeInCode.getValue() == null);

+    }

+

+    public void testsetSubCodeInFaultCode() {

+        soap12FaultSubCodeInCode.setSubCode(

+                soap12Factory.createSOAPFaultSubCode(soap12FaultSubCodeInCode));

+        assertFalse(

+                "SOAP 1.2 Subcode Test In Fault Code : - After calling setSubCode method, getSubCode method returns null",

+                soap12FaultSubCodeInCode.getSubCode() == null);

+        try {

+            soap12FaultSubCodeInCode.setSubCode(

+                    soap12Factory.createSOAPFaultSubCode(soap12FaultCode));

+        } catch (SOAPProcessingException e) {

+            fail(

+                    "SOAP 1.2 SOAPFaultSubCode Test In FaultCode : - FaultSubCode whose parent is FaultCode should not be set in to FaultSubCode, as a child");

+        }

+    }

+

+    public void testGetSubCodeInFaultCode() {

+        //soap12FaultSubCodeInCode has a SubCode because a SubCode was created in setUp method of super class

+//        assertTrue("After creating SOAP12FaultSubCode In Fault Code, it has a FaultSubCode",soap12FaultSubCodeInCode.getSubCode() == null);

+        soap12FaultSubCodeInCode.setSubCode(

+                soap12Factory.createSOAPFaultSubCode(soap12FaultSubCodeInCode));

+        assertFalse(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultCode : - After calling setSubCode method, getSubCode method returns null",

+                soap12FaultSubCodeInCode.getSubCode() == null);

+    }

+

+    //SOAP Fault SubCode(In Fault SubCode) Test (Programaticaly Created)

+    public void testSetValueInFaultSubCode() {

+        soap12FaultSubCodeInSubCode.setValue(

+                soap12Factory.createSOAPFaultValue(soap12FaultSubCodeInSubCode));

+        assertFalse(

+                "SOAP 1.2 Subcode Test In Fault SubCode : - After calling setValue method, getValue method returns null",

+                soap12FaultSubCodeInSubCode.getValue() == null);

+        try {

+            soap12FaultSubCodeInSubCode.setValue(

+                    soap12Factory.createSOAPFaultValue(soap12FaultCode));

+        } catch (SOAPProcessingException e) {

+            fail(

+                    "SOAP 1.2 SOAPFaultSubCode Test In FaultCode : - FaultValue whose parent is FaultCode should not be set in to FaultSubCode, as a child");

+        }

+    }

+

+    public void testGetValueInFaultSubCode() {

+        assertTrue(

+                "After creating SOAP12FaultSubCode In Fault SubCode, it has a Fault Value",

+                soap12FaultSubCodeInSubCode.getValue() == null);

+        soap12FaultSubCodeInSubCode.setValue(

+                soap12Factory.createSOAPFaultValue(soap12FaultSubCodeInSubCode));

+        assertFalse(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultSubCode : - After calling setValue method, getValue method returns null",

+                soap12FaultSubCodeInSubCode.getValue() == null);

+    }

+

+    public void testsetSubCodeInFaultSubCode() {

+        soap12FaultSubCodeInSubCode.setSubCode(

+                soap12Factory.createSOAPFaultSubCode(

+                        soap12FaultSubCodeInSubCode));

+        assertFalse(

+                "SOAP 1.2 Subcode Test In Fault SubCode : - After calling setSubCode method, getSubCode method returns null",

+                soap12FaultSubCodeInSubCode.getSubCode() == null);

+        try {

+            soap12FaultSubCodeInSubCode.setSubCode(

+                    soap12Factory.createSOAPFaultSubCode(soap12FaultCode));

+        } catch (SOAPProcessingException e) {

+            fail(

+                    "SOAP 1.2 SOAPFaultSubCode Test In FaultSubCode : - FaultSubCode whose parent is FaultCode should not be set in to FaultSubCode, as a child");

+        }

+    }

+

+    public void testGetSubCodeInFaultSubCode() {

+        assertTrue(

+                "After creating SOAP12FaultSubCode In Fault SubCode, it has a FaultSubCode",

+                soap12FaultSubCodeInSubCode.getSubCode() == null);

+        soap12FaultSubCodeInSubCode.setSubCode(

+                soap12Factory.createSOAPFaultSubCode(

+                        soap12FaultSubCodeInSubCode));

+        assertFalse(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultSubCode : - After calling setSubCode method, getSubCode method returns null",

+                soap12FaultSubCodeInSubCode.getSubCode() == null);

+    }

+

+    //SOAP Fault SubCode(In Fault Code) Test (With Parser)

+    public void testGetValueInFaultCodeWithParser() {

+        assertFalse(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultCode With Parser : - getValue method returns null",

+                soap12FaultSubCodeInFaultCodeWithParser.getValue() == null);

+        assertTrue(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultCode With Parser : - Value text mismatch",

+                soap12FaultSubCodeInFaultCodeWithParser.getValue().getText()

+                .equals("m:MessageTimeout In First Subcode"));

+    }

+

+    public void testGetSubCodeInFaultCodeWithParser() {

+        assertFalse(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultCode With Parser : - getSubCode method returns null",

+                soap12FaultSubCodeInFaultCodeWithParser.getSubCode() == null);

+        assertTrue(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultCode With Parser : - SubCode local name mismatch",

+                soap12FaultSubCodeInFaultCodeWithParser.getSubCode()

+                .getLocalName()

+                .equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));

+    }

+

+    //SOAP Fault SubCode(In Fault SubCode) Test (With Parser)

+    public void testGetValueInFaultSubCodeWithParser() {

+        assertFalse(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultSubCode With Parser : - getValue method returns null",

+                soap12FaultSubCodeInSubCodeWithParser.getValue() == null);

+        assertTrue(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultSubCode With Parser : - Value text mismatch",

+                soap12FaultSubCodeInSubCodeWithParser.getValue().getText()

+                .equals("m:MessageTimeout In Second Subcode"));

+    }

+

+    public void testGetSubCodeInFaultSubCodeWithParser() {

+        assertFalse(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultSubCode With Parser : - getSubCode method returns null",

+                soap12FaultSubCodeInSubCodeWithParser.getSubCode() == null);

+        assertTrue(

+                "SOAP 1.2 SOAPFaultSubCode Test In FaultSubCode With Parser : - SubCode local name mismatch",

+                soap12FaultSubCodeInSubCodeWithParser.getSubCode()

+                .getLocalName()

+                .equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultSubCodeTestCase.java b/test/org/apache/ws/commons/soap/SOAPFaultSubCodeTestCase.java
new file mode 100644
index 0000000..1e5c859
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultSubCodeTestCase.java
@@ -0,0 +1,62 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public class SOAPFaultSubCodeTestCase extends SOAPFaultCodeTestCase {

+    protected SOAPFaultValue soap11FaultValue;

+    protected SOAPFaultValue soap12FaultValueInFaultCode;

+    protected SOAPFaultSubCode soap12FaultSubCodeInCode;

+

+    protected SOAPFaultValue soap12FaultValueInFaultSubCode;

+    protected SOAPFaultSubCode soap12FaultSubCodeInSubCode;

+

+    protected SOAPFaultValue soap11FaultValueWithParser;

+    protected SOAPFaultValue soap12FaultValueInFaultCodeWithParser;

+    protected SOAPFaultSubCode soap12FaultSubCodeInFaultCodeWithParser;

+

+    protected SOAPFaultValue soap12FaultValueInFaultSubCodeWithParser;

+    protected SOAPFaultSubCode soap12FaultSubCodeInSubCodeWithParser;

+

+    public SOAPFaultSubCodeTestCase(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11FaultValue = soap11Factory.createSOAPFaultValue(soap11FaultCode);

+

+        soap12FaultValueInFaultCode =

+                soap12Factory.createSOAPFaultValue(soap12FaultCode);

+        soap12FaultSubCodeInCode =

+                soap12Factory.createSOAPFaultSubCode(soap12FaultCode);

+

+

+        soap12FaultSubCodeInSubCode =

+                soap12Factory.createSOAPFaultSubCode(soap12FaultSubCodeInCode);

+

+        soap11FaultValueWithParser = soap11FaultCodeWithParser.getValue();

+        soap12FaultValueInFaultCodeWithParser =

+                soap12FaultCodeWithParser.getValue();

+        soap12FaultSubCodeInFaultCodeWithParser =

+                soap12FaultCodeWithParser.getSubCode();

+

+        soap12FaultValueInFaultSubCodeWithParser =

+                soap12FaultSubCodeInFaultCodeWithParser.getValue();

+        soap12FaultSubCodeInSubCodeWithParser =

+                soap12FaultSubCodeInFaultCodeWithParser.getSubCode();

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultTest.java b/test/org/apache/ws/commons/soap/SOAPFaultTest.java
new file mode 100644
index 0000000..3bec61b
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultTest.java
@@ -0,0 +1,416 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+

+public class SOAPFaultTest extends SOAPFaultTestCase {

+

+    public SOAPFaultTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+    }

+

+    //SOAP 1.1 Fault Test (Programaticaly created)-----------------------------------------------------------------------------------

+    public void testSOAP11SetCode() {

+        soap11Fault.setCode(soap11Factory.createSOAPFaultCode(soap11Fault));

+        assertNotNull(

+                "SOAP 1.1 Fault Test:- After calling setCode method, Fault has no code",

+                soap11Fault.getCode());

+        try {

+            soap11Fault.setCode(soap12Factory.createSOAPFaultCode(soap12Fault));

+            fail("SOAP12FaultCode should not not be set in to a SOAP11Fault");

+        } catch (Exception e) {

+        }

+    }

+

+    public void testSOAP11GetCode() {

+        assertTrue(

+                "SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a code",

+                soap11Fault.getCode() == null);

+        soap11Fault.setCode(soap11Factory.createSOAPFaultCode(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setCode method, Fault has no code",

+                soap11Fault.getCode() == null);

+    }

+

+    public void testSOAP11SetReason() {

+        soap11Fault.setReason(soap11Factory.createSOAPFaultReason(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setReason method, Fault has no reason",

+                soap11Fault.getReason() == null);

+        try {

+            soap11Fault.setReason(

+                    soap12Factory.createSOAPFaultReason(soap12Fault));

+            fail("SOAP12FaultReason should not be set in to a SOAP11Fault");

+

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP11GetReason() {

+        assertTrue(

+                "SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a reason",

+                soap11Fault.getReason() == null);

+        soap11Fault.setReason(soap11Factory.createSOAPFaultReason(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setReason method, Fault has no reason",

+                soap11Fault.getReason() == null);

+    }

+

+    public void testSOAP11SetNode() {

+        soap11Fault.setNode(soap11Factory.createSOAPFaultNode(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setNode method, Fault has no node",

+                soap11Fault.getNode() == null);

+        try {

+            soap11Fault.setNode(soap12Factory.createSOAPFaultNode(soap12Fault));

+            fail("SOAP12FaultNode should not be set in to a SOAP11Fault");

+

+        } catch (Exception e) {

+            assertTrue(true);

+

+        }

+    }

+

+    public void testSOAP11GetNode() {

+        assertTrue(

+                "SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a node",

+                soap11Fault.getNode() == null);

+        soap11Fault.setNode(soap11Factory.createSOAPFaultNode(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setNode method, Fault has no node",

+                soap11Fault.getNode() == null);

+    }

+

+    public void testSOAP11SetRole() {

+        soap11Fault.setRole(soap11Factory.createSOAPFaultRole(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setRole method, Fault has no role",

+                soap11Fault.getRole() == null);

+        try {

+            soap11Fault.setRole(soap12Factory.createSOAPFaultRole(soap12Fault));

+            fail("SOAP12FaultRole should not be set in to a SOAP11Fault");

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP11GetRole() {

+        assertTrue(

+                "SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a role",

+                soap11Fault.getRole() == null);

+        soap11Fault.setRole(soap11Factory.createSOAPFaultRole(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setRole method, Fault has no role",

+                soap11Fault.getRole() == null);

+    }

+

+    public void testSOAP11SetDetail() {

+        soap11Fault.setDetail(soap11Factory.createSOAPFaultDetail(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setDetail method, Fault has no detail",

+                soap11Fault.getDetail() == null);

+        try {

+            soap11Fault.setDetail(

+                    soap12Factory.createSOAPFaultDetail(soap12Fault));

+            fail("SOAP12FaultDetail should not be set in to a SOAP11Fault");

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP11GetDetail() {

+        assertTrue(

+                "SOAP 1.1 Fault Test:- After creating a SOAP11Fault, it has a detail",

+                soap11Fault.getDetail() == null);

+        soap11Fault.setDetail(soap11Factory.createSOAPFaultDetail(soap11Fault));

+        assertFalse(

+                "SOAP 1.1 Fault Test:- After calling setDetail method, Fault has no detail",

+                soap11Fault.getDetail() == null);

+    }

+

+    //SOAP 1.2 Fault Test ((Programaticaly created)--------------------------------------------------------------------------------

+    public void testSOAP12SetCode() {

+        soap12Fault.setCode(soap12Factory.createSOAPFaultCode(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setCode method, Fault has no code",

+                soap12Fault.getCode() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Code local name mismatch",

+                soap12Fault.getCode().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));

+        try {

+            soap12Fault.setCode(soap11Factory.createSOAPFaultCode(soap11Fault));

+            fail("SOAP11FaultCode should not be set in to a SOAP12Fault");

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP12GetCode() {

+        assertTrue(

+                "SOAP 1.2 Fault Test:- After creating a SOAP12Fault, it has a code",

+                soap12Fault.getCode() == null);

+        soap12Fault.setCode(soap12Factory.createSOAPFaultCode(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setCode method, Fault has no code",

+                soap12Fault.getCode() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault code local name mismatch",

+                soap12Fault.getCode().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));

+    }

+

+    public void testSOAP12SetReason() {

+        soap12Fault.setReason(soap12Factory.createSOAPFaultReason(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setReason method, Fault has no reason",

+                soap12Fault.getReason() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault reason local name mismatch",

+                soap12Fault.getReason().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));

+        try {

+            soap12Fault.setReason(

+                    soap11Factory.createSOAPFaultReason(soap11Fault));

+            fail("SOAP11FaultReason should not be set in to a SOAP12Fault");

+

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP12GetReason() {

+        assertTrue(

+                "SOAP 1.2 Fault Test:- After creating a SOAP12Fault, it has a reason",

+                soap12Fault.getReason() == null);

+        soap12Fault.setReason(soap12Factory.createSOAPFaultReason(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setReason method, Fault has no reason",

+                soap12Fault.getReason() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault reason local name mismatch",

+                soap12Fault.getReason().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));

+    }

+

+    public void testSOAP12SetNode() {

+        soap12Fault.setNode(soap12Factory.createSOAPFaultNode(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setNode method, Fault has no node",

+                soap12Fault.getNode() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault node local name mismatch",

+                soap12Fault.getNode().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));

+        try {

+            soap12Fault.setNode(soap11Factory.createSOAPFaultNode(soap11Fault));

+            fail("SOAP11FaultNode should nott be set in to a SOAP12Fault");

+

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP12GetNode() {

+        assertTrue(

+                "SOAP 1.2 Fault Test:- After creating a SOAP12Fault, it has a node",

+                soap12Fault.getNode() == null);

+        soap12Fault.setNode(soap12Factory.createSOAPFaultNode(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setNode method, Fault has no node",

+                soap12Fault.getNode() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault node local name mismatch",

+                soap12Fault.getNode().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));

+    }

+

+    public void testSOAP12SetRole() {

+        soap12Fault.setRole(soap12Factory.createSOAPFaultRole(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 :- After calling setRole method, Fault has no role",

+                soap12Fault.getRole() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault role local name mismatch",

+                soap12Fault.getRole().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));

+        try {

+            soap12Fault.setRole(soap11Factory.createSOAPFaultRole(soap11Fault));

+            fail("SOAP11FaultRole should not be set in to a SOAP12Fault");

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP12GetRole() {

+        assertTrue(

+                "SOAP 1.2 Fault Test:- After creating a SOAP11Fault, it has a role",

+                soap12Fault.getRole() == null);

+        soap12Fault.setRole(soap12Factory.createSOAPFaultRole(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setRole method, Fault has no role",

+                soap12Fault.getRole() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault role local name mismatch",

+                soap12Fault.getRole().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));

+    }

+

+    public void testSOAP12SetDetail() {

+        soap12Fault.setDetail(soap12Factory.createSOAPFaultDetail(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setDetaile method, Fault has no detail",

+                soap12Fault.getDetail() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault detail local name mismatch",

+                soap12Fault.getDetail().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));

+        try {

+            soap12Fault.setDetail(

+                    soap11Factory.createSOAPFaultDetail(soap11Fault));

+            fail("SOAP11FaultDetail should not be set in to a SOAP12Fault");

+

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP12GetDetail() {

+        assertTrue(

+                "SOAP 1.2 Fault Test:- After creating a SOAP12Fault, it has a detail",

+                soap12Fault.getDetail() == null);

+        soap12Fault.setDetail(soap12Factory.createSOAPFaultDetail(soap12Fault));

+        assertFalse(

+                "SOAP 1.2 Fault Test:- After calling setDetail method, Fault has no detail",

+                soap12Fault.getDetail() == null);

+        assertTrue("SOAP 1.2 Fault Test:- Fault detail local name mismatch",

+                soap12Fault.getDetail().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));

+    }

+

+    //SOAP 1.1 Fault Test (With parser)

+    public void testSOAP11GetCodeWithParser() {

+        assertFalse(

+                "SOAP 1.1 Fault Test with parser: - getCode method returns null",

+                soap11FaultWithParser.getCode() == null);

+    }

+

+    public void testSOAP11GetRoleWithParser() {

+        assertFalse(

+                "SOAP 1.1 Fault Test with parser: - getRole method returns null",

+                soap11FaultWithParser.getRole() == null);

+    }

+

+    public void testSOAP11GetDetailWithParser() {

+        assertFalse(

+                "SOAP 1.1 Fault Test with parser: - getDetail method returns null",

+                soap11FaultWithParser.getDetail() == null);

+    }

+

+    //SOAP 1.2 Fault Test (With parser)

+    public void testSOAP12GetCodeWithParser() {

+        assertFalse(

+                "SOAP 1.2 Fault Test with parser: - getCode method returns null",

+                soap12FaultWithParser.getCode() == null);

+        assertTrue(

+                "SOAP 1.2 Fault Test with parser: - Fault code local name mismatch",

+                soap12FaultWithParser.getCode().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));

+    }

+

+    public void testSOAP12GetReasonWithParser() {

+        assertFalse(

+                "SOAP 1.2 Fault Test with parser: - getReason method returns null",

+                soap12FaultWithParser.getReason() == null);

+        assertTrue(

+                "SOAP 1.2 Fault Test with parser: - Fault reason local name mismatch",

+                soap12FaultWithParser.getReason().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));

+    }

+

+    public void testSOAP12GetNodeWithParser() {

+        assertFalse(

+                "SOAP 1.2 Fault Test with parser: - getNode method returns null",

+                soap12FaultWithParser.getNode() == null);

+        assertTrue(

+                "SOAP 1.2 Fault Test with parser: - Fault node local name mismatch",

+                soap12FaultWithParser.getNode().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));

+    }

+

+    public void testSOAP12GetRoleWithParser() {

+        assertFalse(

+                "SOAP 1.2 Fault Test with parser: - getRole method returns null",

+                soap12FaultWithParser.getRole() == null);

+        assertTrue(

+                "SOAP 1.2 Fault Test with parser: - Fault role local name mismatch",

+                soap12FaultWithParser.getRole().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));

+    }

+

+    public void testSOAP12GetDetailWithParser() {

+        assertFalse(

+                "SOAP 1.2 Fault Test with parser: - getDetail method returns null",

+                soap12FaultWithParser.getDetail() == null);

+        assertTrue(

+                "SOAP 1.2 Fault Test with parser: - Fault detail local name mismatch",

+                soap12FaultWithParser.getDetail().getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));

+    }

+

+    public void testMoreChildrenAddition() {

+        try {

+            SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

+            SOAPEnvelope envelope = soapFactory.getDefaultFaultEnvelope();

+

+            assertNotNull("Default FaultEnvelope must have a SOAPFault in it",

+                    envelope.getBody().getFault());

+            assertNotNull(

+                    "Default FaultEnvelope must have a SOAPFaultCode in it",

+                    envelope.getBody().getFault().getCode());

+            assertNotNull(

+                    "Default FaultEnvelope must have a SOAPFaultCodeValue in it",

+                    envelope.getBody().getFault().getCode().getValue());

+            assertNotNull(

+                    "Default FaultEnvelope must have a SOAPFaultReason in it",

+                    envelope.getBody().getFault().getReason());

+            assertNotNull(

+                    "Default FaultEnvelope must have a SOAPFaultText in it",

+                    envelope.getBody().getFault().getReason().getSOAPText());

+

+            SOAPEnvelope soapEnvelope = soapFactory.getDefaultFaultEnvelope();

+            String errorCodeString = "Some Error occurred !!";

+            soapEnvelope.getBody().getFault().getCode().getValue().setText(

+                    errorCodeString);

+

+            SOAPFaultCode code = soapEnvelope.getBody().getFault().getCode();

+            envelope.getBody().getFault().setCode(code);

+

+            assertTrue("Parent Value of Code has not been set to new fault",

+                    code.getParent() == envelope.getBody().getFault());

+            assertTrue("Parent Value of Code is still pointing to old fault",

+                    code.getParent() != soapEnvelope.getBody().getFault());

+            assertNull("Old fault must not have a fault code",

+                    soapEnvelope.getBody().getFault().getCode());

+            assertEquals("The SOAP Code value must be " + errorCodeString,

+                    errorCodeString,

+                    envelope.getBody().getFault().getCode().getValue().getText());

+

+        } catch (Exception e) {

+            fail(e.getMessage());

+        }

+

+

+    }

+}
\ No newline at end of file
diff --git a/test/org/apache/ws/commons/soap/SOAPFaultTestCase.java b/test/org/apache/ws/commons/soap/SOAPFaultTestCase.java
new file mode 100644
index 0000000..d70d559
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultTestCase.java
@@ -0,0 +1,42 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+

+public class SOAPFaultTestCase extends SOAPBodyTestCase {

+    protected SOAPFault soap11Fault;

+    protected SOAPFault soap12Fault;

+    protected SOAPFault soap11FaultWithParser;

+    protected SOAPFault soap12FaultWithParser;

+

+    public SOAPFaultTestCase(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11Fault =

+                OMAbstractFactory.getSOAP11Factory().createSOAPFault(

+                        soap11Body);

+        soap12Fault =

+                OMAbstractFactory.getSOAP12Factory().createSOAPFault(

+                        soap12Body);

+        soap11FaultWithParser = soap11BodyWithParser.getFault();

+        soap12FaultWithParser = soap12BodyWithParser.getFault();

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultTextTest.java b/test/org/apache/ws/commons/soap/SOAPFaultTextTest.java
new file mode 100644
index 0000000..eda4163
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultTextTest.java
@@ -0,0 +1,177 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMAttribute;

+

+public class SOAPFaultTextTest extends SOAPFaultReasonTestCase {

+    protected SOAPFaultText soap11FaultText;

+    protected SOAPFaultText soap12FaultText;

+    protected SOAPFaultText soap11FaultTextWithParser;

+    protected SOAPFaultText soap12FaultTextWithParser;

+

+    public SOAPFaultTextTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11FaultText = soap11Factory.createSOAPFaultText(soap11FaultReason);

+        soap12FaultText = soap12Factory.createSOAPFaultText(soap12FaultReason);

+        soap11FaultTextWithParser = soap11FaultReasonWithParser.getSOAPText();

+        soap12FaultTextWithParser = soap12FaultReasonWithParser.getSOAPText();

+    }

+

+    //SOAP 1.1 Fault Text Test (Programaticaly Created)

+    public void testSOAP11SetLang() {

+        soap11FaultText.setLang("en");

+        assertTrue(

+                "SOAP 1.1 Fault Text Test : - After calling setLang method, Lang attribute value mismatch",

+                soap11FaultText.getLang().equals("en"));

+        OMAttribute langAttribute = (OMAttribute) soap11FaultText.getAllAttributes()

+                .next();

+        assertTrue(

+                "SOAP 1.1 Fault Text Test : - After calling setLang method, Lang attribute local name mismaatch",

+                langAttribute.getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME));

+        assertTrue(

+                "SOAP 1.1 Fault Text Test : - After calling setLang method, Lang attribute namespace prefix mismatch",

+                langAttribute.getNamespace().getPrefix().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX));

+        assertTrue(

+                "SOAP 1.1 Fault Text Test : - After calling setLang method, Lang attribute namespace uri mismatch",

+                langAttribute.getNamespace().getName().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_URI));

+    }

+

+    public void testSOAP11GetLang() {

+

+

+        assertNull(

+                "SOAP 1.1 Fault Text Test : - After creating SOAPFaultText, it has a Lnag attribute",

+                soap11FaultText.getLang());

+

+        soap11FaultText.setLang("en");

+        assertTrue(

+                "SOAP 1.1 Fault Text Test : - After calling setLang method, Lang attribute value mismatch",

+                soap11FaultText.getLang().equals("en"));

+    }

+

+    public void testSOAP11SetText() {

+        soap11FaultText.setText("This is only a test");

+        assertTrue(

+                "SOAP 1.1 Fault Text Test : - After calling setText method, getText method return incorrect string",

+                soap11FaultText.getText().equals("This is only a test"));

+    }

+

+    public void testSOAP11GetText() {

+        assertTrue(

+                "SOAP 1.1 Fault Text Test : - After creating SOAPFaultText, it has a text",

+                soap11FaultText.getText().equals(""));

+        soap11FaultText.setText("This is only a test");

+        assertTrue(

+                "SOAP 1.1 Fault Text Test : - After calling setText method, getText method return incorrect string",

+                soap11FaultText.getText().equals("This is only a test"));

+    }

+

+    //SOAP 1.2 Fault Text Test (Programaticaly Created)

+    public void testSOAP12SetLang() {

+        soap12FaultText.setLang("en");

+        assertTrue(

+                "SOAP 1.2 Fault Text Test : - After calling setLang method, Lang attribute value mismatch",

+                soap12FaultText.getLang().equals("en"));

+        OMAttribute langAttribute = (OMAttribute) soap12FaultText.getAllAttributes()

+                .next();

+        assertTrue(

+                "SOAP 1.2 Fault Text Test : - After calling setLang method, Lang attribute local name mismaatch",

+                langAttribute.getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME));

+        assertTrue(

+                "SOAP 1.2 Fault Text Test : - After calling setLang method, Lang attribute namespace prefix mismatch",

+                langAttribute.getNamespace().getPrefix().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX));

+        assertTrue(

+                "SOAP 1.2 Fault Text Test : - After calling setLang method, Lang attribute namespace uri mismatch",

+                langAttribute.getNamespace().getName().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_URI));

+    }

+

+    public void testSOAP12GetLang() {

+

+        assertNull(

+                "SOAP 1.2 Fault Text Test : - After creating SOAPFaultText, it has a Lnag attribute",

+                soap12FaultText.getLang());

+

+        soap12FaultText.setLang("en");

+        assertTrue(

+                "SOAP 1.2 Fault Text Test : - After calling setLang method, Lang attribute value mismatch",

+                soap12FaultText.getLang().equals("en"));

+    }

+

+    public void testSOAP12SetText() {

+        soap12FaultText.setText("This is only a test");

+        assertTrue(

+                "SOAP 1.2 Fault Text Test : - After calling setText method, getText method return incorrect string",

+                soap12FaultText.getText().equals("This is only a test"));

+    }

+

+    public void testSOAP12GetText() {

+        assertTrue(

+                "SOAP 1.2 Fault Text Test : - After creating SOAPFaultText, it has a text",

+                soap12FaultText.getText().equals(""));

+        soap12FaultText.setText("This is only a test");

+        assertTrue(

+                "SOAP 1.2 Fault Text Test : - After calling setText method, getText method return incorrect string",

+                soap12FaultText.getText().equals("This is only a test"));

+    }

+

+    //SOAP 1.1 Fault Text Test (With Parser)

+    public void testSOAP11GetTextWithParser() {

+        assertTrue(

+                "SOAP 1.1 Fault Text Test With Parser : - getText method returns incorrect string",

+                soap11FaultTextWithParser.getText().trim().equals("Sender Timeout"));

+    }

+

+    //SOAP 1.2 Fault Text Test (With Parser)

+    public void testSOAP12GetLangWithParser() {

+        assertTrue(

+                "SOAP 1.2 Fault Text Test With Parser : - getLang method returns incorrect string",

+                soap12FaultTextWithParser.getLang().equals("en"));

+        OMAttribute langAttribute = (OMAttribute) soap12FaultTextWithParser.getAllAttributes()

+                .next();

+        assertTrue(

+                "SOAP 1.2 Fault Text Test With Parser : - Lang attribute local name mismaatch",

+                langAttribute.getLocalName().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_LOCAL_NAME));

+        assertTrue(

+                "SOAP 1.2 Fault Text Test With Parser : - Lang attribute namespace prefix mismatch",

+                langAttribute.getNamespace().getPrefix().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_PREFIX));

+        assertTrue(

+                "SOAP 1.2 Fault Text Test With Parser : - Lang attribute namespace uri mismatch",

+                langAttribute.getNamespace().getName().equals(

+                        SOAP12Constants.SOAP_FAULT_TEXT_LANG_ATTR_NS_URI));

+    }

+

+    public void testSOAP12GetTextWithParser() {

+    	

+        assertTrue(

+                "SOAP 1.2 Fault Text Test With Parser : - getText method returns incorrect string",

+                soap12FaultTextWithParser.getText().equals("Sender Timeout"));

+        													

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPFaultValueTest.java b/test/org/apache/ws/commons/soap/SOAPFaultValueTest.java
new file mode 100644
index 0000000..009f080
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPFaultValueTest.java
@@ -0,0 +1,118 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+public class SOAPFaultValueTest extends SOAPFaultSubCodeTestCase {

+

+    public SOAPFaultValueTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap12FaultValueInFaultSubCode =

+                soap12Factory.createSOAPFaultValue(soap12FaultSubCodeInCode);

+    }

+

+    //SOAP 1.1 Fault Value Test (Programaticaly Created)

+    public void testSOAP11setText() {

+        soap11FaultValue.setText("This is only Test");

+        assertTrue("SOAP 1.1 Fault Value Test : - value text mismatch",

+                soap11FaultValue.getText().equals("This is only Test"));

+    }

+

+    public void testSOAP11GetText() {

+        assertTrue(

+                "SOAP 1.1 Fault Value Test : - After creating Fault Value, it has a text",

+                soap11FaultValue.getText().equals(""));

+        soap11FaultValue.setText("This is only Test");

+        assertFalse(

+                "SOAP 1.1 Fault Value Test : - After calling setText method, getText method returns null",

+                soap11FaultValue.getText().equals(""));

+        assertTrue("SOAP 1.1 Fault Value Test : - value text mismatch",

+                soap11FaultValue.getText().equals("This is only Test"));

+    }

+

+    //SOAP 1.2 Fault Value(In Fault Code) Test (Programaticaly Created)

+    public void testSOAP12setTextInFaultCode() {

+        soap12FaultValueInFaultCode.setText("This is only Test");

+        assertTrue(

+                "SOAP 1.2 Fault Value Test in Fault Code : - value text mismatch",

+                soap12FaultValueInFaultCode.getText().equals(

+                        "This is only Test"));

+    }

+

+    public void testSOAP12GetTextInFaultCode() {

+        assertTrue(

+                "SOAP 1.2 Fault Value Test in Fault Code : - After creating Fault Value, it has a text",

+                soap12FaultValueInFaultCode.getText().equals(""));

+        soap12FaultValueInFaultCode.setText("This is only Test");

+        assertFalse(

+                "SOAP 1.2 Fault Value Test in Fault Code : - After calling setText method, getText method returns null",

+                soap12FaultValueInFaultCode.getText().equals(""));

+        assertTrue(

+                "SOAP 1.2 Fault Value Test in Fault Code : - value text mismatch",

+                soap12FaultValueInFaultCode.getText().equals(

+                        "This is only Test"));

+    }

+

+    //SOAP 1.2 Fault Value(In Fault SubCode) Test (Programaticaly Created)

+    public void testSOAP12setTextInFaultSubCode() {

+        soap12FaultValueInFaultSubCode.setText("This is only Test");

+        assertTrue(

+                "SOAP 1.2 Fault Value Test in Fault SubCode : - value text mismatch",

+                soap12FaultValueInFaultSubCode.getText().equals(

+                        "This is only Test"));

+    }

+

+    public void testSOAP12GetTextInFaultSubCode() {

+        assertTrue(

+                "SOAP 1.2 Fault Value Test in Fault SubCode : - After creating Fault Value, it has a text",

+                soap12FaultValueInFaultSubCode.getText().equals(""));

+        soap12FaultValueInFaultSubCode.setText("This is only Test");

+        assertFalse(

+                "SOAP 1.2 Fault Value Test in Fault SubCode : - After calling setText method, getText method returns null",

+                soap12FaultValueInFaultSubCode.getText().equals(""));

+        assertTrue(

+                "SOAP 1.2 Fault Value Test in Fault SubCode : - value text mismatch",

+                soap12FaultValueInFaultSubCode.getText().equals(

+                        "This is only Test"));

+    }

+

+    //SOAP 1.1 Fault Value Test (With Parser)

+    public void testSOAP11GetTextWithParser() {

+        assertTrue(

+                "SOAP 1.1 Fault Value Test with parser : - value text mismatch",

+                soap11FaultValueWithParser.getText().trim().equals("env:Sender"));

+    }

+

+    //SOAP 1.2 Fault Value(In Fault Code) Test (With Parser)

+    public void testSOAP12setTextWithParserInFaultCode() {

+        assertTrue(

+                "SOAP 1.2 Fault Value Test with parser in Fault Code : - value text mismatch",

+                soap12FaultValueInFaultCodeWithParser.getText().equals(

+                        "env:Sender"));

+    }

+

+    //SOAP 1.2 Fault Value(In Fault SubCode) Test (With Parser)

+    public void testSOAP12setTextWithParserInFaultSubCode() {

+        assertTrue(

+                "SOAP 1.2 Fault Value Test with parser in Fault SubCode : - value text mismatch",

+                soap12FaultValueInFaultSubCodeWithParser.getText().equals(

+                        "m:MessageTimeout In First Subcode"));

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPHeaderBlockTest.java b/test/org/apache/ws/commons/soap/SOAPHeaderBlockTest.java
new file mode 100644
index 0000000..aba3b7f
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPHeaderBlockTest.java
@@ -0,0 +1,238 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import java.util.Iterator;

+

+public class SOAPHeaderBlockTest extends SOAPHeaderTestCase {

+    protected SOAPHeaderBlock soap11HeaderBlock;

+    protected SOAPHeaderBlock soap12HeaderBlock;

+    protected SOAPHeaderBlock soap11HeaderBlock1WithParser;

+    protected SOAPHeaderBlock soap12HeaderBlock1WithParser;

+    protected SOAPHeaderBlock soap11HeaderBlock2WithParser;

+    protected SOAPHeaderBlock soap12HeaderBlock2WithParser;

+    protected SOAPHeaderBlock soap11HeaderBlock3WithParser;

+    protected SOAPHeaderBlock soap12HeaderBlock3WithParser;

+

+    public SOAPHeaderBlockTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11HeaderBlock =

+                soap11Factory.createSOAPHeaderBlock("testHeaderBlock",

+                        namespace,

+                        soap11Header);

+        soap12HeaderBlock =

+                soap12Factory.createSOAPHeaderBlock("testHeaderBlock",

+                        namespace,

+                        soap12Header);

+        Iterator iterator = soap11HeaderWithParser.examineAllHeaderBlocks();

+        iterator.next();

+        soap11HeaderBlock1WithParser = (SOAPHeaderBlock) iterator.next();

+        iterator.next();

+        soap11HeaderBlock2WithParser = (SOAPHeaderBlock) iterator.next();

+        iterator.next();

+        soap11HeaderBlock3WithParser = (SOAPHeaderBlock) iterator.next();

+

+        iterator = soap12HeaderWithParser.examineAllHeaderBlocks();

+        iterator.next();

+        soap12HeaderBlock1WithParser = (SOAPHeaderBlock) iterator.next();

+        iterator.next();

+        soap12HeaderBlock2WithParser = (SOAPHeaderBlock) iterator.next();

+        iterator.next();

+        soap12HeaderBlock3WithParser = (SOAPHeaderBlock) iterator.next();

+    }

+

+    //SOAP 1.1 SOAPHeaderBlock Test (Programaticaly Created)

+    public void testSOAP11SetRole() {

+        soap11HeaderBlock.setRole(

+                "http://schemas.xmlsoap.org/soap/envelope/actor/next");

+        assertTrue(

+                "SOAP 1.1 HeaderBlock Test : - After calling setRole method, getRole method returns incorrect role value",

+                soap11HeaderBlock.getRole().equals(

+                        "http://schemas.xmlsoap.org/soap/envelope/actor/next"));

+        try {

+            soap11HeaderBlock.setRole("Any Value");

+        } catch (Exception e) {

+            fail(

+                    "SOAP 1.1 HeaderBlock Test : - role value can not be set to any value");

+        }

+    }

+

+    public void testSOAP11GetRole() {

+        assertTrue(

+                "SOAP 1.1 HeaderBlock Test : - After creating SOAPHeaderBlock, it has a role",

+                soap11HeaderBlock.getRole() == null);

+        soap11HeaderBlock.setRole(

+                "http://schemas.xmlsoap.org/soap/envelope/actor/next");

+        assertTrue(

+                "SOAP 1.1 HeaderBlock Test : - After calling setRole method, getRole method returns incorrect role value",

+                soap11HeaderBlock.getRole().equals(

+                        "http://schemas.xmlsoap.org/soap/envelope/actor/next"));

+    }

+

+    public void testSOAP11SetMustUnderstand() {

+        soap11HeaderBlock.setMustUnderstand(true);

+        assertTrue(

+                "SOAP 1.1 HeaderBlock Test : - After setting MustUnderstand true calling setMustUnderstand method , getMustUnderstand method returns false",

+                soap11HeaderBlock.getMustUnderstand());

+        soap11HeaderBlock.setMustUnderstand(false);

+        assertFalse(

+                "SOAP 1.1 HeaderBlock Test : - After setting MustUnderstand false calling setMustUnderstand method , getMustUnderstand method returns true",

+                soap11HeaderBlock.getMustUnderstand());

+        soap11HeaderBlock.setMustUnderstand("1");

+        assertTrue(

+                "SOAP 1.1 HeaderBlock Test : - After setting MustUnderstand \"1\" calling setMustUnderstand method , getMustUnderstand method returns false",

+                soap11HeaderBlock.getMustUnderstand());

+        soap11HeaderBlock.setMustUnderstand("0");

+        assertFalse(

+                "SOAP 1.1 HeaderBlock Test : - After setting MustUnderstand \"0\" calling setMustUnderstand method , getMustUnderstand method returns true",

+                soap11HeaderBlock.getMustUnderstand());

+        try {

+            soap11HeaderBlock.setMustUnderstand("true");

+        } catch (Exception e) {

+            fail(

+                    "SOAP 1.1 HeaderBlock Test : - MustUnderstatnd value can not be set to any value rather than 1 or 0");

+        }

+    }

+

+    public void testSOAP11GetMustUnderstand() {

+        assertFalse(

+                "SOAP 1.1 HeaderBlock Test : - After creating SOAPHeaderBlock, default MustUnderstand value true",

+                soap11HeaderBlock.getMustUnderstand());

+        soap11HeaderBlock.setMustUnderstand(true);

+        assertTrue(

+                "SOAP 1.1 HeaderBlock Test : - After setting MustUnderstand true calling setMustUnderstand method , getMustUnderstand method returns false",

+                soap11HeaderBlock.getMustUnderstand());

+    }

+

+    //SOAP 1.2 SOAPHeaderBlock Test (Programaticaly Created)

+    public void testSOAP12SetRole() {

+        soap12HeaderBlock.setRole(

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test : - After calling setRole method, getRole method returns incorrect role value",

+                soap12HeaderBlock.getRole().equals(

+                        "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));

+        try {

+            soap12HeaderBlock.setRole("Any Value");

+        } catch (Exception e) {

+            fail(

+                    "SOAP 1.2 HeaderBlock Test : - role value can not be set to any value");

+        }

+    }

+

+    public void testSOAP12GetRole() {

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test : - After creating SOAPHeaderBlock, it has a role",

+                soap12HeaderBlock.getRole() == null);

+        soap12HeaderBlock.setRole(

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test : - After calling setRole method, getRole method returns incorrect role value",

+                soap12HeaderBlock.getRole().equals(

+                        "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));

+    }

+

+    public void testSOAP12SetMustUnderstand() {

+        soap12HeaderBlock.setMustUnderstand(true);

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test : - After setting MustUnderstand true calling setMustUnderstand method , getMustUnderstand method returns false",

+                soap12HeaderBlock.getMustUnderstand());

+        soap12HeaderBlock.setMustUnderstand(false);

+        assertFalse(

+                "SOAP 1.2 HeaderBlock Test : - After setting MustUnderstand false calling setMustUnderstand method , getMustUnderstand method returns true",

+                soap12HeaderBlock.getMustUnderstand());

+        soap12HeaderBlock.setMustUnderstand("true");

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test : - After setting MustUnderstand \"true\" calling setMustUnderstand method , getMustUnderstand method returns false",

+                soap12HeaderBlock.getMustUnderstand());

+        soap12HeaderBlock.setMustUnderstand("false");

+        assertFalse(

+                "SOAP 1.2 HeaderBlock Test : - After setting MustUnderstand \"false\" calling setMustUnderstand method , getMustUnderstand method returns true",

+                soap12HeaderBlock.getMustUnderstand());

+        soap12HeaderBlock.setMustUnderstand("1");

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test : - After setting MustUnderstand \"1\" calling setMustUnderstand method , getMustUnderstand method returns false",

+                soap12HeaderBlock.getMustUnderstand());

+        soap12HeaderBlock.setMustUnderstand("0");

+        assertFalse(

+                "SOAP 1.2 HeaderBlock Test : - After setting MustUnderstand \"0\" calling setMustUnderstand method , getMustUnderstand method returns true",

+                soap12HeaderBlock.getMustUnderstand());

+        try {

+            soap12HeaderBlock.setMustUnderstand("otherValue");

+            fail(

+                    "SOAP 1.2 HeaderBlock Test : - MustUnderstatnd value can not be set to any value rather than 1 , 0 , true , false");

+

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+    }

+

+    public void testSOAP12GetMustUnderstand() {

+        assertFalse(

+                "SOAP 1.2 HeaderBlock Test : - After creating SOAPHeaderBlock, default MustUnderstand value true",

+                soap12HeaderBlock.getMustUnderstand());

+        soap12HeaderBlock.setMustUnderstand(true);

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test : - After setting MustUnderstand true calling setMustUnderstand method , getMustUnderstand method returns false",

+                soap12HeaderBlock.getMustUnderstand());

+    }

+

+    //SOAP 1.1 SOAPHeaderBlock Test (With Parser)

+    public void testSOAP11GetRoleWithParser() {

+        assertTrue(

+                "SOAP 1.1 HeaderBlock Test Wiht Parser : - getRole method returns incorrect role value",

+                soap11HeaderBlock1WithParser.getRole().equals(

+                        "http://schemas.xmlsoap.org/soap/actor/next"));

+    }

+

+    public void testSOAP11GetMustUnderstandWithParser() {

+        assertTrue(

+                "SOAP 1.1 HeaderBlock Test Wiht Parser : - getMustUnderstatnd method returns incorrect value",

+                soap11HeaderBlock2WithParser.getMustUnderstand());

+        assertFalse(

+                "SOAP 1.1 HeaderBlock Test Wiht Parser : - getMustUnderstatnd method returns incorrect value",

+                soap11HeaderBlock3WithParser.getMustUnderstand());

+

+    }

+

+    //SOAP 1.2 SOAPHeaderBlock Test (With Parser)

+    public void testSOAP12GetRoleWithParser() {

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test Wiht Parser : - getRole method returns incorrect role value",

+                soap12HeaderBlock1WithParser.getRole().equals(

+                        "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));

+    }

+

+    public void testSOAP12GetMustUnderstandWithParser() {

+        assertTrue(

+                "SOAP 1.2 HeaderBlock Test Wiht Parser : - getMustUnderstatnd method returns incorrect value",

+                soap12HeaderBlock1WithParser.getMustUnderstand());

+        assertFalse(

+                "SOAP 1.2 HeaderBlock Test Wiht Parser : - getMustUnderstatnd method returns incorrect value",

+                soap12HeaderBlock2WithParser.getMustUnderstand());

+        try {

+            soap12HeaderBlock3WithParser.getMustUnderstand();

+        } catch (Exception e) {

+            fail(

+                    "SOAP 1.2 HeaderBlock Test Wiht Parser : - getMustUnderstatnd method should returns exception when mustunderstand value is incorrect");

+        }

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPHeaderTest.java b/test/org/apache/ws/commons/soap/SOAPHeaderTest.java
new file mode 100644
index 0000000..52d610c
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPHeaderTest.java
@@ -0,0 +1,465 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import java.util.ArrayList;

+import java.util.Iterator;

+

+public class SOAPHeaderTest extends SOAPHeaderTestCase {

+    protected boolean isThereException;

+

+    public SOAPHeaderTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+    }

+

+    //SOAP 1.1 Header Test (Programaticaly Created)--------------------------------------------------------------------------------

+    public void testSOAP11AddHeadearBlock() {

+        soap11Header.addHeaderBlock("echoOk1", namespace);

+        soap11Header.addHeaderBlock("echoOk2", namespace);

+        Iterator iterator = soap11Header.getChildren();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, getChildren method returns empty iterator",

+                headerBlock1 == null);

+        assertTrue("SOAP 1.1 Header Test : - HeaderBlock1 local name mismatch",

+                headerBlock1.getLocalName().equals("echoOk1"));

+        assertTrue(

+                "SOAP 1.1 Header Test : - HeaderBlock1 namespace uri mismatch",

+                headerBlock1.getNamespace().getName().equals(

+                        "http://www.example.org"));

+

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, getChildren method returns an iterator with only one object",

+                headerBlock2 == null);

+        assertTrue("SOAP 1.1 Header Test : - HeaderBlock2 local name mismatch",

+                headerBlock2.getLocalName().equals("echoOk2"));

+        assertTrue(

+                "SOAP 1.1 Header Test : - HeaderBlock2 namespace uri mismatch",

+                headerBlock2.getNamespace().getName().equals(

+                        "http://www.example.org"));

+

+        assertTrue(

+                "SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, getChildren method returns an iterator with more than two object",

+                iterator.next() == null);

+    }

+

+    public void testSOAP11ExamineHeaderBlocks() {

+        soap11Header.addHeaderBlock("echoOk1", namespace).setRole(

+                "http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver");

+        soap11Header.addHeaderBlock("echoOk2", namespace).setRole(

+                "http://schemas.xmlsoap.org/soap/envelope/actor/next");

+        Iterator iterator = soap11Header.examineHeaderBlocks(

+                "http://schemas.xmlsoap.org/soap/envelope/actor/next");

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlockWithRole1 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.1 Header Test : - headerBlockWithRole local name mismatch",

+                headerBlockWithRole1.getLocalName().equals("echoOk2"));

+        assertTrue(

+                "SOAP 1.1 Header Test : - headerBlockWithRole role value mismatch",

+                headerBlockWithRole1.getRole().equals(

+                        "http://schemas.xmlsoap.org/soap/envelope/actor/next"));

+

+

+        assertFalse(

+                "SOAP 1.1 Header Test : - header has three headerBlocks with the given role, but examineHeaderBlocks(String role) method returns an iterator with more than three objects",

+                iterator.hasNext());

+    }

+

+//    public void testSOAP11ExtractHeaderBlocks() {

+

+//    }

+

+

+

+    public void testSOAP11ExamineAllHeaderBlocks() {

+        soap11Header.addHeaderBlock("echoOk1", namespace);

+        soap11Header.addHeaderBlock("echoOk2", namespace);

+        Iterator iterator = soap11Header.examineAllHeaderBlocks();

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns empty iterator",

+                headerBlock1 == null);

+        assertTrue("SOAP 1.1 Header Test : - HeaderBlock1 local name mismatch",

+                headerBlock1.getLocalName().equals("echoOk1"));

+        assertTrue(

+                "SOAP 1.1 Header Test : - HeaderBlock1 namespace uri mismatch",

+                headerBlock1.getNamespace().getName().equals(

+                        "http://www.example.org"));

+

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns an iterator with only one object",

+                headerBlock2 == null);

+        assertTrue("SOAP 1.1 Header Test : - HeaderBlock2 local name mismatch",

+                headerBlock2.getLocalName().equals("echoOk2"));

+        assertTrue(

+                "SOAP 1.1 Header Test : - HeaderBlock2 namespace uri mismatch",

+                headerBlock2.getNamespace().getName().equals(

+                        "http://www.example.org"));

+

+        assertFalse(

+                "SOAP 1.1 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns an iterator with more than two object",

+                iterator.hasNext());

+

+    }

+

+//    public void testSOAP11ExtractAllHeaderBlocks() {

+//

+//    }

+

+

+    public void testSOAP11getHeaderBlocksWithNSURI() {

+        soap11Header.addHeaderBlock("echoOk1", namespace);

+        soap11Header.addHeaderBlock("echoOk2",

+                omFactory.createOMNamespace("http://www.test1.org", "test1"));

+        ArrayList arrayList = soap11Header.getHeaderBlocksWithNSURI(

+                "http://www.test1.org");

+        assertTrue(

+                "SOAP 1.1 Header Test : - getHeaderBlocksWithNSURI returns an arrayList of incorrect size",

+                arrayList.size() == 1);

+        assertTrue(

+                "SOAP 1.1 Header Test : - headerBlock of given namespace uri mismatch",

+                ((SOAPHeaderBlock) arrayList.get(0)).getNamespace().getName()

+                .equals("http://www.test1.org"));

+    }

+

+    //SOAP 1.2 Header Test (Programaticaly Created)----------------------------------------------------------------------------------

+    public void testSOAP12AddHeadearBlock() {

+        soap12Header.addHeaderBlock("echoOk1", namespace);

+        soap12Header.addHeaderBlock("echoOk2", namespace);

+        Iterator iterator = soap12Header.getChildren();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Header Test : - After calling addHeaderBlock method, getChildren method returns empty iterator",

+                headerBlock1 == null);

+        assertTrue("SOAP 1.2 Header Test : - HeaderBlock1 local name mismatch",

+                headerBlock1.getLocalName().equals("echoOk1"));

+        assertTrue(

+                "SOAP 1.2 Header Test : - HeaderBlock1 namespace uri mismatch",

+                headerBlock1.getNamespace().getName().equals(

+                        "http://www.example.org"));

+

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Header Test : - After calling addHeaderBlock method, getChildren method returns an iterator with only one object",

+                headerBlock2 == null);

+        assertTrue("SOAP 1.2 Header Test : - HeaderBlock2 local name mismatch",

+                headerBlock2.getLocalName().equals("echoOk2"));

+        assertTrue(

+                "SOAP 1.2 Header Test : - HeaderBlock2 namespace uri mismatch",

+                headerBlock2.getNamespace().getName().equals(

+                        "http://www.example.org"));

+

+        assertTrue(

+                "SOAP 1.2 Header Test : - After calling addHeaderBlock method twice, getChildren method returns an iterator with more than two elements",

+                iterator.next() == null);

+    }

+

+    public void testSOAP12ExamineHeaderBlocks() {

+        soap12Header.addHeaderBlock("echoOk1", namespace);

+        soap12Header.addHeaderBlock("echoOk2", namespace).setRole(

+                "http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver");

+        Iterator iterator = soap12Header.examineHeaderBlocks(

+                "http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver");

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlockWithRole = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.2 Header Test : - headerBlockWithRole local name mismatch",

+                headerBlockWithRole.getLocalName().equals("echoOk2"));

+        assertTrue(

+                "SOAP 1.2 Header Test : - headerBlockWithRole role value mismatch",

+                headerBlockWithRole.getRole().equals(

+                        "http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver"));

+

+        assertFalse(

+                "SOAP 1.2 Header Test : - header has one headerBlock with role, but examineHeaderBlocks(String role) method returns an iterator with more than one object",

+                iterator.hasNext());

+

+    }

+

+

+    public void testSOAP12ExamineMustUnderstandHeaderBlocks() {

+        soap12Header.addHeaderBlock("echoOk1", namespace).setRole(

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+

+        SOAPHeaderBlock headerBlock1 = soap12Header.addHeaderBlock("echoOk2",

+                namespace);

+        headerBlock1.setRole(

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+        headerBlock1.setMustUnderstand(true);

+

+        soap12Header.addHeaderBlock("echoOk3", namespace).setMustUnderstand(

+                true);

+

+        Iterator iterator = soap12Header.examineMustUnderstandHeaderBlocks(

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Header Test : - examineMustUnderstandHeaderBlocks method returns empty iterator",

+                headerBlock == null);

+        assertTrue("SOAP 1.2 Header Test : - HeaderBlock local name mismatch",

+                headerBlock.getLocalName().equals("echoOk2"));

+        assertTrue("SOAP 1.2 Header Test : - HeaderBlock role value mismatch",

+                headerBlock.getRole().equals(

+                        "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));

+        assertFalse(

+                "SOAP 1.2 Header Test : - examineMustUnderstandHeaderBlocks method returns an iterator with more than one object",

+                iterator.hasNext());

+    }

+

+    public void testSOAP12ExamineAllHeaderBlocks() {

+        soap12Header.addHeaderBlock("echoOk1", namespace);

+        soap12Header.addHeaderBlock("echoOk2", namespace);

+        Iterator iterator = soap12Header.examineAllHeaderBlocks();

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns empty iterator",

+                headerBlock1 == null);

+        assertTrue("SOAP 1.2 Header Test : - HeaderBlock1 local name mismatch",

+                headerBlock1.getLocalName().equals("echoOk1"));

+        assertTrue(

+                "SOAP 1.2 Header Test : - HeaderBlock1 namespace uri mismatch",

+                headerBlock1.getNamespace().getName().equals(

+                        "http://www.example.org"));

+

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertFalse(

+                "SOAP 1.2 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns an iterator with only one object",

+                headerBlock2 == null);

+        assertTrue("SOAP 1.2 Header Test : - HeaderBlock2 local name mismatch",

+                headerBlock2.getLocalName().equals("echoOk2"));

+        assertTrue(

+                "SOAP 1.2 Header Test : - HeaderBlock2 namespace uri mismatch",

+                headerBlock2.getNamespace().getName().equals(

+                        "http://www.example.org"));

+

+        assertFalse(

+                "SOAP 1.2 Header Test : - After calling addHeaderBlock method twice, examineAllHeaderBlocks method returns an iterator with more than two object",

+                iterator.hasNext());

+    }

+//    public void testSOAP12ExtractAllHeaderBlocks() {

+//

+//    }

+

+    public void testSOAP12getHeaderBlocksWithNSURI() {

+        soap12Header.addHeaderBlock("echoOk1", namespace);

+        soap12Header.addHeaderBlock("echoOk2",

+                omFactory.createOMNamespace("http://www.test1.org", "test1"));

+        ArrayList arrayList = soap12Header.getHeaderBlocksWithNSURI(

+                "http://www.test1.org");

+        assertTrue(

+                "SOAP 1.2 Header Test : - getHeaderBlocksWithNSURI returns an arrayList of incorrect size",

+                arrayList.size() == 1);

+        assertTrue(

+                "SOAP 1.2 Header Test : - headerBlock of given namespace uri, mismatch",

+                ((SOAPHeaderBlock) arrayList.get(0)).getNamespace().getName()

+                .equals("http://www.test1.org"));

+    }

+

+    //SOAP 1.1 Header Test (With Parser)---------------------------------------------------------------------------------------------

+    public void testSOAP11ExamineHeaderBlocksWithParser() {

+        Iterator iterator = soap11HeaderWithParser.examineHeaderBlocks(

+                "http://schemas.xmlsoap.org/soap/actor/next");

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertEquals(

+                "SOAP 1.1 Header Test With Parser : - headerBlock1 localname mismatch",

+                headerBlock1.getLocalName(),

+                "From");

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock1 role value mismatch",

+                headerBlock1.getRole().equals(

+                        "http://schemas.xmlsoap.org/soap/actor/next"));

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock2 localname mmismatch",

+                headerBlock2.getLocalName().equals("MessageID"));

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock2 role value mmismatch",

+                headerBlock2.getRole().equals(

+                        "http://schemas.xmlsoap.org/soap/actor/next"));

+

+        assertFalse(

+                "SOAP 1.1 Header Test With Parser : - examineHeaderBlocks(String role) method returns an iterator with more than two objects",

+                iterator.hasNext());

+    }

+

+    public void testSOAP11ExamineMustUnderstandHeaderBlocksWithParser() {

+        Iterator iterator = soap11HeaderWithParser.examineMustUnderstandHeaderBlocks(

+                "http://schemas.xmlsoap.org/soap/actor/next");

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock1 localname mmismatch",

+                headerBlock1.getLocalName().equals("MessageID"));

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock1 role value mmismatch",

+                headerBlock1.getRole().equals(

+                        "http://schemas.xmlsoap.org/soap/actor/next"));

+

+        assertFalse(

+                "SOAP 1.1 Header Test With Parser : - examineMustUnderstandHeaderBlocks(String role) method returns an iterator with more than one objects",

+                iterator.hasNext());

+    }

+

+    public void testSOAP11ExamineAllHeaderBlocksWithParser() {

+        Iterator iterator = soap11HeaderWithParser.examineAllHeaderBlocks();

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock1 localname mmismatch",

+                headerBlock1.getLocalName().equals("From"));

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock1 localname mmismatch",

+                headerBlock2.getLocalName().equals("MessageID"));

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock3 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock1 localname mmismatch",

+                headerBlock3.getLocalName().equals("To"));

+

+        assertFalse(

+                "SOAP 1.1 Header Test With Parser : - examineAllHeaderBlocks method returns an iterator with more than three objects",

+                iterator.hasNext());

+    }

+

+    public void testSOAP11getHeaderBlocksWithNSURIWithParser() {

+        ArrayList arrayList = soap11HeaderWithParser.getHeaderBlocksWithNSURI(

+                "http://example.org/ts-tests");

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - getHeaderBlocksWithNSURI returns an arrayList of incorrect size",

+                arrayList.size() == 1);

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock of given namespace uri, local name mismatch",

+                ((SOAPHeaderBlock) arrayList.get(0)).getLocalName().equals(

+                        "MessageID"));

+        assertTrue(

+                "SOAP 1.1 Header Test With Parser : - headerBlock of given namespace uri, mismatch",

+                ((SOAPHeaderBlock) arrayList.get(0)).getNamespace().getName()

+                .equals("http://example.org/ts-tests"));

+    }

+

+    //SOAP 1.2 Header Test (With Parser)-------------------------------------------------------------------------------------------

+    public void testSOAP12ExamineHeaderBlocksWithParser() {

+        Iterator iterator = soap12HeaderWithParser.examineHeaderBlocks(

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock1 localname mmismatch",

+                headerBlock1.getLocalName().equals("echoOk"));

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock1 role value mmismatch",

+                headerBlock1.getRole().equals(

+                        "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock2 localname mmismatch",

+                headerBlock2.getLocalName().equals("echoOk2"));

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock2 role value mmismatch",

+                headerBlock2.getRole().equals(

+                        "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));

+

+        assertFalse(

+                "SOAP 1.2 Header Test With Parser : - examineHeaderBlocks(String role) method returns an iterator with more than two objects",

+                iterator.hasNext());

+    }

+

+    public void testSOAP12ExamineMustUnderstandHeaderBlocksWithParser() {

+        Iterator iterator = soap12HeaderWithParser.examineMustUnderstandHeaderBlocks(

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertEquals(

+                "SOAP 1.2 Header Test With Parser : - headerBlock localname mmismatch",

+                headerBlock1.getLocalName(),

+                "echoOk");

+        assertEquals(

+                "SOAP 1.2 Header Test With Parser : - headerBlock role value mmismatch",

+                headerBlock1.getRole(),

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+

+        iterator.hasNext();

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertEquals(

+                "SOAP 1.2 Header Test With Parser : - headerBlock localname mmismatch",

+                headerBlock2.getLocalName(),

+                "echoOk2");

+        assertEquals(

+                "SOAP 1.2 Header Test With Parser : - headerBlock role value mmismatch",

+                headerBlock1.getRole(),

+                "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");

+

+        assertFalse(

+                "SOAP 1.2 Header Test With Parser : - examineMustUnderstandHeaderBlocks(String role) method returns an iterator with more than one objects",

+                iterator.hasNext());

+    }

+

+    public void testSOAP12ExamineAllHeaderBlocksWithParser() {

+        Iterator iterator = soap12HeaderWithParser.examineAllHeaderBlocks();

+        iterator.next();

+        SOAPHeaderBlock headerBlock1 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock1 localname mmismatch",

+                headerBlock1.getLocalName().equals("echoOk"));

+        iterator.next();

+        SOAPHeaderBlock headerBlock2 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock1 localname mmismatch",

+                headerBlock2.getLocalName().equals("echoOk1"));

+        iterator.next();

+        SOAPHeaderBlock headerBlock3 = (SOAPHeaderBlock) iterator.next();

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock1 localname mmismatch",

+                headerBlock3.getLocalName().equals("echoOk2"));

+

+        assertFalse(

+                "SOAP 1.2 Header Test With Parser : - examineAllHeaderBlocks method returns an iterator with more than three objects",

+                iterator.hasNext());

+    }

+

+    public void testSOAP12getHeaderBlocksWithNSURIWithParser() {

+        ArrayList arrayList = soap12HeaderWithParser.getHeaderBlocksWithNSURI(

+                "http://example.org/ts-tests");

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - getHeaderBlocksWithNSURI returns an arrayList of incorrect size",

+                arrayList.size() == 1);

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock of given namespace uri, local name mismatch",

+                ((SOAPHeaderBlock) arrayList.get(0)).getLocalName().equals(

+                        "echoOk"));

+        assertTrue(

+                "SOAP 1.2 Header Test With Parser : - headerBlock of given namespace uri, mismatch",

+                ((SOAPHeaderBlock) arrayList.get(0)).getNamespace().getName()

+                .equals("http://example.org/ts-tests"));

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPHeaderTestCase.java b/test/org/apache/ws/commons/soap/SOAPHeaderTestCase.java
new file mode 100644
index 0000000..1f86efb
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPHeaderTestCase.java
@@ -0,0 +1,41 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMNamespace;

+

+public class SOAPHeaderTestCase extends SOAPTestCase {

+    protected SOAPHeader soap11Header;

+    protected SOAPHeader soap12Header;

+    protected SOAPHeader soap11HeaderWithParser;

+    protected SOAPHeader soap12HeaderWithParser;

+    protected OMNamespace namespace;

+

+    public SOAPHeaderTestCase(String testName) {

+        super(testName);

+        namespace =

+                omFactory.createOMNamespace("http://www.example.org", "test");

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soap11Header = soap11Factory.createSOAPHeader(soap11Envelope);

+        soap12Header = soap12Factory.createSOAPHeader(soap12Envelope);

+        soap11HeaderWithParser = soap11EnvelopeWithParser.getHeader();

+        soap12HeaderWithParser = soap12EnvelopeWithParser.getHeader();

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPMessageTest.java b/test/org/apache/ws/commons/soap/SOAPMessageTest.java
new file mode 100644
index 0000000..192d596
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPMessageTest.java
@@ -0,0 +1,38 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.OMTestCase;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+public class SOAPMessageTest extends OMTestCase {

+

+    public SOAPMessageTest(String testName) {

+        super(testName);

+    }

+

+    public void testSOAPMessageCreation(){

+        try {

+            StAXSOAPModelBuilder soapBuilder = getOMBuilder("");

+            SOAPMessage soapMessage = soapBuilder.getSoapMessage();

+            assertNotNull(soapMessage);

+            assertNotNull(soapMessage.getSOAPEnvelope());

+        } catch (Exception e) {

+            fail("Exception thrown "+ e);

+        }

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/SOAPTestCase.java b/test/org/apache/ws/commons/soap/SOAPTestCase.java
new file mode 100644
index 0000000..41845f2
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/SOAPTestCase.java
@@ -0,0 +1,84 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import org.apache.ws.commons.om.AbstractTestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import java.io.FileNotFoundException;

+import java.io.FileReader;

+

+public class SOAPTestCase extends AbstractTestCase {

+    protected SOAPFactory soap11Factory;

+    protected SOAPFactory soap12Factory;

+    protected OMFactory omFactory;

+

+    protected SOAPEnvelope soap11Envelope;

+    protected SOAPEnvelope soap12Envelope;

+

+    protected SOAPEnvelope soap11EnvelopeWithParser;

+    protected SOAPEnvelope soap12EnvelopeWithParser;

+

+    protected static final String SOAP11_FILE_NAME = "soap/soap11/soap11message.xml";

+    protected static final String SOAP12_FILE_NAME = "soap/soap12message.xml";

+    private Log log = LogFactory.getLog(getClass());

+    /**

+     * @param testName

+     */

+    public SOAPTestCase(String testName) {

+        super(testName);

+        soap11Factory = OMAbstractFactory.getSOAP11Factory();

+        soap12Factory = OMAbstractFactory.getSOAP12Factory();

+        omFactory = OMAbstractFactory.getOMFactory();

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+

+        soap11Envelope = soap11Factory.createSOAPEnvelope();

+        soap12Envelope = soap12Factory.createSOAPEnvelope();

+

+        soap11EnvelopeWithParser =

+                (SOAPEnvelope) this.getSOAPBuilder(SOAP11_FILE_NAME)

+                .getDocumentElement();

+        soap12EnvelopeWithParser =

+                (SOAPEnvelope) this.getSOAPBuilder(SOAP12_FILE_NAME)

+                .getDocumentElement();

+    }

+

+    protected StAXSOAPModelBuilder getSOAPBuilder(String fileName) {

+        XMLStreamReader parser = null;

+        try {

+            parser =

+                    XMLInputFactory.newInstance().createXMLStreamReader(

+                            new FileReader(getTestResourceFile(fileName)));

+        } catch (XMLStreamException e) {

+            log.info(e.getMessage());

+        } catch (FileNotFoundException e) {

+            log.info(e.getMessage());

+        }

+        return new StAXSOAPModelBuilder(parser, null);

+    }

+

+}

diff --git a/test/org/apache/ws/commons/soap/WrongEnvelopeNamespaceTester.java b/test/org/apache/ws/commons/soap/WrongEnvelopeNamespaceTester.java
new file mode 100644
index 0000000..b987625
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/WrongEnvelopeNamespaceTester.java
@@ -0,0 +1,49 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.impl.llom.builder.StAXBuilder;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.io.FileInputStream;

+import java.io.FileNotFoundException;

+

+public class WrongEnvelopeNamespaceTester extends TestCase {

+    public void testCode() {

+        try {

+            String filename = "test-resources/soap/wrongEnvelopeNamespace.xml";

+            XMLStreamReader xmlr = XMLInputFactory.newInstance()

+                    .createXMLStreamReader(new FileInputStream(filename));

+            StAXBuilder builder = new StAXSOAPModelBuilder(xmlr, null); //exception here

+            fail("Builder must fail here due to wrong SOAP namespace");

+        } catch (SOAPProcessingException e) {

+            assertTrue(true);

+        } catch (FileNotFoundException e) {

+            fail("Only SOAPProcessingException can be thrown here");

+        }catch (Exception e) {

+            fail("Only SOAPProcessingException can be thrown here");

+        }

+    }

+

+    public static void main(String[] args) {

+        WrongEnvelopeNamespaceTester tester = new WrongEnvelopeNamespaceTester();

+        tester.testCode();

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/impl/llom/CharacterEncodingTest.java b/test/org/apache/ws/commons/soap/impl/llom/CharacterEncodingTest.java
new file mode 100644
index 0000000..66f4778
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/impl/llom/CharacterEncodingTest.java
@@ -0,0 +1,140 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMOutputFormat;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFactory;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+import javax.xml.stream.FactoryConfigurationError;

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamException;

+import java.io.ByteArrayInputStream;

+import java.io.ByteArrayOutputStream;

+import java.io.IOException;

+

+

+/**

+ * Test for serialization and deserialization using UTF-16

+ * character encoding 

+ */

+public class CharacterEncodingTest extends TestCase {

+

+	public static final String UTF_16 = "utf-16";

+	

+	public CharacterEncodingTest(String name) {

+		super(name);

+	}

+	

+	public void runTest(String value, String expected) throws XMLStreamException, FactoryConfigurationError, IOException {

+		

+		SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();

+		SOAPEnvelope envelope = factory.getDefaultEnvelope();

+		String ns = "http://testuri.org";

+		OMNamespace namespace = factory.createOMNamespace(ns,"tst");

+		

+		String ln = "Child";

+		

+		OMElement bodyChild = factory.createOMElement(ln,namespace);

+		bodyChild.addChild(factory.createText(value));

+		

+		envelope.getBody().addChild(bodyChild);

+

+

+		ByteArrayOutputStream byteOutStr = new ByteArrayOutputStream();

+		

+		OMOutputFormat outputFormat = new OMOutputFormat();

+        outputFormat.setCharSetEncoding(UTF_16);

+		envelope.serialize(byteOutStr, outputFormat);

+		

+		ByteArrayInputStream byteInStr = new ByteArrayInputStream(byteOutStr.toByteArray());

+		

+		StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(XMLInputFactory.newInstance().createXMLStreamReader(byteInStr, UTF_16),null);

+

+		SOAPEnvelope resultEnv = builder.getSOAPEnvelope();

+		

+		OMElement bodyChildResult = resultEnv.getBody().getFirstElement();

+		

+		assertNotNull("No child in body element", bodyChildResult);

+		

+		String result = bodyChildResult.getText();

+		

+		assertNotNull("No value for testParam param", result);

+		

+		assertEquals("Expected result not received.", expected, result);

+	

+		

+	}

+	

+    private void runtest(String value) throws Exception {

+        runTest(value, value);

+    }

+    

+    public void testSimpleString() throws Exception {

+        runtest("a simple string");

+    }

+    

+    public void testStringWithApostrophes() throws Exception {

+        runtest("this isn't a simple string");

+    }

+    

+    public void testStringWithEntities() throws Exception {

+        runTest("&amp;&lt;&gt;&apos;&quot;", "&amp;&lt;&gt;&apos;&quot;");

+    }

+    

+    public void testStringWithRawEntities() throws Exception {

+        runTest("&<>'\"", "&<>'\"");

+    }

+    public void testStringWithLeadingAndTrailingSpaces() throws Exception {

+        runtest("          centered          ");

+    }

+    

+    public void testWhitespace() throws Exception {

+        runtest(" \n \t "); // note: \r fails

+    }

+    

+    public void testFrenchAccents() throws Exception {

+        runtest("\u00e0\u00e2\u00e4\u00e7\u00e8\u00e9\u00ea\u00eb\u00ee\u00ef\u00f4\u00f6\u00f9\u00fb\u00fc");

+    }

+    

+    public void testGermanUmlauts() throws Exception {

+        runtest(" Some text \u00df with \u00fc special \u00f6 chars \u00e4.");

+    }

+    

+    public void testWelcomeUnicode() throws Exception {

+        // welcome in several languages

+        runtest(

+          "Chinese (trad.) : \u6b61\u8fce  ");

+    }

+

+    public void testWelcomeUnicode2() throws Exception {

+        // welcome in several languages

+        runtest(

+          "Greek : \u03ba\u03b1\u03bb\u03ce\u03c2 \u03bf\u03c1\u03af\u03c3\u03b1\u03c4\u03b5");

+    }

+

+    public void testWelcomeUnicode3() throws Exception {

+        // welcome in several languages

+        runtest(

+          "Japanese : \u3088\u3046\u3053\u305d");

+    }

+	

+}

diff --git a/test/org/apache/ws/commons/soap/impl/llom/OMElementTest.java b/test/org/apache/ws/commons/soap/impl/llom/OMElementTest.java
new file mode 100644
index 0000000..57a3066
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/impl/llom/OMElementTest.java
@@ -0,0 +1,128 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMConstants;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMFactory;

+import org.apache.ws.commons.om.OMNamespace;

+import org.apache.ws.commons.om.OMTestCase;

+import org.apache.ws.commons.om.OMText;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+import javax.xml.namespace.QName;

+import java.util.Iterator;

+

+public class OMElementTest extends OMTestCase implements OMConstants {

+    private static final String WSA_URI = "http://schemas.xmlsoap.org/ws/2004/03/addressing";

+    private static final String WSA_TO = "To";

+    private Log log = LogFactory.getLog(getClass());

+

+    OMFactory factory = OMAbstractFactory.getOMFactory();

+    private OMElement firstElement;

+    private OMElement secondElement;

+

+

+    public OMElementTest(String testName) {

+        super(testName);

+    }

+

+    /*

+     * @see TestCase#setUp()

+     */

+    protected void setUp() throws Exception {

+       OMNamespace testingNamespace = factory.createOMNamespace(

+                        "http://testing.ws.org", "ws");

+        firstElement = factory.createOMElement("FirstElement", testingNamespace);

+        secondElement = factory.createOMElement("SecondElement", factory.createOMNamespace(

+                                "http://moretesting.ws.org", "ws"), firstElement);

+    }

+

+    public void testGetText() {

+        try {

+            StAXSOAPModelBuilder soapBuilder = getOMBuilder(

+                    "soap/OMElementTest.xml");

+            SOAPEnvelope soapEnvelope = (SOAPEnvelope) soapBuilder.getDocumentElement();

+            OMElement wsaTo = soapEnvelope.getHeader().getFirstChildWithName(

+                    new QName(WSA_URI, WSA_TO));

+

+            String expectedString = "http://localhost:8081/axis/services/BankPort";

+            assertEquals("getText is not returning the correct value",

+                    wsaTo.getText().trim(),

+                    expectedString);

+        } catch (Exception e) {

+            log.info(e.getMessage());

+        }

+    }

+

+    public void testConstructors(){

+

+        try {

+            factory.createOMElement("", null);

+            fail("This should fail as OMElement should not be allowed to create without a local name ");

+        } catch (Exception e) {

+            assertTrue(true);

+        }

+

+        assertTrue("Namespace having same information, declared in the same context, should share" +

+                " the same namespace object",firstElement.getNamespace() != secondElement.getNamespace());

+        assertEquals("OMElement children addition has not worked properly", secondElement, firstElement.getFirstElement());

+

+        OMNamespace testNamespace2 = factory.createOMNamespace("ftp://anotherTest.ws.org", "ws");

+        firstElement.declareNamespace(testNamespace2);

+

+        OMNamespace inheritedSecondNamespace = secondElement.findNamespace(testNamespace2.getName(),

+                testNamespace2.getPrefix());

+        assertNotNull("Children should inherit namespaces declared in parent", inheritedSecondNamespace);

+        assertEquals("inherited namespace uri should be equal", inheritedSecondNamespace.getName(), testNamespace2.getName());

+        assertEquals("inherited namespace prefix should be equal", inheritedSecondNamespace.getPrefix(), testNamespace2.getPrefix());

+

+

+    }

+

+    public void testChildDetachment() {

+        OMNamespace testNamespace2 = factory.createOMNamespace("ftp://anotherTest.ws.org", "ws");

+        

+        secondElement.detach();

+        assertTrue("OMElement children detachment has not worked properly", !secondElement.equals(firstElement.getFirstElement()));

+        assertNull("First Element should not contain elements after detaching. ", firstElement.getFirstElement());

+        assertNull("First Element should not contain elements after detaching. ", firstElement.getFirstOMChild());

+        assertNull(secondElement.findNamespace(testNamespace2.getName(), testNamespace2.getPrefix()));

+

+        firstElement.addChild(secondElement);

+        firstElement.setText("Some Sample Text");

+

+        assertTrue("First added child must be the first child", secondElement.equals(firstElement.getFirstOMChild()));

+        Iterator children = firstElement.getChildren();

+        int childCount = 0;

+        while (children.hasNext()) {

+        	children.next();

+            childCount++;

+        }

+        assertEquals("Children count should be two", childCount, 2);

+

+        secondElement.detach();

+        assertTrue("First child should be the text child", firstElement.getFirstOMChild() instanceof OMText);

+

+

+    }

+

+}

diff --git a/test/org/apache/ws/commons/soap/impl/llom/OMEnvelopeTest.java b/test/org/apache/ws/commons/soap/impl/llom/OMEnvelopeTest.java
new file mode 100644
index 0000000..c1886ec
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/impl/llom/OMEnvelopeTest.java
@@ -0,0 +1,82 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMAbstractFactory;

+import org.apache.ws.commons.om.OMTestCase;

+import org.apache.ws.commons.om.OMTestUtils;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPProcessingException;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+public class OMEnvelopeTest extends OMTestCase {

+    private Log log = LogFactory.getLog(getClass());

+    public OMEnvelopeTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+    }

+

+    public void testGetHeader1() {

+        SOAPHeader header = soapEnvelope.getHeader();

+        assertTrue("Header information retrieved not correct",

+                (header != null &&

+                header.getLocalName().equalsIgnoreCase("Header")));

+    }

+

+    public void testGetBody1() {

+        SOAPBody body = soapEnvelope.getBody();

+        assertTrue("Header information retrieved not correct",

+                (body != null && body.getLocalName().equalsIgnoreCase("Body")));

+    }

+

+    private SOAPEnvelope getSecondEnvelope() throws Exception {

+        return (SOAPEnvelope) OMTestUtils.getOMBuilder(

+                getTestResourceFile("soap/sample1.xml"))

+                .getDocumentElement();

+    }

+

+    public void testGetHeader2() throws Exception {

+        SOAPHeader header = getSecondEnvelope().getHeader();

+        assertTrue("Header information retrieved not correct",

+                (header != null &&

+                header.getLocalName().equalsIgnoreCase("Header")));

+    }

+

+    public void testGetBody2() throws Exception {

+        SOAPBody body = getSecondEnvelope().getBody();

+        assertTrue("Header information retrieved not correct",

+                (body != null && body.getLocalName().equalsIgnoreCase("Body")));

+    }

+

+    public void testDefaultEnveleope() {

+        SOAPEnvelope env = null;

+        try {

+            env = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();

+        } catch (SOAPProcessingException e) {

+            log.info(e.getMessage());

+            fail(e.getMessage());

+        }

+        assertNotNull(env);

+        assertNotNull("Body should not be null", env.getBody());

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/impl/llom/OMHeaderBlockTest.java b/test/org/apache/ws/commons/soap/impl/llom/OMHeaderBlockTest.java
new file mode 100644
index 0000000..ffbdfcb
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/impl/llom/OMHeaderBlockTest.java
@@ -0,0 +1,59 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMTestCase;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+

+import java.util.Iterator;

+

+public class OMHeaderBlockTest extends OMTestCase {

+    SOAPHeader soapHeader;

+    SOAPHeaderBlock soapHeaderElement;

+

+    public OMHeaderBlockTest(String testName) {

+        super(testName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soapHeader = soapEnvelope.getHeader();

+        Iterator headerElementIter = soapHeader.examineAllHeaderBlocks();

+        if (headerElementIter.hasNext()) {

+            soapHeaderElement = (SOAPHeaderBlock) headerElementIter.next();

+        }

+    }

+

+    public void testSetAndGetActor() {

+        String newActorURI = "http://newActor.org";

+        soapHeaderElement.setRole(newActorURI);

+        assertTrue("Actor was not properly set",

+                soapHeaderElement.getRole().equalsIgnoreCase(newActorURI));

+    }

+

+    public void testSetAndGetMustUnderstand() {

+        soapHeaderElement.setMustUnderstand(false);

+        assertTrue("MustUnderstand was not properly set",

+                !soapHeaderElement.getMustUnderstand());

+    }

+

+    public void testGetMustUnderstand() {

+        //TODO Implement getMustUnderstand().

+    }

+

+}

diff --git a/test/org/apache/ws/commons/soap/impl/llom/OMHeaderTest.java b/test/org/apache/ws/commons/soap/impl/llom/OMHeaderTest.java
new file mode 100644
index 0000000..2cc86e4
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/impl/llom/OMHeaderTest.java
@@ -0,0 +1,85 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom;

+

+import org.apache.ws.commons.om.OMTestCase;

+import org.apache.ws.commons.om.impl.llom.OMNamespaceImpl;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+

+import java.util.Iterator;

+

+public class OMHeaderTest extends OMTestCase {

+    SOAPHeader soapHeader;

+

+    public OMHeaderTest(String testName) {

+        super(testName);

+    }

+

+    public static void main(String[] args) {

+    }

+

+    /*

+     * @see TestCase#setUp()

+     */

+    protected void setUp() throws Exception {

+        super.setUp();

+        soapHeader = soapEnvelope.getHeader();

+    }

+

+    public void testAddHeaderElement() {

+        String newElementName = "MyHeaderElement";

+        SOAPHeaderBlock soapHeaderElement = soapHeader.addHeaderBlock(

+                newElementName,

+                new OMNamespaceImpl("http://opensource.lk", "lsf"));

+        assertTrue(

+                "Header Element added has different parent than it should have",

+                soapHeaderElement.getParent() == soapHeader);

+        assertTrue(

+                "Header Element added has different localname than it was given",

+                soapHeaderElement.getLocalName().equalsIgnoreCase(

+                        newElementName));

+    }

+

+    public void testExamineHeaderElements() {

+    }

+

+    public void testExtractHeaderElements() {

+        //TODO Implement extractHeaderBlocks().

+    }

+

+    public void testExamineMustUnderstandHeaderElements() {

+        //TODO Implement examineMustUnderstandHeaderBlocks().

+    }

+

+    public void testExamineAllHeaderElements() {

+        Iterator iterator = soapHeader.examineAllHeaderBlocks();

+        int headerElementCount = 0;

+        while (iterator.hasNext()) {

+            iterator.next();

+            headerElementCount++;

+        }

+        assertTrue(

+                "Number of header elements in the header differs from expected value of 3",

+                headerElementCount == 3);

+    }

+

+    public void testExtractAllHeaderElements() {

+        //TODO Implement extractAllHeaderBlocks().

+    }

+

+}

diff --git a/test/org/apache/ws/commons/soap/impl/llom/builder/StAXSOAPModelBuilderTest.java b/test/org/apache/ws/commons/soap/impl/llom/builder/StAXSOAPModelBuilderTest.java
new file mode 100644
index 0000000..2a12e96
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/impl/llom/builder/StAXSOAPModelBuilderTest.java
@@ -0,0 +1,560 @@
+package org.apache.ws.commons.soap.impl.llom.builder;

+

+import junit.framework.TestCase;

+import org.apache.ws.commons.om.OMAttribute;

+import org.apache.ws.commons.om.OMElement;

+import org.apache.ws.commons.om.OMXMLParserWrapper;

+import org.apache.ws.commons.soap.SOAP11Constants;

+import org.apache.ws.commons.soap.SOAP12Constants;

+import org.apache.ws.commons.soap.SOAPBody;

+import org.apache.ws.commons.soap.SOAPConstants;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.SOAPFault;

+import org.apache.ws.commons.soap.SOAPFaultCode;

+import org.apache.ws.commons.soap.SOAPFaultDetail;

+import org.apache.ws.commons.soap.SOAPFaultNode;

+import org.apache.ws.commons.soap.SOAPFaultReason;

+import org.apache.ws.commons.soap.SOAPFaultRole;

+import org.apache.ws.commons.soap.SOAPFaultSubCode;

+import org.apache.ws.commons.soap.SOAPFaultText;

+import org.apache.ws.commons.soap.SOAPFaultValue;

+import org.apache.ws.commons.soap.SOAPHeader;

+import org.apache.ws.commons.soap.SOAPHeaderBlock;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamException;

+import javax.xml.stream.XMLStreamReader;

+import java.io.StringReader;

+import java.util.Iterator;

+

+public class StAXSOAPModelBuilderTest extends TestCase {

+

+    private Log log = LogFactory.getLog(getClass());

+    public void setUp() {

+

+    }

+

+    public void testStAXSOAPModelBuilder() {

+        String soap12Message =

+                "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">\n" +

+                "   <env:Header>\n" +

+                "       <test:echoOk xmlns:test=\"http://example.org/ts-tests\"\n" +

+                "                    env:role=\"http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver\"\n" +

+                "                    env:mustUnderstand=\"true\">\n" +

+                "                       foo\n" +

+                "       </test:echoOk>\n" +

+                "   </env:Header>\n" +

+                "   <env:Body>\n" +

+                "       <env:Fault>\n" +

+                "           <env:Code>\n" +

+                "               <env:Value>env:Sender</env:Value>\n" +

+                "               <env:Subcode>\n" +

+                "                   <env:Value>m:MessageTimeout</env:Value>\n" +

+                "                   <env:Subcode>\n" +

+                "                       <env:Value>m:MessageTimeout</env:Value>\n" +

+                "                   </env:Subcode>\n" +

+                "               </env:Subcode>\n" +

+                "           </env:Code>\n" +

+                "           <env:Reason>\n" +

+                "               <env:Text>Sender Timeout</env:Text>\n" +

+                "           </env:Reason>\n" +

+                "           <env:Node>\n" +

+                "               http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver\n" +

+                "           </env:Node>\n" +

+                "           <env:Role>\n" +

+                "               ultimateReceiver\n" +

+                "           </env:Role>\n" +

+                "           <env:Detail xmlns:m=\"http:www.sample.org\">\n" +

+                "               Details of error\n" +

+                "               <m:MaxTime m:detail=\"This is only a test\">\n" +

+                "                   P5M\n" +

+                "               </m:MaxTime>\n" +

+                "               <m:AveTime>\n" +

+                "                   <m:Time>\n" +

+                "                       P3M\n" +

+                "                   </m:Time>\n" +

+                "               </m:AveTime>\n" +

+                "           </env:Detail>\n" +

+                "       </env:Fault>\n" +

+                "   </env:Body>\n" +

+                "</env:Envelope>";

+

+        String soap11Message =

+                "<?xml version='1.0' ?>" +

+                "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +

+                "   <env:Header>\n" +

+                "       <test:echoOk xmlns:test=\"http://example.org/ts-tests\"\n" +

+                "                    env:actor=\"http://schemas.xmlsoap.org/soap/actor/next\"\n" +

+                "                    env:mustUnderstand=\"1\"" +

+                "       >\n" +

+                "                       foo\n" +

+                "       </test:echoOk>\n" +

+                "   </env:Header>\n" +

+                "   <env:Body>\n" +

+                "       <env:Fault>\n" +

+                "           <env:faultcode>\n" +

+                "               env:Sender\n" +

+                "           </env:faultcode>\n" +

+                "           <env:faultstring>\n" +

+                "               Sender Timeout\n" +

+                "           </env:faultstring>\n" +

+                "           <env:faultactor>\n" +

+                "               http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver\n" +

+                "           </env:faultactor>\n" +

+                "           <env:detail xmlns:m=\"http:www.sample.org\">\n" +

+                "               Details of error\n" +

+                "               <m:MaxTime m:detail=\"This is only a test\">\n" +

+                "                   P5M\n" +

+                "               </m:MaxTime>\n" +

+                "               <m:AveTime>\n" +

+                "                   <m:Time>\n" +

+                "                       P3M\n" +

+                "                   </m:Time>\n" +

+                "               </m:AveTime>\n" +

+                "           </env:detail>\n" +

+                "           <n:Test xmlns:n=\"http:www.Test.org\">\n" +

+                "               <n:TestElement>\n" +

+                "                   This is only a test\n" +

+                "               </n:TestElement>\n" +

+                "           </n:Test>\n" +

+                "       </env:Fault>\n" +

+                "   </env:Body>\n" +

+                "</env:Envelope>";

+

+

+        try {

+            XMLStreamReader sopa12Parser = XMLInputFactory.newInstance()

+                    .createXMLStreamReader(new StringReader(soap12Message));

+            OMXMLParserWrapper soap12Builder = new StAXSOAPModelBuilder(sopa12Parser, null);

+            SOAPEnvelope soap12Envelope = (SOAPEnvelope) soap12Builder.getDocumentElement();

+//            soap12Envelope.build();

+//            XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);

+//            soap12Envelope.serializeAndConsume(writer);

+//		    writer.flush();

+

+            assertTrue("SOAP 1.2 :- envelope local name mismatch",

+                    soap12Envelope.getLocalName().equals(

+                            SOAPConstants.SOAPENVELOPE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- envelope namespace uri mismatch",

+                    soap12Envelope.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            SOAPHeader header = soap12Envelope.getHeader();

+            assertTrue("SOAP 1.2 :- Header local name mismatch",

+                    header.getLocalName().equals(

+                            SOAPConstants.HEADER_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Header namespace uri mismatch",

+                    header.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) header.getFirstElement();

+            assertTrue("SOAP 1.2 :- Header block name mismatch",

+                    headerBlock.getLocalName().equals("echoOk"));

+            assertTrue("SOAP 1.2 :- Header block name space uri mismatch",

+                    headerBlock.getNamespace().getName().equals(

+                            "http://example.org/ts-tests"));

+            assertEquals("SOAP 1.2 :- Header block text mismatch",headerBlock.getText().trim(),"foo");

+

+            Iterator headerBlockAttributes = headerBlock.getAllAttributes();

+            OMAttribute roleAttribute = (OMAttribute) headerBlockAttributes.next();

+            assertTrue("SOAP 1.2 :- Role attribute name mismatch",

+                    roleAttribute.getLocalName().equals(

+                            SOAP12Constants.SOAP_ROLE));

+            

+

+            assertTrue("SOAP 1.2 :- Role value mismatch",

+                    roleAttribute.getAttributeValue().trim().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI + "/" +

+                    SOAP12Constants.SOAP_ROLE +

+                    "/" +

+                    "ultimateReceiver"));

+            assertTrue("SOAP 1.2 :- Role attribute namespace uri mismatch",

+                    roleAttribute.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            OMAttribute mustUnderstandAttribute = (OMAttribute) headerBlockAttributes.next();

+            assertTrue("SOAP 1.2 :- Mustunderstand attribute name mismatch",

+                    mustUnderstandAttribute.getLocalName().equals(

+                            SOAPConstants.ATTR_MUSTUNDERSTAND));

+            assertTrue("SOAP 1.2 :- Mustunderstand value mismatch",

+                    mustUnderstandAttribute.getAttributeValue().equals(

+                            SOAPConstants.ATTR_MUSTUNDERSTAND_TRUE));

+            assertTrue(

+                    "SOAP 1.2 :- Mustunderstand attribute namespace uri mismatch",

+                    mustUnderstandAttribute.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            SOAPBody body = soap12Envelope.getBody();

+            assertTrue("SOAP 1.2 :- Body local name mismatch",

+                    body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Body namespace uri mismatch",

+                    body.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            SOAPFault fault = body.getFault();

+            assertTrue("SOAP 1.2 :- Fault local name mismatch",

+                    fault.getLocalName().equals(

+                            SOAPConstants.SOAPFAULT_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault namespace uri mismatch",

+                    fault.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            Iterator iteratorInFault = fault.getChildren();

+

+            iteratorInFault.next();

+            SOAPFaultCode code = (SOAPFaultCode) iteratorInFault.next();

+            assertTrue("SOAP 1.2 :- Fault code local name mismatch",

+                    code.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch",

+                    code.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            Iterator iteratorInCode = code.getChildren();

+

+            iteratorInCode.next();

+            SOAPFaultValue value1 = (SOAPFaultValue) iteratorInCode.next();

+            assertTrue("SOAP 1.2 :- Fault code value local name mismatch",

+                    value1.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch",

+                    value1.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.2 :- Value1 text mismatch",

+                    value1.getText().equals("env:Sender"));

+

+            iteratorInCode.next();

+            SOAPFaultSubCode subCode1 = (SOAPFaultSubCode) iteratorInCode.next();

+            assertTrue("SOAP 1.2 :- Fault sub code local name mismatch",

+                    subCode1.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault subcode namespace uri mismatch",

+                    subCode1.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            Iterator iteratorInSubCode1 = subCode1.getChildren();

+

+            iteratorInSubCode1.next();

+            SOAPFaultValue value2 = (SOAPFaultValue) iteratorInSubCode1.next();

+            assertTrue("SOAP 1.2 :- Fault code value local name mismatch",

+                    value2.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch",

+                    value2.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.2 :- Value2 text mismatch",

+                    value2.getText().equals("m:MessageTimeout"));

+

+            iteratorInSubCode1.next();

+            SOAPFaultSubCode subCode2 = (SOAPFaultSubCode) iteratorInSubCode1.next();

+            assertTrue("SOAP 1.2 :- Fault sub code local name mismatch",

+                    subCode2.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault subcode namespace uri mismatch",

+                    subCode2.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            Iterator iteratorInSubCode2 = subCode2.getChildren();

+

+            iteratorInSubCode2.next();

+            SOAPFaultValue value3 = (SOAPFaultValue) iteratorInSubCode2.next();

+            assertTrue("SOAP 1.2 :- Fault code value local name mismatch",

+                    value3.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault code namespace uri mismatch",

+                    value3.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.2 :- Value2 text mismatch",

+                    value3.getText().equals("m:MessageTimeout"));

+

+            iteratorInFault.next();

+            SOAPFaultReason reason = (SOAPFaultReason) iteratorInFault.next();

+            assertTrue("SOAP 1.2 :- Fault reason local name mismatch",

+                    reason.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault reason namespace uri mismatch",

+                    reason.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            Iterator iteratorInReason = reason.getChildren();

+

+            iteratorInReason.next();

+            SOAPFaultText text = (SOAPFaultText) iteratorInReason.next();

+            assertTrue("SOAP 1.2 :- Fault text local name mismatch",

+                    text.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Text namespace uri mismatch",

+                    text.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.2 :- Text value mismatch",

+                    text.getText().equals("Sender Timeout"));

+

+            iteratorInFault.next();

+            SOAPFaultNode node = (SOAPFaultNode) iteratorInFault.next();

+            assertTrue("SOAP 1.2 :- Fault node local name mismatch",

+                    node.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault node namespace uri mismatch",

+                    node.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.2 :- Node value mismatch",

+                    node.getText().trim().equals(

+                            "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));

+

+            iteratorInFault.next();

+            SOAPFaultRole role = (SOAPFaultRole) iteratorInFault.next();

+            assertTrue("SOAP 1.2 :- Fault role local name mismatch",

+                    role.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault role namespace uri mismatch",

+                    role.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.2 :- Role value mismatch",

+                    role.getText().trim().equals("ultimateReceiver"));

+

+            iteratorInFault.next();

+            SOAPFaultDetail detail = (SOAPFaultDetail) iteratorInFault.next();

+            assertTrue("SOAP 1.2 :- Fault detail local name mismatch",

+                    detail.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault detail namespace uri mismatch",

+                    detail.getNamespace().getName().equals(

+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            assertTrue("SOAP 1.2 :- Text in detail mismatch",

+                    detail.getText().trim().equals("Details of error"));

+

+            Iterator iteratorInDetail = detail.getChildren();

+

+            iteratorInDetail.next();

+            OMElement element1 = (OMElement) iteratorInDetail.next();

+            assertTrue("SOAP 1.2 :- MaxTime element mismatch",

+                    element1.getLocalName().equals("MaxTime"));

+            assertTrue("SOAP 1.2 :- MaxTime element namespace mismatch",

+                    element1.getNamespace().getName().equals(

+                            "http:www.sample.org"));

+            assertTrue("SOAP 1.2 :- Text value in MaxTime element mismatch",

+                    element1.getText().trim().equals("P5M"));

+

+            Iterator attributeIterator = element1.getAllAttributes();

+            OMAttribute attributeInMaxTime = (OMAttribute) attributeIterator.next();

+            assertTrue("SOAP 1.2 :- Attribute local name mismatch",

+                    attributeInMaxTime.getLocalName().equals("detail"));

+            assertTrue("SOAP 1.2 :- Attribute namespace mismatch",

+                    attributeInMaxTime.getNamespace().getName().equals(

+                            "http:www.sample.org"));

+            assertTrue("SOAP 1.2 :- Attribute value mismatch",

+                    attributeInMaxTime.getAttributeValue().trim().equals("This is only a test"));

+

+            iteratorInDetail.next();

+            OMElement element2 = (OMElement) iteratorInDetail.next();

+            assertTrue("SOAP 1.2 :- AveTime element mismatch",

+                    element2.getLocalName().equals("AveTime"));

+            assertTrue("SOAP 1.2 :- AveTime element namespace mismatch",

+                    element2.getNamespace().getName().equals(

+                            "http:www.sample.org"));

+

+            Iterator iteratorInAveTimeElement = element2.getChildren();

+

+            iteratorInAveTimeElement.next();

+            OMElement element21 = (OMElement) iteratorInAveTimeElement.next();

+            assertTrue("SOAP 1.2 :- Time element mismatch",

+                    element21.getLocalName().equals("Time"));

+            assertTrue("SOAP 1.2 :- Time element namespace mismatch",

+                    element21.getNamespace().getName().equals(

+                            "http:www.sample.org"));

+            assertTrue("SOAP 1.2 :- Text value in Time element mismatch",

+                    element21.getText().trim().equals("P3M"));

+

+            XMLStreamReader sopa11Parser = XMLInputFactory.newInstance()

+                    .createXMLStreamReader(new StringReader(soap11Message));

+            OMXMLParserWrapper soap11Builder = new StAXSOAPModelBuilder(sopa11Parser, null);

+            SOAPEnvelope soap11Envelope = (SOAPEnvelope) soap11Builder.getDocumentElement();

+//            soap11Envelope.build();

+//            writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);

+//            soap11Envelope.serializeAndConsume(writer);

+//		    writer.flush();

+

+            assertTrue("SOAP 1.1 :- envelope local name mismatch",

+                    soap11Envelope.getLocalName().equals(

+                            SOAPConstants.SOAPENVELOPE_LOCAL_NAME));

+            assertTrue("SOAP 1.1 :- envelope namespace uri mismatch",

+                    soap11Envelope.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            header = soap11Envelope.getHeader();

+            assertTrue("SOAP 1.1 :- Header local name mismatch",

+                    header.getLocalName().equals(

+                            SOAPConstants.HEADER_LOCAL_NAME));

+            assertTrue("SOAP 1.1 :- Header namespace uri mismatch",

+                    header.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            headerBlock = (SOAPHeaderBlock) header.getFirstElement();

+            assertTrue("SOAP 1.1 :- Header block name mismatch",

+                    headerBlock.getLocalName().equals("echoOk"));

+            assertTrue("SOAP 1.1 :- Header block name space uri mismatch",

+                    headerBlock.getNamespace().getName().equals(

+                            "http://example.org/ts-tests"));

+            assertTrue("SOAP 1.1 :- Headaer block text mismatch",

+                    headerBlock.getText().trim().equals("foo"));

+

+            headerBlockAttributes = headerBlock.getAllAttributes();

+

+            mustUnderstandAttribute =

+                    (OMAttribute) headerBlockAttributes.next();

+            assertTrue("SOAP 1.1 :- Mustunderstand attribute name mismatch",

+                    mustUnderstandAttribute.getLocalName().equals(

+                            SOAPConstants.ATTR_MUSTUNDERSTAND));

+            assertTrue("SOAP 1.1 :- Mustunderstand value mismatch",

+                    mustUnderstandAttribute.getAttributeValue().equals(

+                            SOAPConstants.ATTR_MUSTUNDERSTAND_1));

+            assertTrue(

+                    "SOAP 1.1 :- Mustunderstand attribute namespace uri mismatch",

+                    mustUnderstandAttribute.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            OMAttribute actorAttribute = (OMAttribute) headerBlockAttributes.next();

+            assertTrue("SOAP 1.1 :- Actor attribute name mismatch",

+                    actorAttribute.getLocalName().equals(

+                            SOAP11Constants.ATTR_ACTOR));

+            assertTrue("SOAP 1.1 :- Actor value mismatch",

+                    actorAttribute.getAttributeValue().trim().equals(

+                            "http://schemas.xmlsoap.org/soap/" +

+                    SOAP11Constants.ATTR_ACTOR +

+                    "/" +

+                    "next"));

+            assertTrue("SOAP 1.1 :- Actor attribute namespace uri mismatch",

+                    actorAttribute.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            body = soap11Envelope.getBody();

+            assertTrue("SOAP 1.1 :- Body local name mismatch",

+                    body.getLocalName().equals(SOAPConstants.BODY_LOCAL_NAME));

+            assertTrue("SOAP 1.1 :- Body namespace uri mismatch",

+                    body.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            fault = body.getFault();

+            assertTrue("SOAP 1.1 :- Fault namespace uri mismatch",

+                    fault.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+

+            iteratorInFault = fault.getChildren();

+

+            iteratorInFault.next();

+            code = (SOAPFaultCode) iteratorInFault.next();

+            assertEquals("SOAP Fault code local name mismatch",

+                    code.getLocalName(),

+                    (SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));

+            assertTrue("SOAP 1.1 :- Fault code namespace uri mismatch",

+                    code.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertEquals("SOAP 1.1 :- Fault code value mismatch", code.getValue().getText().trim(),

+                    "env:Sender");

+

+            iteratorInFault.next();

+            reason = (SOAPFaultReason) iteratorInFault.next();

+            assertTrue("SOAP 1.1 :- Fault string local name mismatch",

+                    reason.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));

+            assertTrue("SOAP 1.2 :- Fault string namespace uri mismatch",

+                    reason.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.1 :- Fault string value mismatch",

+                    reason.getSOAPText().getText().trim().equals("Sender Timeout"));

+

+            iteratorInFault.next();

+            role = (SOAPFaultRole) iteratorInFault.next();

+            assertTrue("SOAP 1.1 :- Fault actor local name mismatch",

+                    role.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));

+            assertTrue("SOAP 1.1 :- Fault actor namespace uri mismatch",

+                    role.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.1 :- Actor value mismatch",

+                    role.getText().trim().equals(

+                            "http://schemas.xmlsoap.org/soap/envelope/actor/ultimateReceiver"));

+

+            iteratorInFault.next();

+            detail = (SOAPFaultDetail) iteratorInFault.next();

+            assertTrue("SOAP 1.1 :- Fault detail local name mismatch",

+                    detail.getLocalName().equals(

+                            SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));

+            assertTrue("SOAP 1.1 :- Fault detail namespace uri mismatch",

+                    detail.getNamespace().getName().equals(

+                            SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI));

+            assertTrue("SOAP 1.2 :- Text in detail mismatch",

+                    detail.getText().trim().equals("Details of error"));

+

+            iteratorInDetail = detail.getChildren();

+

+            iteratorInDetail.next();

+            element1 = (OMElement) iteratorInDetail.next();

+            assertTrue("SOAP 1.1 :- MaxTime element mismatch",

+                    element1.getLocalName().equals("MaxTime"));

+            assertTrue("SOAP 1.1 :- MaxTime element namespace mismatch",

+                    element1.getNamespace().getName().equals(

+                            "http:www.sample.org"));

+            assertTrue("SOAP 1.1 :- Text value in MaxTime element mismatch",

+                    element1.getText().trim().equals("P5M"));

+

+            attributeIterator = element1.getAllAttributes();

+            attributeInMaxTime = (OMAttribute) attributeIterator.next();

+            assertTrue("SOAP 1.1 :- Attribute local name mismatch",

+                    attributeInMaxTime.getLocalName().equals("detail"));

+            assertTrue("SOAP 1.1 :- Attribute namespace mismatch",

+                    attributeInMaxTime.getNamespace().getName().equals(

+                            "http:www.sample.org"));

+            assertTrue("SOAP 1.1 :- Attribute value mismatch",

+                    attributeInMaxTime.getAttributeValue().equals("This is only a test"));

+

+            iteratorInDetail.next();

+            element2 = (OMElement) iteratorInDetail.next();

+            assertTrue("SOAP 1.1 :- AveTime element mismatch",

+                    element2.getLocalName().equals("AveTime"));

+            assertTrue("SOAP 1.1 :- AveTime element namespace mismatch",

+                    element2.getNamespace().getName().equals(

+                            "http:www.sample.org"));

+

+            iteratorInAveTimeElement = element2.getChildren();

+

+            iteratorInAveTimeElement.next();

+            element21 = (OMElement) iteratorInAveTimeElement.next();

+            assertTrue("SOAP 1.1 :- Time element mismatch",

+                    element21.getLocalName().equals("Time"));

+            assertTrue("SOAP 1.1 :- Time element namespace mismatch",

+                    element21.getNamespace().getName().equals(

+                            "http:www.sample.org"));

+            assertTrue("SOAP 1.1 :- Text value in Time element mismatch",

+                    element21.getText().trim().equals("P3M"));

+

+            iteratorInFault.next();

+            OMElement testElement = (OMElement) iteratorInFault.next();

+            assertTrue("SOAP 1.1 :- Test element mismatch",

+                    testElement.getLocalName().equals("Test"));

+            assertTrue("SOAP 1.1 :- Test element namespace mismatch",

+                    testElement.getNamespace().getName().equals(

+                            "http:www.Test.org"));

+

+            OMElement childOfTestElement = testElement.getFirstElement();

+            assertTrue("SOAP 1.1 :- Test element child local name mismatch",

+                    childOfTestElement.getLocalName().equals("TestElement"));

+            assertTrue("SOAP 1.1 :- Test element child namespace mismatch",

+                    childOfTestElement.getNamespace().getName().equals(

+                            "http:www.Test.org"));

+            assertTrue("SOAP 1.1 :- Test element child value mismatch",

+                    childOfTestElement.getText().trim().equals("This is only a test"));

+

+        } catch (XMLStreamException e) {

+            log.info(e.getMessage());

+            fail("Test failed. Reason -> " + e.getMessage());

+        } catch (Exception e) {

+            log.info(e.getMessage());

+            fail("Test failed. Reason -> " + e.getMessage());

+

+        }

+    }

+}

diff --git a/test/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11SerializerTest.java b/test/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11SerializerTest.java
new file mode 100644
index 0000000..0b70a19
--- /dev/null
+++ b/test/org/apache/ws/commons/soap/impl/llom/soap11/SOAP11SerializerTest.java
@@ -0,0 +1,51 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.soap.impl.llom.soap11;

+

+import org.apache.ws.commons.om.OMTestCase;

+import org.apache.ws.commons.soap.SOAPEnvelope;

+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;

+

+import javax.xml.stream.XMLOutputFactory;

+import javax.xml.stream.XMLStreamWriter;

+public class SOAP11SerializerTest extends OMTestCase {

+

+    public SOAP11SerializerTest(String testName) {

+        super(testName);

+    }

+

+    protected StAXSOAPModelBuilder getOMBuilder(String fileName) throws Exception {

+        return super.getOMBuilder(fileName);

+    }

+

+    protected void setUp() throws Exception {

+        super.setUp();

+        soapEnvelope =

+                (SOAPEnvelope) getOMBuilder("soap/soap11/soap11fault.xml")

+                .getDocumentElement();

+    }

+

+    public void testSerialize() throws Exception {

+        XMLStreamWriter output = XMLOutputFactory.newInstance().

+                createXMLStreamWriter(System.out);

+        soapEnvelope.serialize(output);

+

+        output = XMLOutputFactory.newInstance().

+                createXMLStreamWriter(System.out);

+        soapEnvelope.serializeAndConsume(output);

+    }

+}

diff --git a/test/org/apache/ws/commons/xpath/AXIOMXPathTest.java b/test/org/apache/ws/commons/xpath/AXIOMXPathTest.java
new file mode 100644
index 0000000..ccae7de
--- /dev/null
+++ b/test/org/apache/ws/commons/xpath/AXIOMXPathTest.java
@@ -0,0 +1,56 @@
+/*

+ * Copyright 2004,2005 The Apache Software Foundation.

+ *

+ * Licensed 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.ws.commons.xpath;

+

+import junit.framework.Test;

+import junit.framework.TestSuite;

+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;

+import org.apache.ws.commons.om.xpath.DocumentNavigator;

+import org.jaxen.FunctionCallException;

+import org.jaxen.Navigator;

+

+import javax.xml.stream.XMLInputFactory;

+import javax.xml.stream.XMLStreamReader;

+import java.io.FileInputStream;

+

+public class AXIOMXPathTest extends XPathTestBase {

+    public AXIOMXPathTest(String name) {

+        super(name);

+    }

+

+    public static Test suite() {

+        return new TestSuite(AXIOMXPathTest.class);

+    }

+

+    public Navigator getNavigator() {

+        return new DocumentNavigator();

+    }

+

+    public Object getDocument(String uri) throws Exception {

+        try {

+            XMLStreamReader parser =

+                    XMLInputFactory.newInstance().createXMLStreamReader(

+                            new FileInputStream(uri));

+            StAXOMBuilder builder =

+                    new StAXOMBuilder(parser);

+            return builder.getDocumentElement();

+        } catch (Exception e) {

+            throw new FunctionCallException(e);

+        }

+    }

+}

diff --git a/test/org/apache/ws/commons/xpath/XPathTestBase.java b/test/org/apache/ws/commons/xpath/XPathTestBase.java
new file mode 100644
index 0000000..0cf3ec0
--- /dev/null
+++ b/test/org/apache/ws/commons/xpath/XPathTestBase.java
@@ -0,0 +1,1810 @@
+/*

+ * $Header: /home/projects/jaxen/scm/jaxen/src/java/test/org/jaxen/XPathTestBase.java,v 1.36 2005/06/17 13:22:31 elharo Exp $

+ * $Revision: 1.36 $

+ * $Date: 2005/06/17 13:22:31 $

+ *

+ * ====================================================================

+ *

+ * Copyright (C) 2000-2002 bob mcwhirter & James Strachan.

+ * All rights reserved.

+ *

+ * Redistribution and use in source and binary forms, with or without

+ * modification, are permitted provided that the following conditions

+ * are met:

+ *

+ * 1. Redistributions of source code must retain the above copyright

+ *    notice, this list of conditions, and the following disclaimer.

+ *

+ * 2. Redistributions in binary form must reproduce the above copyright

+ *    notice, this list of conditions, and the disclaimer that follows

+ *    these conditions in the documentation and/or other materials

+ *    provided with the distribution.

+ *

+ * 3. The name "Jaxen" must not be used to endorse or promote products

+ *    derived from this software without prior written permission.  For

+ *    written permission, please contact license@jaxen.org.

+ *

+ * 4. Products derived from this software may not be called "Jaxen", nor

+ *    may "Jaxen" appear in their name, without prior written permission

+ *    from the Jaxen Project Management (pm@jaxen.org).

+ *

+ * In addition, we request (but do not require) that you include in the

+ * end-user documentation provided with the redistribution and/or in the

+ * software itself an acknowledgement equivalent to the following:

+ *     "This product includes software developed by the

+ *      Jaxen Project (http://www.jaxen.org/)."

+ * Alternatively, the acknowledgment may be graphical using the logos

+ * available at http://www.jaxen.org/

+ *

+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED

+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES

+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

+ * DISCLAIMED.  IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT

+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF

+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND

+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,

+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT

+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF

+ * SUCH DAMAGE.

+ *

+ * ====================================================================

+ * This software consists of voluntary contributions made by many

+ * individuals on behalf of the Jaxen Project and was originally

+ * created by bob mcwhirter <bob@werken.com> and

+ * James Strachan <jstrachan@apache.org>.  For more information on the

+ * Jaxen Project, please see <http://www.jaxen.org/>.

+ *

+ * $Id: XPathTestBase.java,v 1.36 2005/06/17 13:22:31 elharo Exp $

+ */

+

+

+package org.apache.ws.commons.xpath;

+

+import junit.framework.TestCase;

+import org.apache.commons.logging.Log;

+import org.apache.commons.logging.LogFactory;

+import org.jaxen.BaseXPath;

+import org.jaxen.Context;

+import org.jaxen.ContextSupport;

+import org.jaxen.FunctionCallException;

+import org.jaxen.JaxenException;

+import org.jaxen.Navigator;

+import org.jaxen.SimpleNamespaceContext;

+import org.jaxen.SimpleVariableContext;

+import org.jaxen.UnsupportedAxisException;

+import org.jaxen.XPath;

+import org.jaxen.XPathFunctionContext;

+import org.jaxen.function.StringFunction;

+import org.jaxen.pattern.Pattern;

+import org.jaxen.saxpath.helpers.XPathReaderFactory;

+

+import java.util.ArrayList;

+import java.util.Iterator;

+import java.util.List;

+

+public abstract class XPathTestBase extends TestCase

+{

+    protected static String VAR_URI   = "http://jaxen.org/test-harness/var";

+    protected static String TESTS_ROOT = "test-resources/";

+    protected static String TESTS_XML = TESTS_ROOT + "xml/test/tests.xml";

+

+    protected static boolean verbose = false;

+    protected static boolean debug = false;

+    private ContextSupport contextSupport;

+    private Log log = LogFactory.getLog(getClass());

+

+    public XPathTestBase(String name)

+    {

+        super(name);

+    }

+

+    public void setUp()

+    {

+        this.contextSupport = null;

+        System.setProperty(XPathReaderFactory.DRIVER_PROPERTY,

+                "");

+        log("-----------------------------");

+    }

+

+    public void log(String text)

+    {

+        log(verbose,

+                text);

+    }

+

+    public void log(boolean actualVerbose,

+                    String text)

+    {

+        if (actualVerbose) log.info(text);

+    }

+

+    protected void assertCountXPath(int expectedSize, Object context, String xpathStr) throws JaxenException

+    {

+        assertCountXPath2(expectedSize, context, xpathStr);

+    }

+

+    protected Object assertCountXPath2(int expectedSize, Object context, String xpathStr) throws JaxenException

+    {

+        log(debug,

+                "  Select :: " + xpathStr);

+        BaseXPath xpath = new BaseXPath(xpathStr, getNavigator());

+        List results = xpath.selectNodes(getContext(context));

+        log(debug,

+                "    Expected Size :: " + expectedSize);

+        log(debug,

+                "    Result Size   :: " + results.size());

+        if (expectedSize != results.size())

+        {

+            log(debug,

+                    "      ## FAILED");

+            log(debug,

+                    "      ## xpath: " + xpath + " = " + xpath.debug());

+            Iterator resultIter = results.iterator();

+            while (resultIter.hasNext())

+            {

+                log(debug,

+                        "      --> " + resultIter.next());

+            }

+        }

+        assertEquals(xpathStr,

+                expectedSize,

+                results.size());

+        if (expectedSize > 0)

+        {

+            return results.get(0);

+        }

+        return null;

+    }

+

+    protected void assertInvalidXPath(Object context, String xpathStr)

+    {

+        try

+        {

+            log(debug,

+                    "  Select :: " + xpathStr);

+            BaseXPath xpath = new BaseXPath(xpathStr, getNavigator());

+            List results = xpath.selectNodes(getContext(context));

+            log(debug,

+                    "    Result Size   :: " + results.size());

+            fail("An exception was expected.");

+        }

+        catch (UnsupportedAxisException e)

+        {

+            log(debug,

+                    "      ## SKIPPED -- Unsupported Axis");

+        }

+        catch (JaxenException e)

+        {

+            log(debug, "    Caught expected exception " + e.getMessage());

+        }

+    }

+

+    protected void assertValueOfXPath(String expected, Object context, String xpathStr) throws JaxenException

+    {

+        try

+        {

+            BaseXPath xpath = new BaseXPath(xpathStr, getNavigator());

+            Object node = xpath.evaluate(getContext(context));

+            String result = StringFunction.evaluate(node,

+                    getNavigator());

+            log(debug,

+                    "  Select :: " + xpathStr);

+            log(debug,

+                    "    Expected :: " + expected);

+            log(debug,

+                    "    Result   :: " + result);

+            if (!expected.equals(result))

+            {

+                log(debug,

+                        "      ## FAILED");

+                log(debug,

+                        "      ## xpath: " + xpath + " = " + xpath.debug());

+            }

+            assertEquals(xpathStr,

+                    expected,

+                    result);

+        }

+        catch (UnsupportedAxisException e)

+        {

+            log(debug,

+                    "      ## SKIPPED -- Unsupported Axis ");

+        }

+    }

+

+    protected Context getContext(Object contextNode)

+    {

+        Context context = new Context(getContextSupport());

+        List list = new ArrayList(1);

+        list.add(contextNode);

+        context.setNodeSet(list);

+        return context;

+    }

+

+    public ContextSupport getContextSupport()

+    {

+        if (this.contextSupport == null)

+        {

+            this.contextSupport = new ContextSupport(new SimpleNamespaceContext(),

+                    XPathFunctionContext.getInstance(),

+                    new SimpleVariableContext(),

+                    getNavigator());

+        }

+        return this.contextSupport;

+    }

+

+    public abstract Navigator getNavigator();

+

+    public abstract Object getDocument(String url) throws Exception;

+

+    public void testGetNodeType() throws FunctionCallException, UnsupportedAxisException

+    {

+        Navigator nav = getNavigator();

+        Object document = nav.getDocument(TESTS_ROOT + "xml/testNamespaces.xml");

+        int count = 0;

+        Iterator descendantOrSelfAxisIterator = nav.getDescendantOrSelfAxisIterator(document);

+        while (descendantOrSelfAxisIterator.hasNext())

+        {

+            Object node = descendantOrSelfAxisIterator.next();

+            Iterator namespaceAxisIterator = nav.getNamespaceAxisIterator(node);

+            while (namespaceAxisIterator.hasNext())

+            {

+                count++;

+                assertEquals("Node type mismatch", Pattern.NAMESPACE_NODE, nav.getNodeType(namespaceAxisIterator.next()));

+            }

+        }

+        assertEquals(25, count);

+    }

+

+

+    /* test for jaxen-24

+    */

+    public void testid53371() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/jaxen24.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/body/div", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "preceding::*[1]");

+            assertValueOfXPath("span", context, "local-name(preceding::*[1])");

+        }

+    }

+

+    /* jaxen-58

+    */

+    public void testid53391() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/jaxen24.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(0, context, "//preceding::x");

+            assertCountXPath(0, context, "//following::x");

+            assertCountXPath(0, context, "/descendant::*/preceding::x");

+            assertCountXPath(0, context, "/descendant::node()/preceding::x");

+        }

+    }

+

+    /* test for jaxen-3

+    */

+    public void testid53430() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/simple.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("abd", context, "string()");

+        }

+    }

+

+    public void testid53441() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/simple.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/root", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("abd", context, "string()");

+        }

+    }

+

+    public void testid53452() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/simple.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/root/a", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("a", context, "string()");

+        }

+    }

+

+    public void testid53463() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/simple.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/root/c", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("d", context, "string()");

+        }

+    }

+

+    /* test for jaxen-3

+    */

+    public void testid53482() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/jaxen3.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "/Configuration/hostname/attrlist/hostname[. = 'CE-A'] ");

+        }

+    }

+

+    /* parser test cases all of which should fail

+    */

+    public void testid53502() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/numbers.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* repeated xpaths, jaxen-35

+            */

+            assertInvalidXPath(context, "/numbers numbers");

+            /* invalid xpath, jaxen-34

+            */

+            assertInvalidXPath(context, "/a/b[c > d]efg");

+            /* invalid xpath, jaxen-27

+            */

+            assertInvalidXPath(context, "/inv/child::");

+            /* invalid xpath, jaxen-26

+            */

+            assertInvalidXPath(context, "/invoice/@test[abcd");

+            assertInvalidXPath(context, "/invoice/@test[abcd > x");

+            /* unterminated string

+            */

+            assertInvalidXPath(context, "string-length('a");

+            /* various edge cases where code threw no exception

+            */

+            assertInvalidXPath(context, "/descendant::()");

+            assertInvalidXPath(context, "(1 + 1");

+        }

+    }

+

+    /* test cases for the use of underscores in names

+    */

+    public void testid53602() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/underscore.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "/root/@a");

+            assertCountXPath(1, context, "/root/@_a");

+            assertCountXPath(1, context, "/root/b");

+            assertCountXPath(1, context, "/root/_b");

+            assertValueOfXPath("1", context, "/root/@a");

+            assertValueOfXPath("2", context, "/root/@_a");

+            assertValueOfXPath("1", context, "/root/b");

+            assertValueOfXPath("2", context, "/root/_b");

+        }

+    }

+

+    /* test cases for the use of = with node-sets

+    */

+    public void testid53662() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'file'");

+            assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'snoop'");

+        }

+    }

+

+    public void testid53685() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/numbers.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("true", context, "/numbers/set/nr = '-3'");

+            assertValueOfXPath("true", context, "/numbers/set/nr = -3");

+            assertValueOfXPath("true", context, "/numbers/set/nr = 24");

+            assertValueOfXPath("true", context, "/numbers/set/nr/@value = '9999'");

+            assertValueOfXPath("true", context, "/numbers/set/nr/@value = 9999.0");

+            assertValueOfXPath("true", context, "/numbers/set/nr/@value = 66");

+        }

+    }

+

+    /* test basic math...

+    */

+    public void testid53733() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/numbers.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("true", context, "(8 * 2 + 1) = 17");

+            assertValueOfXPath("true", context, "(1 + 8 * 2) = 17");

+            assertValueOfXPath("true", context, "(7 - 3 + 1) = 5");

+            assertValueOfXPath("true", context, "(8 - 4 + 5 - 6) = 3");

+            /* left-assoc tests, comments show WRONG evaluation

+            */

+            /* 3 - 2 - 1 != 2

+            */

+            assertValueOfXPath("0", context, "3 - 2 - 1");

+            /* 8 div 4 div 2 != 4

+            */

+            assertValueOfXPath("1", context, "8 div 4 div 2");

+            /* 3 mod 5 mod 7 != 1

+            */

+            assertValueOfXPath("3", context, "3 mod 7 mod 5");

+            /* 1=(2=2) is true

+            */

+            assertValueOfXPath("false", context, "1 = 2 = 2");

+            /*  2!=(3!=1) => 2!=1 => true, (2!=3)!=1 => 1!=1 => false

+            */

+            assertValueOfXPath("false", context, "2 != 3 != 1");

+            /* 3 > (2 > 1) is true

+            */

+            assertValueOfXPath("false", context, "3 > 2 > 1");

+            /* 3 >= (2 >= 2) is true

+            */

+            assertValueOfXPath("false", context, "3 >= 2 >= 2");

+            /* 1 < (2 < 3) is false

+            */

+            assertValueOfXPath("true", context, "1 < 2 < 3");

+            /* 0 <= (2 <= 3) is true

+            */

+            assertValueOfXPath("true", context, "2 <= 2 <= 3");

+        }

+    }

+

+    /* test cases for preceding axis with different node types

+    */

+    public void testid53850() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/pi2.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/a/c", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "//processing-instruction()");

+            assertCountXPath(1, context, "preceding-sibling::*");

+            assertCountXPath(5, context, "preceding-sibling::node()");

+            assertCountXPath(1, context, "preceding-sibling::*[1]");

+            assertCountXPath(1, context, "preceding-sibling::processing-instruction()");

+            assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::processing-instruction()");

+            assertValueOfXPath("foo", context, "preceding-sibling::*[1]");

+            assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::node()[2]");

+        }

+    }

+

+    public void testid53911() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/id.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        SimpleVariableContext varContext = new SimpleVariableContext();

+        varContext.setVariableValue(null, "foobar", "foobar");

+        varContext.setVariableValue(null, "foo", "foo");

+        getContextSupport().setVariableContext(varContext);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("foobar", context, "$foobar");

+            assertCountXPath(1, context, "/foo[@id=$foobar]");

+            assertCountXPath(0, context, "/foo[@id='$foobar']");

+            assertCountXPath(1, context, "/foo[concat($foo, 'bar')=@id]");

+            assertCountXPath(0, context, "CD_Library/artist[@name=$artist]");

+        }

+    }

+

+    public void testid53957() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/id.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* attributes have a parent: their element

+            */

+            assertCountXPath(1, context, "/foo/@id/parent::foo");

+        }

+    }

+

+    /* attributes can also be used as context nodes

+    */

+    public void testid53975() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/id.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/foo/@id", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "parent::foo");

+        }

+    }

+

+    public void testid53992() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/pi.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(3, context, "//processing-instruction()");

+            assertCountXPath(2, context, "//processing-instruction('cheese')");

+            try

+            {

+                Object result = assertCountXPath2(1, context, "//processing-instruction('toast')");

+                assertValueOfXPath("is tasty", result, "string()");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+        }

+    }

+

+    /* test evaluate() extension function

+    */

+    public void testid54032() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/evaluate.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(3, context, "evaluate('//jumps/*')");

+            assertCountXPath(1, context, "evaluate('//jumps/object/dog')");

+            assertCountXPath(0, context, "evaluate('//jumps/object')/evaluate");

+            assertCountXPath(1, context, "evaluate('//jumps/object')/dog");

+            assertCountXPath(1, context, "evaluate('//jumps/*')/dog");

+            assertCountXPath(1, context, "//metatest[ evaluate(@select) = . ]");

+        }

+    }

+

+    public void testid54082() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/numbers.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/numbers/set[1]", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "*[-3 = .]");

+            assertValueOfXPath("true", context, "54 < *");

+            assertValueOfXPath("true", context, "55 <= *");

+            assertValueOfXPath("false", context, "69 < *");

+            assertValueOfXPath("true", context, "-2 > *");

+            assertValueOfXPath("true", context, "-3 >= *");

+            assertValueOfXPath("false", context, "-4 >= *");

+        }

+    }

+

+    /* TODO

+    This context should work, but needs a fixed version of saxpath to parse the right-hand side

+    of the greater-than expression.

+    <context select="/numbers/set[2]">

+      <valueOf select="1 &gt; nr/@value">false</valueOf>

+      <valueOf select="55 &gt; nr/@value">false</valueOf>

+      <valueOf select="55 &gt;= nr/@value">true</valueOf>

+      <valueOf select="1000000 &gt; nr/@value">true</valueOf>

+    </context>

+    

+    */

+    /* test sibling axes 

+    */

+    public void testid54145() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/axis.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/root", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(0, context, "preceding-sibling::*");

+        }

+    }

+

+    public void testid54156() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/axis.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/root/a/a.3", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(2, context, "preceding::*");

+        }

+    }

+

+    public void testid54168() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/axis.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/root/a/a.3", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(2, context, "preceding-sibling::*");

+        }

+    }

+

+    public void testid54180() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/axis.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("a.2", context, "name(/root/a/a.3/preceding-sibling::*[1])");

+            assertValueOfXPath("a.1", context, "name(/root/a/a.3/preceding-sibling::*[2])");

+        }

+    }

+

+    public void testid54197() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/axis.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("a.4", context, "name(/root/a/a.3/following-sibling::*[1])");

+            assertValueOfXPath("a.5", context, "name(/root/a/a.3/following-sibling::*[2])");

+        }

+    }

+

+    public void testid54219() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("snoop", context, "/web-app/servlet[1]/servlet-name");

+            assertValueOfXPath("snoop", context, "/web-app/servlet[1]/servlet-name/text()");

+            assertValueOfXPath("file", context, "/web-app/servlet[2]/servlet-name");

+            assertValueOfXPath("file", context, "/web-app/servlet[2]/servlet-name/text()");

+        }

+    }

+

+    public void testid54249() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/web-app/servlet[1]", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("snoop", context, "servlet-name");

+            assertValueOfXPath("snoop", context, "servlet-name/text()");

+        }

+    }

+

+    public void testid54266() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/web-app/servlet[2]/servlet-name", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(3, context, "preceding::*");

+        }

+    }

+

+    public void testid54278() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/web-app/servlet[2]/servlet-name", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(13, context, "following::*");

+        }

+    }

+

+    /* test name

+    */

+    public void testid54298() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            try

+            {

+                Object result = assertCountXPath2(1, context, "*");

+                assertValueOfXPath("web-app", result, "name()");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            /* NOTE that the child::node() tests only work if the

+              XML document does not comments or PIs

+

+            */

+            try

+            {

+                Object result = assertCountXPath2(1, context, "./*");

+                assertValueOfXPath("web-app", result, "name()");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                Object result = assertCountXPath2(1, context, "child::*");

+                assertValueOfXPath("web-app", result, "name()");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                Object result = assertCountXPath2(1, context, "/*");

+                assertValueOfXPath("web-app", result, "name()");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                Object result = assertCountXPath2(1, context, "/child::node()");

+                assertValueOfXPath("web-app", result, "name(.)");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                Object result = assertCountXPath2(1, context, "child::node()");

+                assertValueOfXPath("web-app", result, "name(.)");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            /* empty names

+            */

+            assertValueOfXPath("", context, "name()");

+            assertValueOfXPath("", context, "name(.)");

+            assertValueOfXPath("", context, "name(parent::*)");

+            assertValueOfXPath("", context, "name(/)");

+            assertValueOfXPath("", context, "name(/.)");

+            assertValueOfXPath("", context, "name(/self::node())");

+            /* name of root elemet

+            */

+            assertValueOfXPath("web-app", context, "name(node())");

+            assertValueOfXPath("web-app", context, "name(/node())");

+            assertValueOfXPath("web-app", context, "name(/*)");

+            assertValueOfXPath("web-app", context, "name(/child::*)");

+            assertValueOfXPath("web-app", context, "name(/child::node())");

+            assertValueOfXPath("web-app", context, "name(/child::node())");

+            assertValueOfXPath("web-app", context, "name(child::node())");

+            assertValueOfXPath("web-app", context, "name(./*)");

+            assertValueOfXPath("web-app", context, "name(*)");

+        }

+    }

+

+    public void testid54467() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/*", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* empty names

+            */

+            assertValueOfXPath("", context, "name(..)");

+            assertValueOfXPath("", context, "name(parent::node())");

+            assertValueOfXPath("", context, "name(parent::*)");

+            /* name of root elemet

+            */

+            assertValueOfXPath("web-app", context, "name()");

+            assertValueOfXPath("web-app", context, "name(.)");

+            assertValueOfXPath("web-app", context, "name(../*)");

+            assertValueOfXPath("web-app", context, "name(../child::node())");

+        }

+    }

+

+    /* test predicates

+    */

+    public void testid54522() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/nitf.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/nitf/head/docdata", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "doc-id[@regsrc='AP' and @id-string='D76UIMO80']");

+        }

+    }

+

+    public void testid54534() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/nitf.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/nitf/head", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "meta[@name='ap-cycle']");

+            assertCountXPath(1, context, "meta[@content='AP']");

+            assertCountXPath(8, context, "meta[@name and @content]");

+            assertCountXPath(1, context, "meta[@name='ap-cycle' and @content='AP']");

+            assertCountXPath(7, context, "meta[@name != 'ap-cycle']");

+        }

+    }

+

+    public void testid54570() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/nitf.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "/nitf/head/meta[@name='ap-cycle']");

+            assertCountXPath(1, context, "/nitf/head/meta[@content='AP']");

+            assertCountXPath(8, context, "/nitf/head/meta[@name and @content]");

+            assertCountXPath(1, context, "/nitf/head/meta[@name='ap-cycle' and @content='AP']");

+            assertCountXPath(7, context, "/nitf/head/meta[@name != 'ap-cycle']");

+        }

+    }

+

+    public void testid54614() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/moreover.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "/child::node()");

+            assertCountXPath(1, context, "/*");

+            assertCountXPath(20, context, "/*/article");

+            assertCountXPath(221, context, "//*");

+            assertCountXPath(20, context, "//*[local-name()='article']");

+            assertCountXPath(20, context, "//article");

+            assertCountXPath(20, context, "/*/*[@code]");

+            assertCountXPath(1, context, "/moreovernews/article[@code='13563275']");

+            try

+            {

+                BaseXPath xpath = new BaseXPath("/moreovernews/article[@code='13563275']", getNavigator());

+                List results = xpath.selectNodes(getContext(context));

+                Object result = results.get(0);

+                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                BaseXPath xpath = new BaseXPath("/*/article[@code='13563275']", getNavigator());

+                List results = xpath.selectNodes(getContext(context));

+                Object result = results.get(0);

+                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                BaseXPath xpath = new BaseXPath("//article[@code='13563275']", getNavigator());

+                List results = xpath.selectNodes(getContext(context));

+                Object result = results.get(0);

+                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                BaseXPath xpath = new BaseXPath("//*[@code='13563275']", getNavigator());

+                List results = xpath.selectNodes(getContext(context));

+                Object result = results.get(0);

+                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                BaseXPath xpath = new BaseXPath("/child::node()/child::node()[@code='13563275']", getNavigator());

+                List results = xpath.selectNodes(getContext(context));

+                Object result = results.get(0);

+                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            try

+            {

+                BaseXPath xpath = new BaseXPath("/*/*[@code='13563275']", getNavigator());

+                List results = xpath.selectNodes(getContext(context));

+                Object result = results.get(0);

+                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+        }

+    }

+

+    /* test other node types

+    */

+    public void testid54747() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/contents.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(3, context, "processing-instruction()");

+            assertCountXPath(3, context, "/processing-instruction()");

+            assertCountXPath(1, context, "/comment()");

+            assertCountXPath(1, context, "comment()");

+            assertCountXPath(2, context, "/child::node()/comment()");

+            assertCountXPath(2, context, "/*/comment()");

+            assertCountXPath(3, context, "//comment()");

+        }

+    }

+

+    /* test positioning

+    */

+    public void testid54802() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/fibo.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(9, context, "/*/fibonacci[position() < 10]");

+            assertValueOfXPath("196417", context, "sum(//fibonacci)");

+            assertValueOfXPath("325", context, "sum(//fibonacci/@index)");

+            assertValueOfXPath("1", context, "/*/fibonacci[2]");

+            assertValueOfXPath("75025", context, "/*/fibonacci[ count(/*/fibonacci) ]");

+            assertValueOfXPath("46368", context, "/*/fibonacci[ count(/*/fibonacci) - 1 ]");

+        }

+    }

+

+    /* test number functions

+    */

+    /* test Axes 

+    */

+    public void testid54853() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(19, context, "descendant-or-self::*");

+            assertCountXPath(19, context, "descendant::*");

+            assertCountXPath(19, context, "/descendant::*");

+            assertCountXPath(19, context, "/descendant-or-self::*");

+            assertCountXPath(2, context, "/descendant::servlet");

+            assertCountXPath(2, context, "/descendant-or-self::servlet");

+            assertCountXPath(2, context, "descendant-or-self::servlet");

+            assertCountXPath(2, context, "descendant::servlet");

+            assertCountXPath(2, context, "/*/servlet");

+            assertValueOfXPath("2", context, "count(/*/servlet)");

+            assertCountXPath(2, context, "//servlet");

+            assertValueOfXPath("2", context, "count(//servlet)");

+        }

+    }

+

+    public void testid54932() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/web-app", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(2, context, "/descendant::servlet");

+            assertCountXPath(2, context, "/descendant-or-self::servlet");

+            assertCountXPath(2, context, "descendant-or-self::servlet");

+            assertCountXPath(2, context, "descendant::servlet");

+        }

+    }

+

+    public void testid54968() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/much_ado.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(5, context, "/descendant::ACT");

+            assertCountXPath(5, context, "descendant::ACT");

+            assertValueOfXPath("Much Ado about Nothing", context, "/PLAY/TITLE");

+            assertValueOfXPath("4", context, "2+2");

+            assertValueOfXPath("21", context, "5 * 4 + 1");

+            assertValueOfXPath("5", context, "count(descendant::ACT)");

+            assertValueOfXPath("35", context, "10 + count(descendant::ACT) * 5");

+            assertValueOfXPath("75", context, "(10 + count(descendant::ACT)) * 5");

+        }

+    }

+

+    public void testid55020() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/much_ado.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/PLAY/ACT[2]/SCENE[1]", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(5, context, "/descendant::ACT");

+            assertCountXPath(5, context, "../../descendant::ACT");

+            assertCountXPath(141, context, "/PLAY/ACT[2]/SCENE[1]/descendant::SPEAKER");

+            assertCountXPath(141, context, "descendant::SPEAKER");

+            assertValueOfXPath("646", context, "count(descendant::*)+1");

+            assertValueOfXPath("142", context, "count(descendant::SPEAKER)+1");

+            assertValueOfXPath("2", context, "count(ancestor::*)");

+            assertValueOfXPath("1", context, "count(ancestor::PLAY)");

+            assertValueOfXPath("3", context, "count(ancestor-or-self::*)");

+            assertValueOfXPath("1", context, "count(ancestor-or-self::PLAY)");

+            assertValueOfXPath("6", context, "5+count(ancestor::*)-1");

+        }

+    }

+

+    public void testid55090() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/much_ado.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* Test correct predicate application

+            */

+            assertValueOfXPath("5", context, "count(/PLAY/ACT/SCENE[1])");

+        }

+    }

+

+    /* test axis node ordering

+    */

+    public void testid55112() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* Reported as Jira issue JAXEN-24

+            */

+            assertCountXPath(1, context, "//servlet-mapping/preceding::*[1][name()='description']");

+            assertCountXPath(1, context, "/web-app/servlet//description/following::*[1][name()='servlet-mapping']");

+            assertCountXPath(1, context, "/web-app/servlet//description/following::*[2][name()='servlet-name']");

+        }

+    }

+

+    /* test document function

+    */

+    public void testid55150() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/text.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            try

+            {

+                Object result = assertCountXPath2(1, context, "document('test-resources/xml/web.xml')");

+                assertValueOfXPath("snoop", result, "/web-app/servlet[1]/servlet-name");

+                assertValueOfXPath("snoop", result, "/web-app/servlet[1]/servlet-name/text()");

+            }

+            catch (UnsupportedAxisException e)

+            {

+                log(debug, "      ## SKIPPED -- Unsupported Axis");

+            }

+            assertValueOfXPath("snoop", context, "document('test-resources/xml/web.xml')/web-app/servlet[1]/servlet-name");

+        }

+    }

+

+    /* Test to check if the context changes when an extension function is used.

+    First test is an example, second is the actual test.

+    

+    */

+    public void testid55189() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/text.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/foo/bar/cheese[1]", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("3foo3", context, "concat(./@id,'foo',@id)");

+            assertValueOfXPath("3snoop3", context, "concat(./@id,document('test-resources/xml/web.xml')/web-app/servlet[1]/servlet-name,./@id)");

+        }

+    }

+

+    public void testid55211() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/message.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("Pruefgebiete", context, "/message/body/data/items/item[name/text()='parentinfo']/value");

+            assertValueOfXPath("Pruefgebiete", context, "document('test-resources/xml/message.xml')/message/body/data/items/item[name/text()='parentinfo']/value");

+        }

+    }

+

+    /* test behaviour of AbsoluteLocationPath

+    */

+    public void testid55183() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/simple.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/root/a", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("ab", context, "concat( ., /root/b )");

+            assertValueOfXPath("ba", context, "concat( ../b, . )");

+            assertValueOfXPath("ba", context, "concat( /root/b, . )");

+            assertValueOfXPath("db", context, "concat( /root/c/d, ../b )");

+        }

+    }

+

+    /* test the translate() function

+    */

+    public void testid55268() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/simple.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("", context, "translate( '', '', '' )");

+            assertValueOfXPath("abcd", context, "translate( 'abcd', '', '' )");

+            assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcd', 'abcd' )");

+            assertValueOfXPath("abcd", context, "translate( 'abcd', 'dcba', 'dcba' )");

+            assertValueOfXPath("dcba", context, "translate( 'abcd', 'abcd', 'dcba' )");

+            assertValueOfXPath("ab", context, "translate( 'abcd', 'abcd', 'ab' )");

+            assertValueOfXPath("cd", context, "translate( 'abcd', 'cdab', 'cd' )");

+            assertValueOfXPath("xy", context, "translate( 'abcd', 'acbd', 'xy' )");

+            assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcdb', 'abcdb' )");

+            assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcd', 'abcdb' )");

+        }

+    }

+

+    public void testid55331() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/simple.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("234", context, "substring('12345', 1.5, 2.6)");

+            assertValueOfXPath("12", context, "substring('12345', 0, 3)");

+            assertValueOfXPath("", context, "substring('12345', 0 div 0, 3)");

+            assertValueOfXPath("", context, "substring('12345', 1, 0 div 0)");

+            assertValueOfXPath("12345", context, "substring('12345', -42, 1 div 0)");

+            assertValueOfXPath("", context, "substring('12345', -1 div 0, 1 div 0)");

+            assertValueOfXPath("345", context, "substring('12345', 3)");

+            assertValueOfXPath("12345", context, "substring('12345',1,15)");

+        }

+    }

+

+    /* Some tests for the normalize-space() function

+    */

+    public void testid55382() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/simple.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("abc", context, "normalize-space('    abc    ')");

+            assertValueOfXPath("a b c", context, "normalize-space(' a  b  c  ')");

+            assertValueOfXPath("a b c", context, "normalize-space(' a \n b \n  c')");

+            /* Next test case addresses issue JAXEN-22

+            */

+            assertValueOfXPath("", context, "normalize-space(' ')");

+            /* Next test case addresses issue JAXEN-29

+            */

+            assertValueOfXPath("", context, "normalize-space('')");

+        }

+    }

+

+    /* test cases for String extension functions

+    */

+    public void testid55429() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/web.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/web-app/servlet[1]", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class )");

+            assertValueOfXPath("snoopservlet", context, "lower-case( servlet-class )");

+            assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'fr' )");

+            assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'fr-CA' )");

+            assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'es-ES-Traditional_WIN' )");

+            assertValueOfXPath("true", context, "ends-with( servlet-class, 'Servlet' )");

+            assertValueOfXPath("false", context, "ends-with( servlet-class, 'S' )");

+        }

+    }

+

+    /* test cases for the lang() function

+    */

+    public void testid55485() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/lang.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(0, context, "/e1/e2[lang('hr')]");

+//            assertCountXPath(1, context, "/e1/e2/e3[lang('en')]");

+//            assertCountXPath(1, context, "/e1/e2/e3[lang('en-US')]");

+            assertCountXPath(0, context, "/e1/e2/e3[lang('en-GB')]");

+            assertCountXPath(2, context, "/e1/e2/e3[lang('hu')]");

+            assertCountXPath(0, context, "/e1/e2/e3[lang('hu-HU')]");

+            assertCountXPath(1, context, "/e1/e2/e3[lang('es')]");

+            assertCountXPath(0, context, "/e1/e2/e3[lang('es-BR')]");

+        }

+    }

+

+    /* test namespace

+    */

+    public void testid55235() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/namespaces.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();

+        nsContext.addNamespace("alias", "http://fooNamespace/");

+        nsContext.addNamespace("bar", "http://barNamespace/");

+        nsContext.addNamespace("voo", "http://fooNamespace/");

+        nsContext.addNamespace("foo", "http://fooNamespace/");

+        getContextSupport().setNamespaceContext(nsContext);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "/*");

+            assertCountXPath(1, context, "/foo:a");

+            assertCountXPath(1, context, "/foo:a/b");

+            assertCountXPath(1, context, "/voo:a/b/c");

+            assertCountXPath(1, context, "/voo:a/bar:f");

+            assertCountXPath(1, context, "/*[namespace-uri()='http://fooNamespace/' and local-name()='a']");

+            assertCountXPath(1, context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']");

+            assertCountXPath(1, context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']/*[local-name()='y' and namespace-uri()='http://fooNamespace/']");

+        }

+    }

+

+    /* the prefix here and in the document have no relation; it's their

+    namespace-uri binding that counts 

+    */

+    public void testid55615() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/namespaces.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();

+        nsContext.addNamespace("foo", "http://somethingElse/");

+        getContextSupport().setNamespaceContext(nsContext);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(0, context, "/foo:a/b/c");

+        }

+    }

+

+    public void testid55632() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/namespaces.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();

+        nsContext.addNamespace("alias", "http://fooNamespace/");

+        nsContext.addNamespace("bar", "http://barNamespace/");

+        nsContext.addNamespace("foo", "http://fooNamespace/");

+        getContextSupport().setNamespaceContext(nsContext);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertValueOfXPath("Hello", context, "/foo:a/b/c");

+            assertValueOfXPath("Hey", context, "/foo:a/foo:d/foo:e");

+            assertValueOfXPath("Hey3", context, "/foo:a/alias:x/alias:y");

+            assertValueOfXPath("Hey3", context, "/foo:a/foo:x/foo:y");

+            assertValueOfXPath("Hey3", context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']/*[local-name()='y' and namespace-uri()='http://fooNamespace/']");

+        }

+    }

+

+    public void testid55676() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/defaultNamespace.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* NOTE: /a/b/c selects elements in no namespace only!

+            */

+            assertCountXPath(0, context, "/a/b/c");

+            /*

+                The following test uses an unbound prefix 'x' and should throw an exception.

+                Addresses issue JAXEN-18.

+                Turns out this isn't really tested as the test didn't fail when the exception wasn't thrown.

+              <test select="/x:a/x:b/x:c" count="0" exception="true"/>

+

+            */

+        }

+    }

+

+    public void testid55692() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/defaultNamespace.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();

+        nsContext.addNamespace("dummy", "http://dummyNamespace/");

+        getContextSupport().setNamespaceContext(nsContext);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "/dummy:a/dummy:b/dummy:c");

+        }

+    }

+

+    public void testid55716() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/text.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(3, context, "/foo/bar/text()");

+            assertValueOfXPath("baz", context, "normalize-space(/foo/bar/text())");

+        }

+    }

+

+    public void testid55739() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/testNamespaces.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* the root is not an element, so no namespaces

+            */

+            assertCountXPath(0, context, "namespace::*");

+            assertCountXPath(0, context, "/namespace::*");

+            /* must count the default xml: prefix as well

+            */

+            assertCountXPath(3, context, "/Template/Application1/namespace::*");

+            assertCountXPath(3, context, "/Template/Application2/namespace::*");

+            /* every element has separate copies

+            */

+            assertCountXPath(25, context, "//namespace::*");

+        }

+    }

+

+    public void testid55797() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/testNamespaces.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/Template/Application1", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* must count the default xml: prefix as well

+            */

+            assertCountXPath(3, context, "namespace::*");

+            assertCountXPath(0, context, "/namespace::*");

+            assertCountXPath(3, context, "/Template/Application1/namespace::*");

+            assertCountXPath(3, context, "/Template/Application2/namespace::*");

+            assertCountXPath(25, context, "//namespace::*");

+            assertCountXPath(8, context, "//namespace::xplt");

+            /* the name test literally matches the prefix as given in the

+              document, and does not use the uri

+            */

+            assertCountXPath(0, context, "//namespace::somethingelse");

+        }

+    }

+

+    public void testid55873() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/testNamespaces.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            /* namespace nodes have their element as their parent

+            */

+            assertCountXPath(1, context, "/Template/namespace::xml/parent::Template");

+        }

+    }

+

+    /* namespace nodes can also be used as context nodes

+    */

+    public void testid55893() throws JaxenException

+    {

+        Navigator nav = getNavigator();

+        String url = TESTS_ROOT + "xml/testNamespaces.xml";

+        log("Document [" + url + "]");

+        Object document = nav.getDocument(url);

+        XPath contextpath = new BaseXPath("/Template/namespace::xml", nav);

+        log("Initial Context :: " + contextpath);

+        List list = contextpath.selectNodes(document);

+        Iterator iter = list.iterator();

+        while (iter.hasNext())

+        {

+            Object context = iter.next();

+            assertCountXPath(1, context, "parent::Template");

+        }

+    }

+}            

+        
\ No newline at end of file