You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ve...@apache.org on 2005/04/28 08:42:28 UTC

svn commit: r165108 [4/6] - in /webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance: ./ XMLConformanceTestingProject/ XMLConformanceTestingProject/bin/ XMLConformanceTestingProject/src/ XMLConformanceTestingProject/src/org/ XMLConformanceTestingProject/src/org/apache/ XMLConformanceTestingProject/src/org/apache/axis/ XMLConformanceTestingProject/src/org/apache/axis/om/ XMLConformanceTestingProject/src/org/apache/axis/om/impl/ XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/ XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/builder/ XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/exception/ XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/factory/ XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/serialize/ XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/traverse/ XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/util/ XMLConformanceTestingProject/test/ XMLConformanceTestingProject/test/junittesting/

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMElementImpl.java?rev=165108&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMElementImpl.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMElementImpl.java Wed Apr 27 23:42:26 2005
@@ -0,0 +1,962 @@
+/*
+ * 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.axis.om.impl.llom;
+
+import org.apache.axis.om.*;
+import org.apache.axis.om.impl.llom.serialize.StreamWriterToContentHandlerConverter;
+import org.apache.axis.om.impl.llom.serialize.StreamingOMSerializer;
+import org.apache.axis.om.impl.llom.traverse.OMChildrenIterator;
+import org.apache.axis.om.impl.llom.traverse.OMChildrenQNameIterator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * Class OMElementImpl
+ */
+public class OMElementImpl extends OMNodeImpl
+        implements OMElement, OMConstants {
+
+    protected OMNamespace ns;
+
+    /**
+     * Field localName
+     */
+    protected String localName;
+    /**
+     * Field firstChild
+     */
+    protected OMNode firstChild;
+
+    /**
+     * Field builder
+     */
+    protected OMXMLParserWrapper builder;
+
+    /**
+     * Field namespaces
+     */
+    private HashMap namespaces = null;
+
+    /**
+     * Field attributes
+     */
+    private HashMap attributes = null;
+
+    /**
+     * Field log
+     */
+    private Log log = LogFactory.getLog(getClass());
+
+    /**
+     * Field noPrefixNamespaceCounter
+     */
+    private int noPrefixNamespaceCounter = 0;
+
+    /**
+     * Constructor OMElementImpl
+     *
+     * @param localName
+     * @param ns
+     * @param parent
+     * @param builder
+     */
+    public OMElementImpl(String localName, OMNamespace ns, OMElement parent,
+                         OMXMLParserWrapper builder) {
+        super(parent);
+        declareNamespace( new OMNamespaceImpl("http://www.w3.org/XML/1998/namespace", "xml"));
+        this.localName = localName;
+        if (ns != null) {
+            setNamespace(handleNamespace(ns));
+        }
+        this.builder = builder;
+        firstChild = null;
+    }
+
+    /**
+     * @param parent
+     * @param parent
+     */
+    protected OMElementImpl(OMElement parent) {
+        super(parent);
+        declareNamespace( new OMNamespaceImpl("http://www.w3.org/XML/1998/namespace", "xml"));
+        this.done = true;
+    }
+
+    /**
+     * Constructor OMElementImpl
+     *
+     * @param localName
+     * @param ns
+     */
+    public OMElementImpl(String localName, OMNamespace ns) {
+        super(null);
+        declareNamespace( new OMNamespaceImpl("http://www.w3.org/XML/1998/namespace", "xml"));
+        this.localName = localName;
+        this.done = true;
+        if (ns != null) {
+            setNamespace(handleNamespace(ns));
+        }
+    }
+
+    /**
+     * Here it is assumed that this QName passed, at least contains the localName for this element
+     *
+     * @param qname
+     * @param parent
+     * @throws OMException
+     */
+    public OMElementImpl(QName qname, OMElement parent) throws OMException {
+        super(parent);
+        declareNamespace( new OMNamespaceImpl("http://www.w3.org/XML/1998/namespace", "xml"));
+        this.localName = qname.getLocalPart();
+        this.done = true;
+        handleNamespace(qname, parent);
+    }
+
+    /**
+     * Method handleNamespace
+     *
+     * @param qname
+     * @param parent
+     */
+    private void handleNamespace(QName qname, OMElement parent) {
+        OMNamespace ns;
+
+        // first try to find a namespace from the scope
+        String namespaceURI = qname.getNamespaceURI();
+        if (!"".equals(namespaceURI)) {
+            ns = findInScopeNamespace(qname.getNamespaceURI(),
+                    qname.getPrefix());
+        } else {
+            if (parent != null) {
+                ns = parent.getNamespace();
+            } else {
+                throw new OMException(
+                        "Element can not be declared without a namespaceURI. Every Element should be namespace qualified");
+            }
+        }
+
+        /**
+         * 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) && !"".equals(namespaceURI)) {
+            String prefix = qname.getPrefix();
+            if (!"".equals(prefix)) {
+                ns = declareNamespace(namespaceURI, prefix);
+            } else {
+                ns = declareNamespace(namespaceURI, getNextNamespacePrefix());
+            }
+        }
+        if (ns == null) {
+            throw new OMException(
+                    "Element can not be declared without a namespaceURI. Every Element should be namespace qualified");
+        }
+        this.setNamespace(ns);
+    }
+
+    /**
+     * Method handleNamespace
+     *
+     * @param ns
+     * @return
+     */
+    private OMNamespace handleNamespace(OMNamespace ns) {
+        OMNamespace namespace = findInScopeNamespace(ns.getName(),
+                ns.getPrefix());
+        if (namespace == null) {
+            namespace = declareNamespace(ns);
+        }
+        return namespace;
+    }
+
+    /**
+     * This will add child to the element. One can decide whether he append the child or he adds to the
+     * front of the children list
+     *
+     * @param child
+     */
+    public void addChild(OMNode child) {
+        addChild((OMNodeImpl) child);
+    }
+
+    /**
+     * This will search for children with a given QName and will return an iterator to traverse through
+     * the OMNodes.
+     * This QName can contain any combination of prefix, localname and URI
+     *
+     * @param elementQName
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public Iterator getChildrenWithName(QName elementQName) throws OMException {
+        return new OMChildrenQNameIterator((OMNodeImpl) getFirstChild(),
+                elementQName);
+    }
+
+    /**
+     * Method getChildWithName
+     *
+     * @param elementQName
+     * @return
+     * @throws OMException
+     */
+    public OMNode getChildWithName(QName elementQName) throws OMException {
+        OMChildrenQNameIterator omChildrenQNameIterator =
+        new OMChildrenQNameIterator((OMNodeImpl) getFirstChild(),
+                elementQName);
+        OMNode omNode = null;
+        if (omChildrenQNameIterator.hasNext()) {
+            omNode = (OMNode) omChildrenQNameIterator.next();
+        }
+        return omNode;
+    }
+
+    /**
+     * Method addChild
+     *
+     * @param child
+     */
+    private void addChild(OMNodeImpl child) {
+        if ((firstChild == null) && !done) {
+            builder.next();
+        }
+
+
+        child.setParent(this);
+
+        child.setPreviousSibling(null);
+        child.setNextSibling(firstChild);
+        if (firstChild != null) {
+            OMNodeImpl firstChildImpl = (OMNodeImpl) firstChild;
+            firstChildImpl.setPreviousSibling(child);
+        }
+        this.setFirstChild(child);
+    }
+
+    /**
+     * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
+     *
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public OMNode getNextSibling() throws OMException {
+        while (!done) {
+            builder.next();
+        }
+        return super.getNextSibling();
+    }
+
+    /**
+     * This returns a collection of this element.
+     * Children can be of types OMElement, OMText.
+     *
+     * @return
+     */
+    public Iterator getChildren() {
+        return new OMChildrenIterator(getFirstChild());
+    }
+
+    /**
+     * THis will create a namespace in the current element scope
+     *
+     * @param uri
+     * @param prefix
+     * @return
+     */
+    public OMNamespace declareNamespace(String uri, String prefix) {
+        OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
+        return declareNamespace(ns);
+    }
+
+    /**
+     * Method setValue
+     *
+     * @param value
+     */
+    public void setValue(String value) {
+        OMText txt = OMFactory.newInstance().createText(value);
+        this.addChild(txt);
+    }
+
+    /**
+     * @param namespace
+     * @return
+     */
+    public OMNamespace declareNamespace(OMNamespace namespace) {
+        if (namespaces == null) {
+            this.namespaces = new HashMap(5);
+        }
+        namespaces.put(namespace.getPrefix(), namespace);
+        return namespace;
+    }
+
+    /**
+     * This will find a namespace with the given uri and prefix, in the scope of the docuemnt.
+     * This will start to find from the current element and goes up in the hiararchy until this finds one.
+     * If none is found, return null
+     *
+     * @param uri
+     * @param prefix
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public OMNamespace findInScopeNamespace(String uri, String prefix)
+            throws OMException {
+
+        // check in the current element
+        OMNamespace namespace = findDeclaredNamespace(uri, prefix);
+        if (namespace != null) {
+            return namespace;
+        }
+
+        // go up to check with ancestors
+        if (parent != null) {
+            return ((OMElement)parent).findInScopeNamespace(uri, prefix);
+        }
+        return null;
+    }
+
+    /**
+     * This will ckeck for the namespace <B>only</B> in the current Element
+     * This can also be used to retrieve the prefix of a known namespace URI
+     *
+     * @param uri
+     * @param prefix
+     * @return
+     * @throws OMException
+     */
+    public OMNamespace findDeclaredNamespace(String uri, String prefix)
+            throws OMException {
+        if (namespaces == null) {
+            return null;
+        }
+        if (prefix == null || "".equals(prefix)) {
+            Iterator namespaceListIterator = namespaces.values().iterator();
+            while (namespaceListIterator.hasNext()) {
+                OMNamespace omNamespace =
+                        (OMNamespace) namespaceListIterator.next();
+                if (omNamespace.getName().equals(uri)) {
+                    return omNamespace;
+                }
+            }
+            return null;
+        } else {
+            return (OMNamespace) namespaces.get(prefix);
+        }
+    }
+
+    /**
+     * Method getAllDeclaredNamespaces
+     *
+     * @return
+     */
+    public Iterator getAllDeclaredNamespaces() {
+        if (namespaces == null) {
+            return null;
+        }
+        return namespaces.values().iterator();
+    }
+
+    /**
+     * This will help to search for an attribute with a given QName within this Element
+     *
+     * @param qname
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public OMAttribute getAttributeWithQName(QName qname) throws OMException {
+        if (attributes == null) {
+            return null;
+        }
+        return (OMAttribute) attributes.get(qname);
+    }
+
+    /**
+     * This will return a List of OMAttributes
+     *
+     * @return
+     */
+    public Iterator getAttributes() {
+        if (attributes == null) {
+            return new Iterator(){
+
+                public void remove() {
+                    throw new UnsupportedOperationException();
+
+                }
+
+                public boolean hasNext() {
+                    return false;  //To change body of implemented methods use File | Settings | File Templates.
+                }
+
+                public Object next() {
+                    throw new UnsupportedOperationException();
+                }
+            };
+        }
+        return attributes.values().iterator();
+    }
+
+    /**
+     * This will insert attribute to this element. Implementor can decide as to insert this
+     * in the front or at the end of set of attributes
+     *
+     * @param attr
+     * @return
+     */
+    public OMAttribute insertAttribute(OMAttribute attr) {
+        if (attributes == null) {
+            this.attributes = new HashMap(5);
+        }
+        attributes.put(attr.getQName(), attr);
+        return attr;
+    }
+
+    /**
+     * Method removeAttribute
+     *
+     * @param attr
+     */
+    public void removeAttribute(OMAttribute attr) {
+        if (attributes != null) {
+            attributes.remove(attr.getQName());
+        }
+    }
+
+    /**
+     * Method insertAttribute
+     *
+     * @param attributeName
+     * @param value
+     * @param ns
+     * @return
+     */
+    public OMAttribute insertAttribute(String attributeName, String value,
+                                       OMNamespace ns) {
+        OMNamespace namespace = null;
+        if (ns != null) {
+            namespace = findInScopeNamespace(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 insertAttribute(new OMAttributeImpl(attributeName, ns, value));
+    }
+
+    /**
+     * Method setBuilder
+     *
+     * @param wrapper
+     */
+    public void setBuilder(OMXMLParserWrapper wrapper) {
+        this.builder = wrapper;
+    }
+
+    /**
+     * Method getBuilder
+     *
+     * @return
+     */
+    public OMXMLParserWrapper getBuilder() {
+        return builder;
+    }
+
+    /**
+     * This will force the parser to proceed, if parser has not yet finished with the XML input
+     */
+    public void buildNext() {
+        builder.next();
+    }
+
+    /**
+     * Method getFirstChild
+     *
+     * @return
+     */
+    public OMNode getFirstChild() {
+        while ((firstChild == null) && !done) {
+            buildNext();
+        }
+        return firstChild;
+    }
+
+    /**
+     * Method setFirstChild
+     *
+     * @param firstChild
+     */
+    public void setFirstChild(OMNode firstChild) {
+        this.firstChild = firstChild;
+    }
+
+    /**
+     * This will remove this information item and its children, from the model completely
+     *
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public void detach() throws OMException {
+        if (done) {
+            super.detach();
+        } else {
+            builder.discard(this);
+        }
+    }
+
+    /**
+     * Method isComplete
+     *
+     * @return
+     */
+    public boolean isComplete() {
+        return done;
+    }
+
+    /**
+     * This will return the literal value of the node.
+     * OMText --> the text
+     * OMElement --> local name of the element in String format
+     * OMAttribute --> the value of the attribue
+     *
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public String getValue() throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This is to get the type of node, as this is the super class of all the nodes
+     *
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public short getType() throws OMException {
+        return OMNode.ELEMENT_NODE;
+    }
+
+    /**
+     * @param cacheOff
+     * @return
+     */
+    public XMLStreamReader getPullParser(boolean cacheOff) {
+        if ((builder == null) && cacheOff) {
+            throw new UnsupportedOperationException(
+                    "This element was not created in a manner to be switched");
+        }
+        return new OMStAXWrapper(builder, this, cacheOff);
+    }
+
+    public String getText() {
+        String childText = "";
+        OMNode child = this.getFirstChild();
+        while(child != null){
+            if(child.getType() == OMNode.TEXT_NODE && child.getValue() != null && !"".equals(child.getValue().trim())){
+               childText += child.getValue().trim();
+            }
+            child = child.getNextSibling();
+        }
+
+        return childText;
+    }
+
+    /**
+     * Method serialize
+     *
+     * @param writer
+     * @param cache
+     * @throws XMLStreamException
+     */
+    public void serialize(XMLStreamWriter writer, boolean cache)
+            throws XMLStreamException {
+        boolean firstElement = false;
+        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(writer));
+
+            // for now only SAX
+        }
+
+        // Special case for the pull type building with cache off
+        // The getPullParser method returns the current elements itself.
+        if (!cache) {
+            if ((firstChild == null) && (nextSibling == null) && !isComplete()
+                    && (builderType == PULL_TYPE_BUILDER)) {
+                StreamingOMSerializer streamingOMSerializer =
+                new StreamingOMSerializer();
+                streamingOMSerializer.serialize(this.getPullParser(!cache),
+                        writer);
+                return;
+            }
+        }
+        if (!cache) {
+            if (isComplete()) {
+
+                // serialize own normally
+                serializeNormal(writer, cache);
+                if (nextSibling != null) {
+
+                    // serilize next sibling
+                    nextSibling.serialize(writer, cache);
+                } else {
+                    if (parent == null) {
+                        return;
+                    } else if (((OMElement)parent).isComplete()) {
+                        return;
+                    } else {
+
+                        // do the special serialization
+                        // Only the push serializer is left now
+                        builder.setCache(cache);
+                        builder.next();
+                    }
+                }
+            } else if (firstChild != null) {
+            	if (!(this instanceof OMDocument)) {
+            		serializeStartpart(writer);
+            		log.info("Serializing the Element from " + localName
+                                + " the generated OM tree");
+            	}
+                firstChild.serialize(writer, cache);
+                if (!(this instanceof OMDocument)) {
+                	serializeEndpart(writer);
+                }
+            } else {
+
+                // do the special serilization
+                // Only the push serializer is left now
+                builder.setCache(cache);
+                if (!(this instanceof OMDocument)) {
+                	serializeStartpart(writer);
+                }
+                builder.next();
+                if (!(this instanceof OMDocument)) {
+                	serializeEndpart(writer);
+                }
+            }
+        } else {
+
+            // serialize own normally
+            serializeNormal(writer, cache);
+
+            // serialize the siblings if this is not the first element
+            if (!firstElement) {
+                OMNode nextSibling = this.getNextSibling();
+                if (nextSibling != null) {
+                    nextSibling.serialize(writer, cache);
+                }
+            }
+        }
+    }
+
+    /**
+     * This was requested during the second Axis2 summit. When one call this method, this will
+     * serialise without building the object structure in the memory. Misuse of this method will cause loss of data.
+     * So its adviced to use populateYourSelf() method, before this, if you want to preserve data in the stream.
+     * @param writer
+     * @throws XMLStreamException
+     */
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        this.serialize(writer, false);
+    }
+
+
+
+    /**
+     * Method serializeStartpart
+     *
+     * @param writer
+     * @throws XMLStreamException
+     */
+    private void serializeStartpart(XMLStreamWriter writer)
+            throws XMLStreamException {
+        String nameSpaceName = null;
+        String writer_prefix = null;
+        String prefix = null;
+        if (ns != null) {
+            nameSpaceName = ns.getName();
+            writer_prefix = writer.getPrefix(nameSpaceName);
+            prefix = ns.getPrefix();
+            if (nameSpaceName != null) {
+                if (writer_prefix != null) {
+                    writer.writeStartElement(nameSpaceName,
+                            this.getLocalName());
+                } else {
+                    if (prefix != null) {
+                        writer.writeStartElement(prefix, this.getLocalName(),
+                                nameSpaceName);
+                        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());
+//                throw new OMException(
+//                        "Non namespace qualified elements are not allowed");
+            }
+        } else {
+            writer.writeStartElement(this.getLocalName());
+//            throw new OMException(
+//                    "Non namespace qualified elements are not allowed");
+        }
+
+        // add the elements attributes
+        if (attributes != null) {
+            Iterator attributesList = attributes.values().iterator();
+            while (attributesList.hasNext()) {
+                serializeAttribute((OMAttribute) attributesList.next(), writer);
+            }
+        }
+
+        // add the namespaces
+        Iterator namespaces = this.getAllDeclaredNamespaces();
+        if (namespaces != null) {
+            while (namespaces.hasNext()) {
+                serializeNamespace((OMNamespace) namespaces.next(), writer);
+            }
+        }
+    }
+
+    /**
+     * Method serializeEndpart
+     *
+     * @param writer
+     * @throws XMLStreamException
+     */
+    private void serializeEndpart(XMLStreamWriter writer)
+            throws XMLStreamException {
+        writer.writeEndElement();
+    }
+
+    /**
+     * Method serializeNormal
+     *
+     * @param writer
+     * @param cache
+     * @throws XMLStreamException
+     */
+    private void serializeNormal(XMLStreamWriter writer, boolean cache)
+            throws XMLStreamException {
+    	if (!(this instanceof OMDocument)) {
+    		serializeStartpart(writer);
+    	}
+        OMNode firstChild = getFirstChild();//todo
+        if (firstChild != null) {
+            firstChild.serialize(writer, cache);
+        }
+        if (!(this instanceof OMDocument)) {
+        	serializeEndpart(writer);
+        }
+    }
+
+    /**
+     * Method serializeAttribute
+     *
+     * @param attr
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeAttribute(OMAttribute attr, XMLStreamWriter writer)
+            throws XMLStreamException {
+
+        // first check whether the attribute is associated with a namespace
+        OMNamespace ns = attr.getNamespace();
+        String prefix = null;
+        String namespaceName = null;
+        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.getValue());
+            } else {
+                writer.writeAttribute(namespaceName, attr.getLocalName(),
+                        attr.getValue());
+            }
+        } else {
+            writer.writeAttribute(attr.getLocalName(), attr.getValue());
+        }
+    }
+
+    /**
+     * Method serializeNamespace
+     *
+     * @param namespace
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeNamespace(
+            OMNamespace namespace, XMLStreamWriter writer)
+            throws XMLStreamException {
+        if (namespace != null) {
+            String uri = namespace.getName();
+            String prefix = writer.getPrefix(uri);
+            String ns_prefix = namespace.getPrefix();
+            if (prefix == null) {
+                writer.writeNamespace(ns_prefix, namespace.getName());
+                writer.setPrefix(ns_prefix, uri);
+            }
+        }
+    }
+
+    /**
+     * Method getNextNamespacePrefix
+     *
+     * @return
+     */
+    private String getNextNamespacePrefix() {
+        return "ns" + ++noPrefixNamespaceCounter;
+    }
+
+    public OMElement getFirstElement() {
+        OMNode node = getFirstChild();
+        while(node != null){
+            if(node.getType() == OMNode.ELEMENT_NODE){
+                return (OMElement)node;
+            }else{
+                node = node.getNextSibling();
+            }
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.axis.om.OMElement#getNextSiblingElement()
+     */
+    public OMElement getNextSiblingElement() throws OMException {
+        OMNode node = getNextSibling();
+        while(node != null){
+            if(node.getType() == OMNode.ELEMENT_NODE){
+                return (OMElement)node;
+            }else{
+                node = node.getNextSibling();
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * Method getLocalName
+     *
+     * @return
+     */
+    public String getLocalName() {
+        return localName;
+    }
+
+    /**
+     * Method setLocalName
+     *
+     * @param localName
+     */
+    public void setLocalName(String localName) {
+        this.localName = localName;
+    }
+
+    /**
+     * Method getNamespace
+     *
+     * @return
+     * @throws OMException
+     */
+    public OMNamespace getNamespace() throws OMException {
+        if ((ns == null) && (parent != null)) {
+            ns = ((OMElement)parent).getNamespace();
+        }
+        if (ns == null) {
+            throw new OMException("all elements in a soap message must be namespace qualified");
+        }
+        return ns;
+    }
+
+    /**
+     * Method getNamespaceName
+     *
+     * @return
+     */
+    public String getNamespaceName() {
+        if (ns != null) {
+            return ns.getName();
+        }
+        return null;
+    }
+
+    /**
+     * @param namespace
+     */
+    public void setNamespace(OMNamespace namespace) {
+        this.ns = namespace;
+    }
+
+    /**
+     * Method getQName
+     *
+     * @return
+     */
+    public QName getQName() {
+        QName qName = null;
+
+        if (ns != null) {
+            qName = new QName(ns.getName(), localName, ns.getPrefix());
+        }else{
+            qName = new QName(localName);
+        }
+        return qName;
+    }
+
+    /**
+     * This will completely parse this node and build the object structure in the memory
+     * @throws OMException
+     */
+    public void populateYourSelf() throws OMException {
+        while(!done){
+            builder.next();
+        }
+    }
+
+}

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNamespaceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNamespaceImpl.java?rev=165108&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNamespaceImpl.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNamespaceImpl.java Wed Apr 27 23:42:26 2005
@@ -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.axis.om.impl.llom;
+
+import org.apache.axis.om.OMNamespace;
+
+/**
+ * Class OMNamespaceImpl
+ */
+public class OMNamespaceImpl implements OMNamespace {
+    /**
+     * Field prefix
+     */
+    private String prefix;
+
+    /**
+     * Field uri
+     */
+    private String uri;
+
+    // private String value;
+
+    /**
+     * @param uri
+     * @param prefix
+     */
+    public OMNamespaceImpl(String uri, String prefix) {
+        this.uri = uri;
+        this.prefix = prefix;
+    }
+
+    /**
+     * Method equals
+     *
+     * @param uri
+     * @param prefix
+     * @return
+     */
+    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
+     */
+    public String getPrefix() {
+        return prefix;
+    }
+
+    /**
+     * Method getName
+     *
+     * @return
+     */
+    public String getName() {
+        return uri;
+    }
+}

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNavigator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNavigator.java?rev=165108&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNavigator.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNavigator.java Wed Apr 27 23:42:26 2005
@@ -0,0 +1,191 @@
+/*
+ *
+ * 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.axis.om.impl.llom;
+
+ import org.apache.axis.om.OMElement;
+ import org.apache.axis.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;
+     }
+
+     /**
+      * get the next node
+      *
+      * @return OMnode in the sequence of preorder traversal. Note however that an element node is
+      *         treated slightly diffrently. 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 = (OMNode)next.getParent();
+             if (nextSibling != null) {
+                 next = nextSibling;
+             } else if ((parent != null) && parent.isComplete()) {
+                 next = parent;
+                 backtracked = true;
+             } else {
+                 next = null;
+             }
+         }
+     }
+
+     /**
+      * Method visited
+      *
+      * @return
+      */
+     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 but
+      * the navigator cannot proceed
+      */
+     public void step() {
+         if (!end) {
+             next = node;
+             updateNextNode();
+         }
+     }
+
+     /**
+      * the navigable status
+      *
+      * @return
+      */
+     public boolean isNavigable() {
+         if (end) {
+             return false;
+         } else {
+             return !(next == null);
+         }
+     }
+
+     /**
+      * The completed status
+      *
+      * @return
+      */
+     public boolean isCompleted() {
+         return end;
+     }
+ }

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNodeImpl.java?rev=165108&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNodeImpl.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMNodeImpl.java Wed Apr 27 23:42:26 2005
@@ -0,0 +1,297 @@
+/*
+ * 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.axis.om.impl.llom;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNode;
+//import org.apache.axis.om.OMContainer;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Class OMNodeImpl
+ */
+public abstract class OMNodeImpl implements OMNode {
+    /**
+     * Field parent
+     */
+    //protected OMElementImpl parent;
+	protected OMElementImpl parent;
+
+    /**
+     * Field nextSibling
+     */
+    protected OMNodeImpl nextSibling;
+
+    /**
+     * Field previousSibling
+     */
+    protected OMNodeImpl previousSibling;
+
+    /**
+     * Field value
+     */
+    protected String value;
+
+    /**
+     * Field done
+     */
+    protected boolean done = false;
+
+    /**
+     * Field nodeType
+     */
+    protected short nodeType;
+
+    /**
+     * Constructor OMNodeImpl
+     */
+    public OMNodeImpl() {
+    }
+
+    /**
+     * For a node to exist there must be a parent
+     *
+     * @param parent
+     */
+    public OMNodeImpl(OMElement parent) {
+        if ((parent != null) && (parent.getType() == OMNode.ELEMENT_NODE)) {
+            this.parent = (OMElementImpl) parent;
+        }
+    }
+
+    /**
+     * This method should return the immediate parent of the node.
+     * Parent is always an Element
+     *
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public OMElement getParent() throws OMException {
+        return parent;
+    }
+
+    /**
+     * Method setParent
+     *
+     * @param element
+     */
+    public void setParent(OMElement element) {
+
+        if( ((OMElement)this.parent) == element){
+            return;
+        }
+
+        if (element instanceof OMNodeImpl) {
+            if(this.parent != null){
+                this.detach();
+            }
+            this.parent = (OMElementImpl) element;
+        }
+    }
+
+    /**
+     * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText or OMELement for others.
+     *
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public OMNode getNextSibling() throws OMException {
+        if ((nextSibling == null) && (parent != null) && !((OMElementImpl)parent).isComplete()) {
+            ((OMElementImpl)parent).buildNext();
+        }
+        return nextSibling;
+    }
+
+    /**
+     * Method setNextSibling
+     *
+     * @param node
+     */
+    public void setNextSibling(OMNode node) {
+        this.nextSibling = (OMNodeImpl) node;
+    }
+
+    /**
+     * This will return the literal value of the node.
+     * OMText --> the text
+     * OMElement --> local name of the element in String format
+     * OMAttribute --> the value of the attribue
+     *
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public String getValue() throws OMException {
+        return value;
+    }
+
+    /**
+     * Method setValue
+     *
+     * @param value
+     */
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    /**
+     * this will indicate whether parser has parsed this information item completely or not.
+     * If somethings 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
+     */
+    public boolean isComplete() {
+        return true;
+    }
+
+    /**
+     * Method setComplete
+     *
+     * @param state
+     */
+    public void setComplete(boolean state) {
+        this.done = state;
+    }
+
+    /**
+     * This will remove this information item and its children, from the model completely
+     *
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public void detach() throws OMException {
+        if (parent == null) {
+            throw new OMException(
+                    "Elements that doesn't have a parent can not be detached");
+        }
+        OMNodeImpl nextSibling = (OMNodeImpl) getNextSibling();
+        if (previousSibling == null) {
+            ((OMElementImpl)parent).setFirstChild(nextSibling);
+        } else {
+            previousSibling.setNextSibling(nextSibling);
+        }
+        if (nextSibling != null) {
+            nextSibling.setPreviousSibling(previousSibling);
+        }
+    }
+
+    /**
+     * This will insert a sibling just after the current information item.
+     *
+     * @param sibling
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public void insertSiblingAfter(OMNode sibling) throws OMException {
+        if (parent == null) {
+            throw new OMException();
+        }
+        sibling.setParent(parent);
+        if (sibling instanceof OMNodeImpl) {
+            OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
+            if (nextSibling == null) {
+                getNextSibling();
+            }
+            siblingImpl.setPreviousSibling(this);
+            if (nextSibling != null) {
+                nextSibling.setPreviousSibling(sibling);
+            }
+            sibling.setNextSibling(nextSibling);
+            nextSibling = siblingImpl;
+        }
+    }
+
+    /**
+     * This will insert a sibling just before the current information item
+     *
+     * @param sibling
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public void insertSiblingBefore(OMNode sibling) throws OMException {
+        if (parent == null) {
+            throw new OMException();
+        }
+        sibling.setParent(parent);
+        if (sibling instanceof OMNodeImpl) {
+            OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
+            siblingImpl.setPreviousSibling(previousSibling);
+            siblingImpl.setNextSibling(this);
+            if (previousSibling == null) {
+                ((OMElementImpl)parent).setFirstChild(siblingImpl);
+            } else {
+                previousSibling.setNextSibling(siblingImpl);
+            }
+            previousSibling = siblingImpl;
+        }
+    }
+
+    /**
+     * This is to get the type of node, as this is the super class of all the nodes
+     *
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public short getType() throws OMException {
+        return nodeType;
+    }
+
+    /**
+     * Method setType
+     *
+     * @param nodeType
+     * @throws OMException
+     */
+    public void setType(short nodeType) throws OMException {
+        this.nodeType = nodeType;
+    }
+
+    /**
+     * Method getPreviousSibling
+     *
+     * @return
+     */
+    public OMNode getPreviousSibling() {
+        return previousSibling;
+    }
+
+    /**
+     * Method setPreviousSibling
+     *
+     * @param previousSibling
+     */
+    public void setPreviousSibling(OMNode previousSibling) {
+        this.previousSibling = (OMNodeImpl) previousSibling;
+    }
+
+    /**
+     * Method serialize
+     *
+     * @param writer
+     * @param cache
+     * @throws XMLStreamException
+     */
+
+
+
+}

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMPIImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMPIImpl.java?rev=165108&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMPIImpl.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMPIImpl.java Wed Apr 27 23:42:26 2005
@@ -0,0 +1,76 @@
+/*
+ * Created on Apr 13, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.axis.om.impl.llom;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMPI;
+
+/**
+ * @author sunja07
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class OMPIImpl extends OMNodeImpl implements OMPI {
+
+	String piTarget;
+		
+	/**
+	 * @param parent
+	 */
+	public OMPIImpl(OMElement parent, String piTarget, String content) {
+		super(parent);
+		this.piTarget = piTarget;
+		this.setValue(content);		
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis.om.OMPI#getTarget()
+	 */
+	public String getTarget() {
+		return this.piTarget;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis.om.OMPI#getContent()
+	 */
+	public String getContent() {
+		return getValue();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis.om.OMNode#getParent()
+	 */
+	public OMElement getParent() throws OMException {
+		return super.getParent();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis.om.OMNode#serialize(javax.xml.stream.XMLStreamWriter, boolean)
+	 */
+	public void serialize(XMLStreamWriter writer, boolean cache)
+			throws XMLStreamException {
+		writer.writeProcessingInstruction(piTarget, this.value);
+		OMNode nextSibling = this.getNextSibling();
+        if (nextSibling != null) {
+            nextSibling.serialize(writer, cache);
+        }
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis.om.OMNode#serialize(javax.xml.stream.XMLStreamWriter)
+	 */
+	public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+		serialize(writer,false);
+	}
+
+}

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMStAXWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMStAXWrapper.java?rev=165108&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMStAXWrapper.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMStAXWrapper.java Wed Apr 27 23:42:26 2005
@@ -0,0 +1,1165 @@
+/*
+ * 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.axis.om.impl.llom;
+
+import org.apache.axis.om.OMAttribute;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMText;
+import org.apache.axis.om.OMXMLParserWrapper;
+import org.apache.axis.om.impl.llom.exception.OMStreamingException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+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 log
+     */
+    private Log log = LogFactory.getLog(getClass());
+
+    /**
+     * 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;
+
+    /**
+     * Method setAllowSwitching
+     *
+     * @param b
+     */
+    public void setAllowSwitching(boolean b) {
+        this.switchingAllowed = b;
+    }
+
+    /**
+     * Method isAllowSwitching
+     *
+     * @return
+     */
+    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 wil 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
+     */
+    OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode) {
+        this(builder, startNode, false);
+    }
+
+    /**
+     * Constructor OMStAXWrapper
+     *
+     * @param builder
+     * @param startNode
+     * @param cacheOff
+     */
+    OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode,
+                  boolean cacheOff) {
+
+        // create a navigator
+        this.navigator = new OMNavigator(startNode);
+        this.builder = builder;
+        this.rootNode = startNode;
+
+        // 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 = cacheOff;
+    }
+
+    /**
+     * @return
+     * @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
+     * @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
+     * @see javax.xml.stream.XMLStreamReader#hasName()
+     */
+    public boolean hasName() {
+        if (parser != null) {
+            return parser.hasName();
+        } else {
+            return ((currentEvent == START_ELEMENT)
+                               || (currentEvent == END_ELEMENT));
+        }
+    }
+
+    /**
+     * @return
+     * @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
+     * @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
+     * @see javax.xml.stream.XMLStreamReader#hasText()
+     */
+    public boolean hasText() {
+        return ((currentEvent == CHARACTERS) || (currentEvent == DTD)
+                           || (currentEvent == ENTITY_REFERENCE)
+                           || (currentEvent == COMMENT) || (currentEvent == SPACE));
+    }
+
+    /**
+     * @return
+     * @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.getValue().length();
+        }
+        return returnLength;
+    }
+
+    /**
+     * @return
+     * @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
+     * @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 (hasText()) {
+            if (parser != null) {
+                try {
+                    returnLength = parser.getTextCharacters(i, chars, i1, i2);
+                } catch (XMLStreamException e) {
+                    throw new OMStreamingException(e);
+                }
+            }
+
+            // Note - this has no relevant method in the OM
+        }
+        return returnLength;
+    }
+
+    /**
+     * @return
+     * @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.getValue();
+                returnArray = str.toCharArray();
+            }
+        }
+        return returnArray;
+    }
+
+    /**
+     * @return
+     * @see javax.xml.stream.XMLStreamReader#getText()
+     */
+    public String getText() {
+        String returnString = null;
+        if (parser != null) {
+            returnString = parser.getText();
+        } else {
+            if (hasText()) {
+                OMText textNode = (OMText) lastNode;
+                returnString = textNode.getValue();
+            }
+        }
+        return returnString;
+    }
+
+    /**
+     * @return
+     * @see javax.xml.stream.XMLStreamReader#getEventType()
+     */
+
+    // todo this should be improved
+    public int getEventType() {
+        return currentEvent;
+    }
+
+    /**
+     * @param i
+     * @return
+     * @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
+     * @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
+     * @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
+     * @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
+     * @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.getValue();
+                }
+            } else {
+                throw new IllegalStateException(
+                        "attribute type accessed in illegal event!");
+            }
+        }
+        return returnString;
+    }
+
+    /**
+     * @param i
+     * @return
+     * @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
+     * @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
+     * @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
+     * @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
+     * @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
+     * @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.getAttributes());
+            } else {
+                throw new IllegalStateException(
+                        "attribute count accessed in illegal event!");
+            }
+        }
+        return returnCount;
+    }
+
+    // todo
+
+    /**
+     * Method getAttributeValue
+     *
+     * @param s
+     * @param s1
+     * @return
+     */
+    public String getAttributeValue(String s, String s1) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method isWhiteSpace
+     *
+     * @return
+     */
+    public boolean isWhiteSpace() {
+        boolean b;
+        if (parser != null) {
+            b = parser.isWhiteSpace();
+        } else {
+            b = (currentEvent == SPACE);
+        }
+        return b;
+    }
+
+    /**
+     * Method isCharacters
+     *
+     * @return
+     */
+    public boolean isCharacters() {
+        boolean b;
+        if (parser != null) {
+            b = parser.isCharacters();
+        } else {
+            b = (currentEvent == CHARACTERS);
+        }
+        return b;
+    }
+
+    /**
+     * Method isEndElement
+     *
+     * @return
+     */
+    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
+     */
+    public boolean isStartElement() {
+        boolean b;
+        if (parser != null) {
+            b = parser.isStartElement();
+        } else {
+            b = (currentEvent == START_ELEMENT);
+        }
+        return b;
+    }
+
+    /**
+     * Method getNamespaceURI
+     *
+     * @param s
+     * @return
+     */
+    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
+     * @throws XMLStreamException
+     */
+    public boolean hasNext() throws XMLStreamException {
+        return !(state == DOCUMENT_COMPLETE);
+    }
+
+    /**
+     * Not implemented yet
+     *
+     * @return
+     * @throws org.apache.axis.om.impl.llom.exception.OMStreamingException
+     *
+     * @throws XMLStreamException
+     */
+    public int nextTag() throws XMLStreamException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * @return
+     * @throws XMLStreamException
+     * @see javax.xml.stream.XMLStreamReader#getElementText()
+     */
+    public String getElementText() throws XMLStreamException {
+        String returnText = "";
+        if (parser != null) {
+            try {
+                returnText = parser.getElementText();
+            } catch (XMLStreamException e) {
+                throw new OMStreamingException(e);
+            }
+        } else {
+            if (currentNode.getType() == OMNode.ELEMENT_NODE) {
+
+                // todo complete this
+                return null;
+            }
+        }
+        return returnText;
+    }
+
+    /**
+     * Method next
+     *
+     * @return
+     * @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 UnsupportedOperationException(
+                            "incompatible parser found!");
+                }
+                log.info(
+                        "Switching to the Real Stax parser to generated the future events");
+                currentEvent = parser.getEventType();
+                updateCompleteStatus();
+                break;
+            case NAVIGABLE:
+                currentEvent = generateEvents(currentNode);
+                updateCompleteStatus();
+                updateLastNode();
+                break;
+            case SWITCHED:
+                currentEvent = parser.next();
+                updateCompleteStatus();
+                break;
+            default :
+                throw new OMStreamingException("unsuppported state!");
+        }
+        return currentEvent;
+    }
+
+    /**
+     * Method getProperty
+     *
+     * @param s
+     * @return
+     * @throws IllegalArgumentException
+     */
+    public Object getProperty(String s) throws IllegalArgumentException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This is a very important method. this keeps the
+     * navigator one step ahead and pushes the navigator
+     * 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 {
+            state = (currentEvent == END_DOCUMENT)
+                    ? DOCUMENT_COMPLETE
+                    : state;
+        }
+    }
+
+    /**
+     * Method getNamespaceContext
+     *
+     * @return
+     */
+    public NamespaceContext getNamespaceContext() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method getEncoding
+     *
+     * @return
+     */
+    public String getEncoding() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method getLocation
+     *
+     * @return
+     */
+    public Location getLocation() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method getVersion
+     *
+     * @return
+     */
+    public String getVersion() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method isStandalone
+     *
+     * @return
+     */
+    public boolean isStandalone() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method standaloneSet
+     *
+     * @return
+     */
+    public boolean standaloneSet() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method getCharacterEncodingScheme
+     *
+     * @return
+     */
+    public String getCharacterEncodingScheme() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method getPITarget
+     *
+     * @return
+     */
+    public String getPITarget() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method getPIData
+     *
+     * @return
+     */
+    public String getPIData() {
+        throw new UnsupportedOperationException();
+    }
+
+    /*
+     *
+     * ################################################################
+     * Generator methods for the OMNodes returned by the navigator
+     * ################################################################
+     *
+     */
+
+    /**
+     * Method generateEvents
+     *
+     * @param node
+     * @return
+     */
+    private int generateEvents(OMNode node) {
+        int returnEvent = 0;
+        int nodeType = node.getType();
+        switch (nodeType) {
+            case OMNode.ELEMENT_NODE:
+                OMElement element = (OMElement) node;
+                log.info("Generating events from element {"
+                                + element.getNamespaceName() + '}'
+                                + element.getLocalName() + " Generated OM tree");
+                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
+     */
+    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
+     */
+    private int generateTextEvents() {
+        return CHARACTERS;
+    }
+
+    /**
+     * Method generateCommentEvents
+     *
+     * @return
+     */
+    private int generateCommentEvents() {
+        return COMMENT;
+    }
+
+    /**
+     * Method generateCdataEvents
+     *
+     * @return
+     */
+    private int generateCdataEvents() {
+        return CDATA;
+    }
+
+    /*
+     * ####################################################################
+     * Other helper methods
+     * ####################################################################
+     */
+
+    /**
+     * helper method
+     *
+     * @param it
+     * @return
+     */
+    private int getCount(Iterator it) {
+        int count = 0;
+        if (it != null) {
+            while (it.hasNext()) {
+                it.next();
+                count++;
+            }
+        }
+        return count;
+    }
+
+    /**
+     * Helper method
+     *
+     * @param it
+     * @param index
+     * @return
+     */
+    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
+     *
+     * @param element
+     * @return
+     */
+    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
+     */
+    private OMAttribute getAttribute(OMElement elt, int index) {
+        OMAttribute returnAttrib = null;
+        if (elt != null) {
+            returnAttrib =
+            (OMAttribute) getItemFromIterator(elt.getAttributes(), index);
+        }
+        return returnAttrib;
+    }
+}

Added: webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMTextImpl.java?rev=165108&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMTextImpl.java (added)
+++ webservices/axis/trunk/archive/java/scratch/ashu_jaya_venkat/xml_conformance/XMLConformanceTestingProject/src/org/apache/axis/om/impl/llom/OMTextImpl.java Wed Apr 27 23:42:26 2005
@@ -0,0 +1,134 @@
+/*
+ * 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.axis.om.impl.llom;
+
+import org.apache.axis.om.OMConstants;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMException;
+import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMText;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Class OMTextImpl
+ */
+public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {
+    /**
+     * Field textType
+     */
+    protected short textType = TEXT_NODE;
+
+    /**
+     * Constructor OMTextImpl
+     *
+     * @param parent
+     * @param text
+     */
+    public OMTextImpl(OMElement parent, String text) {
+        super(parent);
+        setValue(text);
+        done = true;
+    }
+
+    /**
+     * Constructor OMTextImpl
+     *
+     * @param s
+     */
+    public OMTextImpl(String s) {
+        setValue(s);
+    }
+
+    /**
+     * We use the OMText class to hold comments, text, characterData, CData, etc.,
+     * The codes are found in OMNode class
+     *
+     * @param type
+     */
+    public void setTextType(short type) {
+        if ((type == TEXT_NODE) || (type == COMMENT_NODE)
+                || (type == CDATA_SECTION_NODE)) {
+            this.textType = type;
+        } else {
+            throw new UnsupportedOperationException(
+                    "Attempt to set wrong type");
+        }
+    }
+
+    /**
+     * Method getTextType
+     *
+     * @return
+     */
+    public short getTextType() {
+        return textType;
+    }
+
+    /**
+     * Method getFirstChild
+     *
+     * @return
+     * @throws OMException
+     */
+    public OMNode getFirstChild() throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Method setFirstChild
+     *
+     * @param node
+     * @throws OMException
+     */
+    public void setFirstChild(OMNode node) throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * @return
+     * @throws org.apache.axis.om.OMException
+     * @throws OMException
+     */
+    public short getType() throws OMException {
+        return textType;
+    }
+
+    /**
+     * @param writer
+     * @param cache
+     * @throws XMLStreamException
+     */
+    public void serialize(XMLStreamWriter writer, boolean cache)
+            throws XMLStreamException {
+        if (textType == TEXT_NODE) {
+            writer.writeCharacters(this.value);            
+        } else if (textType == COMMENT_NODE) {
+            writer.writeComment(this.value);
+        } else if (textType == CDATA_SECTION_NODE) {
+            writer.writeCData(this.value);
+        }
+        OMNode nextSibling = this.getNextSibling();
+        if (nextSibling != null) {
+            nextSibling.serialize(writer, cache);
+        }
+    }
+
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        this.serialize(writer, false);
+    }
+}