You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mirae-dev@ws.apache.org by ia...@apache.org on 2005/07/26 18:22:14 UTC

svn commit: r225342 [3/3] - in /webservices/mirae/trunk/src/mirae/stax/org: ./ apache/ apache/mirae/ apache/mirae/stax/ apache/mirae/stax/util/ apache/mirae/util/

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/MXParser.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/MXParserFactory.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/MXParserFactory.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/MXParserFactory.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/MXParserFactory.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+public class MXParserFactory extends XMLInputFactory {
+
+    ConfigurationContextBase config = new ConfigurationContextBase();
+
+    public static XMLInputFactory newInstance() {
+        return XMLInputFactory.newInstance();
+    }
+
+    /**
+     * Create a new XMLStreamReader from a java.io.stream
+     * 
+     * @param stream
+     *            the InputStream to read from
+     */
+    public XMLStreamReader createXMLStreamReader(java.io.InputStream stream)
+            throws XMLStreamException {
+        return createXMLStreamReader(new InputStreamReader(stream));
+    }
+
+    /**
+     * Specifies that the stream produced by this code will append all adjacent
+     * text nodes.
+     */
+    public void setCoalescing(boolean coalescing) {
+        config.setCoalescing(coalescing);
+    }
+
+    /**
+     * Indicates whether or not the factory is configured to produced streams
+     * that coalesce adjacent text nodes.
+     */
+    public boolean isCoalescing() {
+        return config.isCoalescing();
+    }
+
+    public void setProperty(String name, Object value)
+            throws IllegalArgumentException {
+        // TODO - cwitt : check against supported feature list
+        config.setProperty(name, value);
+    }
+
+    public Object getProperty(String name) throws IllegalArgumentException {
+        return config.getProperty(name);
+    }
+
+    public XMLStreamReader createXMLStreamReader(Reader in)
+            throws XMLStreamException {
+        MXParser pp = new MXParser();
+        pp.setInput(in);
+        pp.setConfigurationContext(config);
+        return pp;
+    }
+
+    public boolean isPropertySupported(String name) {
+        return config.isPropertySupported(name);
+    }
+
+    public XMLStreamReader createXMLStreamReader(Reader in,
+            boolean requiringXMLDeclaration) throws XMLStreamException {
+        MXParser pp = new MXParser();
+        pp.setRequiringXMLDeclaration(requiringXMLDeclaration);
+        pp.setInput(in);
+        pp.setConfigurationContext(config);
+        return pp;
+    }
+
+    public XMLStreamReader createXMLStreamReader(InputStream in,
+            boolean requiringXMLDeclaration) throws XMLStreamException {
+        // TODO Auto-generated method stub
+        return createXMLStreamReader(new InputStreamReader(in),
+                requiringXMLDeclaration);
+    }
+
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/MXParserFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/NamespaceBase.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/NamespaceBase.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/NamespaceBase.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/NamespaceBase.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax;
+
+import javax.xml.stream.XMLStreamConstants;
+
+/**
+ * <p>
+ * The default implementation of the namespace class
+ * </p>
+ */
+
+public class NamespaceBase extends AttributeBase {
+    boolean declaresDefaultNamespace = false;
+
+    public NamespaceBase(String prefix, String namespaceURI) {
+        super("xmlns", prefix, namespaceURI);
+        declaresDefaultNamespace = false;
+    }
+
+    public NamespaceBase(String namespaceURI) {
+        super("xmlns", "", namespaceURI);
+        declaresDefaultNamespace = true;
+    }
+
+    public int getEventType() {
+        return XMLStreamConstants.NAMESPACE;
+    }
+
+    public boolean isAttribute() {
+        return false;
+    }
+
+    public boolean isNamespace() {
+        return true;
+    }
+
+    public String getPrefix() {
+        if (declaresDefaultNamespace)
+            return "";
+        return super.getLocalName();
+    }
+
+    public String getNamespaceURI() {
+        return super.getValue();
+    }
+
+    public boolean isDefaultNamespaceDeclaration() {
+        return declaresDefaultNamespace;
+    }
+
+    public String toString() {
+        if (declaresDefaultNamespace)
+            return "xmlns='" + getNamespaceURI() + "'";
+        else
+            return "xmlns:" + getPrefix() + "='" + getNamespaceURI() + "'";
+    }
+
+}

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReadOnlyNamespaceContextBase.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReadOnlyNamespaceContextBase.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReadOnlyNamespaceContextBase.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReadOnlyNamespaceContextBase.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+
+/**
+ * <p>
+ * This class provides a ReadOnlyNamespace context that takes a snapshot of the
+ * current namespaces in scope
+ * </p>
+ */
+
+public class ReadOnlyNamespaceContextBase implements NamespaceContext {
+    private String[] prefixes;
+
+    private String[] uris;
+
+    public ReadOnlyNamespaceContextBase(String[] prefixArray,
+            String[] uriArray, int size) {
+        prefixes = new String[size];
+        uris = new String[size];
+        System.arraycopy(prefixArray, 0, prefixes, 0, prefixes.length);
+        System.arraycopy(uriArray, 0, uris, 0, uris.length);
+    }
+
+    public String getNamespaceURI(String prefix) {
+        if (prefix == null)
+            throw new IllegalArgumentException("Prefix may not be null.");
+        if (!"".equals(prefix)) {
+            for (int i = uris.length - 1; i >= 0; i--) {
+                if (prefix.equals(prefixes[i])) {
+                    return uris[i];
+                }
+            }
+            if ("xml".equals(prefix)) {
+                return XMLConstants.XML_NS_URI;
+            } else if ("xmlns".equals(prefix)) {
+                return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+            }
+        } else {
+            for (int i = uris.length - 1; i >= 0; i--) {
+                if (prefixes[i] == null) {
+                    return uris[i];
+                }
+            }
+        }
+        return null;
+    }
+
+    public String getPrefix(String uri) {
+        if (uri == null)
+            throw new IllegalArgumentException("uri may not be null");
+        if ("".equals(uri))
+            throw new IllegalArgumentException("uri may not be empty string");
+
+        if (uri != null) {
+            for (int i = uris.length - 1; i >= 0; i--) {
+                if (uri.equals(uris[i])) {
+                    return checkNull(prefixes[i]);
+                }
+            }
+        }
+        return null;
+    }
+
+    public String getDefaultNameSpace() {
+        for (int i = uris.length - 1; i >= 0; i--) {
+            if (prefixes[i] == null) {
+                return uris[i];
+            }
+        }
+        return null;
+    }
+
+    private String checkNull(String s) {
+        if (s == null)
+            return "";
+        return s;
+    }
+
+    public Enumeration getPrefixes(String uri) {
+        if (uri == null)
+            throw new IllegalArgumentException("uri may not be null");
+        if ("".equals(uri))
+            throw new IllegalArgumentException("uri may not be empty string");
+        Vector s = new Vector();
+        for (int i = uris.length - 1; i >= 0; i--) {
+            String prefix = checkNull(prefixes[i]);
+            if (uri.equals(uris[i]) && !s.contains(prefix)) {
+                s.addElement(prefix);
+            }
+        }
+        return s.elements();
+    }
+
+    public String toString() {
+        StringBuffer b = new StringBuffer();
+        for (int i = 0; i < uris.length; i++) {
+            b.append("[" + checkNull(prefixes[i]) + "<->" + uris[i] + "]");
+        }
+        return b.toString();
+    }
+
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReadOnlyNamespaceContextBase.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderDelegate.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderDelegate.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderDelegate.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderDelegate.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,298 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * <p>
+ * An implementation of the ReaderDelegate class
+ * </p>
+ */
+
+public class ReaderDelegate implements XMLStreamReader {
+    private XMLStreamReader reader;
+
+    public ReaderDelegate(XMLStreamReader reader) {
+        this.reader = reader;
+    }
+
+    public void setDelegate(XMLStreamReader reader) {
+        this.reader = reader;
+    }
+
+    public XMLStreamReader getDelegate() {
+        return reader;
+    }
+
+    public int next() throws XMLStreamException {
+        return reader.next();
+    }
+
+    public int nextTag() throws XMLStreamException {
+        return reader.nextTag();
+    }
+
+    public String getElementText() throws XMLStreamException {
+        return reader.getElementText();
+    }
+
+    public void require(int type, String namespaceURI, String localName)
+            throws XMLStreamException {
+        reader.require(type, namespaceURI, localName);
+    }
+
+    public boolean hasNext() throws XMLStreamException {
+        return reader.hasNext();
+    }
+
+    // public void skip()
+    // throws XMLStreamException
+    // {
+    // reader.skip();
+    // }
+
+    public void close() throws XMLStreamException {
+        reader.close();
+    }
+
+    public String getNamespaceURI(String prefix) {
+        return reader.getNamespaceURI(prefix);
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return reader.getNamespaceContext();
+    }
+
+    public boolean isStartElement() {
+        return reader.isStartElement();
+    }
+
+    public boolean isEndElement() {
+        return reader.isEndElement();
+    }
+
+    public boolean isCharacters() {
+        return reader.isCharacters();
+    }
+
+    public boolean isWhiteSpace() {
+        return reader.isWhiteSpace();
+    }
+
+    public QName getAttributeName(int index) {
+        return reader.getAttributeName(index);
+    }
+
+    public int getTextCharacters(int sourceStart, char[] target,
+            int targetStart, int length) throws XMLStreamException {
+        return reader.getTextCharacters(sourceStart, target, targetStart,
+                length);
+    }
+
+    /***************************************************************************
+     * ********8 public boolean moveToStartElement() throws XMLStreamException {
+     * return reader.moveToStartElement(); }
+     * 
+     * public boolean moveToStartElement(String localName) throws
+     * XMLStreamException { return reader.moveToStartElement(localName); }
+     * 
+     * public boolean moveToStartElement(String localName, String namespaceUri)
+     * throws XMLStreamException { return
+     * reader.moveToStartElement(localName,namespaceUri); }
+     * 
+     * public boolean moveToEndElement() throws XMLStreamException { return
+     * reader.moveToEndElement(); }
+     * 
+     * public boolean moveToEndElement(String localName) throws
+     * XMLStreamException { return reader.moveToEndElement(localName); }
+     * 
+     * public boolean moveToEndElement(String localName, String namespaceUri)
+     * throws XMLStreamException { return
+     * reader.moveToEndElement(localName,namespaceUri); }
+     * 
+     * public boolean hasAttributes() { return reader.hasAttributes(); }
+     * 
+     * public boolean hasNamespaces() { return reader.hasNamespaces(); }
+     **************************************************************************/
+    public String getAttributeValue(String namespaceUri, String localName) {
+        return reader.getAttributeValue(namespaceUri, localName);
+    }
+
+    public int getAttributeCount() {
+        return reader.getAttributeCount();
+    }
+
+    public String getAttributePrefix(int index) {
+        return reader.getAttributePrefix(index);
+    }
+
+    public String getAttributeNamespace(int index) {
+        return reader.getAttributeNamespace(index);
+    }
+
+    public String getAttributeLocalName(int index) {
+        return reader.getAttributeLocalName(index);
+    }
+
+    public String getAttributeType(int index) {
+        return reader.getAttributeType(index);
+    }
+
+    public String getAttributeValue(int index) {
+        return reader.getAttributeValue(index);
+    }
+
+    public boolean isAttributeSpecified(int index) {
+        return reader.isAttributeSpecified(index);
+    }
+
+    public int getNamespaceCount() {
+        return reader.getNamespaceCount();
+    }
+
+    public String getNamespacePrefix(int index) {
+        return reader.getNamespacePrefix(index);
+    }
+
+    public String getNamespaceURI(int index) {
+        return reader.getNamespaceURI(index);
+    }
+
+    // public AttributeIterator getAttributes() {
+    // return reader.getAttributes();
+    //
+
+    // public NamespaceIterator getNamespaces() {
+    // return reader.getNamespaces();
+    // }
+
+    // public XMLStreamReader subReader()
+    // throws XMLStreamException
+    // {
+    // return reader.subReader();
+    // }
+
+    // public void recycle()
+    // throws XMLStreamException
+    // {
+    // reader.recycle();
+    // }
+
+    public int getEventType() {
+        return reader.getEventType();
+    }
+
+    public String getText() {
+        return reader.getText();
+    }
+
+    public char[] getTextCharacters() {
+        return reader.getTextCharacters();
+    }
+
+    public int getTextStart() {
+        return reader.getTextStart();
+    }
+
+    public int getTextLength() {
+        return reader.getTextLength();
+    }
+
+    public boolean hasText() {
+        return reader.hasText();
+    }
+
+    // public int getLineNumber() {
+    // return reader.getLineNumber();
+    // }
+
+    // public int getColumnNumber() {
+    // return reader.getColumnNumber();
+    // }
+
+    // public int getCharacterOffset() {
+    // return reader.getCharacterOffset();
+    // }
+    public Location getLocation() {
+        return reader.getLocation();
+    }
+
+    public QName getName() {
+        return reader.getName();
+    }
+
+    public String getLocalName() {
+        return reader.getLocalName();
+    }
+
+    public boolean hasName() {
+        return reader.hasName();
+    }
+
+    public String getNamespaceURI() {
+        return reader.getNamespaceURI();
+    }
+
+    public String getPrefix() {
+        return reader.getPrefix();
+    }
+
+    public String getVersion() {
+        return reader.getVersion();
+    }
+
+    public boolean isStandalone() {
+        return reader.isStandalone();
+    }
+
+    public boolean standaloneSet() {
+        return reader.standaloneSet();
+    }
+
+    public String getCharacterEncodingScheme() {
+        return reader.getCharacterEncodingScheme();
+    }
+
+    public String getPITarget() {
+        return reader.getPITarget();
+    }
+
+    public String getPIData() {
+        return reader.getPIData();
+    }
+
+    // public NamespaceIterator getOutOfScopeNamespaces() {
+    // return reader.getOutOfScopeNamespaces();
+    // }
+
+    // public ConfigurationContext getConfigurationContext() {
+    // return reader.getConfigurationContext();
+    // }
+
+    public Object getProperty(String name) {
+        return reader.getProperty(name);
+    }
+
+    // public boolean isRequiringXMLDeclaration() {
+    // return reader.isRequiringXMLDeclaration();
+    // }
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderDelegate.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderToWriter.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderToWriter.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderToWriter.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderToWriter.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * <p>
+ * Automatically write a reader.
+ * </p>
+ */
+
+public class ReaderToWriter {
+
+    private XMLStreamWriter writer;
+
+    public ReaderToWriter() {
+    }
+
+    public ReaderToWriter(XMLStreamWriter xmlw) {
+        writer = xmlw;
+    }
+
+    public void setStreamWriter(XMLStreamWriter xmlw) {
+        writer = xmlw;
+    }
+
+    public void write(XMLStreamReader xmlr) throws XMLStreamException {
+        System.out.println("wrote event");
+        switch (xmlr.getEventType()) {
+        case XMLStreamConstants.START_ELEMENT:
+            String prefix = xmlr.getPrefix();
+            String namespaceURI = xmlr.getNamespaceURI();
+            if (namespaceURI != null) {
+                if (prefix != null)
+                    writer.writeStartElement(xmlr.getPrefix(), xmlr
+                            .getLocalName(), xmlr.getNamespaceURI());
+                else
+                    writer.writeStartElement(xmlr.getNamespaceURI(), xmlr
+                            .getLocalName());
+            } else {
+                writer.writeStartElement(xmlr.getLocalName());
+            }
+
+            for (int i = 0; i < xmlr.getNamespaceCount(); i++) {
+                writer.writeNamespace(xmlr.getNamespacePrefix(i), xmlr
+                        .getNamespaceURI(i));
+            }
+            break;
+        case XMLStreamConstants.END_ELEMENT:
+            writer.writeEndElement();
+            break;
+        case XMLStreamConstants.SPACE:
+        case XMLStreamConstants.CHARACTERS:
+            writer.writeCharacters(xmlr.getTextCharacters(), xmlr
+                    .getTextStart(), xmlr.getTextLength());
+            break;
+        case XMLStreamConstants.PROCESSING_INSTRUCTION:
+            writer.writeProcessingInstruction(xmlr.getPITarget(), xmlr
+                    .getPIData());
+            break;
+        case XMLStreamConstants.CDATA:
+            writer.writeCData(xmlr.getText());
+            break;
+
+        case XMLStreamConstants.COMMENT:
+            writer.writeComment(xmlr.getText());
+            break;
+        case XMLStreamConstants.ENTITY_REFERENCE:
+            writer.writeEntityRef(xmlr.getLocalName());
+            break;
+        case XMLStreamConstants.START_DOCUMENT:
+            String encoding = xmlr.getCharacterEncodingScheme();
+            String version = xmlr.getVersion();
+
+            if (encoding != null && version != null)
+                writer.writeStartDocument(encoding, version);
+            else if (version != null)
+                writer.writeStartDocument(xmlr.getVersion());
+            break;
+        case XMLStreamConstants.END_DOCUMENT:
+            writer.writeEndDocument();
+            break;
+        case XMLStreamConstants.DTD:
+            writer.writeDTD(xmlr.getText());
+            break;
+
+        }
+    }
+
+    public XMLStreamWriter writeAll(XMLStreamReader xmlr)
+            throws XMLStreamException {
+        while (xmlr.hasNext()) {
+            write(xmlr);
+            xmlr.next();
+        }
+        writer.flush();
+        return writer;
+    }
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/ReaderToWriter.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/SubReader.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/SubReader.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/SubReader.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/SubReader.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.mirae.stax.util.ElementTypeNames;
+
+/**
+ * <p>
+ * Creates a SubReader over a node of a document
+ * </p>
+ */
+
+public class SubReader extends ReaderDelegate {
+    private int depth = 0;
+
+    private boolean open = true;
+
+    public SubReader(XMLStreamReader reader) throws XMLStreamException {
+        super(reader);
+        if (!reader.isStartElement())
+            throw new XMLStreamException("Unable to instantiate a subReader "
+                    + "because the underlying reader "
+                    + "was not on a start element.");
+        open = true;
+        depth++;
+    }
+
+    public int next() throws XMLStreamException {
+        if (depth <= 0)
+            open = false;
+        int type = super.next();
+        if (isStartElement())
+            depth++;
+        if (isEndElement()) {
+            depth--;
+        }
+        return type;
+    }
+
+    public int nextElement() throws XMLStreamException {
+        next();
+        while (hasNext() && !isStartElement() && !isEndElement())
+            next();
+        return super.getEventType();
+    }
+
+    public boolean hasNext() throws XMLStreamException {
+        if (!open)
+            return false;
+        return super.hasNext();
+    }
+
+    public boolean moveToStartElement() throws XMLStreamException {
+        if (isStartElement())
+            return true;
+        while (hasNext()) {
+            if (isStartElement())
+                return true;
+            else
+                next();
+        }
+        return false;
+    }
+
+    public boolean moveToStartElement(String localName)
+            throws XMLStreamException {
+        if (localName == null)
+            return false;
+        while (moveToStartElement()) {
+            if (localName.equals(getLocalName()))
+                return true;
+            if (!hasNext())
+                return false;
+            next();
+        }
+        return false;
+    }
+
+    public boolean moveToStartElement(String localName, String namespaceUri)
+            throws XMLStreamException {
+        if (localName == null || namespaceUri == null)
+            return false;
+        while (moveToStartElement(localName)) {
+            if (namespaceUri.equals(getNamespaceURI()))
+                return true;
+            if (!hasNext())
+                return false;
+            next();
+        }
+        return false;
+    }
+
+    public boolean moveToEndElement() throws XMLStreamException {
+        if (isEndElement())
+            return true;
+        while (hasNext()) {
+            if (isEndElement())
+                return true;
+            else
+                next();
+        }
+        return false;
+    }
+
+    public boolean moveToEndElement(String localName) throws XMLStreamException {
+        if (localName == null)
+            return false;
+        while (moveToEndElement()) {
+            if (localName.equals(getLocalName()))
+                return true;
+            if (!hasNext())
+                return false;
+            next();
+        }
+        return false;
+    }
+
+    public boolean moveToEndElement(String localName, String namespaceUri)
+            throws XMLStreamException {
+        if (localName == null || namespaceUri == null)
+            return false;
+        while (moveToEndElement(localName)) {
+            if (namespaceUri.equals(getNamespaceURI()))
+                return true;
+            if (!hasNext())
+                return false;
+            next();
+        }
+        return false;
+    }
+
+    public static void print(XMLStreamReader r, int depth)
+            throws XMLStreamException {
+        System.out.print("[" + depth + "]Sub: "
+                + ElementTypeNames.getEventTypeString(r.getEventType()));
+        if (r.hasName())
+            System.out.println("->" + r.getLocalName());
+        else if (r.hasText())
+            System.out.println("->[" + r.getText() + "]");
+        else
+            System.out.println();
+    }
+
+    public static void sub(XMLStreamReader r, int depth) throws Exception {
+        while (r.hasNext()) {
+            print(r, depth);
+            r.next();
+        }
+    }
+
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/SubReader.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLOutputFactoryBase.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLOutputFactoryBase.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLOutputFactoryBase.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLOutputFactoryBase.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * <p>
+ * Creates instances of the various interfaces for XML output
+ * </p>
+ */
+
+public class XMLOutputFactoryBase extends XMLOutputFactory {
+    ConfigurationContextBase config = new ConfigurationContextBase();
+
+    public static XMLOutputFactory newInstance() {
+        return XMLOutputFactory.newInstance();
+    }
+
+    public XMLStreamWriter createXMLStreamWriter(java.io.Writer stream)
+            throws XMLStreamException {
+        XMLWriterBase b = new XMLWriterBase(stream);
+        b.setConfigurationContext(config);
+        return b;
+    }
+
+    public XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream)
+            throws XMLStreamException {
+        return createXMLStreamWriter(new java.io.OutputStreamWriter(stream));
+    }
+
+    public void setProperty(java.lang.String name, Object value) {
+        config.setProperty(name, value);
+    }
+
+    public Object getProperty(java.lang.String name) {
+        return config.getProperty(name);
+    }
+
+    public boolean isPrefixDefaulting() {
+        return config.isPrefixDefaulting();
+    }
+
+    public void setPrefixDefaulting(boolean value) {
+        config.setPrefixDefaulting(value);
+    }
+
+    public boolean isPropertySupported(String name) {
+        return config.isPropertySupported(name);
+    }
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLOutputFactoryBase.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLWriterBase.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLWriterBase.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLWriterBase.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLWriterBase.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,549 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Enumeration;
+import java.util.Stack;
+import java.util.Vector;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.mirae.stax.util.NamespaceContextImpl;
+
+/**
+ * <p>
+ * The base output class.
+ * </p>
+ */
+
+public class XMLWriterBase extends ReaderToWriter implements XMLStreamWriter {
+    protected static final String DEFAULTNS = "";
+
+    private Writer writer;
+
+    private boolean startElementOpened = false;
+
+    private boolean isEmpty = false;
+
+    private ConfigurationContextBase config;
+
+    // these two stacks are used to implement the
+    // writeEndElement() method
+    private Stack localNameStack = new Stack();
+
+    private Stack prefixStack = new Stack();
+
+    private Stack uriStack = new Stack();
+
+    protected NamespaceContextImpl context = new NamespaceContextImpl();
+
+    private Vector needToWrite;
+
+    private boolean isPrefixDefaulting;
+
+    private int defaultPrefixCount = 0;
+
+    public XMLWriterBase() {
+    }
+
+    public XMLWriterBase(Writer writer) {
+        this.writer = writer;
+        setWriter(writer);
+    }
+
+    public void setWriter(Writer writer) {
+        this.writer = writer;
+        setStreamWriter(this);
+    }
+
+    public void setConfigurationContext(ConfigurationContextBase c) {
+        config = c;
+        isPrefixDefaulting = config.isPrefixDefaulting();
+    }
+
+    protected void write(String s) throws XMLStreamException {
+        try {
+            writer.write(s);
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    protected void write(char c) throws XMLStreamException {
+        try {
+            writer.write(c);
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    protected void write(char[] c) throws XMLStreamException {
+        try {
+            writer.write(c);
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    protected void write(char[] c, int start, int len)
+            throws XMLStreamException {
+        try {
+            writer.write(c, start, len);
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    protected void writeCharactersInternal(char characters[], int start,
+            int length, boolean isAttributeValue) throws XMLStreamException {
+        if (length == 0)
+            return;
+
+        // We expect the common case to be that people do not have these
+        // characters in their XML so we make a pass through the char
+        // array and check. If they're all good, we can call the
+        // underlying Writer once with the entire char array. If we find
+        // a bad character then we punt it to the slow routine. So don't
+        // benchmark an XML document that has to be escaped.
+
+        boolean fastPath = true;
+
+        for (int i = 0, len = length; i < len; i++) {
+            switch (characters[i + start]) {
+            case '&':
+            case '<':
+            case '>':
+            case '\"':
+                fastPath = false;
+                break;
+            }
+        }
+
+        if (fastPath) {
+            write(characters, start, length);
+        } else {
+            slowWriteCharacters(characters, start, length, isAttributeValue);
+        }
+    }
+
+    private void slowWriteCharacters(char chars[], int start, int length,
+            boolean isAttributeValue) throws XMLStreamException {
+        for (int i = 0, len = length; i < len; i++) {
+            final char c = chars[i + start];
+            switch (c) {
+            case '&':
+                write("&amp;");
+                break;
+            case '<':
+                write("&lt;");
+                break;
+            case '>':
+                write("&gt;");
+                break;
+            case '\"':
+                if (isAttributeValue) {
+                    write("&quot;");
+                } else {
+                    write('\"');
+                }
+                break;
+            default:
+                write(c);
+            }
+        }
+    }
+
+    protected void closeStartElement() throws XMLStreamException {
+        if (startElementOpened) {
+            closeStartTag();
+            startElementOpened = false;
+        }
+    }
+
+    protected boolean isOpen() {
+        return startElementOpened;
+    }
+
+    protected void closeStartTag() throws XMLStreamException {
+        flushNamespace();
+        if (isEmpty) {
+            write("/>");
+            isEmpty = false;
+        } else
+            write(">");
+    }
+
+    private void openStartElement() throws XMLStreamException {
+        if (startElementOpened)
+            closeStartTag();
+        else
+            startElementOpened = true;
+    }
+
+    protected String writeName(String prefix, String namespaceURI,
+            String localName) throws XMLStreamException {
+        if (!("".equals(namespaceURI)))
+            prefix = getPrefixInternal(namespaceURI);
+        if (!("".equals(prefix))) {
+            write(prefix);
+            write(":");
+        }
+        write(localName);
+        return prefix;
+
+    }
+
+    private String getPrefixInternal(String namespaceURI) {
+        String prefix = context.getPrefix(namespaceURI);
+        if (prefix == null) {
+            return "";
+        }
+        return prefix;
+    }
+
+    protected String getURIInternal(String prefix) {
+        String uri = context.getNamespaceURI(prefix);
+        if (uri == null) {
+            return "";
+        }
+        return uri;
+    }
+
+    protected void openStartTag() throws XMLStreamException {
+        write("<");
+    }
+
+    private void needToWrite(String uri) {
+        if (needToWrite == null) {
+            needToWrite = new Vector();
+        }
+        if (!needToWrite.contains(uri)) {
+            needToWrite.addElement(uri);
+        }
+    }
+
+    private void prepareNamespace(String uri) throws XMLStreamException {
+        if (!isPrefixDefaulting)
+            return;
+        if ("".equals(uri))
+            return;
+        String prefix = getPrefix(uri);
+        // if the prefix is bound then we can ignore and return
+        if (prefix != null)
+            return;
+
+        defaultPrefixCount++;
+        prefix = "ns" + defaultPrefixCount;
+        needToWrite(uri);
+        setPrefix(prefix, uri);
+    }
+
+    private void flushNamespace() throws XMLStreamException {
+        if (!isPrefixDefaulting || needToWrite == null)
+            return;
+        Enumeration i = needToWrite.elements();
+        while (i.hasMoreElements()) {
+            String uri = (String) i.nextElement();
+            String prefix = context.getPrefix(uri);
+            if (prefix == null) {
+                throw new XMLStreamException(
+                        "Unable to default prefix with uri:" + uri);
+            }
+            writeNamespace(prefix, uri);
+        }
+        needToWrite.removeAllElements();
+    }
+
+    protected void writeStartElementInternal(String namespaceURI,
+            String localName) throws XMLStreamException {
+        if (namespaceURI == null)
+            throw new IllegalArgumentException(
+                    "The namespace URI may not be null");
+        if (localName == null)
+            throw new IllegalArgumentException(
+                    "The local name  may not be null");
+
+        openStartElement();
+        openStartTag();
+        prepareNamespace(namespaceURI);
+        prefixStack.push(writeName("", namespaceURI, localName));
+        localNameStack.push(localName);
+        uriStack.push(namespaceURI);
+    }
+
+    public void writeStartElement(String namespaceURI, String localName)
+            throws XMLStreamException {
+        context.openScope();
+        writeStartElementInternal(namespaceURI, localName);
+    }
+
+    public void writeStartElement(String prefix, String localName,
+            String namespaceURI) throws XMLStreamException {
+        if (namespaceURI == null)
+            throw new IllegalArgumentException(
+                    "The namespace URI may not be null");
+        if (localName == null)
+            throw new IllegalArgumentException("The local name may not be null");
+        if (prefix == null)
+            throw new IllegalArgumentException("The prefix may not be null");
+        context.openScope();
+        prepareNamespace(namespaceURI);
+        context.bindNamespace(prefix, namespaceURI);
+        writeStartElementInternal(namespaceURI, localName);
+    }
+
+    public void writeStartElement(String localName) throws XMLStreamException {
+        context.openScope();
+        writeStartElement("", localName);
+    }
+
+    public void writeEmptyElement(String namespaceURI, String localName)
+            throws XMLStreamException {
+        openStartElement();
+        prepareNamespace(namespaceURI);
+        isEmpty = true;
+        write("<");
+        writeName("", namespaceURI, localName);
+    }
+
+    public void writeEmptyElement(String prefix, String localName,
+            String namespaceURI) throws XMLStreamException {
+        openStartElement();
+        prepareNamespace(namespaceURI);
+        isEmpty = true;
+        write("<");
+        write(prefix);
+        write(":");
+        write(localName);
+    }
+
+    public void writeEmptyElement(String localName) throws XMLStreamException {
+        writeEmptyElement("", localName);
+    }
+
+    protected void openEndTag() throws XMLStreamException {
+        write("</");
+    }
+
+    protected void closeEndTag() throws XMLStreamException {
+        write(">");
+    }
+
+    public void writeEndElement() throws XMLStreamException {
+        closeStartElement();
+        String prefix = (String) prefixStack.pop();
+        String local = (String) localNameStack.pop();
+        uriStack.pop();
+        openEndTag();
+        writeName(prefix, "", local);
+        closeEndTag();
+        context.closeScope();
+    }
+
+    public void writeRaw(String data) throws XMLStreamException {
+        closeStartElement();
+        write(data);
+    }
+
+    public void close() throws XMLStreamException {
+        flush();
+    }
+
+    public void flush() throws XMLStreamException {
+        try {
+            writer.flush();
+        } catch (IOException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    public void writeEndDocument() throws XMLStreamException {
+        while (!localNameStack.isEmpty())
+            writeEndElement();
+    }
+
+    public void writeAttribute(String localName, String value)
+            throws XMLStreamException {
+        writeAttribute("", localName, value);
+    }
+
+    public void writeAttribute(String namespaceURI, String localName,
+            String value) throws XMLStreamException {
+        if (!isOpen())
+            throw new XMLStreamException(
+                    "A start element must be written before an attribute");
+        prepareNamespace(namespaceURI);
+        write(" ");
+        writeName("", namespaceURI, localName);
+        write("=\"");
+        writeCharactersInternal(value.toCharArray(), 0, value.length(), true);
+        write("\"");
+    }
+
+    public void writeAttribute(String prefix, String namespaceURI,
+            String localName, String value) throws XMLStreamException {
+        if (!isOpen())
+            throw new XMLStreamException(
+                    "A start element must be written before an attribute");
+        prepareNamespace(namespaceURI);
+        context.bindNamespace(prefix, namespaceURI);
+        write(" ");
+        writeName(prefix, namespaceURI, localName);
+        write("=\"");
+        writeCharactersInternal(value.toCharArray(), 0, value.length(), true);
+        write("\"");
+    }
+
+    public void writeNamespace(String prefix, String namespaceURI)
+            throws XMLStreamException {
+        if (!isOpen())
+            throw new XMLStreamException(
+                    "A start element must be written before a namespace");
+        if (prefix == null || "".equals(prefix) || "xmlns".equals(prefix)) {
+            writeDefaultNamespace(namespaceURI);
+            return;
+        }
+        write(" xmlns:");
+        write(prefix);
+        write("=\"");
+        write(namespaceURI);
+        write("\"");
+        setPrefix(prefix, namespaceURI);
+    }
+
+    public void writeDefaultNamespace(String namespaceURI)
+            throws XMLStreamException {
+        if (!isOpen())
+            throw new XMLStreamException(
+                    "A start element must be written before the default namespace");
+        write(" xmlns");
+        write("=\"");
+        write(namespaceURI);
+        write("\"");
+        setPrefix(DEFAULTNS, namespaceURI);
+    }
+
+    public void writeComment(String data) throws XMLStreamException {
+        closeStartElement();
+        write("<!--");
+        if (data != null)
+            write(data);
+        write("-->");
+    }
+
+    public void writeProcessingInstruction(String target)
+            throws XMLStreamException {
+        closeStartElement();
+        writeProcessingInstruction(target, null);
+    }
+
+    public void writeProcessingInstruction(String target, String text)
+            throws XMLStreamException {
+        closeStartElement();
+        write("<?");
+        if (target != null)
+            write(target);
+        if (text != null) {
+            write(text);
+        }
+        write("?>");
+    }
+
+    public void writeDTD(String dtd) throws XMLStreamException {
+        write(dtd);
+    }
+
+    public void writeCData(String data) throws XMLStreamException {
+        closeStartElement();
+        write("<![CDATA[");
+        if (data != null)
+            write(data);
+        write("]]>");
+    }
+
+    public void writeEntityRef(String name) throws XMLStreamException {
+        closeStartElement();
+        write("&");
+        write(name);
+        write(";");
+    }
+
+    public void writeStartDocument() throws XMLStreamException {
+        write("<?xml version='1.0' encoding='utf-8'?>");
+    }
+
+    public void writeStartDocument(String version) throws XMLStreamException {
+        write("<?xml version='");
+        write(version);
+        write("'?>");
+    }
+
+    public void writeStartDocument(String encoding, String version)
+            throws XMLStreamException {
+        write("<?xml version='");
+        write(version);
+        write("' encoding='");
+        write(encoding);
+        write("'?>");
+    }
+
+    public void writeCharacters(String text) throws XMLStreamException {
+        closeStartElement();
+        writeCharactersInternal(text.toCharArray(), 0, text.length(), false);
+    }
+
+    public void writeCharacters(char[] text, int start, int len)
+            throws XMLStreamException {
+        closeStartElement();
+        writeCharactersInternal(text, start, len, false);
+    }
+
+    public String getPrefix(String uri) throws XMLStreamException {
+        return context.getPrefix(uri);
+    }
+
+    public void setPrefix(String prefix, String uri) throws XMLStreamException {
+        // needToWrite(uri);
+        context.bindNamespace(prefix, uri);
+    }
+
+    public void setDefaultNamespace(String uri) throws XMLStreamException {
+        needToWrite(uri);
+        context.bindDefaultNameSpace(uri);
+    }
+
+    public void setNamespaceContext(NamespaceContext context)
+            throws XMLStreamException {
+        if (context == null)
+            throw new NullPointerException("The namespace " + " context may"
+                    + " not be null.");
+        this.context = new NamespaceContextImpl(context);
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return context;
+    }
+
+    public Object getProperty(String name) throws IllegalArgumentException {
+        return config.getProperty(name);
+    }
+
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/XMLWriterBase.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/ElementTypeNames.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/ElementTypeNames.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/ElementTypeNames.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/ElementTypeNames.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax.util;
+
+import javax.xml.stream.XMLStreamConstants;
+
+public class ElementTypeNames {
+    public final static String getEventTypeString(int eventType) {
+        switch (eventType) {
+        case XMLStreamConstants.START_ELEMENT:
+            return "START_ELEMENT";
+        case XMLStreamConstants.END_ELEMENT:
+            return "END_ELEMENT";
+        case XMLStreamConstants.PROCESSING_INSTRUCTION:
+            return "PROCESSING_INSTRUCTION";
+        case XMLStreamConstants.CHARACTERS:
+            return "CHARACTERS";
+        case XMLStreamConstants.SPACE:
+            return "SPACE";
+        case XMLStreamConstants.COMMENT:
+            return "COMMENT";
+        case XMLStreamConstants.START_DOCUMENT:
+            return "START_DOCUMENT";
+        case XMLStreamConstants.END_DOCUMENT:
+            return "END_DOCUMENT";
+        case XMLStreamConstants.ENTITY_REFERENCE:
+            return "ENTITY_REFERENCE";
+        case XMLStreamConstants.ATTRIBUTE:
+            return "ATTRIBUTE";
+        case XMLStreamConstants.DTD:
+            return "DTD";
+        case XMLStreamConstants.CDATA:
+            return "CDATA";
+        case XMLStreamConstants.NAMESPACE:
+            return "NAMESPACE";
+        }
+        return "UNKNOWN_EVENT_TYPE";
+    }
+
+    public static int getEventType(String val) {
+        if (val.equals("START_ELEMENT"))
+            return XMLStreamConstants.START_ELEMENT;
+        if (val.equals("SPACE"))
+            return XMLStreamConstants.SPACE;
+        if (val.equals("END_ELEMENT"))
+            return XMLStreamConstants.END_ELEMENT;
+        if (val.equals("PROCESSING_INSTRUCTION"))
+            return XMLStreamConstants.PROCESSING_INSTRUCTION;
+        if (val.equals("CHARACTERS"))
+            return XMLStreamConstants.CHARACTERS;
+        if (val.equals("COMMENT"))
+            return XMLStreamConstants.COMMENT;
+        if (val.equals("START_DOCUMENT"))
+            return XMLStreamConstants.START_DOCUMENT;
+        if (val.equals("END_DOCUMENT"))
+            return XMLStreamConstants.END_DOCUMENT;
+        if (val.equals("ATTRIBUTE"))
+            return XMLStreamConstants.ATTRIBUTE;
+        if (val.equals("DTD"))
+            return XMLStreamConstants.DTD;
+        if (val.equals("CDATA"))
+            return XMLStreamConstants.CDATA;
+        if (val.equals("NAMESPACE"))
+            return XMLStreamConstants.NAMESPACE;
+        return -1;
+    }
+}

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/EmptyEnumeration.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/EmptyEnumeration.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/EmptyEnumeration.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/EmptyEnumeration.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax.util;
+
+public class EmptyEnumeration implements java.util.Enumeration {
+    public static final EmptyEnumeration emptyEnumeration = new EmptyEnumeration();
+
+    public boolean hasMoreElements() {
+        return false;
+    }
+
+    public Object nextElement() {
+        return null;
+    }
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/EmptyEnumeration.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/NamespaceContextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/NamespaceContextImpl.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/NamespaceContextImpl.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/NamespaceContextImpl.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax.util;
+
+import javax.xml.namespace.NamespaceContext;
+
+import org.apache.mirae.stax.util.SymbolTable;
+
+import java.util.Enumeration;
+
+public class NamespaceContextImpl implements NamespaceContext {
+    SymbolTable prefixTable = new SymbolTable();
+
+    SymbolTable uriTable = new SymbolTable();
+
+    NamespaceContext rootContext;
+
+    public NamespaceContextImpl() {
+        init();
+    }
+
+    public NamespaceContextImpl(NamespaceContext rootContext) {
+        this.rootContext = null;
+        init();
+    }
+
+    public void init() {
+        bindNamespace("xml", "http://www.w3.org/XML/1998/namespace");
+        bindNamespace("xmlns", "http://www.w3.org/XML/1998/namespace");
+    }
+
+    public void openScope() {
+        prefixTable.openScope();
+        uriTable.openScope();
+    }
+
+    public void closeScope() {
+        prefixTable.closeScope();
+        uriTable.closeScope();
+    }
+
+    public void bindNamespace(String prefix, String uri) {
+        prefixTable.put(prefix, uri);
+        uriTable.put(uri, prefix);
+    }
+
+    public int getDepth() {
+        return prefixTable.getDepth();
+    }
+
+    public String getNamespaceURI(String prefix) {
+        String value = prefixTable.get(prefix);
+        if (value == null && rootContext != null)
+            return rootContext.getNamespaceURI(prefix);
+        else
+            return value;
+    }
+
+    public String getPrefix(String uri) {
+        String value = uriTable.get(uri);
+        if (value == null && rootContext != null)
+            return rootContext.getPrefix(uri);
+        else
+            return value;
+    }
+
+    public void bindDefaultNameSpace(String uri) {
+        bindNamespace("", uri);
+    }
+
+    public void unbindDefaultNameSpace() {
+        bindNamespace("", null);
+    }
+
+    public void unbindNamespace(String prefix, String uri) {
+        prefixTable.put(prefix, null);
+        prefixTable.put(uri, null);
+    }
+
+    public String getDefaultNameSpace() {
+        return getNamespaceURI("");
+    }
+
+    public Enumeration getPrefixes(String uri) {
+        return (uriTable.getAll(uri)).elements();
+    }
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/NamespaceContextImpl.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/Symbol.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/Symbol.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/Symbol.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/Symbol.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax.util;
+
+class Symbol {
+    String name;
+
+    String value;
+
+    int depth;
+
+    Symbol(String name, String value, int depth) {
+        this.name = name;
+        this.value = value;
+        this.depth = depth;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public int getDepth() {
+        return depth;
+    }
+
+    public String toString() {
+        return ("[" + depth + "][" + name + "][" + value + "]");
+    }
+
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/Symbol.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/SymbolTable.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/SymbolTable.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/SymbolTable.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/SymbolTable.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mirae.stax.util;
+
+import java.util.Stack;
+import java.util.Vector;
+import java.util.Hashtable;
+import java.util.Enumeration;
+
+import org.apache.mirae.stax.util.Symbol;
+
+/**
+ * Maintains a table for namespace scope
+ * 
+ * 
+ * values = map from strings to stacks [a]->[value1,0],[value2,0]
+ * 
+ * table = a stack of bindings
+ */
+public class SymbolTable {
+    private int depth;
+
+    private Stack table;
+
+    private Hashtable values;
+
+    public SymbolTable() {
+        depth = 0;
+        table = new Stack();
+        values = new Hashtable();
+    }
+
+    public void clear() {
+        depth = 0;
+        table.removeAllElements();
+        values.clear();
+    }
+
+    //
+    // Gets the current depth
+    //
+    public int getDepth() {
+        return depth;
+    }
+
+    public boolean withinElement() {
+        return depth > 0;
+    }
+
+    //
+    // Adds a name/value pair
+    //
+    public void put(String name, String value) {
+        table.push(new Symbol(name, value, depth));
+        if (!values.containsKey(name)) {
+            Stack valueStack = new Stack();
+            valueStack.push(value);
+            values.put(name, valueStack);
+        } else {
+            Stack valueStack = (Stack) values.get(name);
+            valueStack.push(value);
+        }
+    }
+
+    //
+    // Gets the value for a variable
+    //
+    public String get(String name) {
+        Stack valueStack = (Stack) values.get(name);
+        if (valueStack == null || valueStack.isEmpty())
+            return null;
+        return (String) valueStack.peek();
+    }
+
+    public Vector getAll(String name) {
+        Vector result = new Vector();
+        Enumeration i = table.elements();
+        while (i.hasMoreElements()) {
+            Symbol s = (Symbol) i.nextElement();
+            if (name.equals(s.getName()))
+                result.addElement(s.getValue());
+        }
+        return result;
+    }
+
+    //
+    // add a new highest level scope to the table
+    // 
+    public void openScope() {
+        depth++;
+    }
+
+    //
+    // remove the highest level scope from the table
+    // 
+
+    public void closeScope() {
+        // Get the top binding
+        Symbol symbol = (Symbol) table.peek();
+        int symbolDepth = symbol.depth;
+
+        // check if it needs to be popped of the table
+        while (symbolDepth == depth && !table.isEmpty()) {
+            symbol = (Symbol) table.pop();
+
+            // pop its value as well
+            Stack valueStack = (Stack) values.get(symbol.name);
+            valueStack.pop();
+
+            // check the next binding
+            if (!table.isEmpty()) {
+                symbol = (Symbol) table.peek();
+                symbolDepth = symbol.depth;
+            } else
+                break;
+        }
+        depth--;
+    }
+
+    public String toString() {
+        Enumeration i = table.elements();
+        String retVal = "";
+        while (i.hasMoreElements()) {
+            Symbol symbol = (Symbol) i.nextElement();
+            retVal = retVal + symbol + "\n";
+        }
+        return retVal;
+    }
+
+}

Propchange: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/stax/util/SymbolTable.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/util/CharacterUtil.java
URL: http://svn.apache.org/viewcvs/webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/util/CharacterUtil.java?rev=225342&view=auto
==============================================================================
--- webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/util/CharacterUtil.java (added)
+++ webservices/mirae/trunk/src/mirae/stax/org/apache/mirae/util/CharacterUtil.java Tue Jul 26 09:22:02 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.mirae.util;
+
+public class CharacterUtil {
+    public static boolean isWhitespace(char ch) {
+        int c = (int) ch;
+        // SPACE_SEPARATOR
+        // Note that 202F, 00A0, 2007 are excluded because they are non-break
+        // ones.
+        if ((c == 0x0020) || (c == 0x1680) || (c == 0x180E)
+                || ((c >= 0x2000) && (c <= 0x2006))
+                || ((c >= 0x2008) && (c <= 0x200B)) || (c == 0x205F)
+                || (c == 0x3000)) {
+            return true;
+        }
+        // LINE_SEPARATOR
+        if (c == 0x2028) {
+            return true;
+        }
+        // PARAGRAPH_SEPARATOR
+        if (c == 0x2029) {
+            return true;
+        }
+        if (((c >= 0x0009) && (c <= 0x000D))
+                || ((c >= 0x001C) && (c <= 0x001F))) {
+            return true;
+        }
+        return false;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: mirae-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: mirae-dev-help@ws.apache.org