xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases MarshalTests.java
Date Fri, 31 Oct 2003 22:23:26 GMT
zieg        2003/10/31 14:23:26

  Modified:    v2       build.xml
               v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        AtomicSimpleTypeConverter.java BindingContext.java
                        ByNameRuntimeBindingType.java Marshaller.java
                        RuntimeBindingProperty.java RuntimeBindingType.java
                        TypeMarshaller.java UnmarshalContext.java
                        Unmarshaller.java UnmarshallerImpl.java
               v2/test/cases/marshal doc.xml example_config.xml
               v2/test/src/drt/drtcases MarshalTests.java
  Added:       v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        ByNameTypeVisitor.java CharacterVisitor.java
                        EmptyLocation.java MarshalContext.java
                        MarshalResult.java MarshallerImpl.java
                        NamespaceTests.java RuntimeGlobalProperty.java
                        RuntimeTypeFactory.java ScopedNamespaceContext.java
                        SimpleTypeVisitor.java XmlTypeVisitor.java
  Log:
  Preliminary marsalling via an implementation of XMLStreamReader.
  Not much actually works yet except builtin types.
  
  CR: pending
  
  Revision  Changes    Path
  1.12      +28 -1     xml-xmlbeans/v2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/build.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.xml	27 Oct 2003 19:17:21 -0000	1.11
  +++ build.xml	31 Oct 2003 22:23:25 -0000	1.12
  @@ -1028,5 +1028,32 @@
           </javac>
       </target>
   
  +    <!-- temporary build utils ... zieg =============
  +    <target name='binding-test' depends='declare-tasks, jam.classes'>
  +        <mkdir dir='build/private/classes/marshal'/>
  +        <java2schema
  +            srcdir='test/cases/marshal'
  +            includes='test/cases/marshal/com/mytest/*.java'
  +            destdir='build/private/classes/marshal'>
  +        </java2schema>
  +    </target>
  +    <target name='declare-tasks'>
  +        <taskdef name='java2schema'
  +            classname='org.apache.xmlbeans.impl.binding.compile.Java2SchemaTask'>
  +            <classpath>
  +                <pathelement location="build/classes/binding"/>
  +                <pathelement location="build/classes/compile"/>
  +                <pathelement location="build/classes/jam"/>
  +                <pathelement location="build/classes/common"/>
  +                <pathelement location="build/classes/configschema"/>
  +                <pathelement location="build/classes/typeimpl"/>
  +                <pathelement location="build/classes/xmlinputstream"/>
  +                <pathelement location="build/classes/xmlpublic"/>
  +                <pathelement location="build/lib/jsr173_07_api.jar"/>
  +                <pathelement location="build/lib/xmlpublic.jar"/>
  +            </classpath>
  +        </taskdef>
  +    </target>
  +   -->
   
  -</project>
  \ No newline at end of file
  +</project>
  
  
  
  1.3       +6 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/AtomicSimpleTypeConverter.java
  
  Index: AtomicSimpleTypeConverter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/AtomicSimpleTypeConverter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AtomicSimpleTypeConverter.java	23 Oct 2003 23:49:03 -0000	1.2
  +++ AtomicSimpleTypeConverter.java	31 Oct 2003 22:23:25 -0000	1.3
  @@ -92,5 +92,11 @@
       {
       }
   
  +    //non simple types can throw a runtime exception
  +    public CharSequence print(Object value, MarshalContext context)
  +    {
  +        return lexerPrinter.print(value, context.getErrorCollection());
  +    }
  +
   
   }
  
  
  
  1.3       +26 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContext.java
  
  Index: BindingContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BindingContext.java	23 Oct 2003 23:49:03 -0000	1.2
  +++ BindingContext.java	31 Oct 2003 22:23:25 -0000	1.3
  @@ -58,6 +58,10 @@
   
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
   
  +import javax.xml.stream.XMLStreamReader;
  +import javax.xml.namespace.NamespaceContext;
  +import java.util.Collection;
  +
   /**
    * Main entry point into marshalling framework.
    * Use the BindingContextFactory to create one
  @@ -81,4 +85,26 @@
       {
           return new UnmarshallerImpl(bindingLoader, typeTable);
       }
  +
  +    //TODO: REVIEW: should error collection concept be exposed here?
  +    public UnmarshalContext createUnmarshallContext(XMLStreamReader reader,
  +                                                    Collection errors)
  +    {
  +        return new UnmarshalContext(reader, bindingLoader, typeTable, errors);
  +    }
  +
  +
  +    public Marshaller createMarshaller()
  +    {
  +        return new MarshallerImpl(bindingLoader, typeTable);
  +    }
  +
  +    //TODO: REVIEW: should error collection concept be exposed here?
  +    public MarshalContext createMarshallContext(NamespaceContext namespaceContext,
  +                                                Collection errors)
  +    {
  +        return new MarshalContext(namespaceContext, bindingLoader, typeTable, errors);
  +    }
  +
  +
   }
  
  
  
  1.3       +23 -1     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java
  
  Index: ByNameRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ByNameRuntimeBindingType.java	28 Oct 2003 17:51:27 -0000	1.2
  +++ ByNameRuntimeBindingType.java	31 Oct 2003 22:23:25 -0000	1.3
  @@ -122,6 +122,11 @@
           return retval;
       }
   
  +    public BindingType getType()
  +    {
  +        return byNameBean;
  +    }
  +
       //TODO: optimize this linear scan
       RuntimeBindingProperty getMatchingElementProperty(String uri,
                                                         String localname)
  @@ -160,6 +165,7 @@
       private static final class Property implements RuntimeBindingProperty
       {
           private final QNameProperty bindingProperty;
  +        private final BindingType bindingType;
           private final TypeUnmarshaller unmarshaller;
           private final Class propertyClass;
           private final Method setMethod;
  @@ -172,7 +178,7 @@
           {
               this.bindingProperty = prop;
               this.unmarshaller = lookupUnmarshaller(prop, typeTable, loader);
  -            final BindingType bindingType = loader.getBindingType(prop.getTypeName());
  +            this.bindingType = loader.getBindingType(prop.getTypeName());
               try {
                   this.propertyClass = getJavaClass(bindingType, getClass().getClassLoader());
               }
  @@ -186,6 +192,16 @@
           }
   
   
  +        public BindingType getType()
  +        {
  +            return bindingType;
  +        }
  +
  +        public QName getName()
  +        {
  +            return bindingProperty.getQName();
  +        }
  +
           private TypeUnmarshaller lookupUnmarshaller(BindingProperty prop,
                                                       RuntimeBindingTypeTable typeTable,
                                                       BindingLoader bindingLoader)
  @@ -233,6 +249,12 @@
               catch (InvocationTargetException e) {
                   throw new XmlRuntimeException(e);
               }
  +        }
  +
  +        //non simple type props can throw some runtime exception.
  +        public CharSequence getLexical(Object parent, MarshalContext context)
  +        {
  +            return "FIXME this="+this;
           }
   
           private static Method getSetterMethod(QNameProperty bindingProperty1,
  
  
  
  1.2       +11 -16    xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Marshaller.java
  
  Index: Marshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Marshaller.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Marshaller.java	16 Oct 2003 00:02:49 -0000	1.1
  +++ Marshaller.java	31 Oct 2003 22:23:25 -0000	1.2
  @@ -56,30 +56,25 @@
   
   package org.apache.xmlbeans.impl.marshal;
   
  -import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  +import org.apache.xmlbeans.XmlException;
   
   import javax.xml.namespace.NamespaceContext;
  +import javax.xml.namespace.QName;
   import javax.xml.stream.XMLStreamReader;
   
   /**
    * Entry point for marshalling java objects to xml.
    */
  -public class Marshaller
  +public interface Marshaller
   {
  -    private final BindingLoader bindingLoader;
  -    private final RuntimeBindingTypeTable typeTable;
  +    //TODO: REVIEW: throws?  errors?
  +    XMLStreamReader marshall(Object obj, NamespaceContext nscontext);
   
   
  -    /*package*/
  -    Marshaller(BindingLoader bindingLoader,
  -               RuntimeBindingTypeTable typeTable)
  -    {
  -        this.bindingLoader = bindingLoader;
  -        this.typeTable = typeTable;
  -    }
  -
  -    public XMLStreamReader marshall(NamespaceContext nscontext)
  -    {
  -        throw new AssertionError("UNIMPLEMENTED");
  -    }
  +    XMLStreamReader marshallType(Object obj,
  +                                 QName elementName,
  +                                 QName schemaType,
  +                                 String javaType,
  +                                 MarshalContext context)
  +        throws XmlException;
   }
  
  
  
  1.3       +12 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingProperty.java
  
  Index: RuntimeBindingProperty.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingProperty.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RuntimeBindingProperty.java	23 Oct 2003 23:49:03 -0000	1.2
  +++ RuntimeBindingProperty.java	31 Oct 2003 22:23:26 -0000	1.3
  @@ -56,10 +56,22 @@
   
   package org.apache.xmlbeans.impl.marshal;
   
  +import org.apache.xmlbeans.impl.binding.bts.BindingType;
  +
  +import javax.xml.namespace.QName;
  +
   
   interface RuntimeBindingProperty
   {
  +    BindingType getType();
  +    
  +    QName getName();
  +
       TypeUnmarshaller getTypeUnmarshaller(UnmarshalContext context);
   
       void fill(Object inter, Object prop_obj);
  +
  +    //non simple type props can throw some runtime exception.
  +    CharSequence getLexical(Object parent, MarshalContext context);
  +
   }
  
  
  
  1.3       +3 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingType.java
  
  Index: RuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingType.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RuntimeBindingType.java	23 Oct 2003 23:49:03 -0000	1.2
  +++ RuntimeBindingType.java	31 Oct 2003 22:23:26 -0000	1.3
  @@ -57,6 +57,7 @@
   package org.apache.xmlbeans.impl.marshal;
   
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  +import org.apache.xmlbeans.impl.binding.bts.BindingType;
   
   /**
    * what we need to know about a binding type at runtime.
  @@ -78,5 +79,7 @@
   
       Object getFinalObjectFromIntermediary(Object retval,
                                             UnmarshalContext context);
  +
  +    BindingType getType();
   
   }
  
  
  
  1.2       +4 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/TypeMarshaller.java
  
  Index: TypeMarshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/TypeMarshaller.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeMarshaller.java	16 Oct 2003 00:02:49 -0000	1.1
  +++ TypeMarshaller.java	31 Oct 2003 22:23:26 -0000	1.2
  @@ -56,9 +56,13 @@
   
   package org.apache.xmlbeans.impl.marshal;
   
  +
  +
   /**
    * A TypeMarshaller knows how to marshall a java object into xml.
    */
   interface TypeMarshaller
   {
  +    //non simple types can throw a runtime exception
  +    CharSequence print(Object value, MarshalContext context);
   }
  
  
  
  1.3       +14 -20    xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalContext.java
  
  Index: UnmarshalContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnmarshalContext.java	28 Oct 2003 17:51:27 -0000	1.2
  +++ UnmarshalContext.java	31 Oct 2003 22:23:26 -0000	1.3
  @@ -76,17 +76,17 @@
    * Only one thread should ever be accessing this object, and a new one will be
    * required for each unmarshalling pass.
    */
  -final class UnmarshalContext
  +public final class UnmarshalContext
   {
       private final XMLStreamReader baseReader;
       private final BindingLoader bindingLoader;
       private final RuntimeBindingTypeTable typeTable;
       private final Collection errors;
   
  -    public UnmarshalContext(XMLStreamReader baseReader,
  -                             BindingLoader bindingLoader,
  -                             RuntimeBindingTypeTable typeTable,
  -                             Collection errors)
  +    UnmarshalContext(XMLStreamReader baseReader,
  +                     BindingLoader bindingLoader,
  +                     RuntimeBindingTypeTable typeTable,
  +                     Collection errors)
       {
           this.baseReader = baseReader;
           this.bindingLoader = bindingLoader;
  @@ -124,12 +124,6 @@
           return um;
       }
   
  -
  -    public BindingLoader getBindingLoader()
  -    {
  -        return bindingLoader;
  -    }
  -
       //package only -- get read/write version of error collection
   
       /**
  @@ -180,7 +174,7 @@
        *
        * @return  false if we hit an end element (any end element at all)
        */
  -    public boolean advanceToNextStartElement()
  +    boolean advanceToNextStartElement()
       {
           try {
               //move past our current start element
  @@ -192,44 +186,44 @@
           return MarshalStreamUtils.advanceToNextStartElement(baseReader);
       }
   
  -    public int getAttributeCount()
  +    int getAttributeCount()
       {
           assert baseReader.isStartElement();
   
           return baseReader.getAttributeCount();
       }
   
  -    public String getLocalName()
  +    String getLocalName()
       {
           return baseReader.getLocalName();
       }
   
  -    public String getNamespaceURI()
  +    String getNamespaceURI()
       {
           return baseReader.getNamespaceURI();
       }
   
  -    public String getAttributeNamespaceURI(int att_idx)
  +    String getAttributeNamespaceURI(int att_idx)
       {
           return baseReader.getAttributeNamespace(att_idx);
       }
   
  -    public String getAttributeLocalName(int att_idx)
  +    String getAttributeLocalName(int att_idx)
       {
           return baseReader.getAttributeLocalName(att_idx);
       }
   
  -    public String getAttributeValue(int att_idx)
  +    String getAttributeValue(int att_idx)
       {
           return baseReader.getAttributeValue(att_idx);
       }
   
  -    public boolean isXsiNilTrue(int att_idx)
  +    boolean isXsiNilTrue(int att_idx)
       {
           return MarshalStreamUtils.isXsiNilTrue(baseReader, att_idx, errors);
       }
   
  -    public void skipElement()
  +    void skipElement()
       {
           MarshalStreamUtils.skipElement(baseReader);
       }
  
  
  
  1.3       +43 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Unmarshaller.java
  
  Index: Unmarshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Unmarshaller.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Unmarshaller.java	23 Oct 2003 23:49:03 -0000	1.2
  +++ Unmarshaller.java	31 Oct 2003 22:23:26 -0000	1.3
  @@ -58,10 +58,53 @@
   
   import org.apache.xmlbeans.XmlException;
   
  +import javax.xml.namespace.QName;
   import javax.xml.stream.XMLStreamReader;
   
   public interface Unmarshaller
   {
  +    /**
  +     * unmarshall an entire xml document.
  +     *
  +     * PRECONDITIONS:
  +     * reader must be positioned at or before the root
  +     * start element of the document.
  +     *
  +     * POSTCONDITIONS:
  +     * reader will be positioned immediately after the end element
  +     * corresponding to the start element from the precondition
  +     *
  +     *
  +     * @param reader
  +     * @return
  +     * @throws XmlException
  +     */
       Object unmarshal(XMLStreamReader reader)
  +        throws XmlException;
  +
  +    /**
  +     * unmarshal an xml instance of a given schema type
  +     *
  +     * No attention is paid to the actual tag on which the reader is positioned.
  +     * It is only the contents that matter
  +     * (including attributes on that start tag).
  +     *
  +     *
  +     * PRECONDITIONS:
  +     * reader.isStartElement() must return true
  +     *
  +     * POSTCONDITIONS:
  +     * reader will be positioned immediately after the end element
  +     * corresponding to the start element from the precondition
  +     *
  +     * @param schemaType
  +     * @param javaType
  +     * @param context
  +     * @return
  +     * @throws XmlException
  +     */
  +    Object unmarshallType(QName schemaType,
  +                          String javaType,
  +                          UnmarshalContext context)
           throws XmlException;
   }
  
  
  
  1.3       +37 -3     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshallerImpl.java
  
  Index: UnmarshallerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshallerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnmarshallerImpl.java	28 Oct 2003 17:51:27 -0000	1.2
  +++ UnmarshallerImpl.java	31 Oct 2003 22:23:26 -0000	1.3
  @@ -60,6 +60,8 @@
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.BindingType;
   import org.apache.xmlbeans.impl.binding.bts.XmlName;
  +import org.apache.xmlbeans.impl.binding.bts.JavaName;
  +import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
   
   import javax.xml.namespace.QName;
   import javax.xml.stream.XMLStreamException;
  @@ -80,7 +82,7 @@
   
       /*package*/
       UnmarshallerImpl(BindingLoader bindingLoader,
  -                 RuntimeBindingTypeTable typeTable)
  +                     RuntimeBindingTypeTable typeTable)
       {
           this.bindingLoader = bindingLoader;
           this.typeTable = typeTable;
  @@ -90,12 +92,20 @@
           throws XmlException
       {
           UnmarshalContext context = createUnmarshallContext(reader,
  -                                                            new ArrayList());
  +                                                           new ArrayList());
   
           advanceToFirstItemOfInterest(reader);
   
           final BindingType bindingType = determineRootType(context);
   
  +        return unmarshalBindingType(bindingType, context);
  +
  +    }
  +
  +    private Object unmarshalBindingType(final BindingType bindingType,
  +                                        UnmarshalContext context)
  +        throws XmlException
  +    {
           TypeUnmarshaller um =
               typeTable.getTypeUnmarshaller(bindingType);
   
  @@ -117,6 +127,30 @@
           return type_instance;
       }
   
  +    public Object unmarshallType(QName schemaType,
  +                                 String javaType,
  +                                 UnmarshalContext context)
  +        throws XmlException
  +    {
  +        assert context.getXmlStream().isStartElement();
  +
  +        BindingType btype = determineBindingType(schemaType, javaType);
  +        if (btype == null) {
  +            final String msg = "unable to find binding type for " +
  +                schemaType + " : " + javaType;
  +            throw new XmlException(msg);
  +        }
  +        return unmarshalBindingType(btype, context);
  +    }
  +
  +    private BindingType determineBindingType(QName schemaType, String javaType)
  +    {
  +        XmlName xname = XmlName.forTypeNamed(schemaType);
  +        JavaName jname = JavaName.forString(javaType);
  +        BindingTypeName btname = BindingTypeName.forPair(jname, xname);
  +        return bindingLoader.getBindingType(btname);
  +    }
  +
       private static String errorsToMsg(final Collection errors)
       {
           final int sz = errors.size();
  @@ -201,7 +235,7 @@
       }
   
       private UnmarshalContext createUnmarshallContext(XMLStreamReader reader,
  -                                                      Collection errors)
  +                                                     Collection errors)
       {
           return new UnmarshalContext(reader, bindingLoader, typeTable, errors);
       }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java
  
  Index: ByNameTypeVisitor.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import javax.xml.namespace.QName;
  
  class ByNameTypeVisitor extends XmlTypeVisitor
  {
  
      public ByNameTypeVisitor(RuntimeBindingProperty property, Object obj)
      {
          super(obj);
      }
  
      // needs to update _currProp AND _currPropObj
      protected void advance()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected boolean hasMoreChildren()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      //return XmlTypeVisitorFactory.createXmlTypeVisitor(_currProp.get, _currPropObj);
      protected XmlTypeVisitor getCurrChild()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected QName getName()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected boolean isCharacters()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected int getAttributeCount()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected String getAttributeValue(int idx)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected QName getAttributeName(int idx)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected CharSequence getCharData()
      {
          throw new IllegalStateException("not text");
      }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/CharacterVisitor.java
  
  Index: CharacterVisitor.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import javax.xml.namespace.QName;
  import java.util.NoSuchElementException;
  
  final class CharacterVisitor
      extends XmlTypeVisitor
  {
      private final RuntimeBindingProperty property;
      private final MarshalContext context;
  
      public CharacterVisitor(RuntimeBindingProperty property,
                              Object parentObject,
                              MarshalContext context)
      {
          super(parentObject);
          assert property != null;
          this.property = property;
          this.context = context;
      }
  
      private static CharSequence getCharData(RuntimeBindingProperty property,
                                              Object parentObject,
                                              MarshalContext context)
      {
          return property.getLexical(parentObject, context);
      }
  
      protected void advance()
      {
      }
  
      protected boolean hasMoreChildren()
      {
          return false;
      }
  
      protected XmlTypeVisitor getCurrChild()
      {
          throw new NoSuchElementException("no children");
      }
  
      protected QName getName()
      {
          throw new IllegalStateException();
      }
  
      protected boolean isCharacters()
      {
          return true;
      }
  
      protected int getAttributeCount()
      {
          return 0;
      }
  
      protected String getAttributeValue(int idx)
      {
          throw new IllegalStateException();
      }
  
      protected QName getAttributeName(int idx)
      {
          throw new IllegalStateException();
      }
  
      protected CharSequence getCharData()
      {
          return getCharData(property, parentObject, context);
      }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/EmptyLocation.java
  
  Index: EmptyLocation.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import javax.xml.stream.Location;
  
  final class EmptyLocation
      implements Location
  {
      private static final Location INSTANCE = new EmptyLocation();
  
      private EmptyLocation() {}
  
      public static Location getInstance()
      {
          return INSTANCE;
      }
  
      public int getLineNumber()
      {
          return -1;
      }
  
      public int getColumnNumber()
      {
          return -1;
      }
  
      public int getCharacterOffset()
      {
          return -1;
      }
  
      public String getLocationURI()
      {
          return null;
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalContext.java
  
  Index: MarshalContext.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  
  import javax.xml.namespace.NamespaceContext;
  import java.util.Collection;
  
  public final class MarshalContext
  {
      private final Collection errors;
      private final BindingLoader loader;
      private final RuntimeBindingTypeTable typeTable;
      private final ScopedNamespaceContext namespaceContext;
      private int prefixCnt = 0;
  
      private static final String NSPREFIX = "n";
  
      MarshalContext(NamespaceContext root_nsctx,
                     BindingLoader loader,
                     RuntimeBindingTypeTable typeTable,
                     Collection errors)
      {
          this.namespaceContext = new ScopedNamespaceContext(root_nsctx);
          this.loader = loader;
          this.typeTable = typeTable;
          this.errors = errors;
      }
  
      Collection getErrorCollection()
      {
          return errors;
      }
  
      BindingLoader getLoader()
      {
          return loader;
      }
  
      RuntimeBindingTypeTable getTypeTable()
      {
          return typeTable;
      }
  
      ScopedNamespaceContext getNamespaceContext()
      {
          return namespaceContext;
      }
  
      String ensurePrefix(String uri)
      {
          String prefix = namespaceContext.getPrefix(uri);
          if (prefix == null) {
              prefix = bindNextPrefix(uri);
          }
          assert prefix != null;
          return prefix;
      }
  
      private String bindNextPrefix(final String uri)
      {
          assert uri != null;
          String testuri;
          String prefix;
          do {
              prefix = NSPREFIX + (++prefixCnt);
              testuri = namespaceContext.getNamespaceURI(prefix);
          } while(testuri != null);
          assert prefix != null;
          namespaceContext.bindNamespace(prefix,  uri);
          return prefix;
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java
  
  Index: MarshalResult.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingType;
  import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
  import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
  import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
  
  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;
  import java.util.Stack;
  
  final class MarshalResult implements XMLStreamReader
  {
      private XmlTypeVisitor currVisitor;
      private final Stack visitorStack = new Stack();
      private final QName topElement;
      private final MarshalContext context;
      private int currentEventType = XMLStreamReader.START_ELEMENT;
  
      MarshalResult(RuntimeBindingProperty property, Object obj,
                    QName elementName, MarshalContext context)
      {
          currVisitor = createVisitor(property, obj, context);
          topElement = elementName;
          this.context = context;
          pushVisitor(currVisitor);
      }
  
      protected static XmlTypeVisitor createVisitor(RuntimeBindingProperty property,
                                                    Object obj,
                                                    MarshalContext context)
      {
          BindingType btype = property.getType();
  
          //TODO: cleanup instanceof
          if (btype instanceof ByNameBean) {
              return new ByNameTypeVisitor(property, obj);
          } else if (btype instanceof SimpleBindingType) {
              return new SimpleTypeVisitor(property, obj, context);
          } else if (btype instanceof BuiltinBindingType) {
              return new SimpleTypeVisitor(property, obj, context);
          }
  
          throw new AssertionError("UNIMP TYPE: " + btype);
      }
  
      public Object getProperty(String s)
          throws IllegalArgumentException
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public int next() throws XMLStreamException
      {
          final int retval;
  
  
          if (currVisitor.hasMoreChildren()) {
              XmlTypeVisitor nextVisitor = currVisitor.getCurrChild();
              currVisitor.advance();
              pushVisitor(currVisitor);
              currVisitor = nextVisitor;
              if (nextVisitor.isCharacters()) {
                  retval = XMLStreamReader.CHARACTERS;
              } else {
                  retval = XMLStreamReader.START_ELEMENT;
              }
          } else {
              currVisitor = popVisitor();
              if (currVisitor.isCharacters())
                  return next(); //chars have no matching end tags
              retval = XMLStreamReader.END_ELEMENT;
          }
  
          currentEventType = retval;
          return retval;
      }
  
      private void pushVisitor(XmlTypeVisitor v)
      {
          visitorStack.push(v);
          context.getNamespaceContext().openScope();
      }
  
      private XmlTypeVisitor popVisitor()
      {
          context.getNamespaceContext().closeScope();
          return (XmlTypeVisitor)visitorStack.pop();
      }
  
      public void require(int i, String s, String s1)
          throws XMLStreamException
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getElementText() throws XMLStreamException
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public int nextTag() throws XMLStreamException
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean hasNext() throws XMLStreamException
      {
          return !visitorStack.isEmpty();
      }
  
      public void close() throws XMLStreamException
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getNamespaceURI(String s)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean isStartElement()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean isEndElement()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean isCharacters()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean isWhiteSpace()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getAttributeValue(String s, String s1)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public int getAttributeCount()
      {
          return currVisitor.getAttributeCount();
      }
  
      public QName getAttributeName(int i)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getAttributeNamespace(int i)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getAttributeLocalName(int i)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getAttributePrefix(int i)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getAttributeType(int i)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getAttributeValue(int i)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean isAttributeSpecified(int i)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public int getNamespaceCount()
      {
          return context.getNamespaceContext().getCurrentScopeNamespaceCount();
      }
  
  
      public String getNamespacePrefix(int i)
      {
          return context.getNamespaceContext().getCurrentScopeNamespacePrefix(i);
      }
  
      public String getNamespaceURI(int i)
      {
          return context.getNamespaceContext().getCurrentScopeNamespaceURI(i);
      }
  
      public NamespaceContext getNamespaceContext()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public int getEventType()
      {
          return currentEventType;
      }
  
      public String getText()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
  
      }
  
      public char[] getTextCharacters()
      {
          CharSequence seq = currVisitor.getCharData();
          return seq.toString().toCharArray();
      }
  
      public int getTextCharacters(int i, char[] chars, int i1, int i2)
          throws XMLStreamException
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public int getTextStart()
      {
          return 0;
      }
  
      public int getTextLength()
      {
          return currVisitor.getCharData().length();
      }
  
      public String getEncoding()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean hasText()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public Location getLocation()
      {
          return EmptyLocation.getInstance();
      }
  
      public QName getName()
      {
          return currVisitor.getName();
      }
  
      public String getLocalName()
      {
          return getName().getLocalPart();
      }
  
      public boolean hasName()
      {
          return ((currentEventType == XMLStreamReader.START_ELEMENT) ||
              (currentEventType == XMLStreamReader.END_ELEMENT));
      }
  
      public String getNamespaceURI()
      {
          return getName().getNamespaceURI();
      }
  
      public String getPrefix()
      {
          return getName().getPrefix();
      }
  
      public String getVersion()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean isStandalone()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public boolean standaloneSet()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getCharacterEncodingScheme()
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public String getPITarget()
      {
          throw new IllegalStateException();
      }
  
      public String getPIData()
      {
          throw new IllegalStateException();
      }
  
  
      private void warn(String s)
      {
          System.err.println("WARNING: " + s);
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshallerImpl.java
  
  Index: MarshallerImpl.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  import org.apache.xmlbeans.impl.binding.bts.BindingType;
  import org.apache.xmlbeans.impl.binding.bts.JavaName;
  import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
  import org.apache.xmlbeans.impl.binding.bts.XmlName;
  import org.apache.xmlbeans.XmlRuntimeException;
  import org.apache.xmlbeans.XmlException;
  
  import javax.xml.namespace.NamespaceContext;
  import javax.xml.namespace.QName;
  import javax.xml.stream.XMLStreamReader;
  import java.util.ArrayList;
  
  /**
   * Entry point for marshalling java objects to xml.
   */
  class MarshallerImpl
      implements Marshaller
  {
      private final BindingLoader bindingLoader;
      private final RuntimeBindingTypeTable typeTable;
  
  
      /*package*/
      MarshallerImpl(BindingLoader bindingLoader,
                     RuntimeBindingTypeTable typeTable)
      {
          this.bindingLoader = bindingLoader;
          this.typeTable = typeTable;
      }
  
      public XMLStreamReader marshall(Object obj,
                                      NamespaceContext nscontext)
      {
          final JavaName jname = JavaName.forString(obj.getClass().getName());
          BindingTypeName root_elem_btype = bindingLoader.lookupElementFor(jname);
          if (root_elem_btype == null) {
              final String msg = "failed to find root " +
                  "element corresponding to " + jname;
              throw new XmlRuntimeException(msg);
          }
  
          final XmlName elem = root_elem_btype.getXmlName();
          assert elem.getComponentType() == XmlName.ELEMENT;
          final QName elem_qn = elem.getQName();
  
          //get type for this element/object pair
          final BindingTypeName type_name = bindingLoader.lookupTypeFor(jname);
          final BindingType btype = bindingLoader.getBindingType(type_name);
  
          RuntimeGlobalProperty prop = new RuntimeGlobalProperty(btype, elem_qn);
  
          final ArrayList errors = new ArrayList();
          MarshalContext ctx = new MarshalContext(nscontext, bindingLoader,
                                                  typeTable, errors);
  
          return new MarshalResult(prop, obj, elem_qn, ctx);
      }
  
      public XMLStreamReader marshallType(Object obj,
                                          QName elementName,
                                          QName schemaType,
                                          String javaType,
                                          MarshalContext context)
          throws XmlException
      {
          //TODO: assert that the passed in context has the same loader and typetable as we do.
          //TODO: REVIEW: should we move this method to the context?
          BindingType type = determineBindingType(obj, schemaType, javaType);
          RuntimeGlobalProperty prop = new RuntimeGlobalProperty(type, elementName);
          return new MarshalResult(prop, obj, elementName, context);
      }
  
      private BindingType determineBindingType(Object obj,
                                               QName schemaType,
                                               String javaType)
      {
          //TODO: consult object when needed for polymorphism
          BindingType binding_type = lookupBindingType(javaType, schemaType,
                                                       bindingLoader);
  
          return binding_type;
      }
  
      private static BindingType lookupBindingType(String javaType,
                                                   QName schemaType,
                                                   BindingLoader loader)
      {
          JavaName jname = JavaName.forString(javaType);
          XmlName xname = XmlName.forTypeNamed(schemaType);
          BindingTypeName btname = BindingTypeName.forPair(jname, xname);
          if (btname == null) {
              final String msg = "failed to find type corresponding to " + btname;
              throw new XmlRuntimeException(msg);
          }
  
          final BindingType binding_type = loader.getBindingType(btname);
          if (binding_type == null) {
              final String msg = "failed to load type " + btname;
              throw new XmlRuntimeException(msg);
          }
          return binding_type;
      }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NamespaceTests.java
  
  Index: NamespaceTests.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  class NamespaceTests
  {
      public static void main(String[] args)
      {
  
          ScopedNamespaceContext ctx = new ScopedNamespaceContext();
  
          assert (0 == ctx.getCurrentScopeNamespaceCount());
          ctx.openScope();
          assert (0 == ctx.getCurrentScopeNamespaceCount());
  
          ctx.bindNamespace("p1.1", "n1.1");
          assert (1 == ctx.getCurrentScopeNamespaceCount());
  
          ctx.bindNamespace("p1.2", "n1.2");
          assert (2 == ctx.getCurrentScopeNamespaceCount());
  
          ctx.openScope();
  
          ctx.bindNamespace("p2.1", "n2.1");
          assert (1 == ctx.getCurrentScopeNamespaceCount());
          ctx.bindNamespace("p2.2", "n2.2");
          assert (2 == ctx.getCurrentScopeNamespaceCount());
  
          assert "n1.1".equals(ctx.getNamespaceURI("p1.1"));
          assert "n2.1".equals(ctx.getNamespaceURI("p2.1"));
  
          ctx.closeScope();
  
          assert "n1.1".equals(ctx.getNamespaceURI("p1.1"));
          assert (ctx.getNamespaceURI("p2.1") == null);
  
  //        final int trials = 100000000;
  //        for(int i = 1 ; i < trials ; i++) {
  //            ctx.openScope();
  //            ctx.bindNamespace("p1.1", "n2.1");
  //            ctx.openScope();
  //            ctx.bindNamespace("p2.2", "n2.2");
  //            ctx.closeScope();
  //            ctx.closeScope();
  //        }
  
  
      }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeGlobalProperty.java
  
  Index: RuntimeGlobalProperty.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingType;
  import org.apache.xmlbeans.XmlRuntimeException;
  
  import javax.xml.namespace.QName;
  
  class RuntimeGlobalProperty
     implements RuntimeBindingProperty
  {
      private final BindingType type;
      private final QName rootElement;
  
      RuntimeGlobalProperty(BindingType type, QName root_element) {
          this.type = type;
          this.rootElement = root_element;
      }
  
  
      public BindingType getType()
      {
          return type;
      }
  
      public QName getName()
      {
          return rootElement;
      }
  
      public TypeUnmarshaller getTypeUnmarshaller(UnmarshalContext context)
      {
          throw new UnsupportedOperationException();
      }
  
      public void fill(Object inter, Object prop_obj)
      {
          throw new UnsupportedOperationException();
      }
  
      //non simple type props can throw some runtime exception.
      public CharSequence getLexical(Object parent, MarshalContext context)
      {
          //TODO: polymorphism checks
  
          final TypeMarshaller tm =
              context.getTypeTable().getTypeMarshaller(type);
  
          if (tm == null) {
              throw new XmlRuntimeException("lookup failed for " + type);
          }
  
          final CharSequence retval = tm.print(parent, context);
          return retval;
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeTypeFactory.java
  
  Index: RuntimeTypeFactory.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingType;
  import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
  
  class RuntimeTypeFactory
  {
      public static RuntimeBindingType createRuntimeType(BindingType type)
      {
          //TODO: fix instanceof nastiness
          if (type instanceof ByNameBean) {
              return new ByNameRuntimeBindingType((ByNameBean)type);
          }
  
          throw new AssertionError("unknown type: " + type);
      }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ScopedNamespaceContext.java
  
  Index: ScopedNamespaceContext.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import javax.xml.namespace.NamespaceContext;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  import java.util.Stack;
  
  final class ScopedNamespaceContext
      implements NamespaceContext
  {
  
      public static final String DEFAULT_NAMESPACE = "";
  
      private final Stack scopeStack;
      private LLNamespaceContext current = null;
  
      public ScopedNamespaceContext()
      {
          this(null, new Stack());
      }
  
      private ScopedNamespaceContext(LLNamespaceContext head, Stack scopeStack)
      {
          this.current = head;
          this.scopeStack = scopeStack;
      }
  
      public ScopedNamespaceContext(NamespaceContext root_nsctx)
      {
          //TODO: copy initial context!
          this(null, new Stack());
      }
  
      public void clear()
      {
          scopeStack.clear();
          current = null;
      }
  
      public String getNamespaceURI(String prefix)
      {
          if (current == null) return null;
  
          return current.getNamespaceURI(prefix);
      }
  
      public String getPrefix(String namespaceURI)
      {
          if (current == null)
              return null;
          else
              return current.getPrefix(namespaceURI);
      }
  
      public Iterator getPrefixes(String namespaceURI)
      {
          return current.getPrefixes(namespaceURI);
      }
  
      public boolean scopeOpened()
      {
          return !scopeStack.isEmpty();
      }
  
      public void openScope()
      {
          scopeStack.push(current);
      }
  
      public void closeScope()
      {
          if (!scopeOpened())
              throw new IllegalStateException("no scope currently open");
  
          final LLNamespaceContext previous = (LLNamespaceContext)scopeStack.pop();
          current = previous;
      }
  
      public void bindNamespace(String prefix, String namespace)
      {
          if (!scopeOpened())
              throw new IllegalStateException("no scope currently open");
          if (namespace == null)
              throw new IllegalArgumentException("null namespace not allowed");
          if (prefix == DEFAULT_NAMESPACE || prefix == null) {
              final String msg = "Cannot use empty string or null as a prefix; " +
                  "use bindDefaultNamespace() to bind the default namespace";
              throw new IllegalArgumentException(msg);
          }
          current = new LLNamespaceContext(prefix, namespace, current);
      }
  
      public void unbindNamespace(String prefix)
      {
          bindNamespace(prefix, null);
      }
  
      public void bindDefaultNamespace(String uri)
      {
          bindNamespace(DEFAULT_NAMESPACE, uri);
      }
  
      public void unbindDefaultNamespace()
      {
          //TODO: FIXME
          bindDefaultNamespace(null);
      }
  
      public int getDepth()
      {
          return scopeStack.size();
      }
  
      public Map getNamespaceMap()
      {
          return getNamespaceMap(current);
      }
  
  
      public int getCurrentScopeNamespaceCount()
      {
          if (current == null) return 0;
  
          final LLNamespaceContext top = (LLNamespaceContext)scopeStack.peek();
          int cnt = 0;
          for (LLNamespaceContext cur = current; cur != top; cur = cur.getPredecessor()) {
              ++cnt;
          }
          return cnt;
      }
  
      public String getCurrentScopeNamespacePrefix(int i)
      {
          return getCurrentScopeNamespace(i).getPrefix();
      }
  
      public String getCurrentScopeNamespaceURI(int i)
      {
          return getCurrentScopeNamespace(i).getNamespace();
      }
  
      private LLNamespaceContext getCurrentScopeNamespace(int i)
      {
          if (i < 0) throw new IllegalArgumentException("negative index: " + i);
  
          final LLNamespaceContext top = (LLNamespaceContext)scopeStack.peek();
          int cnt = 0;
          for (LLNamespaceContext cur = current; cur != top; cur = cur.getPredecessor()) {
              if (cnt == i) {
                  return cur;
              }
              ++cnt;
          }
          throw new IndexOutOfBoundsException("index of out range: " + i);
      }
  
  
      private static final Map getNamespaceMap(LLNamespaceContext ctx)
      {
          if (ctx == null)
              return new HashMap();
          else {
              final Map result = getNamespaceMap(ctx.predecessor);
              result.put(ctx.prefix, ctx.namespace);
              return result;
          }
      }
  
      private static class LLNamespaceContext
      {
          private final String prefix;
          private final String namespace;
          private final LLNamespaceContext predecessor;
  
  
          public LLNamespaceContext(String prefix, String namespace,
                                    LLNamespaceContext predecessor)
          {
              this.prefix = prefix;
              this.namespace = namespace;
              this.predecessor = predecessor;
          }
  
          public final String getNamespace()
          {
              return namespace;
          }
  
          public final String getPrefix()
          {
              return prefix;
          }
  
          protected final LLNamespaceContext getPredecessor()
          {
              return predecessor;
          }
  
          public String getNamespaceURI(String prefix)
          {
              for (LLNamespaceContext entry = this; entry != null; entry = entry.predecessor) {
                  if (prefix.equals(entry.prefix)) return entry.namespace;
              }
              return null;
          }
  
          public String getPrefix(String namespaceURI)
          {
              for (LLNamespaceContext entry = this; entry != null; entry = entry.predecessor) {
                  if (namespaceURI.equals(entry.namespace)) return entry.prefix;
              }
              return null;
          }
  
          public Iterator getPrefixes(String namespaceURI)
          {
              final Set result = getPrefixSet(namespaceURI, this);
              return result.iterator();
          }
  
          protected static final Set getPrefixSet(String namespace,
                                                  LLNamespaceContext context)
          {
              final Stack reversed = new Stack();
              LLNamespaceContext current = context;
              while (current != null) {
                  reversed.push(current);
                  current = current.predecessor;
              }
              Set result = new HashSet(4);
              while (!reversed.isEmpty()) {
                  current = (LLNamespaceContext)reversed.pop();
                  if (namespace.equals(current.namespace))
                      result.add(current.prefix);
                  else
                      result.remove(current.prefix);
              }
  
              return result;
          }
  
      }
  }
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleTypeVisitor.java
  
  Index: SimpleTypeVisitor.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import javax.xml.namespace.QName;
  
  final class SimpleTypeVisitor extends XmlTypeVisitor
  {
      private final RuntimeBindingProperty property;
      private final MarshalContext context;
  
      private boolean beforeChild = true;
      private String prefix;
  
      public SimpleTypeVisitor(RuntimeBindingProperty property, Object obj,
                               MarshalContext context)
      {
          super(obj);
          this.property = property;
          this.context = context;
  
  
      }
  
      protected void advance()
      {
          beforeChild = false;
      }
  
      protected boolean hasMoreChildren()
      {
          return beforeChild;
      }
  
      protected XmlTypeVisitor getCurrChild()
      {
          return new CharacterVisitor(property, parentObject, context);
      }
  
      protected QName getName()
      {
          final QName pname = property.getName();
  
          if (prefix == null) {
              prefix = context.ensurePrefix(pname.getNamespaceURI());
          }
  
          return new QName(pname.getNamespaceURI(), pname.getLocalPart(), prefix);
      }
  
      protected boolean isCharacters()
      {
          return false;
      }
  
      protected int getAttributeCount()
      {
          //TODO: xsi type considerations
          return 0;
      }
  
      protected String getAttributeValue(int idx)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected QName getAttributeName(int idx)
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      protected CharSequence getCharData()
      {
          throw new IllegalStateException("not text");
      }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/XmlTypeVisitor.java
  
  Index: XmlTypeVisitor.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import javax.xml.namespace.QName;
  import javax.xml.stream.XMLStreamReader;
  
  abstract class XmlTypeVisitor
  {
      protected final Object parentObject;
  
      protected XmlTypeVisitor(Object parent)
      {
          parentObject = parent;
      }
  
      static final int CHARACTERS = XMLStreamReader.CHARACTERS;
      static final int START_ELEMENT = XMLStreamReader.START_ELEMENT;
      static final int END_ELEMENT = XMLStreamReader.END_ELEMENT;
  
      // needs to update _currProp AND _currPropObj
      protected abstract void advance();
  
      protected abstract boolean hasMoreChildren();
  
      //return XmlTypeVisitorFactory.createXmlTypeVisitor(_currProp.get, _currPropObj);
      protected abstract XmlTypeVisitor getCurrChild();
  
      protected abstract QName getName();
  
      protected abstract boolean isCharacters();
  
      protected abstract int getAttributeCount();
  
      protected abstract String getAttributeValue(int idx);
  
      protected abstract QName getAttributeName(int idx);
  
      protected abstract CharSequence getCharData();
  
  }
  
  
  
  1.2       +11 -11    xml-xmlbeans/v2/test/cases/marshal/doc.xml
  
  Index: doc.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/doc.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- doc.xml	23 Oct 2003 23:49:03 -0000	1.1
  +++ doc.xml	31 Oct 2003 22:23:26 -0000	1.2
  @@ -1,19 +1,19 @@
   <?xml version="1.0" encoding="utf-8"?>
  -<my:load xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  +<My:load xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  -    xmlns:my="http://www.mytest.com/" xsi:type="my:my-type">
  +    xmlns:My="java:com.mytest" xsi:type="My:MyClass">
   
  -    <my:myelt ignore="someval" my:attrib="4444.3333333"  >
  -        <my:my-float>65.34</my:my-float>
  -        <my:your_class>
  -            <my:myatt xsi:type="xsd:token">inner-str</my:myatt>
  -        </my:your_class>
  -    </my:myelt>
  +    <My:Myelt ignore="someval" My:Attrib="4444.3333333"  >
  +        <My:MyFloat>65.34</My:MyFloat>
  +        <My:MyClass>
  +            <My:Myatt xsi:type="xsd:token">inner-str</My:Myatt>
  +        </My:MyClass>
  +    </My:Myelt>
   
       <!--    not working-->
  -    <!--    <my:myatt xsi:nil="0" xsi:type="my:custom-string" >some string</my:myatt>-->
  +    <!--    <My:Myatt xsi:nil="0" xsi:type="My:custom-string" >some string</My:Myatt>-->
   
  -    <my:myatt xsi:type="xsd:token">strval</my:myatt>
  +    <My:Myatt xsi:type="xsd:token">strval</My:Myatt>
   
  -</my:load>
  +</My:load>
   
  
  
  
  1.2       +70 -80    xml-xmlbeans/v2/test/cases/marshal/example_config.xml
  
  Index: example_config.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/example_config.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- example_config.xml	23 Oct 2003 23:49:03 -0000	1.1
  +++ example_config.xml	31 Oct 2003 22:23:26 -0000	1.2
  @@ -1,81 +1,71 @@
  -<bin:binding-config xmlns:myt="http://www.mytest.com/" xmlns:bin="http://xmlbeans.apache.org/2003/09/binding-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  -    <bin:bindings>
  -        <bin:binding-type xsi:type="bin:by-name-bean">
  -            <bin:xmlcomponent>t=my-type@http://www.mytest.com/</bin:xmlcomponent>
  -            <bin:javatype>com.mytest.MyClass</bin:javatype>
  -            <bin:xmlobj>false</bin:xmlobj>
  -            <bin:qname-property>
  -                <bin:xmlcomponent>t=your-type@http://www.mytest.com/</bin:xmlcomponent>
  -                <bin:javatype>com.mytest.YourClass</bin:javatype>
  -                <bin:getter>getMyelt</bin:getter>
  -                <bin:setter>setMyelt</bin:setter>
  -                <bin:qname>myt:myelt</bin:qname>
  -            </bin:qname-property>
  -            <bin:qname-property>
  -                <bin:xmlcomponent>t=custom-string@http://www.mytest.com/</bin:xmlcomponent>
  -                <bin:javatype>java.lang.String</bin:javatype>
  -                <bin:getter>getMyatt</bin:getter>
  -                <bin:setter>setMyatt</bin:setter>
  -                <bin:qname>myt:myatt</bin:qname>
  -            </bin:qname-property>
  -        </bin:binding-type>
  -        <bin:binding-type xsi:type="bin:by-name-bean">
  -            <bin:xmlcomponent>t=your-type@http://www.mytest.com/</bin:xmlcomponent>
  -            <bin:javatype>com.mytest.YourClass</bin:javatype>
  -            <bin:xmlobj>false</bin:xmlobj>
  -            <bin:qname-property>
  -                <bin:xmlcomponent>t=my-type@http://www.mytest.com/</bin:xmlcomponent>
  -                <bin:javatype>com.mytest.MyClass</bin:javatype>
  -                <bin:getter>getMyClass</bin:getter>
  -                <bin:setter>setMyClass</bin:setter>
  -                <bin:qname>myt:your_class</bin:qname>
  -            </bin:qname-property>
  -            <bin:qname-property>
  -                <bin:xmlcomponent>t=float@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
  -                <bin:javatype>float</bin:javatype>
  -                <bin:getter>getMyFloat</bin:getter>
  -                <bin:setter>setMyFloat</bin:setter>
  -                <bin:qname>myt:my-float</bin:qname>
  -            </bin:qname-property>
  -            <bin:qname-property>
  -                <bin:xmlcomponent>t=float@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
  -                <bin:javatype>float</bin:javatype>
  -                <bin:getter>getAttrib</bin:getter>
  -                <bin:setter>setAttrib</bin:setter>
  -                <bin:qname>myt:attrib</bin:qname>
  -                <bin:attribute>true</bin:attribute>
  -            </bin:qname-property>
  -        </bin:binding-type>
  -        <bin:binding-type xsi:type="bin:simple-type">
  -            <bin:xmlcomponent>t=custom-string@http://www.mytest.com/</bin:xmlcomponent>
  -            <bin:javatype>java.lang.String</bin:javatype>
  -            <bin:xmlobj>false</bin:xmlobj>
  -            <bin:as-xml>t=string@http://www.w3.org/2001/XMLSchema</bin:as-xml>
  -        </bin:binding-type>
  -    </bin:bindings>
  -    <bin:xml-to-pojo>
  -        <bin:mapping>
  -            <bin:xmlcomponent>t=my-type@http://www.mytest.com/</bin:xmlcomponent>
  -            <bin:javatype>com.mytest.MyClass</bin:javatype>
  -        </bin:mapping>
  -        <bin:mapping>
  -            <bin:xmlcomponent>t=your-type@http://www.mytest.com/</bin:xmlcomponent>
  -            <bin:javatype>com.mytest.YourClass</bin:javatype>
  -        </bin:mapping>
  -    </bin:xml-to-pojo>
  -    <bin:xml-to-xmlobj/>
  -    <bin:java-to-xml>
  -        <bin:mapping>
  -            <bin:xmlcomponent>t=my-type@http://www.mytest.com/</bin:xmlcomponent>
  -            <bin:javatype>com.mytest.MyClass</bin:javatype>
  -        </bin:mapping>
  -        <bin:mapping>
  -            <bin:xmlcomponent>t=your-type@http://www.mytest.com/</bin:xmlcomponent>
  -            <bin:javatype>com.mytest.YourClass</bin:javatype>
  -        </bin:mapping>
  -        <bin:mapping>
  -            <bin:xmlcomponent>t=custom-string@http://www.mytest.com/</bin:xmlcomponent>
  -            <bin:javatype>java.lang.String</bin:javatype>
  -        </bin:mapping>
  -    </bin:java-to-xml>
  +<?xml version="1.0" encoding="UTF-8"?>
  +<bin:binding-config xmlns:java="java:com.mytest" xmlns:bin="http://xmlbeans.apache.org/2003/09/binding-config">
  +  <bin:bindings>
  +    <bin:binding-type xsi:type="bin:by-name-bean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  +      <bin:xmlcomponent>t=YourClass@java:com.mytest</bin:xmlcomponent>
  +      <bin:javatype>com.mytest.YourClass</bin:javatype>
  +      <bin:qname-property>
  +        <bin:xmlcomponent>t=float@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
  +        <bin:javatype>float</bin:javatype>
  +        <bin:getter>getAttrib</bin:getter>
  +        <bin:setter>setAttrib</bin:setter>
  +        <bin:qname>java:Attrib</bin:qname>
  +        <bin:attribute>true</bin:attribute>
  +      </bin:qname-property>
  +      <bin:qname-property>
  +        <bin:xmlcomponent>t=MyClass@java:com.mytest</bin:xmlcomponent>
  +        <bin:javatype>com.mytest.MyClass</bin:javatype>
  +        <bin:getter>getMyClass</bin:getter>
  +        <bin:setter>setMyClass</bin:setter>
  +        <bin:qname>java:MyClass</bin:qname>
  +      </bin:qname-property>
  +      <bin:qname-property>
  +        <bin:xmlcomponent>t=float@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
  +        <bin:javatype>float</bin:javatype>
  +        <bin:getter>getMyFloat</bin:getter>
  +        <bin:setter>setMyFloat</bin:setter>
  +        <bin:qname>java:MyFloat</bin:qname>
  +      </bin:qname-property>
  +    </bin:binding-type>
  +    <bin:binding-type xsi:type="bin:by-name-bean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  +      <bin:xmlcomponent>t=MyClass@java:com.mytest</bin:xmlcomponent>
  +      <bin:javatype>com.mytest.MyClass</bin:javatype>
  +      <bin:qname-property>
  +        <bin:xmlcomponent>t=YourClass@java:com.mytest</bin:xmlcomponent>
  +        <bin:javatype>com.mytest.YourClass</bin:javatype>
  +        <bin:getter>getMyelt</bin:getter>
  +        <bin:setter>setMyelt</bin:setter>
  +        <bin:qname>java:Myelt</bin:qname>
  +      </bin:qname-property>
  +      <bin:qname-property>
  +        <bin:xmlcomponent>t=string@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
  +        <bin:javatype>java.lang.String</bin:javatype>
  +        <bin:getter>getMyatt</bin:getter>
  +        <bin:setter>setMyatt</bin:setter>
  +        <bin:qname>java:Myatt</bin:qname>
  +      </bin:qname-property>
  +    </bin:binding-type>
  +  </bin:bindings>
  +  <bin:xml-to-pojo>
  +    <bin:mapping>
  +      <bin:xmlcomponent>t=YourClass@java:com.mytest</bin:xmlcomponent>
  +      <bin:javatype>com.mytest.YourClass</bin:javatype>
  +    </bin:mapping>
  +    <bin:mapping>
  +      <bin:xmlcomponent>t=MyClass@java:com.mytest</bin:xmlcomponent>
  +      <bin:javatype>com.mytest.MyClass</bin:javatype>
  +    </bin:mapping>
  +  </bin:xml-to-pojo>
  +  <bin:xml-to-xmlobj/>
  +  <bin:java-to-xml>
  +    <bin:mapping>
  +      <bin:xmlcomponent>t=YourClass@java:com.mytest</bin:xmlcomponent>
  +      <bin:javatype>com.mytest.YourClass</bin:javatype>
  +    </bin:mapping>
  +    <bin:mapping>
  +      <bin:xmlcomponent>t=MyClass@java:com.mytest</bin:xmlcomponent>
  +      <bin:javatype>com.mytest.MyClass</bin:javatype>
  +    </bin:mapping>
  +  </bin:java-to-xml>
  +  <bin:java-to-element/>
   </bin:binding-config>
  
  
  
  1.3       +137 -6    xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java
  
  Index: MarshalTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MarshalTests.java	23 Oct 2003 23:49:03 -0000	1.2
  +++ MarshalTests.java	31 Oct 2003 22:23:26 -0000	1.3
  @@ -6,11 +6,17 @@
   import junit.framework.TestSuite;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  +import org.apache.xmlbeans.impl.common.XmlStreamUtils;
   import org.apache.xmlbeans.impl.marshal.BindingContext;
   import org.apache.xmlbeans.impl.marshal.BindingContextFactory;
  +import org.apache.xmlbeans.impl.marshal.MarshalContext;
  +import org.apache.xmlbeans.impl.marshal.Marshaller;
  +import org.apache.xmlbeans.impl.marshal.UnmarshalContext;
   import org.apache.xmlbeans.impl.marshal.Unmarshaller;
   import org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument;
   
  +import javax.xml.namespace.NamespaceContext;
  +import javax.xml.namespace.QName;
   import javax.xml.stream.XMLInputFactory;
   import javax.xml.stream.XMLStreamReader;
   import java.io.CharArrayReader;
  @@ -21,6 +27,10 @@
   import java.io.Reader;
   import java.io.StringReader;
   import java.io.Writer;
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import java.util.List;
  +
   
   public class MarshalTests extends TestCase
   {
  @@ -37,14 +47,14 @@
       public void testManySimpleTypesUnmarshall()
           throws Exception
       {
  -        testSimpleTypeUnmarshall(new Long(554345354445555555L), "long");
  -        testSimpleTypeUnmarshall(new Float(54.5423f), "float");
  -        testSimpleTypeUnmarshall("random string", "string");
  +        testSimpleTypeUnmarshal(new Long(554345354445555555L), "long");
  +        testSimpleTypeUnmarshal(new Float(54.5423f), "float");
  +        testSimpleTypeUnmarshal("random string", "string");
       }
   
   
       //only works for values where .toString() is equivalent to marshalling
  -    public void testSimpleTypeUnmarshall(Object expected, String xsd_type)
  +    public void testSimpleTypeUnmarshal(Object expected, String xsd_type)
           throws Exception
       {
           Unmarshaller unmarshaller = getSimpleUnmarshaller();
  @@ -64,7 +74,59 @@
           System.out.println("OK for " + expected);
       }
   
  -    public void testByNameBeanUnmarshall()
  +
  +    public void testManySimpleTypesMarshall()
  +        throws Exception
  +    {
  +        testSimpleTypeMarshal(new Long(554345354445555555L), "long");
  +        testSimpleTypeMarshal("some text here", "string");
  +        testSimpleTypeMarshal("       ", "string");
  +    }
  +
  +
  +    //only works for values where .toString() is equivalent to marshalling
  +    public void testSimpleTypeMarshal(Object orig, String xsd_type)
  +        throws Exception
  +    {
  +        BindingFile bf = new BindingFile();
  +        BindingConfigDocument bindingConfigDocument = bf.write();
  +
  +        BindingContext bindingContext =
  +            BindingContextFactory.createBindingContext(bindingConfigDocument);
  +
  +        Marshaller m = bindingContext.createMarshaller();
  +
  +        EmptyNamespaceContext namespaceContext = new EmptyNamespaceContext();
  +        final ArrayList errors = new ArrayList();
  +        MarshalContext ctx =
  +            bindingContext.createMarshallContext(namespaceContext, errors);
  +
  +        final XMLStreamReader reader =
  +            m.marshallType(orig, new QName("uri", "lname"),
  +                           new QName("http://www.w3.org/2001/XMLSchema", xsd_type),
  +                           orig.getClass().getName(),
  +                           ctx);
  +
  +
  +        System.out.println("==================OBJ: " + orig);
  +        while (reader.hasNext()) {
  +            System.out.println("STATE: " + XmlStreamUtils.printEvent(reader));
  +            final int state = reader.next();
  +            System.out.println("next is " + state);
  +        }
  +
  +
  +//        StringWriter sw = new StringWriter();
  +//        XMLStreamWriter xwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
  +//        final ReaderToWriter rtow = new ReaderToWriter(xwriter);
  +//        rtow.write(reader);
  +//        xwriter.close();
  +//        sw.close();
  +//
  +//        System.out.println("OUTPUT=|" + sw.getBuffer() + "|");
  +    }
  +
  +    public void testByNameBeanUnmarshal()
           throws Exception
       {
           BindingConfigDocument bcdoc = getBindingConfigDocument();
  @@ -89,6 +151,43 @@
           System.out.println("obj = " + obj);
       }
   
  +    public void testByNameBeanUnmarshalType()
  +        throws Exception
  +    {
  +        BindingConfigDocument bcdoc = getBindingConfigDocument();
  +
  +        BindingContext bindingContext =
  +            BindingContextFactory.createBindingContext(bcdoc);
  +
  +
  +        Unmarshaller unmarshaller = bindingContext.createUnmarshaller();
  +
  +        Assert.assertNotNull(unmarshaller);
  +
  +        //TODO: remove hard coded values
  +        final File doc = new File("test/cases/marshal/doc.xml");
  +        final String javaType = "com.mytest.MyClass";
  +        final QName schemaType = new QName("java:com.mytest", "MyClass");
  +
  +        final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
  +        XMLStreamReader xrdr =
  +            xmlInputFactory.createXMLStreamReader(new FileReader(doc));
  +
  +        List errors = new ArrayList();
  +
  +        UnmarshalContext ctx = bindingContext.createUnmarshallContext(xrdr, errors);
  +
  +        //this is not very safe but it should work...
  +        while (!xrdr.isStartElement()) {
  +            xrdr.next();
  +        }
  +
  +        Object obj = unmarshaller.unmarshallType(schemaType, javaType, ctx);
  +
  +
  +        System.out.println("type obj = " + obj);
  +    }
  +
       public void testPerfByNameBeanUnmarshall()
           throws Exception
       {
  @@ -163,10 +262,42 @@
           Unmarshaller unmarshaller = bindingContext.createUnmarshaller();
           return unmarshaller;
       }
  -    
  +
  +    private static Marshaller getSimpleMarshaller() throws IOException
  +    {
  +        BindingFile bf = new BindingFile();
  +        BindingConfigDocument bindingConfigDocument = bf.write();
  +
  +        BindingContext bindingContext =
  +            BindingContextFactory.createBindingContext(bindingConfigDocument);
  +
  +        Marshaller m = bindingContext.createMarshaller();
  +        return m;
  +    }
  +
       public static void main(String args[])
       {
           junit.textui.TestRunner.run(suite());
  +    }
  +
  +    private static class EmptyNamespaceContext
  +        implements NamespaceContext
  +    {
  +        public String getNamespaceURI(String s)
  +        {
  +            return null;
  +        }
  +
  +        public String getPrefix(String s)
  +        {
  +            return null;
  +        }
  +
  +        public Iterator getPrefixes(String s)
  +        {
  +            return null;
  +        }
  +
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org


Mime
View raw message