You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/10/11 23:04:44 UTC

svn commit: r583953 - in /incubator/tuscany/java/sca/modules/databinding/src: main/java/org/apache/tuscany/sca/databinding/xml/ test/java/org/apache/tuscany/sca/databinding/xml/

Author: rfeng
Date: Thu Oct 11 14:04:43 2007
New Revision: 583953

URL: http://svn.apache.org/viewvc?rev=583953&view=rev
Log:
Add a tree-iterator based XMLStreamReader base impl

Added:
    incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlAttribute.java   (with props)
    incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElement.java   (with props)
    incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElementIterator.java   (with props)
    incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java   (with props)
    incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java   (with props)

Added: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlAttribute.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlAttribute.java?rev=583953&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlAttribute.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlAttribute.java Thu Oct 11 14:04:43 2007
@@ -0,0 +1,30 @@
+/*
+ * 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.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface XmlAttribute {
+    QName getName();
+    String getValue();
+}

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlAttribute.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlAttribute.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElement.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElement.java?rev=583953&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElement.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElement.java Thu Oct 11 14:04:43 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.tuscany.sca.databinding.xml;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface XmlElement {
+    /**
+     * Returns the child <code>XmlTreeElement</code> at index 
+     * <code>childIndex</code>.
+     */
+    // XmlElement getChildAt(int childIndex);
+
+    /**
+     * Returns the number of children <code>XmlTreeElement</code>s the receiver
+     * contains.
+     */
+    // int getChildCount();
+
+    /**
+     * Returns the parent <code>XmlTreeElement</code> of the receiver.
+     */
+    // XmlElement getParent();
+
+    /**
+     * Returns the index of <code>node</code> in the receivers children.
+     * If the receiver does not contain <code>node</code>, -1 will be
+     * returned.
+     */
+    // int getIndex(XmlElement node);
+
+    /**
+     * Returns true if the receiver is a leaf.
+     */
+    boolean isLeaf();
+
+    /**
+     * Returns the children of the receiver as an <code>Iterator</code>.
+     */
+    Iterator<XmlElement> children();
+
+    /**
+     * Returns the attributes of the element as an <code>Iterator</code>
+     * @return
+     */
+    List<XmlAttribute> attributes();
+    
+    List<QName> namespaces();
+
+    /**
+     * Return the QName of the element
+     * @return
+     */
+    QName getName();
+
+    /**
+     * Return the text value of the leaf element
+     * @return
+     */
+    String getValue();
+}

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElement.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElementIterator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElementIterator.java?rev=583953&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElementIterator.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElementIterator.java Thu Oct 11 14:04:43 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tuscany.sca.databinding.xml.DelegatingNamespaceContext.FastStack;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XmlElementIterator implements Iterator<XmlElement> {
+    public final static int START = 0;
+    public final static int END = 1;
+
+    protected FastStack<ElementHolder> stack;
+    protected int state;
+
+    public XmlElementIterator(XmlElement rootNode) {
+        super();
+        List<XmlElement> v = new ArrayList<XmlElement>(1);
+        v.add(rootNode);
+        stack = new FastStack<ElementHolder>();
+        Iterator<XmlElement> i = v.iterator();
+        stack.push(new ElementHolder(null, i));
+        this.state = START;
+    }
+
+    public boolean hasNext() {
+        return !(stack.empty() || (state == END && stack.peek().parent == null));
+    }
+
+    public XmlElement next() {
+        this.state = START;
+        ElementHolder element = stack.peek();
+        Iterator<XmlElement> it = element.children;
+        if (it == null || (!it.hasNext())) {
+            // End of the children, return END event of parent
+            stack.pop();
+            this.state = END;
+            return element.parent;
+        }
+        XmlElement node = it.next();
+        stack.push(new ElementHolder(node, node.children()));
+        return node;
+    }
+
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+    public int getState() {
+        return state;
+    }
+
+    private static class ElementHolder {
+        private XmlElement parent;
+        private Iterator<XmlElement> children;
+
+        public ElementHolder(XmlElement parent, Iterator<XmlElement> children) {
+            this.parent = parent;
+            this.children = children;
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElementIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlElementIterator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java?rev=583953&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java Thu Oct 11 14:04:43 2007
@@ -0,0 +1,402 @@
+/*
+ * 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.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+
+/**
+ * 
+ * @version $Rev$ $Date$
+ */
+public class XmlTreeStreamReaderImpl implements XMLFragmentStreamReader {
+
+    // we always create a new namespace context
+    protected DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext();
+
+    protected int state;
+    protected XmlElementIterator iterator;
+    protected XmlElement current;
+
+    /*
+     * we need to pass in a namespace context since when delegated, we've no
+     * idea of the current namespace context. So it needs to be passed on here!
+     */
+    public XmlTreeStreamReaderImpl(XmlElement root) {
+        this.iterator = new XmlElementIterator(root);
+        this.current = null;
+        this.state = START_DOCUMENT;
+    }
+
+    public void close() throws XMLStreamException {
+        // do nothing here - we have no resources to free
+    }
+
+    private void checkElementState() {
+        if (current == null || current.getName() == null) {
+            throw new IllegalStateException();
+        }
+    }
+
+    public int getAttributeCount() {
+        checkElementState();
+        return current.attributes().size();
+    }
+
+    public String getAttributeLocalName(int i) {
+        checkElementState();
+        return current.attributes().get(i).getName().getLocalPart();
+    }
+
+    /**
+     * @param i
+     */
+    public QName getAttributeName(int i) {
+        checkElementState();
+        return current.attributes().get(i).getName();
+    }
+
+    public String getAttributeNamespace(int i) {
+        checkElementState();
+        return current.attributes().get(i).getName().getNamespaceURI();
+    }
+
+    public String getAttributePrefix(int i) {
+        checkElementState();
+        return current.attributes().get(i).getName().getPrefix();
+    }
+
+    public String getAttributeType(int i) {
+        return null; // not supported
+    }
+
+    public String getAttributeValue(int i) {
+        checkElementState();
+        return current.attributes().get(i).getValue();
+    }
+
+    public String getAttributeValue(String nsUri, String localName) {
+        int count = getAttributeCount();
+        String value = null;
+        QName attrQName;
+        for (int i = 0; i < count; i++) {
+            attrQName = getAttributeName(i);
+            if (nsUri == null) {
+                if (localName.equals(attrQName.getLocalPart())) {
+                    value = getAttributeValue(i);
+                    break;
+                }
+            } else {
+                if (localName.equals(attrQName.getLocalPart()) && nsUri.equals(attrQName.getNamespaceURI())) {
+                    value = getAttributeValue(i);
+                    break;
+                }
+            }
+
+        }
+
+        return value;
+    }
+
+    public String getCharacterEncodingScheme() {
+        return null; // todo - should we return something for this ?
+    }
+
+    public String getElementText() throws XMLStreamException {
+        checkElementState();
+        return current.getValue();
+    }
+
+    public String getEncoding() {
+        return "UTF-8";
+    }
+
+    public int getEventType() {
+        return state;
+    }
+
+    public String getLocalName() {
+        checkElementState();
+        return current.getName().getLocalPart();
+    }
+
+    /**
+     */
+    public Location getLocation() {
+        // return a default location
+        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 QName getName() {
+        checkElementState();
+        return current.getName();
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return namespaceContext;
+    }
+
+    public int getNamespaceCount() {
+        return current.namespaces().size();
+    }
+
+    /**
+     * @param i
+     */
+    public String getNamespacePrefix(int i) {
+        return current.namespaces().get(i).getPrefix();
+    }
+
+    public String getNamespaceURI() {
+        return current.getName().getNamespaceURI();
+    }
+
+    public String getNamespaceURI(int i) {
+        return current.namespaces().get(i).getNamespaceURI();
+    }
+
+    public String getNamespaceURI(String prefix) {
+        return namespaceContext.getNamespaceURI(prefix);
+    }
+
+    public String getPIData() {
+        throw new UnsupportedOperationException("Yet to be implemented !!");
+    }
+
+    public String getPITarget() {
+        throw new UnsupportedOperationException("Yet to be implemented !!");
+    }
+
+    public String getPrefix() {
+        if (state == START_ELEMENT || state == END_ELEMENT) {
+            String prefix = current.getName().getPrefix();
+            return "".equals(prefix) ? null : prefix;
+        } else if (state == START_DOCUMENT) {
+            return null;
+        } else {
+            throw new IllegalStateException("State==" + state);
+        }
+    }
+
+    /**
+     * @param key
+     * @throws IllegalArgumentException
+     */
+    public Object getProperty(String key) throws IllegalArgumentException {
+        return null;
+    }
+
+    public String getText() {
+        return current.getValue();
+    }
+
+    public char[] getTextCharacters() {
+        String value = current.getValue();
+        return value == null ? new char[0] : value.toCharArray();
+    }
+
+    private int copy(int sourceStart, char[] target, int targetStart, int length) {
+        char[] source = getTextCharacters();
+        if (sourceStart > source.length) {
+            throw new IndexOutOfBoundsException("source start > source length");
+        }
+        int sourceLen = source.length - sourceStart;
+        if (length > sourceLen) {
+            length = sourceLen;
+        }
+        System.arraycopy(source, sourceStart, target, targetStart, length);
+        return sourceLen;
+    }
+
+    public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+        return copy(i, chars, i1, i2);
+    }
+
+    public int getTextLength() {
+        return getTextCharacters().length;
+    }
+
+    public int getTextStart() {
+        return 0;
+    }
+
+    public String getVersion() {
+        return "1.0";
+    }
+
+    public boolean hasName() {
+        return current.getName() != null;
+    }
+
+    /**
+     * @throws XMLStreamException
+     */
+    public boolean hasNext() throws XMLStreamException {
+        return iterator.hasNext() || state != END_DOCUMENT;
+    }
+
+    public boolean hasText() {
+        return current.getName() == null;
+    }
+
+    /**
+     * we need to split out the calling to the populate namespaces seperately
+     * since this needs to be done *after* setting the parent namespace context.
+     * We cannot assume it will happen at construction!
+     */
+    public void init() {
+        // here we have an extra issue to attend to. we need to look at the
+        // prefixes and uris (the combination) and populate a hashmap of
+        // namespaces. The hashmap of namespaces will be used to serve the
+        // namespace context
+
+        // populateNamespaceContext();
+    }
+
+    public boolean isAttributeSpecified(int i) {
+        return false; // not supported
+    }
+
+    public boolean isCharacters() {
+        return current.getName() == null;
+    }
+
+    /**
+     * are we done ?
+     */
+    public boolean isDone() {
+        return !iterator.hasNext();
+    }
+
+    public boolean isEndElement() {
+        return getEventType() == END_ELEMENT;
+    }
+
+    public boolean isStandalone() {
+        return true;
+    }
+
+    public boolean isStartElement() {
+        return getEventType() == START_ELEMENT;
+    }
+
+    public boolean isWhiteSpace() {
+        return false;
+    }
+
+    /**
+     * By far this should be the most important method in this class this method
+     * changes the state of the parser
+     */
+    public int next() throws XMLStreamException {
+        if (!hasNext()) {
+            throw new IllegalStateException("No more events");
+        }
+        if (!iterator.hasNext()) {
+            state = END_DOCUMENT;
+            current = null;
+            return state;
+        }
+        current = iterator.next();
+        int itState = iterator.getState();
+        if (itState == XmlElementIterator.END) {
+            if (current.getName() != null) {
+                state = END_ELEMENT;
+            } else {
+                state = next();
+            }
+        }
+        if (itState == XmlElementIterator.START) {
+            if (current.getName() != null) {
+                state = START_ELEMENT;
+            } else {
+                state = CHARACTERS;
+            }
+        }
+        return state;
+    }
+
+    /**
+     * todo implement this
+     * 
+     * @throws XMLStreamException
+     */
+    public int nextTag() throws XMLStreamException {
+        while (true) {
+            int event = next();
+            if (event == START_ELEMENT || event == END_ELEMENT) {
+                return event;
+            }
+        }
+    }
+
+    public void require(int i, String ns, String localPart) throws XMLStreamException {
+        int event = getEventType();
+        if (event != i) {
+            throw new IllegalStateException("Event type is " + event + " (!=" + i + ")");
+        }
+        QName name = getName();
+        String ns1 = name.getNamespaceURI();
+        String localName1 = name.getLocalPart();
+
+        if (ns != null && !ns.equals(ns1)) {
+            throw new IllegalStateException("Namespace URI is " + ns1 + " (!=" + ns + ")");
+        }
+
+        if (localPart != null && !localPart.equals(localName1)) {
+            throw new IllegalStateException("Local name is " + localName1 + " (!=" + localPart + ")");
+        }
+
+    }
+
+    public boolean standaloneSet() {
+        return true;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.databinding.xml.XMLFragmentStreamReader#setParentNamespaceContext(javax.xml.namespace.NamespaceContext)
+     */
+    public void setParentNamespaceContext(NamespaceContext nsContext) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java?rev=583953&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java Thu Oct 11 14:04:43 2007
@@ -0,0 +1,168 @@
+/*
+ * 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.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XmlTreeStreamReaderTestCase {
+    private XmlElementImpl root;
+
+    @Before
+    public void setUp() {
+        root = new XmlElementImpl();
+        root.name = new QName("http://ns", "e1");
+
+        XmlElementImpl e11 = new XmlElementImpl();
+        e11.name = new QName("http://ns", "e11");
+
+        XmlElementImpl e12 = new XmlElementImpl();
+        e12.name = new QName("http://ns", "e12");
+
+        root.children.add(e11);
+        root.children.add(e12);
+
+        XmlElementImpl e121 = new XmlElementImpl();
+        e121.name = new QName("http://ns", "e121");
+        e12.children.add(e121);
+
+        XmlElementImpl e111 = new XmlElementImpl();
+        e111.value = "MyText";
+        e11.children.add(e111);
+
+    }
+
+    @Test
+    public void testIterator() {
+        List<QName> elements = new ArrayList<QName>();
+        XmlElementIterator i = new XmlElementIterator(root);
+        for (; i.hasNext();) {
+            XmlElement e = i.next();
+            elements.add(e.getName());
+            // System.out.println(e + " " + i.getState());
+        }
+        QName[] names =
+            {new QName("http://ns", "e1"), new QName("http://ns", "e11"), null, null, new QName("http://ns", "e11"),
+             new QName("http://ns", "e12"), new QName("http://ns", "e121"), new QName("http://ns", "e121"),
+             new QName("http://ns", "e12"), new QName("http://ns", "e1")};
+        Assert.assertEquals(Arrays.asList(names), elements);
+    }
+
+    @Test
+    public void testReader() throws XMLStreamException {
+        XmlTreeStreamReaderImpl reader = new XmlTreeStreamReaderImpl(root);
+        List<String> seq = new ArrayList<String>();
+        while (true) {
+            int e = reader.getEventType();
+            if (e == XMLStreamConstants.START_DOCUMENT) {
+                seq.add("START_DOCUMENT");
+            } else if (e == XMLStreamConstants.END_DOCUMENT) {
+                seq.add("END_DOCUMENT");
+            } else if (e == XMLStreamConstants.CHARACTERS) {
+                seq.add(reader.getText());
+            } else {
+                seq.add(e + ": " + reader.getName());
+            }
+            if (!reader.hasNext()) {
+                break;
+            } else {
+                reader.next();
+            }
+        }
+
+        String[] events =
+            {"START_DOCUMENT", "1: {http://ns}e1", "1: {http://ns}e11", "MyText", "2: {http://ns}e11",
+             "1: {http://ns}e12", "1: {http://ns}e121", "2: {http://ns}e121", "2: {http://ns}e12", "2: {http://ns}e1",
+             "END_DOCUMENT"
+            };
+        
+        Assert.assertEquals(Arrays.asList(events), seq);
+    }
+
+    private static class XmlElementImpl implements XmlElement {
+        private List<XmlElement> children = new ArrayList<XmlElement>();
+        private List<XmlAttribute> attrs = new ArrayList<XmlAttribute>();
+        private List<QName> namespaces = new ArrayList<QName>();
+        private QName name;
+        private boolean isLeaf;
+        private String value = "123";
+
+        /**
+         * @see org.apache.tuscany.sca.databinding.xml.XmlElement#attributes()
+         */
+        public List<XmlAttribute> attributes() {
+            return attrs;
+        }
+
+        /**
+         * @see org.apache.tuscany.sca.databinding.xml.XmlElement#children()
+         */
+        public Iterator<XmlElement> children() {
+            return children.iterator();
+        }
+
+        /**
+         * @see org.apache.tuscany.sca.databinding.xml.XmlElement#getName()
+         */
+        public QName getName() {
+            return name;
+        }
+
+        /**
+         * @see org.apache.tuscany.sca.databinding.xml.XmlElement#getValue()
+         */
+        public String getValue() {
+            return value;
+        }
+
+        /**
+         * @see org.apache.tuscany.sca.databinding.xml.XmlElement#isLeaf()
+         */
+        public boolean isLeaf() {
+            return isLeaf;
+        }
+
+        /**
+         * @see org.apache.tuscany.sca.databinding.xml.XmlElement#namespaces()
+         */
+        public List<QName> namespaces() {
+            return namespaces;
+        }
+
+        public String toString() {
+            return String.valueOf(name);
+        }
+
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



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