You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2007/03/07 21:20:15 UTC

svn commit: r515734 [7/11] - in /incubator/cxf/trunk/rt: ./ core/src/main/java/org/apache/cxf/endpoint/ databinding/aegis/ databinding/aegis/src/ databinding/aegis/src/main/ databinding/aegis/src/main/java/ databinding/aegis/src/main/java/org/ databind...

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxBuilder.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxBuilder.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxBuilder.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,431 @@
+/*--
+
+ Copyright (C) 2000-2004 Jason Hunter & Brett McLaughlin.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions, and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions, and the disclaimer that follows
+ these conditions in the documentation and/or other materials
+ provided with the distribution.
+
+ 3. The name "JDOM" must not be used to endorse or promote products
+ derived from this software without prior written permission.  For
+ written permission, please contact <request_AT_jdom_DOT_org>.
+
+ 4. Products derived from this software may not be called "JDOM", nor
+ may "JDOM" appear in their name, without prior written permission
+ from the JDOM Project Management <request_AT_jdom_DOT_org>.
+
+ In addition, we request (but do not require) that you include in the
+ end-user documentation provided with the redistribution and/or in the
+ software itself an acknowledgement equivalent to the following:
+ "This product includes software developed by the
+ JDOM Project (http://www.jdom.org/)."
+ Alternatively, the acknowledgment may be graphical using the logos
+ available at http://www.jdom.org/images/logos.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED.  IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ This software consists of voluntary contributions made by many
+ individuals on behalf of the JDOM Project and was originally
+ created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
+ Brett McLaughlin <brett_AT_jdom_DOT_org>.  For more information
+ on the JDOM Project, please see <http://www.jdom.org/>.
+
+ */
+
+package org.apache.cxf.aegis.util.jdom;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.aegis.util.STAXUtils;
+import org.jdom.Attribute;
+import org.jdom.Content;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMFactory;
+import org.jdom.Namespace;
+import org.jdom.UncheckedJDOMFactory;
+
+/**
+ * Builds a JDOM {@link org.jdom.Document org.jdom.Document} using a
+ * {@link javax.xml.stream.XMLStreamReader}.
+ * 
+ * @version $Revision$, $Date: 2006-02-15 15:21:25 -0500 (Wed, 15 Feb
+ *          2006) $
+ * @author Tatu Saloranta
+ * @author Bradley S. Huffman
+ */
+public class StaxBuilder {
+
+    /**
+     * Map that contains conversion from textual attribute types StAX uses, to
+     * int values JDOM uses.
+     */
+    final static HashMap<String, Integer> attrTypes = new HashMap<String, Integer>(32);
+    static {
+        attrTypes.put("CDATA", new Integer(Attribute.CDATA_TYPE));
+        attrTypes.put("cdata", new Integer(Attribute.CDATA_TYPE));
+        attrTypes.put("ID", new Integer(Attribute.ID_TYPE));
+        attrTypes.put("id", new Integer(Attribute.ID_TYPE));
+        attrTypes.put("IDREF", new Integer(Attribute.IDREF_TYPE));
+        attrTypes.put("idref", new Integer(Attribute.IDREF_TYPE));
+        attrTypes.put("IDREFS", new Integer(Attribute.IDREFS_TYPE));
+        attrTypes.put("idrefs", new Integer(Attribute.IDREFS_TYPE));
+        attrTypes.put("ENTITY", new Integer(Attribute.ENTITY_TYPE));
+        attrTypes.put("entity", new Integer(Attribute.ENTITY_TYPE));
+        attrTypes.put("ENTITIES", new Integer(Attribute.ENTITIES_TYPE));
+        attrTypes.put("entities", new Integer(Attribute.ENTITIES_TYPE));
+        attrTypes.put("NMTOKEN", new Integer(Attribute.NMTOKEN_TYPE));
+        attrTypes.put("nmtoken", new Integer(Attribute.NMTOKEN_TYPE));
+        attrTypes.put("NMTOKENS", new Integer(Attribute.NMTOKENS_TYPE));
+        attrTypes.put("nmtokens", new Integer(Attribute.NMTOKENS_TYPE));
+        attrTypes.put("NOTATION", new Integer(Attribute.NOTATION_TYPE));
+        attrTypes.put("notation", new Integer(Attribute.NOTATION_TYPE));
+        attrTypes.put("ENUMERATED", new Integer(Attribute.ENUMERATED_TYPE));
+        attrTypes.put("enumerated", new Integer(Attribute.ENUMERATED_TYPE));
+    }
+
+    /** The factory for creating new JDOM objects */
+    private JDOMFactory factory = null;
+
+    private XMLInputFactory xifactory;
+
+    /**
+     * Whether ignorable white space should be ignored, ie not added in the
+     * resulting JDOM tree. If true, it will be ignored; if false, it will be
+     * added in the tree. Default value if false.
+     */
+    protected boolean cfgIgnoreWS = false;
+
+    private Map additionalNamespaces = null;
+
+    public Map getAdditionalNamespaces() {
+        return additionalNamespaces;
+    }
+
+    public void setAdditionalNamespaces(Map additionalNamespaces) {
+        this.additionalNamespaces = additionalNamespaces;
+    }
+
+    /**
+     * Default constructor.
+     */
+    public StaxBuilder() {
+        xifactory = STAXUtils.getXMLInputFactory(null);
+    }
+
+    public StaxBuilder(Map namespaces) {
+        xifactory = STAXUtils.getXMLInputFactory(null);
+        this.additionalNamespaces = namespaces;
+    }
+
+    public StaxBuilder(XMLInputFactory xifactory) {
+        this.xifactory = xifactory;
+    }
+
+    /*
+     * This sets a custom JDOMFactory for the builder. Use this to build the
+     * tree with your own subclasses of the JDOM classes. @param factory <code>JDOMFactory</code>
+     * to use
+     */
+    public void setFactory(JDOMFactory f) {
+        factory = f;
+    }
+
+    public void setIgnoreWhitespace(boolean state) {
+        cfgIgnoreWS = state;
+    }
+
+    /**
+     * Returns the current {@link org.jdom.JDOMFactory} in use, if one has been
+     * previously set with {@link #setFactory}, otherwise null.
+     * 
+     * @return the factory builder will use
+     */
+    public JDOMFactory getFactory() {
+        return factory;
+    }
+
+    /**
+     * This will build a JDOM tree given a StAX stream reader.
+     * 
+     * @param r Stream reader from which input is read.
+     * @return <code>Document</code> - JDOM document object.
+     * @throws XMLStreamException If the reader threw such exception (to
+     *             indicate a parsing or I/O problem)
+     */
+    public Document build(XMLStreamReader r) throws XMLStreamException {
+        /*
+         * Should we do sanity checking to see that r is positioned at
+         * beginning? Not doing so will allow creating documents from sub-trees,
+         * though?
+         */
+        JDOMFactory f = factory;
+        if (f == null) {
+            f = new UncheckedJDOMFactory();
+        }
+        Document doc = f.document(null);
+        buildTree(f, r, doc);
+        return doc;
+    }
+
+    public Document build(InputStream is) throws XMLStreamException {
+        return build(xifactory.createXMLStreamReader(is));
+    }
+
+    public Document build(Reader reader) throws XMLStreamException {
+        return build(xifactory.createXMLStreamReader(reader));
+    }
+
+    /**
+     * This takes a <code>XMLStreamReader</code> and builds up a JDOM tree.
+     * Recursion has been eliminated by using local stack of open elements; this
+     * improves performance somewhat (classic
+     * recursion-by-iteration-and-explicit stack transformation)
+     * 
+     * @param node <code>Code</node> to examine.
+     * @param doc JDOM <code>Document</code> being built.
+     */
+    private void buildTree(JDOMFactory f, XMLStreamReader r, Document doc) throws XMLStreamException {
+        Element current = null; // At top level
+        int event = r.getEventType();
+
+        // if we're at the start then we need to do a next
+        if (event == -1) {
+            event = r.next();
+        }
+
+        while (true) {
+            boolean noadd = false;
+            Content child = null;
+
+            switch (event) {
+            case XMLStreamConstants.CDATA:
+                child = f.cdata(r.getText());
+                break;
+
+            case XMLStreamConstants.SPACE:
+                if (cfgIgnoreWS) {
+                    noadd = true;
+                    break;
+                }
+                // fall through
+
+            case XMLStreamConstants.CHARACTERS:
+                /*
+                 * Small complication: although (ignorable) white space is
+                 * allowed in prolog/epilog, and StAX may report such event,
+                 * JDOM barfs if trying to add it. Thus, let's just ignore all
+                 * textual stuff outside the tree:
+                 */
+                if (current == null) {
+                    noadd = true;
+                    break;
+                }
+                child = f.text(r.getText());
+                break;
+
+            case XMLStreamConstants.COMMENT:
+                child = f.comment(r.getText());
+                break;
+
+            case XMLStreamConstants.END_DOCUMENT:
+                return;
+
+            case XMLStreamConstants.END_ELEMENT:
+                /**
+                 * If current.getParentElement() previously returned null and we
+                 * get this event again we shouldn't bail out with a
+                 * NullPointerException
+                 */
+                if (current != null) {
+                    current = current.getParentElement();
+                }
+                noadd = true;
+                break;
+
+            case XMLStreamConstants.ENTITY_DECLARATION:
+            case XMLStreamConstants.NOTATION_DECLARATION:
+                /*
+                 * Shouldn't really get these, but maybe some stream readers do
+                 * provide the info. If so, better ignore it -- DTD event should
+                 * have most/all we need.
+                 */
+                noadd = true;
+                break;
+
+            case XMLStreamConstants.ENTITY_REFERENCE:
+                child = f.entityRef(r.getLocalName());
+                break;
+
+            case XMLStreamConstants.PROCESSING_INSTRUCTION:
+                child = f.processingInstruction(r.getPITarget(), r.getPIData());
+                break;
+
+            case XMLStreamConstants.START_ELEMENT:
+                // Ok, need to add a new element and simulate recursion
+            {
+                Element newElem = null;
+                String nsURI = r.getNamespaceURI();
+                String elemPrefix = r.getPrefix(); // needed for special
+                // handling of elem's
+                // namespace
+                String ln = r.getLocalName();
+
+                if (nsURI == null || nsURI.length() == 0) {
+                    if (elemPrefix == null || elemPrefix.length() == 0) {
+                        newElem = f.element(ln);
+                    } else {
+                        /*
+                         * Happens when a prefix is bound to the default (empty)
+                         * namespace...
+                         */
+                        newElem = f.element(ln, elemPrefix, "");
+                    }
+                } else {
+                    newElem = f.element(ln, elemPrefix, nsURI);
+                }
+
+                /*
+                 * Let's add element right away (probably have to do it to bind
+                 * attribute namespaces, too)
+                 */
+                if (current == null) { // at root
+                    doc.setRootElement(newElem);
+                    if (additionalNamespaces != null) {
+                        for (Iterator iter = additionalNamespaces.keySet().iterator(); iter.hasNext();) {
+                            String prefix = (String)iter.next();
+                            String uri = (String)additionalNamespaces.get(prefix);
+
+                            newElem.addNamespaceDeclaration(Namespace.getNamespace(prefix, uri));
+                        }
+                    }
+                } else {
+                    f.addContent(current, newElem);
+                }
+
+                // Any declared namespaces?
+                for (int i = 0, len = r.getNamespaceCount(); i < len; ++i) {
+                    String prefix = r.getNamespacePrefix(i);
+                    Namespace ns = Namespace.getNamespace(prefix, r.getNamespaceURI(i));
+                    // JDOM has special handling for element's "own" ns:
+                    if (prefix != null && prefix.equals(elemPrefix)) {
+                        ; // already set by when it was constructed...
+                    } else {
+                        f.addNamespaceDeclaration(newElem, ns);
+                    }
+                }
+
+                // And then the attributes:
+                for (int i = 0, len = r.getAttributeCount(); i < len; ++i) {
+                    String prefix = r.getAttributePrefix(i);
+                    Namespace ns;
+
+                    if (prefix == null || prefix.length() == 0) {
+                        // Attribute not in any namespace
+                        ns = Namespace.NO_NAMESPACE;
+                    } else {
+                        ns = newElem.getNamespace(prefix);
+
+                    }
+                    Attribute attr = f.attribute(r.getAttributeLocalName(i), r.getAttributeValue(i),
+                                                 resolveAttrType(r.getAttributeType(i)), ns);
+                    f.setAttribute(newElem, attr);
+                }
+                // And then 'push' new element...
+                current = newElem;
+            }
+
+                // Already added the element, can continue
+                noadd = true;
+                break;
+
+            case XMLStreamConstants.START_DOCUMENT:
+                /*
+                 * This should only be received at the beginning of document...
+                 * so, should we indicate the problem or not?
+                 */
+                /*
+                 * For now, let it pass: maybe some (broken) readers pass that
+                 * info as first event in beginning of doc?
+                 */
+
+            case XMLStreamConstants.DTD:
+                /*
+                 * !!! Note: StAX does not expose enough information about
+                 * doctype declaration (specifically, public and system id!);
+                 * should (re-)parse information... not yet implemented
+                 */
+                // TBI
+                // continue main_loop;
+                // Should never get these, from a stream reader:
+                /*
+                 * (commented out entries are just FYI; default catches them
+                 * all)
+                 */
+
+                // case XMLStreamConstants.ATTRIBUTE:
+                // case XMLStreamConstants.NAMESPACE:
+            default:
+                /*
+                 * throw new XMLStreamException("Unrecognized iterator event
+                 * type: " + r.getEventType() + "; should not receive such types
+                 * (broken stream reader?)");
+                 */
+                break;
+            }
+
+            if (!noadd && child != null) {
+                if (current == null) {
+                    f.addContent(doc, child);
+                } else {
+                    f.addContent(current, child);
+                }
+            }
+
+            if (r.hasNext()) {
+                event = r.next();
+            } else {
+                break;
+            }
+        }
+    }
+
+    private static int resolveAttrType(String typeStr) {
+        if (typeStr != null && typeStr.length() > 0) {
+            Integer I = attrTypes.get(typeStr);
+            if (I != null) {
+                return I.intValue();
+            }
+        }
+        return Attribute.UNDECLARED_TYPE;
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxSerializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxSerializer.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxSerializer.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxSerializer.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,148 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.jdom;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.jdom.Attribute;
+import org.jdom.CDATA;
+import org.jdom.Comment;
+import org.jdom.Content;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.EntityRef;
+import org.jdom.Namespace;
+import org.jdom.Text;
+
+public class StaxSerializer {
+    public void writeDocument(Document doc, XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeStartDocument("1.0");
+
+        for (Iterator itr = doc.getContent().iterator(); itr.hasNext();) {
+            Content content = (Content)itr.next();
+
+            if (content instanceof Element) {
+                writeElement((Element)content, writer);
+            }
+        }
+
+        writer.writeEndDocument();
+    }
+
+    public void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException {
+        // need to check if the namespace is declared before we write the
+        // start element because that will put the namespace in the context.
+        String elPrefix = e.getNamespacePrefix();
+        String elUri = e.getNamespaceURI();
+
+        String boundPrefix = writer.getPrefix(elUri);
+        boolean writeElementNS = false;
+        if (boundPrefix == null || !elPrefix.equals(boundPrefix)) {
+            writeElementNS = true;
+        }
+
+        writer.writeStartElement(elPrefix, e.getName(), elUri);
+
+        List namespaces = e.getAdditionalNamespaces();
+        for (Iterator itr = namespaces.iterator(); itr.hasNext();) {
+            Namespace ns = (Namespace)itr.next();
+
+            String prefix = ns.getPrefix();
+            String uri = ns.getURI();
+
+            writer.setPrefix(prefix, uri);
+            writer.writeNamespace(prefix, uri);
+
+            if (elUri.equals(uri) && elPrefix.equals(prefix)) {
+                writeElementNS = false;
+            }
+        }
+
+        for (Iterator itr = e.getAttributes().iterator(); itr.hasNext();) {
+            Attribute attr = (Attribute)itr.next();
+            String attPrefix = attr.getNamespacePrefix();
+            String attUri = attr.getNamespaceURI();
+
+            if (attUri == null || attUri.equals("")) {
+                writer.writeAttribute(attr.getName(), attr.getValue());
+            } else {
+                writer.writeAttribute(attPrefix, attUri, attr.getName(), attr.getValue());
+
+                if (!isDeclared(writer, attPrefix, attUri)) {
+                    if (elUri.equals(attUri) && elPrefix.equals(attPrefix)) {
+                        if (writeElementNS) {
+                            writer.setPrefix(attPrefix, attUri);
+                            writer.writeNamespace(attPrefix, attUri);
+                            writeElementNS = false;
+                        }
+                    } else {
+                        writer.setPrefix(attPrefix, attUri);
+                        writer.writeNamespace(attPrefix, attUri);
+                    }
+                }
+            }
+        }
+
+        if (writeElementNS) {
+            if (elPrefix == null || elPrefix.length() == 0) {
+                writer.writeDefaultNamespace(elUri);
+            } else {
+                writer.writeNamespace(elPrefix, elUri);
+            }
+        }
+
+        for (Iterator itr = e.getContent().iterator(); itr.hasNext();) {
+            Content n = (Content)itr.next();
+            if (n instanceof CDATA) {
+                writer.writeCData(n.getValue());
+            } else if (n instanceof Text) {
+                writer.writeCharacters(((Text)n).getText());
+            } else if (n instanceof Element) {
+                writeElement((Element)n, writer);
+            } else if (n instanceof Comment) {
+                writer.writeComment(n.getValue());
+            } else if (n instanceof EntityRef) {
+                // EntityRef ref = (EntityRef) n;
+                // writer.writeEntityRef(ref.)
+            }
+        }
+
+        writer.writeEndElement();
+    }
+
+    /**
+     * @param writer
+     * @param prefix
+     * @param uri
+     * @throws XMLStreamException
+     */
+    private boolean isDeclared(XMLStreamWriter writer, String prefix, String uri) throws XMLStreamException {
+        for (Iterator pxs = writer.getNamespaceContext().getPrefixes(uri); pxs.hasNext();) {
+            String px = (String)pxs.next();
+            if (px.equals(prefix)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/jdom/StaxSerializer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamReader.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamReader.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamReader.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,323 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.aegis.util.FastStack;
+
+/**
+ * Abstract logic for creating XMLStreamReader from DOM documents. Its works
+ * using adapters for Element, Node and Attribute (
+ * 
+ * @see ElementAdapter }
+ * @author <a href="mailto:tsztelak@gmail.com">Tomasz Sztelak</a>
+ */
+public abstract class DOMStreamReader implements XMLStreamReader {
+    public Map properties = new HashMap();
+
+    private FastStack<ElementFrame> frames = new FastStack<ElementFrame>();
+
+    private ElementFrame frame;
+
+    private int currentEvent = XMLStreamConstants.START_DOCUMENT;
+
+    /**
+     *     
+     */
+    public static class ElementFrame {
+        public ElementFrame(Object element, ElementFrame parent) {
+            this.element = element;
+            this.parent = parent;
+        }
+
+        Object element;
+
+        boolean started = false;
+
+        boolean ended = false;
+
+        int currentChild = -1;
+
+        int currentAttribute = -1;
+
+        int currentNamespace = -1;
+
+        int currentElement = -1;
+        List<String> uris;
+        List<String> prefixes;
+        List<Object> attributes;
+        List<Object> allAttributes;
+
+        final ElementFrame parent;
+    }
+
+    /**
+     * @param element
+     */
+    public DOMStreamReader(ElementFrame frame) {
+        this.frame = frame;
+        frames.push(this.frame);
+        newFrame(frame);
+    }
+
+    protected ElementFrame getCurrentFrame() {
+        return frame;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#getProperty(java.lang.String)
+     */
+    public Object getProperty(String key) throws IllegalArgumentException {
+        return properties.get(key);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#next()
+     */
+    public int next() throws XMLStreamException {
+        if (frame.ended) {
+            frames.pop();
+            if (!frames.empty()) {
+                frame = (ElementFrame)frames.peek();
+            } else {
+                currentEvent = END_DOCUMENT;
+                return currentEvent;
+            }
+        }
+
+        if (!frame.started) {
+            frame.started = true;
+            currentEvent = START_ELEMENT;
+        } else if (frame.currentAttribute < getAttributeCount() - 1) {
+            frame.currentAttribute++;
+            currentEvent = ATTRIBUTE;
+        } else if (frame.currentNamespace < getNamespaceCount() - 1) {
+            frame.currentNamespace++;
+            currentEvent = NAMESPACE;
+        } else if (frame.currentChild < getChildCount() - 1) {
+            frame.currentChild++;
+
+            currentEvent = moveToChild(frame.currentChild);
+
+            if (currentEvent == START_ELEMENT) {
+                ElementFrame newFrame = getChildFrame(frame.currentChild);
+                newFrame.started = true;
+                frame = newFrame;
+                frames.push(this.frame);
+                currentEvent = START_ELEMENT;
+
+                newFrame(newFrame);
+            }
+        } else {
+            frame.ended = true;
+            currentEvent = END_ELEMENT;
+            endElement();
+        }
+        return currentEvent;
+    }
+
+    protected void newFrame(ElementFrame newFrame) {
+    }
+
+    protected void endElement() {
+    }
+
+    protected abstract int moveToChild(int currentChild);
+
+    protected abstract ElementFrame getChildFrame(int currentChild);
+
+    protected abstract int getChildCount();
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#require(int, java.lang.String,
+     *      java.lang.String)
+     */
+    public void require(int arg0, String arg1, String arg2) throws XMLStreamException {
+        throw new UnsupportedOperationException();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#getElementText()
+     */
+    public abstract String getElementText() throws XMLStreamException;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#nextTag()
+     */
+    public int nextTag() throws XMLStreamException {
+        while (hasNext()) {
+            if (START_ELEMENT == next()) {
+                return START_ELEMENT;
+            }
+        }
+
+        return currentEvent;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#hasNext()
+     */
+    public boolean hasNext() throws XMLStreamException {
+        return !(frames.size() == 0 && frame.ended);
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#close()
+     */
+    public void close() throws XMLStreamException {
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#getNamespaceURI(java.lang.String)
+     */
+    public abstract String getNamespaceURI(String prefix);
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#isStartElement()
+     */
+    public boolean isStartElement() {
+        return (currentEvent == START_ELEMENT);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#isEndElement()
+     */
+    public boolean isEndElement() {
+        return (currentEvent == END_ELEMENT);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#isCharacters()
+     */
+    public boolean isCharacters() {
+        return (currentEvent == CHARACTERS);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.xml.stream.XMLStreamReader#isWhiteSpace()
+     */
+    public boolean isWhiteSpace() {
+        return (currentEvent == SPACE);
+    }
+
+    public int getEventType() {
+        return currentEvent;
+    }
+
+    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
+        throws XMLStreamException {
+        char[] src = getText().toCharArray();
+
+        if (sourceStart + length >= src.length) {
+            length = src.length - sourceStart;
+        }
+
+        for (int i = 0; i < length; i++) {
+            target[targetStart + i] = src[i + sourceStart];
+        }
+
+        return length;
+    }
+
+    public boolean hasText() {
+        return (currentEvent == CHARACTERS || currentEvent == DTD || currentEvent == ENTITY_REFERENCE
+                || currentEvent == COMMENT || currentEvent == SPACE);
+    }
+
+    public Location getLocation() {
+        return new Location() {
+
+            public int getCharacterOffset() {
+                return 0;
+            }
+
+            public int getColumnNumber() {
+                return 0;
+            }
+
+            public int getLineNumber() {
+                return 0;
+            }
+
+            public String getPublicId() {
+                return null;
+            }
+
+            public String getSystemId() {
+                return null;
+            }
+
+        };
+    }
+
+    public boolean hasName() {
+        return (currentEvent == START_ELEMENT || currentEvent == END_ELEMENT);
+    }
+
+    public String getVersion() {
+        return null;
+    }
+
+    public boolean isStandalone() {
+        return false;
+    }
+
+    public boolean standaloneSet() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public String getCharacterEncodingScheme() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamWriter.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamWriter.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamWriter.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public abstract class DOMStreamWriter implements XMLStreamWriter {
+
+    public void close() throws XMLStreamException {
+    }
+
+    public void flush() throws XMLStreamException {
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamWriter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DepthXMLStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DepthXMLStreamReader.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DepthXMLStreamReader.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DepthXMLStreamReader.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,272 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+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;
+
+/**
+ * An XMLStreamReader which keeps track of the depth where we are.
+ * 
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse </a>
+ * @since Nov 4, 2004
+ */
+public class DepthXMLStreamReader implements XMLStreamReader {
+    XMLStreamReader reader;
+
+    private int depth = 0;
+
+    public DepthXMLStreamReader(XMLStreamReader reader) {
+        this.reader = reader;
+    }
+
+    public int getDepth() {
+        return depth;
+    }
+
+    public void close() throws XMLStreamException {
+        reader.close();
+    }
+
+    public int getAttributeCount() {
+        return reader.getAttributeCount();
+    }
+
+    public String getAttributeLocalName(int arg0) {
+        return reader.getAttributeLocalName(arg0);
+    }
+
+    public QName getAttributeName(int arg0) {
+        return reader.getAttributeName(arg0);
+    }
+
+    public String getAttributeNamespace(int arg0) {
+        return reader.getAttributeNamespace(arg0);
+    }
+
+    public String getAttributePrefix(int arg0) {
+        return reader.getAttributePrefix(arg0);
+    }
+
+    public String getAttributeType(int arg0) {
+        return reader.getAttributeType(arg0);
+    }
+
+    public String getAttributeValue(int arg0) {
+        return reader.getAttributeValue(arg0);
+    }
+
+    public String getAttributeValue(String arg0, String arg1) {
+        return reader.getAttributeValue(arg0, arg1);
+    }
+
+    public String getCharacterEncodingScheme() {
+        return reader.getCharacterEncodingScheme();
+    }
+
+    public String getElementText() throws XMLStreamException {
+        return reader.getElementText();
+    }
+
+    public String getEncoding() {
+        return reader.getEncoding();
+    }
+
+    public int getEventType() {
+        return reader.getEventType();
+    }
+
+    public String getLocalName() {
+        return reader.getLocalName();
+    }
+
+    public Location getLocation() {
+        return reader.getLocation();
+    }
+
+    public QName getName() {
+        return reader.getName();
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return reader.getNamespaceContext();
+    }
+
+    public int getNamespaceCount() {
+        return reader.getNamespaceCount();
+    }
+
+    public String getNamespacePrefix(int arg0) {
+        return reader.getNamespacePrefix(arg0);
+    }
+
+    public String getNamespaceURI() {
+        return reader.getNamespaceURI();
+    }
+
+    public String getNamespaceURI(int arg0) {
+
+        return reader.getNamespaceURI(arg0);
+    }
+
+    public String getNamespaceURI(String arg0) {
+        return reader.getNamespaceURI(arg0);
+    }
+
+    public String getPIData() {
+        return reader.getPIData();
+    }
+
+    public String getPITarget() {
+        return reader.getPITarget();
+    }
+
+    public String getPrefix() {
+        return reader.getPrefix();
+    }
+
+    public Object getProperty(String arg0) throws IllegalArgumentException {
+
+        return reader.getProperty(arg0);
+    }
+
+    public String getText() {
+
+        return reader.getText();
+    }
+
+    public char[] getTextCharacters() {
+        return reader.getTextCharacters();
+    }
+
+    public int getTextCharacters(int arg0, char[] arg1, int arg2, int arg3) throws XMLStreamException {
+        return reader.getTextCharacters(arg0, arg1, arg2, arg3);
+    }
+
+    public int getTextLength() {
+        return reader.getTextLength();
+    }
+
+    public int getTextStart() {
+
+        return reader.getTextStart();
+    }
+
+    public String getVersion() {
+        return reader.getVersion();
+    }
+
+    public boolean hasName() {
+
+        return reader.hasName();
+    }
+
+    public boolean hasNext() throws XMLStreamException {
+        return reader.hasNext();
+    }
+
+    public boolean hasText() {
+        return reader.hasText();
+    }
+
+    public boolean isAttributeSpecified(int arg0) {
+        return reader.isAttributeSpecified(arg0);
+    }
+
+    public boolean isCharacters() {
+
+        return reader.isCharacters();
+    }
+
+    public boolean isEndElement() {
+
+        return reader.isEndElement();
+    }
+
+    public boolean isStandalone() {
+
+        return reader.isStandalone();
+    }
+
+    public boolean isStartElement() {
+
+        return reader.isStartElement();
+    }
+
+    public boolean isWhiteSpace() {
+
+        return reader.isWhiteSpace();
+    }
+
+    public int next() throws XMLStreamException {
+        int next = reader.next();
+
+        if (next == START_ELEMENT) {
+            depth++;
+        } else if (next == END_ELEMENT) {
+            depth--;
+        }
+
+        return next;
+    }
+
+    public int nextTag() throws XMLStreamException {
+        int eventType = next();
+        while ((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace())
+               || (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;
+    }
+
+    public void require(int arg0, String arg1, String arg2) throws XMLStreamException {
+        reader.require(arg0, arg1, arg2);
+    }
+
+    public boolean standaloneSet() {
+        return reader.standaloneSet();
+    }
+
+    @Override
+    public int hashCode() {
+        return reader.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object arg0) {
+        return reader.equals(arg0);
+    }
+
+    @Override
+    public String toString() {
+        return reader.toString();
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DepthXMLStreamReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DepthXMLStreamReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/FragmentStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/FragmentStreamReader.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/FragmentStreamReader.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/FragmentStreamReader.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Wraps a XMLStreamReader and provides START_DOCUMENT and END_DOCUMENT events.
+ * 
+ * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ */
+public class FragmentStreamReader extends DepthXMLStreamReader {
+    private boolean startDoc = false;
+    private boolean startElement = false;
+    private boolean middle = true;
+    private boolean endDoc = false;
+
+    private int depth;
+    private int current = -1;
+    private boolean filter = true;
+    private boolean advanceAtEnd = true;
+
+    public FragmentStreamReader(XMLStreamReader reader) {
+        super(reader);
+    }
+
+    @Override
+    public int getEventType() {
+        return current;
+    }
+
+    @Override
+    public boolean hasNext() throws XMLStreamException {
+        if (!startDoc) {
+            return true;
+        }
+
+        if (endDoc) {
+            return false;
+        }
+
+        return reader.hasNext();
+    }
+
+    @Override
+    public int next() throws XMLStreamException {
+        if (!startDoc) {
+            startDoc = true;
+            current = START_DOCUMENT;
+        } else if (!startElement) {
+            depth = getDepth();
+
+            current = reader.getEventType();
+
+            if (filter) {
+                while (current != START_ELEMENT && depth >= getDepth() && super.hasNext()) {
+                    current = super.next();
+                }
+
+                filter = false;
+            }
+
+            startElement = true;
+            current = START_ELEMENT;
+        } else if (middle) {
+            current = super.next();
+
+            if (current == END_ELEMENT && getDepth() < depth) {
+                middle = false;
+            }
+        } else if (!endDoc) {
+            // Move past the END_ELEMENT token.
+            if (advanceAtEnd) {
+                super.next();
+            }
+
+            endDoc = true;
+            current = END_DOCUMENT;
+        } else {
+            throw new XMLStreamException("Already at the end of the document.");
+        }
+
+        return current;
+    }
+
+    public boolean isAdvanceAtEnd() {
+        return advanceAtEnd;
+    }
+
+    /**
+     * Set whether or not the FragmentStreamReader should move past the
+     * END_ELEMENT when it is done parsing.
+     * 
+     * @param advanceAtEnd
+     */
+    public void setAdvanceAtEnd(boolean advanceAtEnd) {
+        this.advanceAtEnd = advanceAtEnd;
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/FragmentStreamReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/FragmentStreamReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.NamespaceContext;
+
+import org.apache.cxf.aegis.util.NamespaceHelper;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+public class JDOMNamespaceContext implements NamespaceContext {
+    private Element element;
+
+    public String getNamespaceURI(String prefix) {
+        Namespace namespace = element.getNamespace(prefix);
+        if (namespace == null) {
+            return null;
+        }
+
+        return namespace.getURI();
+    }
+
+    public String getPrefix(String uri) {
+        return NamespaceHelper.getPrefix(element, uri);
+    }
+
+    public Iterator<String> getPrefixes(String uri) {
+        List<String> prefixes = new ArrayList<String>();
+        NamespaceHelper.getPrefixes(element, uri, prefixes);
+        return prefixes.iterator();
+    }
+
+    public Element getElement() {
+        return element;
+    }
+
+    public void setElement(Element element) {
+        this.element = element;
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,321 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.cxf.aegis.util.FastStack;
+import org.jdom.Attribute;
+import org.jdom.CDATA;
+import org.jdom.Comment;
+import org.jdom.Content;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.EntityRef;
+import org.jdom.Namespace;
+import org.jdom.Text;
+
+/**
+ * Facade for DOMStreamReader using JDOM implmentation.
+ * 
+ * @author <a href="mailto:tsztelak@gmail.com">Tomasz Sztelak</a>
+ */
+public class JDOMStreamReader extends DOMStreamReader {
+    public static String toStaxType(int jdom) {
+        switch (jdom) {
+        case Attribute.CDATA_TYPE:
+            return "CDATA";
+        case Attribute.ID_TYPE:
+            return "ID";
+        case Attribute.IDREF_TYPE:
+            return "IDREF";
+        case Attribute.IDREFS_TYPE:
+            return "IDREFS";
+        case Attribute.ENTITY_TYPE:
+            return "ENTITY";
+        case Attribute.ENTITIES_TYPE:
+            return "ENTITIES";
+        case Attribute.ENUMERATED_TYPE:
+            return "ENUMERATED";
+        case Attribute.NMTOKEN_TYPE:
+            return "NMTOKEN";
+        case Attribute.NMTOKENS_TYPE:
+            return "NMTOKENS";
+        case Attribute.NOTATION_TYPE:
+            return "NOTATION";
+        default:
+            return null;
+        }
+    }
+
+    private Content content;
+
+    private FastStack<Map> namespaceStack = new FastStack<Map>();
+
+    private List<Namespace> namespaces = new ArrayList<Namespace>();
+
+    private Map<String, Namespace> prefix2decNs;
+
+    private JDOMNamespaceContext namespaceContext;
+
+    /**
+     * @param element
+     */
+    public JDOMStreamReader(Element element) {
+        super(new ElementFrame(element, null));
+
+        namespaceContext = new JDOMNamespaceContext();
+        setupNamespaces(element);
+    }
+
+    private void setupNamespaces(Element element) {
+        namespaceContext.setElement(element);
+
+        if (prefix2decNs != null) {
+            namespaceStack.push(prefix2decNs);
+        }
+
+        prefix2decNs = new HashMap<String, Namespace>();
+        namespaces.clear();
+
+        for (Iterator itr = element.getAdditionalNamespaces().iterator(); itr.hasNext();) {
+            declare((Namespace)itr.next());
+        }
+
+        Namespace ns = element.getNamespace();
+
+        if (shouldDeclare(ns)) {
+            declare(ns);
+        }
+
+        for (Iterator itr = element.getAttributes().iterator(); itr.hasNext();) {
+            ns = ((Attribute)itr.next()).getNamespace();
+            if (shouldDeclare(ns)) {
+                declare(ns);
+            }
+        }
+    }
+
+    private void declare(Namespace ns) {
+        prefix2decNs.put(ns.getPrefix(), ns);
+        namespaces.add(ns);
+    }
+
+    private boolean shouldDeclare(Namespace ns) {
+        if (ns == Namespace.XML_NAMESPACE) {
+            return false;
+        }
+
+        if (ns == Namespace.NO_NAMESPACE && getDeclaredURI("") == null) {
+            return false;
+        }
+
+        String decUri = getDeclaredURI(ns.getPrefix());
+
+        return !(decUri != null && decUri.equals(ns.getURI()));
+    }
+
+    private String getDeclaredURI(String string) {
+        for (int i = namespaceStack.size() - 1; i == 0; i--) {
+            Map namespaces = namespaceStack.get(i);
+
+            Namespace dec = (Namespace)namespaces.get(string);
+
+            if (dec != null) {
+                return dec.getURI();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected void endElement() {
+        if (namespaceStack.size() > 0) {
+            prefix2decNs = (Map<String, Namespace>)namespaceStack.pop();
+        }
+    }
+
+    /**
+     * @param document
+     */
+    public JDOMStreamReader(Document document) {
+        this(document.getRootElement());
+    }
+
+    public Element getCurrentElement() {
+        return (Element)getCurrentFrame().element;
+    }
+
+    @Override
+    protected ElementFrame getChildFrame(int currentChild) {
+        return new ElementFrame(getCurrentElement().getContent(currentChild), getCurrentFrame());
+    }
+
+    @Override
+    protected int getChildCount() {
+        return getCurrentElement().getContentSize();
+    }
+
+    @Override
+    protected int moveToChild(int currentChild) {
+        this.content = getCurrentElement().getContent(currentChild);
+
+        if (content instanceof Text) {
+            return CHARACTERS;
+        } else if (content instanceof Element) {
+            setupNamespaces((Element)content);
+            return START_ELEMENT;
+        } else if (content instanceof CDATA) {
+            return CHARACTERS;
+        } else if (content instanceof Comment) {
+            return CHARACTERS;
+        } else if (content instanceof EntityRef) {
+            return ENTITY_REFERENCE;
+        }
+
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public String getElementText() throws XMLStreamException {
+        return ((Text)content).getText();
+    }
+
+    @Override
+    public String getNamespaceURI(String prefix) {
+        return getCurrentElement().getNamespace(prefix).getURI();
+    }
+
+    public String getAttributeValue(String ns, String local) {
+        return getCurrentElement().getAttributeValue(local, Namespace.getNamespace(ns));
+    }
+
+    public int getAttributeCount() {
+        return getCurrentElement().getAttributes().size();
+    }
+
+    Attribute getAttribute(int i) {
+        return (Attribute)getCurrentElement().getAttributes().get(i);
+    }
+
+    public QName getAttributeName(int i) {
+        Attribute at = getAttribute(i);
+
+        return new QName(at.getNamespaceURI(), at.getName(), at.getNamespacePrefix());
+    }
+
+    public String getAttributeNamespace(int i) {
+        return getAttribute(i).getNamespaceURI();
+    }
+
+    public String getAttributeLocalName(int i) {
+        return getAttribute(i).getName();
+    }
+
+    public String getAttributePrefix(int i) {
+        return getAttribute(i).getNamespacePrefix();
+    }
+
+    public String getAttributeType(int i) {
+        return toStaxType(getAttribute(i).getAttributeType());
+    }
+
+    public String getAttributeValue(int i) {
+        return getAttribute(i).getValue();
+    }
+
+    public boolean isAttributeSpecified(int i) {
+        return getAttribute(i).getValue() != null;
+    }
+
+    public int getNamespaceCount() {
+        return namespaces.size();
+    }
+
+    Namespace getNamespace(int i) {
+        return namespaces.get(i);
+    }
+
+    public String getNamespacePrefix(int i) {
+        return getNamespace(i).getPrefix();
+    }
+
+    public String getNamespaceURI(int i) {
+        return getNamespace(i).getURI();
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return namespaceContext;
+    }
+
+    public String getText() {
+        return (content).getValue();
+    }
+
+    public char[] getTextCharacters() {
+        return getText().toCharArray();
+    }
+
+    public int getTextStart() {
+        return 0;
+    }
+
+    public int getTextLength() {
+        return getText().length();
+    }
+
+    public String getEncoding() {
+        return null;
+    }
+
+    public QName getName() {
+        Element el = getCurrentElement();
+
+        return new QName(el.getNamespaceURI(), el.getName(), el.getNamespacePrefix());
+    }
+
+    public String getLocalName() {
+        return getCurrentElement().getName();
+    }
+
+    public String getNamespaceURI() {
+        return getCurrentElement().getNamespaceURI();
+    }
+
+    public String getPrefix() {
+        return getCurrentElement().getNamespacePrefix();
+    }
+
+    public String getPITarget() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getPIData() {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,204 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.cxf.aegis.util.NamespaceHelper;
+import org.jdom.Attribute;
+import org.jdom.CDATA;
+import org.jdom.Comment;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.EntityRef;
+import org.jdom.Namespace;
+
+public class JDOMStreamWriter extends DOMStreamWriter {
+    private Stack<Element> stack = new Stack<Element>();
+
+    private Document document;
+
+    private Element currentNode;
+
+    private NamespaceContext context;
+
+    private Map properties = new HashMap();
+
+    public JDOMStreamWriter() {
+    }
+
+    public JDOMStreamWriter(Element e) {
+        newChild(e);
+    }
+
+    public void writeStartElement(String local) throws XMLStreamException {
+        newChild(new Element(local));
+    }
+
+    private void newChild(Element element) {
+        if (currentNode != null) {
+            stack.push(currentNode);
+            currentNode.addContent(element);
+        } else {
+            if (document != null) {
+                document.setRootElement(element);
+            }
+        }
+
+        JDOMNamespaceContext context = new JDOMNamespaceContext();
+        context.setElement(element);
+        this.context = context;
+
+        currentNode = element;
+    }
+
+    public void writeStartElement(String namespace, String local) throws XMLStreamException {
+        newChild(new Element(local, namespace));
+    }
+
+    public void writeStartElement(String prefix, String local, String namespace) throws XMLStreamException {
+        if (prefix == null || prefix.equals("")) {
+            writeStartElement(namespace, local);
+        } else {
+            newChild(new Element(local, prefix, namespace));
+        }
+    }
+
+    public void writeEmptyElement(String namespace, String local) throws XMLStreamException {
+        writeStartElement(namespace, local);
+    }
+
+    public void writeEmptyElement(String prefix, String namespace, String local) throws XMLStreamException {
+        writeStartElement(prefix, namespace, local);
+    }
+
+    public void writeEmptyElement(String local) throws XMLStreamException {
+        writeStartElement(local);
+    }
+
+    public void writeEndElement() throws XMLStreamException {
+        currentNode = stack.pop();
+    }
+
+    public void writeEndDocument() throws XMLStreamException {
+    }
+
+    public void writeAttribute(String local, String value) throws XMLStreamException {
+        currentNode.setAttribute(new Attribute(local, value));
+    }
+
+    public void writeAttribute(String prefix, String namespace, String local, String value)
+        throws XMLStreamException {
+        currentNode.setAttribute(new Attribute(local, value, Namespace.getNamespace(prefix, namespace)));
+    }
+
+    public void writeAttribute(String namespace, String local, String value) throws XMLStreamException {
+        currentNode.setAttribute(new Attribute(local, value, Namespace.getNamespace(namespace)));
+    }
+
+    public void writeNamespace(String prefix, String namespace) throws XMLStreamException {
+        Namespace decNS = currentNode.getNamespace(prefix);
+
+        if (decNS == null || !decNS.getURI().equals(namespace)) {
+            currentNode.addNamespaceDeclaration(Namespace.getNamespace(prefix, namespace));
+        }
+    }
+
+    public void writeDefaultNamespace(String namespace) throws XMLStreamException {
+        currentNode.addNamespaceDeclaration(Namespace.getNamespace("", namespace));
+    }
+
+    public void writeComment(String value) throws XMLStreamException {
+        currentNode.addContent(new Comment(value));
+    }
+
+    public void writeProcessingInstruction(String arg0) throws XMLStreamException {
+    }
+
+    public void writeProcessingInstruction(String arg0, String arg1) throws XMLStreamException {
+    }
+
+    public void writeCData(String data) throws XMLStreamException {
+        currentNode.addContent(new CDATA(data));
+    }
+
+    public void writeDTD(String arg0) throws XMLStreamException {
+
+    }
+
+    public void writeEntityRef(String ref) throws XMLStreamException {
+        currentNode.addContent(new EntityRef(ref));
+    }
+
+    public void writeStartDocument() throws XMLStreamException {
+        document = new Document(new Element("root"));
+    }
+
+    public void writeStartDocument(String version) throws XMLStreamException {
+        writeStartDocument();
+
+        // TODO: set encoding/version
+    }
+
+    public void writeStartDocument(String encoding, String version) throws XMLStreamException {
+        writeStartDocument();
+
+        // TODO: set encoding/version
+    }
+
+    public void writeCharacters(String text) throws XMLStreamException {
+        currentNode.addContent(text);
+    }
+
+    public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
+        // TODO Auto-generated method stub
+        currentNode.addContent(new String(text, start, len));
+    }
+
+    public String getPrefix(String uri) throws XMLStreamException {
+        return NamespaceHelper.getPrefix(currentNode, uri);
+    }
+
+    public void setPrefix(String arg0, String arg1) throws XMLStreamException {
+    }
+
+    public void setDefaultNamespace(String arg0) throws XMLStreamException {
+    }
+
+    public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
+        this.context = context;
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return context;
+    }
+
+    public Object getProperty(String prop) throws IllegalArgumentException {
+        return properties.get(prop);
+    }
+
+    public Document getDocument() {
+        return document;
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamReader.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamReader.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamReader.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,328 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+import java.util.ArrayList;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+import org.apache.cxf.helpers.DOMUtils;
+
+public class W3CDOMStreamReader extends DOMStreamReader {
+    private Node content;
+
+    private Document document;
+
+    private W3CNamespaceContext context;
+
+    /**
+     * @param element
+     */
+    public W3CDOMStreamReader(Element element) {
+        super(new ElementFrame(element, null));
+
+        this.document = element.getOwnerDocument();
+    }
+
+    /**
+     * Get the document associated with this stream.
+     * 
+     * @return
+     */
+    public Document getDocument() {
+        return document;
+    }
+
+    /**
+     * Find name spaces declaration in atrributes and move them to separate
+     * collection.
+     */
+    @Override
+    protected void newFrame(ElementFrame frame) {
+        Element element = getCurrentElement();
+        frame.uris = new ArrayList<String>();
+        frame.prefixes = new ArrayList<String>();
+        frame.attributes = new ArrayList<Object>();
+
+        if (context == null) {
+            context = new W3CNamespaceContext();
+        }
+
+        context.setElement(element);
+
+        NamedNodeMap nodes = element.getAttributes();
+
+        String ePrefix = element.getPrefix();
+        if (ePrefix == null) {
+            ePrefix = "";
+        }
+
+        if (nodes != null) {
+            for (int i = 0; i < nodes.getLength(); i++) {
+                Node node = nodes.item(i);
+                String prefix = node.getPrefix();
+                String localName = node.getLocalName();
+                String value = node.getNodeValue();
+                String name = node.getNodeName();
+
+                if (prefix == null) {
+                    prefix = "";
+                }
+
+                if (name != null && name.equals("xmlns")) {
+                    frame.uris.add(value);
+                    frame.prefixes.add("");
+                } else if (prefix.length() > 0 && prefix.equals("xmlns")) {
+                    frame.uris.add(value);
+                    frame.prefixes.add(localName);
+                } else if (name.startsWith("xmlns:")) {
+                    prefix = name.substring(6);
+                    frame.uris.add(value);
+                    frame.prefixes.add(prefix);
+                } else {
+                    frame.attributes.add(node);
+                }
+            }
+        }
+    }
+
+    @Override
+    protected void endElement() {
+        super.endElement();
+    }
+
+    Element getCurrentElement() {
+        return (Element)getCurrentFrame().element;
+    }
+
+    @Override
+    protected ElementFrame getChildFrame(int currentChild) {
+        return new ElementFrame(getCurrentElement().getChildNodes().item(currentChild), getCurrentFrame());
+    }
+
+    @Override
+    protected int getChildCount() {
+        return getCurrentElement().getChildNodes().getLength();
+    }
+
+    @Override
+    protected int moveToChild(int currentChild) {
+        this.content = getCurrentElement().getChildNodes().item(currentChild);
+
+        if (content instanceof Text) {
+            return CHARACTERS;
+        } else if (content instanceof Element) {
+            return START_ELEMENT;
+        } else if (content instanceof CDATASection) {
+            return CDATA;
+        } else if (content instanceof Comment) {
+            return CHARACTERS;
+        } else if (content instanceof EntityReference) {
+            return ENTITY_REFERENCE;
+        }
+
+        throw new IllegalStateException();
+    }
+
+    @Override
+    public String getElementText() throws XMLStreamException {
+        return DOMUtils.getContent(content);
+    }
+
+    @Override
+    public String getNamespaceURI(String prefix) {
+        ElementFrame frame = getCurrentFrame();
+
+        while (null != frame) {
+            int index = frame.prefixes.indexOf(prefix);
+            if (index != -1) {
+                return frame.uris.get(index);
+            }
+
+            frame = frame.parent;
+        }
+
+        return null;
+    }
+
+    public String getAttributeValue(String ns, String local) {
+        Attr at;
+        if (ns == null || ns.equals("")) {
+            at = getCurrentElement().getAttributeNode(local);
+        } else {
+            at = getCurrentElement().getAttributeNodeNS(ns, local);
+        }
+
+        if (at == null) {
+            return null;
+        }
+
+        return DOMUtils.getContent(at);
+    }
+
+    public int getAttributeCount() {
+        return getCurrentFrame().attributes.size();
+    }
+
+    Attr getAttribute(int i) {
+        return (Attr)getCurrentFrame().attributes.get(i);
+    }
+
+    private String getLocalName(Attr attr) {
+
+        String name = attr.getLocalName();
+        if (name == null) {
+            name = attr.getNodeName();
+        }
+        return name;
+    }
+
+    public QName getAttributeName(int i) {
+        Attr at = getAttribute(i);
+
+        String prefix = at.getPrefix();
+        String ln = getLocalName(at);
+        // at.getNodeName();
+        String ns = at.getNamespaceURI();
+
+        if (prefix == null) {
+            return new QName(ns, ln);
+        } else {
+            return new QName(ns, ln, prefix);
+        }
+    }
+
+    public String getAttributeNamespace(int i) {
+        return getAttribute(i).getNamespaceURI();
+    }
+
+    public String getAttributeLocalName(int i) {
+        Attr attr = getAttribute(i);
+        String name = getLocalName(attr);
+        return name;
+    }
+
+    public String getAttributePrefix(int i) {
+        return getAttribute(i).getPrefix();
+    }
+
+    public String getAttributeType(int i) {
+        return toStaxType(getAttribute(i).getNodeType());
+    }
+
+    public static String toStaxType(short jdom) {
+        switch (jdom) {
+        default:
+            return null;
+        }
+    }
+
+    public String getAttributeValue(int i) {
+        return getAttribute(i).getValue();
+    }
+
+    public boolean isAttributeSpecified(int i) {
+        return getAttribute(i).getValue() != null;
+    }
+
+    public int getNamespaceCount() {
+        return getCurrentFrame().prefixes.size();
+    }
+
+    public String getNamespacePrefix(int i) {
+        return getCurrentFrame().prefixes.get(i);
+    }
+
+    public String getNamespaceURI(int i) {
+        return getCurrentFrame().uris.get(i);
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return context;
+    }
+
+    public String getText() {
+        return DOMUtils.getRawContent(getCurrentElement());
+    }
+
+    public char[] getTextCharacters() {
+        return getText().toCharArray();
+    }
+
+    public int getTextStart() {
+        return 0;
+    }
+
+    public int getTextLength() {
+        return getText().length();
+    }
+
+    public String getEncoding() {
+        return null;
+    }
+
+    public QName getName() {
+        Element el = getCurrentElement();
+
+        String prefix = getPrefix();
+        String ln = getLocalName();
+
+        if (prefix == null) {
+            return new QName(el.getNamespaceURI(), ln);
+        } else {
+            return new QName(el.getNamespaceURI(), ln, prefix);
+        }
+    }
+
+    public String getLocalName() {
+        return getCurrentElement().getLocalName();
+    }
+
+    public String getNamespaceURI() {
+        return getCurrentElement().getNamespaceURI();
+    }
+
+    public String getPrefix() {
+        String prefix = getCurrentElement().getPrefix();
+        if (prefix == null) {
+            prefix = "";
+        }
+        return prefix;
+    }
+
+    public String getPITarget() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getPIData() {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamWriter.java?view=auto&rev=515734
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamWriter.java (added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamWriter.java Wed Mar  7 12:20:07 2007
@@ -0,0 +1,217 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.aegis.util.stax;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class W3CDOMStreamWriter extends DOMStreamWriter {
+    static final String XML_NS = "http://www.w3.org/2000/xmlns/";
+    private Stack<Element> stack = new Stack<Element>();
+    private Document document;
+    private Element currentNode;
+    private NamespaceContext context;
+    private Map properties = Collections.EMPTY_MAP;
+
+    public void setProperties(Map properties) {
+        this.properties = properties;
+    }
+
+    public W3CDOMStreamWriter() throws ParserConfigurationException {
+        this(DocumentBuilderFactory.newInstance().newDocumentBuilder());
+    }
+
+    public W3CDOMStreamWriter(DocumentBuilder builder) {
+        document = builder.newDocument();
+    }
+
+    public W3CDOMStreamWriter(Document document) {
+        this.document = document;
+    }
+
+    public Document getDocument() {
+        return document;
+    }
+
+    public void writeStartElement(String local) throws XMLStreamException {
+        newChild(document.createElement(local));
+    }
+
+    private void newChild(Element element) {
+        if (currentNode != null) {
+            stack.push(currentNode);
+            currentNode.appendChild(element);
+        } else {
+            document.appendChild(element);
+        }
+
+        W3CNamespaceContext context = new W3CNamespaceContext();
+        context.setElement(element);
+        this.context = context;
+
+        currentNode = element;
+    }
+
+    public void writeStartElement(String namespace, String local) throws XMLStreamException {
+        newChild(document.createElementNS(namespace, local));
+    }
+
+    public void writeStartElement(String prefix, String local, String namespace) throws XMLStreamException {
+        if (prefix == null || prefix.equals("")) {
+            writeStartElement(namespace, local);
+        } else {
+            newChild(document.createElementNS(namespace, prefix + ":" + local));
+        }
+    }
+
+    public void writeEmptyElement(String namespace, String local) throws XMLStreamException {
+        writeStartElement(namespace, local);
+    }
+
+    public void writeEmptyElement(String prefix, String namespace, String local) throws XMLStreamException {
+        writeStartElement(prefix, namespace, local);
+    }
+
+    public void writeEmptyElement(String local) throws XMLStreamException {
+        writeStartElement(local);
+    }
+
+    public void writeEndElement() throws XMLStreamException {
+        if (stack.size() > 0) {
+            currentNode = stack.pop();
+        } else {
+            currentNode = null;
+        }
+        ((W3CNamespaceContext)context).setElement(currentNode);
+    }
+
+    public void writeEndDocument() throws XMLStreamException {
+    }
+
+    public void writeAttribute(String local, String value) throws XMLStreamException {
+        Attr a = document.createAttribute(local);
+        a.setValue(value);
+        currentNode.setAttributeNode(a);
+    }
+
+    public void writeAttribute(String prefix, String namespace, String local, String value)
+        throws XMLStreamException {
+        if (prefix.length() > 0) {
+            local = prefix + ":" + local;
+        }
+
+        Attr a = document.createAttributeNS(namespace, local);
+        a.setValue(value);
+        currentNode.setAttributeNodeNS(a);
+    }
+
+    public void writeAttribute(String namespace, String local, String value) throws XMLStreamException {
+        Attr a = document.createAttributeNS(namespace, local);
+        a.setValue(value);
+        currentNode.setAttributeNodeNS(a);
+    }
+
+    public void writeNamespace(String prefix, String namespace) throws XMLStreamException {
+        if (prefix.length() == 0) {
+            writeDefaultNamespace(namespace);
+        } else {
+            currentNode.setAttributeNS(XML_NS, "xmlns:" + prefix, namespace);
+        }
+    }
+
+    public void writeDefaultNamespace(String namespace) throws XMLStreamException {
+        currentNode.setAttributeNS(XML_NS, "xmlns", namespace);
+    }
+
+    public void writeComment(String value) throws XMLStreamException {
+        currentNode.appendChild(document.createComment(value));
+    }
+
+    public void writeProcessingInstruction(String target) throws XMLStreamException {
+        currentNode.appendChild(document.createProcessingInstruction(target, null));
+    }
+
+    public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
+        currentNode.appendChild(document.createProcessingInstruction(target, data));
+    }
+
+    public void writeCData(String data) throws XMLStreamException {
+        currentNode.appendChild(document.createCDATASection(data));
+    }
+
+    public void writeDTD(String arg0) throws XMLStreamException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void writeEntityRef(String ref) throws XMLStreamException {
+        currentNode.appendChild(document.createEntityReference(ref));
+    }
+
+    public void writeStartDocument() throws XMLStreamException {
+    }
+
+    public void writeStartDocument(String version) throws XMLStreamException {
+        writeStartDocument();
+    }
+
+    public void writeStartDocument(String encoding, String version) throws XMLStreamException {
+        writeStartDocument();
+    }
+
+    public void writeCharacters(String text) throws XMLStreamException {
+        currentNode.appendChild(document.createTextNode(text));
+    }
+
+    public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
+        writeCharacters(new String(text, start, len));
+    }
+
+    public String getPrefix(String uri) throws XMLStreamException {
+        return context.getPrefix(uri);
+    }
+
+    public void setPrefix(String arg0, String arg1) throws XMLStreamException {
+    }
+
+    public void setDefaultNamespace(String arg0) throws XMLStreamException {
+    }
+
+    public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
+        this.context = context;
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return context;
+    }
+
+    public Object getProperty(String prop) throws IllegalArgumentException {
+        return properties.get(prop);
+    }
+}

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamWriter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date