You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ch...@apache.org on 2006/02/01 11:36:10 UTC

svn commit: r374036 [4/15] - in /webservices/commons/trunk/axiom: src/org/apache/ws/ src/org/apache/ws/commons/ src/org/apache/ws/commons/attachments/ src/org/apache/ws/commons/attachments/utils/ src/org/apache/ws/commons/om/ src/org/apache/ws/commons/...

Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/OMStAXWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/OMStAXWrapper.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/OMStAXWrapper.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/OMStAXWrapper.java Wed Feb  1 02:33:37 2006
@@ -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;
+    }
+
+}

Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/OMTextImpl.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/OMTextImpl.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/OMTextImpl.java Wed Feb  1 02:33:37 2006
@@ -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);
+        }
+    }
+}

Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/SAXOMBuilder.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/SAXOMBuilder.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/SAXOMBuilder.java Wed Feb  1 02:33:37 2006
@@ -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;
+    }
+}

Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/StAXBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/StAXBuilder.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/StAXBuilder.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/StAXBuilder.java Wed Feb  1 02:33:37 2006
@@ -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;
+    }
+}

Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/StAXOMBuilder.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/StAXOMBuilder.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/builder/StAXOMBuilder.java Wed Feb  1 02:33:37 2006
@@ -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++;
+    }
+
+}

Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/OMBuilderException.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/OMBuilderException.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/OMBuilderException.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/OMBuilderException.java Wed Feb  1 02:33:37 2006
@@ -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);
+    }
+}

Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/OMStreamingException.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/OMStreamingException.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/OMStreamingException.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/OMStreamingException.java Wed Feb  1 02:33:37 2006
@@ -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);
+    }
+}