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 Thu, 06 May 2004 17:47:14 GMT
zieg        2004/05/06 10:47:14

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/bts
                        JavaTypeName.java
               v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        ByNameTypeVisitor.java CharacterVisitor.java
                        LiteralMarshalResult.java MarshalResult.java
                        MarshallerImpl.java NamedXmlTypeVisitor.java
                        QNameTypeConverter.java RefdObjectVisitor.java
                        SimpleContentTypeVisitor.java
                        SimpleContentVisitor.java SimpleTypeVisitor.java
                        Soap11RefdObjectVisitor.java SoapMarshalResult.java
                        SoapMarshallerImpl.java
                        WrappedArrayTypeVisitor.java XmlTypeVisitor.java
               v2/test/cases/marshal/com/mytest MySubClass.java
                        MySubSubClass.java
               v2/test/src/drt/drtcases MarshalTests.java
  Added:       v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        PullMarshalResult.java PushMarshalResult.java
  Log:
  provide first class push based marshalling
  
  Revision  Changes    Path
  1.15      +12 -0     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/JavaTypeName.java
  
  Index: JavaTypeName.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/JavaTypeName.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JavaTypeName.java	4 May 2004 21:33:22 -0000	1.14
  +++ JavaTypeName.java	6 May 2004 17:47:13 -0000	1.15
  @@ -227,6 +227,18 @@
       }
   
   
  +    /**
  +     * Is this JavaTypeName a name for the given class
  +     *
  +     * @param c
  +     * @return
  +     */
  +    public boolean isNameForClass(Class c) {
  +        //TODO: optimize this method, or better yet avoid using it
  +        JavaTypeName cname = forClassName(c.getName());
  +        return this.equals(cname);
  +    }
  +
       // ========================================================================
       // Object implementation
   
  
  
  
  1.24      +4 -3      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java
  
  Index: ByNameTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameTypeVisitor.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- ByNameTypeVisitor.java	12 Apr 2004 22:39:46 -0000	1.23
  +++ ByNameTypeVisitor.java	6 May 2004 17:47:13 -0000	1.24
  @@ -33,8 +33,9 @@
       private boolean haveMultipleItem;
   
   
  -    ByNameTypeVisitor(RuntimeBindingProperty property, Object obj,
  -                      MarshalResult result)
  +    ByNameTypeVisitor(RuntimeBindingProperty property,
  +                      Object obj,
  +                      PullMarshalResult result)
           throws XmlException
       {
           super(obj, property, result);
  @@ -170,7 +171,7 @@
       static void initAttributesInternal(NamedXmlTypeVisitor typeVisitor,
                                          AttributeRuntimeBindingType rtt,
                                          int maxAttributePropCount,
  -                                       MarshalResult marshalResult)
  +                                       PullMarshalResult marshalResult)
           throws XmlException
       {
           final Object parent = typeVisitor.getParentObject();
  
  
  
  1.14      +1 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/CharacterVisitor.java
  
  Index: CharacterVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/CharacterVisitor.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CharacterVisitor.java	12 Apr 2004 22:39:46 -0000	1.13
  +++ CharacterVisitor.java	6 May 2004 17:47:13 -0000	1.14
  @@ -27,7 +27,7 @@
   
       CharacterVisitor(RuntimeBindingProperty property,
                        Object parentObject,
  -                     MarshalResult result)
  +                     PullMarshalResult result)
           throws XmlException
       {
           super(parentObject, property, result);
  
  
  
  1.2       +8 -8      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/LiteralMarshalResult.java
  
  Index: LiteralMarshalResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/LiteralMarshalResult.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LiteralMarshalResult.java	30 Apr 2004 21:31:48 -0000	1.1
  +++ LiteralMarshalResult.java	6 May 2004 17:47:13 -0000	1.2
  @@ -15,23 +15,23 @@
   
   package org.apache.xmlbeans.impl.marshal;
   
  -import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  -import org.apache.xmlbeans.XmlOptions;
   import org.apache.xmlbeans.XmlException;
  +import org.apache.xmlbeans.XmlOptions;
  +import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
   
   import javax.xml.namespace.NamespaceContext;
   
   final class LiteralMarshalResult
  -    extends MarshalResult
  +    extends PullMarshalResult
   {
   
       //TODO: REVIEW: consider ways to reduce the number of parameters here
       LiteralMarshalResult(BindingLoader loader,
  -                      RuntimeBindingTypeTable tbl,
  -                      NamespaceContext root_nsctx,
  -                      RuntimeBindingProperty property,
  -                      Object obj,
  -                      XmlOptions options)
  +                         RuntimeBindingTypeTable tbl,
  +                         NamespaceContext root_nsctx,
  +                         RuntimeBindingProperty property,
  +                         Object obj,
  +                         XmlOptions options)
           throws XmlException
       {
           super(loader, tbl, root_nsctx, property, obj, options);
  
  
  
  1.32      +69 -665   xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java
  
  Index: MarshalResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- MarshalResult.java	5 May 2004 16:49:31 -0000	1.31
  +++ MarshalResult.java	6 May 2004 17:47:13 -0000	1.32
  @@ -15,198 +15,56 @@
   
   package org.apache.xmlbeans.impl.marshal;
   
  -import org.apache.xmlbeans.XmlError;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlOptions;
  -import org.apache.xmlbeans.XmlRuntimeException;
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.BindingType;
   import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
  -import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
  -import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
  -import org.apache.xmlbeans.impl.binding.bts.JaxrpcEnumType;
  -import org.apache.xmlbeans.impl.binding.bts.ListArrayType;
  -import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
  -import org.apache.xmlbeans.impl.binding.bts.SimpleContentBean;
  -import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
  -import org.apache.xmlbeans.impl.binding.bts.WrappedArrayType;
  -import org.apache.xmlbeans.impl.common.XmlStreamUtils;
  -import org.apache.xmlbeans.impl.common.XmlWhitespace;
  -import org.apache.xmlbeans.impl.marshal.util.AttributeHolder;
   import org.apache.xmlbeans.impl.util.XsTypeConverter;
   
   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.Collection;
  -import java.util.Stack;
   
   
  -abstract class MarshalResult implements XMLStreamReader
  +abstract class MarshalResult
   {
  -
       //per binding context constants
  -    private final BindingLoader bindingLoader;
  -    private final RuntimeBindingTypeTable typeTable;
  +    protected final BindingLoader bindingLoader;
  +    protected final RuntimeBindingTypeTable typeTable;
   
       //state fields
  -    private final BindingTypeVisitor bindingTypeVisitor =
  -        new BindingTypeVisitor(this);
       private final Collection errors;
  -    private final ScopedNamespaceContext namespaceContext;
  -    private final Stack visitorStack = new Stack();
  -
  -    private XmlTypeVisitor currVisitor;
  -    private int currentEventType = XMLStreamReader.START_ELEMENT;
  -    private boolean initedAttributes = false;
  -    private AttributeHolder attributeHolder;
       private int prefixCnt = 0;
   
  -    private static final String ATTRIBUTE_XML_TYPE = "CDATA";
       private static final String NSPREFIX = "n";
   
   
       //TODO: REVIEW: consider ways to reduce the number of parameters here
       MarshalResult(BindingLoader loader,
                     RuntimeBindingTypeTable tbl,
  -                  NamespaceContext root_nsctx,
  -                  RuntimeBindingProperty property,
  -                  Object obj,
                     XmlOptions options)
           throws XmlException
       {
           bindingLoader = loader;
           typeTable = tbl;
  -        namespaceContext = new ScopedNamespaceContext(root_nsctx);
  -        namespaceContext.openScope();
           errors = BindingContextImpl.extractErrorHandler(options);
  -        currVisitor = createInitialVisitor(property, obj);
       }
   
  -    //reset to initial state but with new property and object
  -    protected void reset(RuntimeBindingProperty property, Object obj)
  -        throws XmlException
  +    protected void resetPrefixCount()
       {
  -        namespaceContext.clear();
  -        namespaceContext.openScope();
  -        visitorStack.clear();
  -        currVisitor = createInitialVisitor(property, obj);
  -        currentEventType = XMLStreamReader.START_ELEMENT;
  -        initedAttributes = false;
  -        if (attributeHolder != null) attributeHolder.clear();
           prefixCnt = 0;
       }
   
  -    protected XmlTypeVisitor createInitialVisitor(RuntimeBindingProperty property,
  -                                                  Object obj)
  -        throws XmlException
  -    {
  -        return createVisitor(property, obj);
  -    }
  +    public abstract NamespaceContext getNamespaceContext();
   
  -    protected XmlTypeVisitor createVisitor(RuntimeBindingProperty property,
  -                                           Object obj)
  +    protected String ensurePrefix(String uri)
           throws XmlException
       {
  -        assert property != null;
  -
  -        BindingType btype = property.getRuntimeBindingType().getBindingType();
  -        final BindingTypeVisitor type_visitor = bindingTypeVisitor;
  -        type_visitor.setParentObject(obj);
  -        type_visitor.setRuntimeBindingProperty(property);
  -        btype.accept(type_visitor);
  -        return type_visitor.getXmlTypeVisitor();
  -    }
  -
  -
  -    public Object getProperty(String s)
  -        throws IllegalArgumentException
  -    {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  -    }
  -
  -    public int next()
  -        throws XMLStreamException
  -    {
  -        switch (currVisitor.getState()) {
  -            case XmlTypeVisitor.START:
  -                break;
  -            case XmlTypeVisitor.CHARS:
  -            case XmlTypeVisitor.END:
  -                currVisitor = popVisitor();
  -                break;
  -            default:
  -                throw new AssertionError("invalid: " + currVisitor.getState());
  -        }
  -
  -        try {
  -            return (currentEventType = advanceToNext());
  -        }
  -        catch (XmlException e) {
  -            //TODO: consider passing Location to exception ctor
  -            XMLStreamException xse = new XMLStreamException(e);
  -            xse.initCause(e);
  -            throw xse;
  -        }
  -    }
  -
  -    private int advanceToNext()
  -        throws XmlException
  -    {
  -        final int next_state = currVisitor.advance();
  -        switch (next_state) {
  -            case XmlTypeVisitor.CONTENT:
  -                pushVisitor(currVisitor);
  -                currVisitor = currVisitor.getCurrentChild();
  -                return START_ELEMENT;
  -            case XmlTypeVisitor.CHARS:
  -                pushVisitor(currVisitor);
  -                currVisitor = currVisitor.getCurrentChild();
  -                return CHARACTERS;
  -            case XmlTypeVisitor.END:
  -                return END_ELEMENT;
  -            default:
  -                throw new AssertionError("bad state: " + next_state);
  -        }
  -    }
  -
  -    private void pushVisitor(XmlTypeVisitor v)
  -    {
  -        visitorStack.push(v);
  -        namespaceContext.openScope();
  -        initedAttributes = false;
  -    }
  -
  -    private XmlTypeVisitor popVisitor()
  -    {
  -        namespaceContext.closeScope();
  -        final XmlTypeVisitor tv = (XmlTypeVisitor)visitorStack.pop();
  -        return tv;
  -    }
  -
  -    QName fillPrefix(final QName pname)
  -    {
  -        final String uri = pname.getNamespaceURI();
  -
  -        assert uri != null;  //QName's should use "" for no namespace
  -
  -        if (uri.length() == 0) {
  -            return createQName(pname.getLocalPart());
  -        } else {
  -            String prefix = ensurePrefix(uri);
  -            return createQName(uri, pname.getLocalPart(), prefix);
  -        }
  -    }
  -
  -
  -    String ensurePrefix(String uri)
  -    {
           assert uri != null;  //QName's should use "" for no namespace
           assert (uri.length() > 0);
   
  -        String prefix = namespaceContext.getPrefix(uri);
  +        String prefix = getNamespaceContext().getPrefix(uri);
           if (prefix == null) {
               prefix = bindNextPrefix(uri);
           }
  @@ -214,459 +72,34 @@
           return prefix;
       }
   
  -
       private String bindNextPrefix(final String uri)
  +        throws XmlException
  +    {
  +        String prefix = findNextPrefix(uri);
  +        bindNamespace(prefix, uri);
  +        return prefix;
  +    }
  +
  +    protected final String findNextPrefix(final String uri)
       {
           assert uri != null;
           String testuri;
           String prefix;
           do {
               prefix = NSPREFIX + (++prefixCnt);
  -            testuri = namespaceContext.getNamespaceURI(prefix);
  +            testuri = getNamespaceContext().getNamespaceURI(prefix);
           }
           while (testuri != null);
           assert prefix != null;
  -        namespaceContext.bindNamespace(prefix, uri);
           return prefix;
       }
   
  -    //TODO: improve this method by going up the type hierarchy
  -    RuntimeBindingType determineRuntimeBindingType(RuntimeBindingType expected,
  -                                                   Object instance)
  -        throws XmlException
  -    {
  -        if (instance == null ||
  -            expected.isJavaPrimitive() ||
  -            expected.isJavaFinal()) {
  -            return expected;
  -        }
  -
  -        final Class instance_class = instance.getClass();
  -        if (instance_class.equals(expected.getJavaType())) {
  -            return expected;
  -        }
  -
  -        final BindingTypeName type_name = expected.getBindingType().getName();
  -        if (!instance_class.getName().equals(type_name.getJavaName().toString())) {
  -            final BindingType actual_type =
  -                MarshallerImpl.lookupBindingType(instance_class,
  -                                                 type_name.getJavaName(),
  -                                                 type_name.getXmlName(),
  -                                                 bindingLoader);
  -            if (actual_type != null) {
  -                return typeTable.createRuntimeType(actual_type, bindingLoader);
  -            }
  -            //else go with original type and hope for the best...
  -        }
  -        return expected;
  -    }
  -
  -    public void require(int i, String s, String s1)
  -        throws XMLStreamException
  -    {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  -    }
  +    protected abstract void bindNamespace(String prefix, String uri)
  +        throws XmlException;
   
  -    public String getElementText() throws XMLStreamException
  -    {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  -    }
  -
  -    public int nextTag() throws XMLStreamException
  -    {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  -    }
  -
  -    public boolean hasNext() throws XMLStreamException
  -    {
  -        if (visitorStack.isEmpty()) {
  -            return (currVisitor.getState() != XmlTypeVisitor.END);
  -        } else {
  -            return true;
  -        }
  -    }
  -
  -    public void close() throws XMLStreamException
  -    {
  -        //TODO: consider freeing memory
  -    }
  -
  -    public String getNamespaceURI(String s)
  -    {
  -        if (s == null)
  -            throw new IllegalArgumentException("prefix cannot be null");
  -
  -        return getNamespaceContext().getNamespaceURI(s);
  -    }
  -
  -    public boolean isStartElement()
  -    {
  -        return currentEventType == START_ELEMENT;
  -    }
  -
  -    public boolean isEndElement()
  -    {
  -        return currentEventType == END_ELEMENT;
  -    }
  -
  -    public boolean isCharacters()
  -    {
  -        return currentEventType == CHARACTERS;
  -    }
  -
  -    public boolean isWhiteSpace()
  -    {
  -        if (!isCharacters()) return false;
  -        CharSequence seq = currVisitor.getCharData();
  -        return XmlWhitespace.isAllSpace(seq);
  -    }
  -
  -    public String getAttributeValue(String uri, String lname)
  -    {
  -        initAttributes();
  -
  -        //TODO: do better than this basic and slow implementation
  -        for (int i = 0, len = getAttributeCount(); i < len; i++) {
  -            final QName aname = getAttributeName(i);
  -
  -            if (lname.equals(aname.getLocalPart())) {
  -                if (uri == null || uri.equals(aname.getNamespaceURI()))
  -                    return getAttributeValue(i);
  -            }
  -        }
  -        return null;
  -    }
  -
  -    public int getAttributeCount()
  -    {
  -        initAttributes();
  -        if (attributeHolder == null)
  -            return 0;
  -        else
  -            return attributeHolder.getAttributeCount();
  -    }
  -
  -    public QName getAttributeName(int i)
  -    {
  -        initAttributes();
  -        assert attributeHolder != null;
  -        return attributeHolder.getAttributeName(i);
  -    }
  -
  -    public String getAttributeNamespace(int i)
  -    {
  -        initAttributes();
  -        assert attributeHolder != null;
  -        return attributeHolder.getAttributeNamespace(i);
  -    }
  -
  -    public String getAttributeLocalName(int i)
  -    {
  -        initAttributes();
  -        assert attributeHolder != null;
  -        return attributeHolder.getAttributeLocalName(i);
  -    }
  -
  -    public String getAttributePrefix(int i)
  -    {
  -        initAttributes();
  -        assert attributeHolder != null;
  -        return attributeHolder.getAttributePrefix(i);
  -    }
  -
  -    public String getAttributeType(int i)
  -    {
  -        attributeRangeCheck(i);
  -        return ATTRIBUTE_XML_TYPE;
  -    }
  -
  -    public String getAttributeValue(int i)
  -    {
  -        initAttributes();
  -        assert attributeHolder != null;
  -        return attributeHolder.getAttributeValue(i);
  -    }
  -
  -    public boolean isAttributeSpecified(int i)
  -    {
  -        initAttributes();
  -
  -        assert attributeHolder != null;
  -        return attributeHolder.isAttributeSpecified(i);
  -    }
  -
  -    public int getNamespaceCount()
  -    {
  -        initAttributes();
  -        return namespaceContext.getCurrentScopeNamespaceCount();
  -    }
  -
  -
  -    public String getNamespacePrefix(int i)
  -    {
  -        initAttributes();
  -        return namespaceContext.getCurrentScopeNamespacePrefix(i);
  -    }
  -
  -    public String getNamespaceURI(int i)
  -    {
  -        initAttributes();
  -        return namespaceContext.getCurrentScopeNamespaceURI(i);
  -    }
  -
  -    public NamespaceContext getNamespaceContext()
  -    {
  -        return namespaceContext;
  -    }
  -
  -    public int getEventType()
  -    {
  -        return currentEventType;
  -    }
  -
  -    public String getText()
  -    {
  -        CharSequence seq = currVisitor.getCharData();
  -        return seq.toString();
  -    }
  -
  -    public char[] getTextCharacters()
  -    {
  -        CharSequence seq = currVisitor.getCharData();
  -        if (seq instanceof String) {
  -            return seq.toString().toCharArray();
  -        }
  -
  -        final int len = seq.length();
  -        char[] val = new char[len];
  -        for (int i = 0; i < len; i++) {
  -            val[i] = seq.charAt(i);
  -        }
  -        return val;
  -    }
  -
  -
  -    public int getTextCharacters(int sourceStart,
  -                                 char[] target,
  -                                 int targetStart,
  -                                 int length)
  -        throws XMLStreamException
  -    {
  -        if (length < 0)
  -            throw new IndexOutOfBoundsException("negative length: " + length);
  -
  -        if (targetStart < 0)
  -            throw new IndexOutOfBoundsException("negative targetStart: " + targetStart);
  -
  -        final int target_length = target.length;
  -        if (targetStart >= target_length)
  -            throw new IndexOutOfBoundsException("targetStart(" + targetStart + ") past end of target(" + target_length + ")");
  -
  -        if ((targetStart + length) > target_length) {
  -            throw new IndexOutOfBoundsException("insufficient data in target(length is " + target_length + ")");
  -        }
  -
  -        CharSequence seq = currVisitor.getCharData();
  -        if (seq instanceof String) {
  -            final String s = seq.toString();
  -            s.getChars(sourceStart, sourceStart + length, target, targetStart);
  -            return length;
  -        }
  -
  -        //TODO: review this code
  -        int cnt = 0;
  -        for (int src_idx = sourceStart, dest_idx = targetStart; cnt < length; cnt++) {
  -            target[dest_idx++] = seq.charAt(src_idx++);
  -        }
  -        return cnt;
  -    }
  -
  -    public int getTextStart()
  -    {
  -        return 0;
  -    }
  -
  -    public int getTextLength()
  -    {
  -        return currVisitor.getCharData().length();
  -    }
  -
  -    public String getEncoding()
  -    {
  -        return null;
  -    }
  -
  -    public boolean hasText()
  -    {
  -        //we'll likely never return some of these but just in case...
  -        switch (currentEventType) {
  -            case CHARACTERS:
  -            case COMMENT:
  -            case SPACE:
  -            case ENTITY_REFERENCE:
  -            case DTD:
  -                return true;
  -            default:
  -                return false;
  -        }
  -    }
  -
  -    public Location getLocation()
  -    {
  -        //TODO: something better than this, like give the object instance
  -        return EmptyLocation.getInstance();
  -    }
  -
  -    public QName getName()
  -    {
  -        return currVisitor.getName();
  -    }
  -
  -    public String getLocalName()
  -    {
  -        return currVisitor.getLocalPart();
  -    }
  -
  -    public boolean hasName()
  -    {
  -        return ((currentEventType == XMLStreamReader.START_ELEMENT) ||
  -            (currentEventType == XMLStreamReader.END_ELEMENT));
  -    }
  -
  -    public String getNamespaceURI()
  -    {
  -        return currVisitor.getNamespaceURI();
  -    }
  -
  -    public String getPrefix()
  -    {
  -        return currVisitor.getPrefix();
  -    }
  -
  -    public String getVersion()
  -    {
  -        return null;
  -    }
  -
  -    public boolean isStandalone()
  -    {
  -        return false;
  -    }
  -
  -    public boolean standaloneSet()
  -    {
  -        return false;
  -    }
  -
  -    public String getCharacterEncodingScheme()
  -    {
  -        return null;
  -    }
  -
  -    public String getPITarget()
  -    {
  -        throw new IllegalStateException();
  -    }
  -
  -    public String getPIData()
  -    {
  -        throw new IllegalStateException();
  -    }
  -
  -    protected void initAttributes()
  -    {
  -        if (!initedAttributes) {
  -            try {
  -                if (attributeHolder != null) {
  -                    attributeHolder.clear();
  -                }
  -                currVisitor.initAttributes();
  -            }
  -            catch (XmlException e) {
  -                //public attribute interfaces of XMLStreamReader
  -                //force us into this behavior
  -                throw new XmlRuntimeException(e);
  -            }
  -            initedAttributes = true;
  -        }
  -    }
  -
  -    private void attributeRangeCheck(int i)
  -    {
  -        final int att_cnt = getAttributeCount();
  -        if (i >= att_cnt) {
  -            String msg = "index" + i + " invalid. " +
  -                " attribute count is " + att_cnt;
  -            throw new IndexOutOfBoundsException(msg);
  -        }
  -    }
  -
  -
  -    public String toString()
  -    {
  -        return "org.apache.xmlbeans.impl.marshal.MarshalResult{" +
  -            "currentEvent=" + XmlStreamUtils.printEvent(this) +
  -            ", visitorStack=" + (visitorStack == null ? null : "size:" + visitorStack.size() + visitorStack) +
  -            ", currVisitor=" + currVisitor +
  -            "}";
  -    }
  -
  -    Collection getErrorCollection()
  -    {
  -        return errors;
  -    }
  -
  -    public RuntimeBindingTypeTable getTypeTable()
  -    {
  -        return typeTable;
  -    }
  -
  -    BindingLoader getBindingLoader()
  -    {
  -        return bindingLoader;
  -    }
  -
  -    public void addWarning(String msg)
  -    {
  -        XmlError e = XmlError.forMessage(msg, XmlError.SEVERITY_WARNING);
  -        getErrorCollection().add(e);
  -    }
  -
  -    private QName createQName(String uri, String localpart, String prefix)
  -    {
  -        return new QName(uri, localpart, prefix);
  -    }
  -
  -    private QName createQName(String localpart)
  -    {
  -        return new QName(localpart);
  -    }
  -
  -    void fillAndAddAttribute(QName qname_without_prefix,
  -                             String value)
  -    {
  -        final String uri = qname_without_prefix.getNamespaceURI();
  -        final String prefix;
  -        if (uri.length() == 0) {
  -            prefix = null;
  -        } else {
  -            prefix = ensurePrefix(uri);
  -        }
  -        addAttribute(uri, qname_without_prefix.getLocalPart(), prefix, value);
  -    }
  -
  -    private void addAttribute(String namespaceURI,
  -                              String localPart,
  -                              String prefix,
  -                              String value)
  -    {
  -        if (attributeHolder == null) {
  -            attributeHolder = new AttributeHolder();
  -        }
  -        attributeHolder.add(namespaceURI, localPart, prefix, value);
  -    }
   
       void addXsiNilAttribute()
  +        throws XmlException
       {
           addAttribute(MarshalStreamUtils.XSI_NS,
                        MarshalStreamUtils.XSI_NIL_ATTR,
  @@ -674,7 +107,8 @@
                        NamedXmlTypeVisitor.TRUE_LEX);
       }
   
  -    void addXsiTypeAttribute(RuntimeBindingType rtt)
  +    final void addXsiTypeAttribute(RuntimeBindingType rtt)
  +        throws XmlException
       {
           final QName schema_type = rtt.getSchemaTypeName();
           final String type_uri = schema_type.getNamespaceURI();
  @@ -695,98 +129,68 @@
       }
   
   
  -    private static final class BindingTypeVisitor
  -        implements org.apache.xmlbeans.impl.binding.bts.BindingTypeVisitor
  +    void fillAndAddAttribute(QName qname_without_prefix,
  +                             String value)
  +        throws XmlException
       {
  -        private final MarshalResult marshalResult;
  -
  -        private Object parentObject;
  -        private RuntimeBindingProperty runtimeBindingProperty;
  -
  -        private XmlTypeVisitor xmlTypeVisitor;
  -
  -        public BindingTypeVisitor(MarshalResult marshalResult)
  -        {
  -            this.marshalResult = marshalResult;
  -        }
  -
  -        public void setParentObject(Object parentObject)
  -        {
  -            this.parentObject = parentObject;
  -        }
  -
  -        public void setRuntimeBindingProperty(RuntimeBindingProperty runtimeBindingProperty)
  -        {
  -            this.runtimeBindingProperty = runtimeBindingProperty;
  -        }
  -
  -        public XmlTypeVisitor getXmlTypeVisitor()
  -        {
  -            return xmlTypeVisitor;
  +        final String uri = qname_without_prefix.getNamespaceURI();
  +        if (uri.length() == 0) {
  +            addAttribute(qname_without_prefix.getLocalPart(), value);
  +        } else {
  +            addAttribute(uri, qname_without_prefix.getLocalPart(),
  +                         ensurePrefix(uri), value);
           }
  +    }
   
  -        public void visit(BuiltinBindingType builtinBindingType)
  -            throws XmlException
  -        {
  -            xmlTypeVisitor = new SimpleTypeVisitor(runtimeBindingProperty,
  -                                                   parentObject,
  -                                                   marshalResult);
  -        }
   
  -        public void visit(ByNameBean byNameBean)
  -            throws XmlException
  -        {
  -            xmlTypeVisitor = new ByNameTypeVisitor(runtimeBindingProperty,
  -                                                   parentObject,
  -                                                   marshalResult);
  -        }
  +    protected abstract void addAttribute(String lname,
  +                                         String value)
  +        throws XmlException;
   
  -        public void visit(SimpleContentBean simpleContentBean)
  -            throws XmlException
  -        {
  -            xmlTypeVisitor = new SimpleContentTypeVisitor(runtimeBindingProperty,
  -                                                          parentObject,
  -                                                          marshalResult);
  -        }
  +    protected abstract void addAttribute(String uri,
  +                                         String lname,
  +                                         String prefix,
  +                                         String value)
  +        throws XmlException;
   
  -        public void visit(SimpleBindingType simpleBindingType)
  -            throws XmlException
  -        {
  -            xmlTypeVisitor = new SimpleTypeVisitor(runtimeBindingProperty,
  -                                                   parentObject,
  -                                                   marshalResult);
  -        }
   
  -        public void visit(JaxrpcEnumType jaxrpcEnumType)
  -            throws XmlException
  -        {
  -            xmlTypeVisitor = new SimpleTypeVisitor(runtimeBindingProperty,
  -                                                   parentObject,
  -                                                   marshalResult);
  +    RuntimeBindingType determineRuntimeBindingType(RuntimeBindingType expected,
  +                                                   Object instance)
  +        throws XmlException
  +    {
  +        if (instance == null ||
  +            expected.isJavaPrimitive() ||
  +            expected.isJavaFinal()) {
  +            return expected;
           }
   
  -        public void visit(SimpleDocumentBinding simpleDocumentBinding)
  -            throws XmlException
  -        {
  -            throw new AssertionError("unexpected type: " + simpleDocumentBinding);
  +        final Class instance_class = instance.getClass();
  +        if (instance_class.equals(expected.getJavaType())) {
  +            return expected;
           }
   
  -        public void visit(WrappedArrayType wrappedArrayType)
  -            throws XmlException
  -        {
  -            xmlTypeVisitor = new WrappedArrayTypeVisitor(runtimeBindingProperty,
  -                                                         parentObject,
  -                                                         marshalResult);
  +        final BindingTypeName type_name = expected.getBindingType().getName();
  +        //TODO: avoid expensive comparison here by having RuntimeBindingType
  +        //cache stuff to make it faster.
  +        if (!type_name.getJavaName().isNameForClass(instance_class)) {
  +            //NOTE: lookupBindingType will go up the type heirarchy
  +            final BindingType actual_type =
  +                MarshallerImpl.lookupBindingType(instance_class,
  +                                                 type_name.getJavaName(),
  +                                                 type_name.getXmlName(),
  +                                                 bindingLoader);
  +            if (actual_type != null) {
  +                return typeTable.createRuntimeType(actual_type, bindingLoader);
  +            }
  +            //else go with original type and hope for the best...
           }
  +        return expected;
  +    }
   
  -        public void visit(ListArrayType listArrayType)
  -            throws XmlException
  -        {
  -            xmlTypeVisitor = new SimpleTypeVisitor(runtimeBindingProperty,
  -                                                   parentObject,
  -                                                   marshalResult);
  -        }
   
  +    Collection getErrorCollection()
  +    {
  +        return errors;
       }
   
   }
  
  
  
  1.30      +93 -65    xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshallerImpl.java
  
  Index: MarshallerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshallerImpl.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- MarshallerImpl.java	30 Apr 2004 21:31:48 -0000	1.29
  +++ MarshallerImpl.java	6 May 2004 17:47:13 -0000	1.30
  @@ -25,7 +25,6 @@
   import org.apache.xmlbeans.impl.binding.bts.JavaTypeName;
   import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
   import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
  -import org.apache.xmlbeans.impl.common.XmlReaderToWriter;
   
   import javax.xml.namespace.NamespaceContext;
   import javax.xml.namespace.QName;
  @@ -59,8 +58,16 @@
                                      NamespaceContext nscontext)
           throws XmlException
       {
  -        JavaTypeName jname = determineJavaType(obj);
  -        BindingTypeName root_elem_btype = loader.lookupElementFor(jname);
  +        final JavaTypeName jname = determineJavaType(obj);
  +        final XmlTypeName elem = lookupRootElementName(jname);
  +        final BindingType btype = loadBindingTypeForGlobalElem(elem, jname, obj);
  +        return createMarshalResult(btype, elem.getQName(), nscontext, obj);
  +    }
  +
  +    private XmlTypeName lookupRootElementName(final JavaTypeName jname)
  +        throws XmlException
  +    {
  +        final BindingTypeName root_elem_btype = loader.lookupElementFor(jname);
           if (root_elem_btype == null) {
               final String msg = "failed to find root " +
                   "element corresponding to " + jname;
  @@ -69,28 +76,14 @@
   
           final XmlTypeName elem = root_elem_btype.getXmlName();
           assert elem.getComponentType() == XmlTypeName.ELEMENT;
  -        final QName elem_qn = elem.getQName();
  -
  -        //get type for this element/object pair
  -        final BindingTypeName type_name = loader.lookupTypeFor(jname);
  -        if (type_name == null) {
  -            String msg = "failed to lookup type for " + jname;
  -            throw new XmlException(msg);
  -        }
  -        final BindingType btype = loader.getBindingType(type_name);
  -        if (btype == null) {
  -            String msg = "failed to load type " + type_name;
  -            throw new XmlException(msg);
  -        }
  -
  -        return createMarshalResult(btype, elem_qn, nscontext, obj);
  +        return elem;
       }
   
   
  -    private MarshalResult createMarshalResult(final BindingType btype,
  -                                              QName elem_qn,
  -                                              NamespaceContext nscontext,
  -                                              Object obj)
  +    private PullMarshalResult createMarshalResult(final BindingType btype,
  +                                                  QName elem_qn,
  +                                                  NamespaceContext nscontext,
  +                                                  Object obj)
           throws XmlException
       {
           assert btype != null;
  @@ -130,13 +123,7 @@
       public void marshal(XMLStreamWriter writer, Object obj)
           throws XmlException
       {
  -        XMLStreamReader rdr = marshal(obj, writer.getNamespaceContext());
  -        try {
  -            XmlReaderToWriter.writeAll(rdr, writer);
  -        }
  -        catch (XMLStreamException e) {
  -            throw new XmlException(e);
  -        }
  +        marshal(writer, obj, null);
       }
   
       public void marshal(XMLStreamWriter writer, Object obj, XmlOptions options)
  @@ -144,8 +131,37 @@
       {
           //TODO: javadoc that pretty is not supported here.
   
  +        final JavaTypeName jname = determineJavaType(obj);
  +        final XmlTypeName elem = lookupRootElementName(jname);
  +        BindingType btype = loadBindingTypeForGlobalElem(elem, jname, obj);
  +
           String encoding = getEncoding(options);
  -        marshalToOutputStream(obj, encoding, writer);
  +        if (encoding != null)
  +            try {
  +                writer.writeStartDocument(encoding, XML_VERSION);
  +            }
  +            catch (XMLStreamException e) {
  +                throw new XmlException(e);
  +            }
  +
  +        marshalBindingType(writer, btype, obj, elem.getQName());
  +    }
  +
  +    private BindingType loadBindingTypeForGlobalElem(final XmlTypeName elem,
  +                                                     final JavaTypeName jname,
  +                                                     Object obj)
  +        throws XmlException
  +    {
  +        final XmlTypeName elem_type =
  +            determineDocumentType(elem).getTypeOfElement();
  +        final BindingType btype = loadBindingType(elem_type, jname, loader);
  +        if (btype == null) {
  +            final String msg = "failed to find a suitable binding type for" +
  +                " use in marshalling object \"" + obj + "\". " +
  +                " using schema type: " + elem_type;
  +            throw new XmlException(msg);
  +        }
  +        return btype;
       }
   
       private static String getEncoding(XmlOptions options)
  @@ -159,8 +175,7 @@
       {
           try {
               XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
  -            XMLStreamReader rdr = marshal(obj, writer.getNamespaceContext());
  -            XmlReaderToWriter.writeAll(rdr, writer);
  +            marshal(writer, obj);
           }
           catch (XMLStreamException xse) {
               throw new XmlException(xse);
  @@ -271,11 +286,11 @@
                                    elementName, obj, loader);
       }
   
  -    static BindingType lookupBindingType(XmlTypeName schema_type,
  -                                         String javaType,
  -                                         QName elementName,
  -                                         Object obj,
  -                                         BindingLoader loader)
  +    private static BindingType lookupBindingType(XmlTypeName schema_type,
  +                                                 String javaType,
  +                                                 QName elementName,
  +                                                 Object obj,
  +                                                 BindingLoader loader)
           throws XmlException
       {
           final BindingType type =
  @@ -301,15 +316,31 @@
                               String javaType)
           throws XmlException
       {
  -        XMLStreamReader rdr = marshalType(obj, elementName, schemaType,
  -                                          javaType,
  -                                          writer.getNamespaceContext());
  -        try {
  -            XmlReaderToWriter.writeAll(rdr, writer);
  -        }
  -        catch (XMLStreamException e) {
  -            throw new XmlException(e);
  -        }
  +        final BindingType btype = lookupBindingType(schemaType, javaType,
  +                                                    elementName, obj, loader);
  +        assert btype != null;
  +
  +        marshalBindingType(writer, btype, obj, elementName);
  +    }
  +
  +    private void marshalBindingType(XMLStreamWriter writer,
  +                                    final BindingType btype,
  +                                    Object obj,
  +                                    QName elementName)
  +        throws XmlException
  +    {
  +        final RuntimeBindingType runtime_type =
  +            typeTable.createRuntimeType(btype, loader);
  +
  +        runtime_type.checkInstance(obj);
  +
  +        RuntimeGlobalProperty prop =
  +            new RuntimeGlobalProperty(elementName, runtime_type);
  +
  +        final PushMarshalResult pmr =
  +            new PushMarshalResult(loader, typeTable, writer, null);
  +
  +        pmr.marshalType(obj, prop);
       }
   
       public void marshalElement(XMLStreamWriter writer,
  @@ -322,15 +353,14 @@
           if (writer == null)
               throw new IllegalArgumentException("null writer");
   
  -        final XMLStreamReader rdr =
  -            marshalElement(obj, elementName, javaType, options);
  +        final XmlTypeName elem_name =
  +            XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, elementName);
   
  -        try {
  -            XmlReaderToWriter.writeAll(rdr, writer);
  -        }
  -        catch (XMLStreamException e) {
  -            throw new XmlException(e);
  -        }
  +        final BindingType btype =
  +            loadBindingTypeForGlobalElem(elem_name,
  +                                         determineJavaType(obj), obj);
  +
  +        marshalBindingType(writer, btype, obj, elementName);
       }
   
       public void marshalType(XMLStreamWriter writer,
  @@ -396,7 +426,14 @@
       {
           final XmlTypeName type_name =
               XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, global_element);
  -        BindingType doc_binding_type = getPojoBindingType(type_name);
  +        return determineDocumentType(type_name);
  +    }
  +
  +    private SimpleDocumentBinding determineDocumentType(XmlTypeName global_element)
  +        throws XmlException
  +    {
  +        BindingType doc_binding_type = getPojoBindingType(global_element);
  +        assert doc_binding_type != null;
           return (SimpleDocumentBinding)doc_binding_type;
       }
   
  @@ -418,6 +455,7 @@
               throw new XmlException(msg);
           }
   
  +        assert bt != null;
           return bt;
       }
   
  @@ -488,16 +526,6 @@
       {
           BindingTypeName btname = BindingTypeName.forPair(jname, xname);
           return loader.getBindingType(btname);
  -    }
  -
  -    BindingLoader getLoader()
  -    {
  -        return loader;
  -    }
  -
  -    RuntimeBindingTypeTable getTypeTable()
  -    {
  -        return typeTable;
       }
   
   }
  
  
  
  1.12      +1 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NamedXmlTypeVisitor.java
  
  Index: NamedXmlTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/NamedXmlTypeVisitor.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- NamedXmlTypeVisitor.java	28 Apr 2004 00:01:38 -0000	1.11
  +++ NamedXmlTypeVisitor.java	6 May 2004 17:47:13 -0000	1.12
  @@ -34,7 +34,7 @@
   
       NamedXmlTypeVisitor(Object parentObject,
                           RuntimeBindingProperty property,
  -                        MarshalResult result)
  +                        PullMarshalResult result)
           throws XmlException
       {
           super(parentObject, property, result);
  
  
  
  1.8       +1 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/QNameTypeConverter.java
  
  Index: QNameTypeConverter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/QNameTypeConverter.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- QNameTypeConverter.java	6 Apr 2004 00:53:09 -0000	1.7
  +++ QNameTypeConverter.java	6 May 2004 17:47:13 -0000	1.8
  @@ -45,6 +45,7 @@
   
       //non simple types can throw a runtime exception
       public CharSequence print(Object value, MarshalResult result)
  +        throws XmlException
       {
           QName val = (QName)value;
           final String uri = val.getNamespaceURI();
  
  
  
  1.2       +2 -2      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RefdObjectVisitor.java
  
  Index: RefdObjectVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RefdObjectVisitor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RefdObjectVisitor.java	30 Apr 2004 21:31:48 -0000	1.1
  +++ RefdObjectVisitor.java	6 May 2004 17:47:13 -0000	1.2
  @@ -18,7 +18,6 @@
   import org.apache.xmlbeans.XmlException;
   
   import javax.xml.namespace.QName;
  -import java.lang.AssertionError;
   
   abstract class RefdObjectVisitor
       extends NamedXmlTypeVisitor
  @@ -30,7 +29,7 @@
   
       public RefdObjectVisitor(RuntimeBindingProperty property,
                                Object obj,
  -                             MarshalResult result,
  +                             PullMarshalResult result,
                                int id)
           throws XmlException
       {
  @@ -62,6 +61,7 @@
       }
   
       protected abstract QName getRefQName();
  +
       protected abstract String getRefValue();
   
       public XmlTypeVisitor getCurrentChild()
  
  
  
  1.5       +1 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentTypeVisitor.java
  
  Index: SimpleContentTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentTypeVisitor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleContentTypeVisitor.java	4 May 2004 22:11:57 -0000	1.4
  +++ SimpleContentTypeVisitor.java	6 May 2004 17:47:13 -0000	1.5
  @@ -24,7 +24,7 @@
   
       public SimpleContentTypeVisitor(RuntimeBindingProperty property,
                                       Object obj,
  -                                    MarshalResult result)
  +                                    PullMarshalResult result)
           throws XmlException
       {
           super(property, obj, result);
  
  
  
  1.3       +3 -2      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentVisitor.java
  
  Index: SimpleContentVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentVisitor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleContentVisitor.java	4 May 2004 22:11:57 -0000	1.2
  +++ SimpleContentVisitor.java	6 May 2004 17:47:13 -0000	1.3
  @@ -24,8 +24,9 @@
   
       private int state = START;
   
  -    public SimpleContentVisitor(RuntimeBindingProperty property, Object obj,
  -                                MarshalResult result)
  +    public SimpleContentVisitor(RuntimeBindingProperty property,
  +                                Object obj,
  +                                PullMarshalResult result)
           throws XmlException
       {
           super(obj, property, result);
  
  
  
  1.18      +1 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleTypeVisitor.java
  
  Index: SimpleTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleTypeVisitor.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SimpleTypeVisitor.java	27 Apr 2004 02:36:14 -0000	1.17
  +++ SimpleTypeVisitor.java	6 May 2004 17:47:13 -0000	1.18
  @@ -23,7 +23,7 @@
   
       public SimpleTypeVisitor(RuntimeBindingProperty property,
                                Object obj,
  -                             MarshalResult result)
  +                             PullMarshalResult result)
           throws XmlException
       {
           super(property, obj, result);
  
  
  
  1.2       +3 -3      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Soap11RefdObjectVisitor.java
  
  Index: Soap11RefdObjectVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Soap11RefdObjectVisitor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Soap11RefdObjectVisitor.java	30 Apr 2004 21:31:48 -0000	1.1
  +++ Soap11RefdObjectVisitor.java	6 May 2004 17:47:13 -0000	1.2
  @@ -27,9 +27,9 @@
       private static final String REF_PREFIX = '#' + SoapMarshalResult.ID_PREFIX;
   
       public Soap11RefdObjectVisitor(RuntimeBindingProperty property,
  -                             Object obj,
  -                             MarshalResult result,
  -                             int id)
  +                                   Object obj,
  +                                   PullMarshalResult result,
  +                                   int id)
           throws XmlException
       {
           super(property, obj, result, id);
  
  
  
  1.2       +2 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SoapMarshalResult.java
  
  Index: SoapMarshalResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SoapMarshalResult.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SoapMarshalResult.java	30 Apr 2004 21:31:48 -0000	1.1
  +++ SoapMarshalResult.java	6 May 2004 17:47:13 -0000	1.2
  @@ -23,7 +23,7 @@
   import javax.xml.namespace.QName;
   
   abstract class SoapMarshalResult
  -    extends MarshalResult
  +    extends PullMarshalResult
   {
       private final ObjectRefTable objectRefTable;
       private final boolean writingMultiRefdObjs;
  @@ -60,6 +60,7 @@
       }
   
       private void topLevelIdInit(Object top_lvl_obj)
  +        throws XmlException
       {
           initAttributes();
   
  
  
  
  1.6       +2 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SoapMarshallerImpl.java
  
  Index: SoapMarshallerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SoapMarshallerImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SoapMarshallerImpl.java	30 Apr 2004 21:31:48 -0000	1.5
  +++ SoapMarshallerImpl.java	6 May 2004 17:47:13 -0000	1.6
  @@ -79,7 +79,8 @@
               objectRefTable = new ObjectRefTable();
           }
   
  -        final MarshalResult retval =
  +
  +        final SoapMarshalResult retval =
               createMarshalResult(nscontext, prop, obj, options, false);
   
           addObjectGraphToRefTable(obj, runtime_type, prop, retval);
  
  
  
  1.8       +1 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayTypeVisitor.java
  
  Index: WrappedArrayTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayTypeVisitor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WrappedArrayTypeVisitor.java	5 May 2004 16:49:31 -0000	1.7
  +++ WrappedArrayTypeVisitor.java	6 May 2004 17:47:13 -0000	1.8
  @@ -28,7 +28,7 @@
   
       WrappedArrayTypeVisitor(RuntimeBindingProperty property,
                               Object obj,
  -                            MarshalResult result)
  +                            PullMarshalResult result)
           throws XmlException
       {
           super(obj, property, result);
  
  
  
  1.14      +2 -2      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/XmlTypeVisitor.java
  
  Index: XmlTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/XmlTypeVisitor.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XmlTypeVisitor.java	27 Apr 2004 02:36:15 -0000	1.13
  +++ XmlTypeVisitor.java	6 May 2004 17:47:13 -0000	1.14
  @@ -23,11 +23,11 @@
   {
       private final Object parentObject;
       private final RuntimeBindingProperty bindingProperty;
  -    protected final MarshalResult marshalResult;
  +    protected final PullMarshalResult marshalResult;
   
       XmlTypeVisitor(Object obj,
                      RuntimeBindingProperty property,
  -                   MarshalResult result)
  +                   PullMarshalResult result)
           throws XmlException
       {
           this.parentObject = obj;
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/PullMarshalResult.java
  
  Index: PullMarshalResult.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xmlbeans.XmlRuntimeException;
  import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  import org.apache.xmlbeans.impl.binding.bts.BindingType;
  import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
  import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingType;
  import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
  import org.apache.xmlbeans.impl.binding.bts.JaxrpcEnumType;
  import org.apache.xmlbeans.impl.binding.bts.ListArrayType;
  import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
  import org.apache.xmlbeans.impl.binding.bts.SimpleContentBean;
  import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
  import org.apache.xmlbeans.impl.binding.bts.WrappedArrayType;
  import org.apache.xmlbeans.impl.common.XmlStreamUtils;
  import org.apache.xmlbeans.impl.common.XmlWhitespace;
  import org.apache.xmlbeans.impl.marshal.util.AttributeHolder;
  
  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;
  
  
  abstract class PullMarshalResult
      extends MarshalResult
      implements XMLStreamReader
  {
      private final BindingTypeVisitor bindingTypeVisitor =
          new BindingTypeVisitor(this);
      private final ScopedNamespaceContext namespaceContext;
      private final Stack visitorStack = new Stack();
  
      private XmlTypeVisitor currVisitor;
      private int currentEventType = XMLStreamReader.START_ELEMENT;
      private boolean initedAttributes = false;
      private AttributeHolder attributeHolder;
  
      private static final String ATTRIBUTE_XML_TYPE = "CDATA";
  
  
      //TODO: REVIEW: consider ways to reduce the number of parameters here
      PullMarshalResult(BindingLoader loader,
                        RuntimeBindingTypeTable tbl,
                        NamespaceContext root_nsctx,
                        RuntimeBindingProperty property,
                        Object obj,
                        XmlOptions options)
          throws XmlException
      {
          super(loader, tbl, options);
          namespaceContext = new ScopedNamespaceContext(root_nsctx);
          namespaceContext.openScope();
          currVisitor = createInitialVisitor(property, obj);
      }
  
      //reset to initial state but with new property and object
      protected void reset(RuntimeBindingProperty property, Object obj)
          throws XmlException
      {
          resetPrefixCount();
          namespaceContext.clear();
          namespaceContext.openScope();
          visitorStack.clear();
          currVisitor = createInitialVisitor(property, obj);
          currentEventType = XMLStreamReader.START_ELEMENT;
          initedAttributes = false;
          if (attributeHolder != null) attributeHolder.clear();
      }
  
      protected XmlTypeVisitor createInitialVisitor(RuntimeBindingProperty property,
                                                    Object obj)
          throws XmlException
      {
          return createVisitor(property, obj);
      }
  
      protected XmlTypeVisitor createVisitor(RuntimeBindingProperty property,
                                             Object obj)
          throws XmlException
      {
          assert property != null;
  
          BindingType btype = property.getRuntimeBindingType().getBindingType();
          final BindingTypeVisitor type_visitor = bindingTypeVisitor;
          type_visitor.setParentObject(obj);
          type_visitor.setRuntimeBindingProperty(property);
          btype.accept(type_visitor);
          return type_visitor.getXmlTypeVisitor();
      }
  
  
      public Object getProperty(String s)
          throws IllegalArgumentException
      {
          throw new UnsupportedOperationException("UNIMPLEMENTED");
      }
  
      public int next()
          throws XMLStreamException
      {
          switch (currVisitor.getState()) {
              case XmlTypeVisitor.START:
                  break;
              case XmlTypeVisitor.CHARS:
              case XmlTypeVisitor.END:
                  currVisitor = popVisitor();
                  break;
              default:
                  throw new AssertionError("invalid: " + currVisitor.getState());
          }
  
          try {
              return (currentEventType = advanceToNext());
          }
          catch (XmlException e) {
              //TODO: consider passing Location to exception ctor
              XMLStreamException xse = new XMLStreamException(e);
              xse.initCause(e);
              throw xse;
          }
      }
  
      private int advanceToNext()
          throws XmlException
      {
          final int next_state = currVisitor.advance();
          switch (next_state) {
              case XmlTypeVisitor.CONTENT:
                  pushVisitor(currVisitor);
                  currVisitor = currVisitor.getCurrentChild();
                  return START_ELEMENT;
              case XmlTypeVisitor.CHARS:
                  pushVisitor(currVisitor);
                  currVisitor = currVisitor.getCurrentChild();
                  return CHARACTERS;
              case XmlTypeVisitor.END:
                  return END_ELEMENT;
              default:
                  throw new AssertionError("bad state: " + next_state);
          }
      }
  
      private void pushVisitor(XmlTypeVisitor v)
      {
          visitorStack.push(v);
          namespaceContext.openScope();
          initedAttributes = false;
      }
  
      private XmlTypeVisitor popVisitor()
      {
          namespaceContext.closeScope();
          final XmlTypeVisitor tv = (XmlTypeVisitor)visitorStack.pop();
          return tv;
      }
  
  
  
      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
      {
          if (visitorStack.isEmpty()) {
              return (currVisitor.getState() != XmlTypeVisitor.END);
          } else {
              return true;
          }
      }
  
      public void close() throws XMLStreamException
      {
          //TODO: consider freeing memory
      }
  
      public String getNamespaceURI(String s)
      {
          if (s == null)
              throw new IllegalArgumentException("prefix cannot be null");
  
          return getNamespaceContext().getNamespaceURI(s);
      }
  
      public boolean isStartElement()
      {
          return currentEventType == START_ELEMENT;
      }
  
      public boolean isEndElement()
      {
          return currentEventType == END_ELEMENT;
      }
  
      public boolean isCharacters()
      {
          return currentEventType == CHARACTERS;
      }
  
      public boolean isWhiteSpace()
      {
          if (!isCharacters()) return false;
          CharSequence seq = currVisitor.getCharData();
          return XmlWhitespace.isAllSpace(seq);
      }
  
      public String getAttributeValue(String uri, String lname)
      {
          initAttributes();
  
          //TODO: do better than this basic and slow implementation
          for (int i = 0, len = getAttributeCount(); i < len; i++) {
              final QName aname = getAttributeName(i);
  
              if (lname.equals(aname.getLocalPart())) {
                  if (uri == null || uri.equals(aname.getNamespaceURI()))
                      return getAttributeValue(i);
              }
          }
          return null;
      }
  
      public int getAttributeCount()
      {
          initAttributes();
          if (attributeHolder == null)
              return 0;
          else
              return attributeHolder.getAttributeCount();
      }
  
      public QName getAttributeName(int i)
      {
          initAttributes();
          assert attributeHolder != null;
          return attributeHolder.getAttributeName(i);
      }
  
      public String getAttributeNamespace(int i)
      {
          initAttributes();
          assert attributeHolder != null;
          return attributeHolder.getAttributeNamespace(i);
      }
  
      public String getAttributeLocalName(int i)
      {
          initAttributes();
          assert attributeHolder != null;
          return attributeHolder.getAttributeLocalName(i);
      }
  
      public String getAttributePrefix(int i)
      {
          initAttributes();
          assert attributeHolder != null;
          return attributeHolder.getAttributePrefix(i);
      }
  
      public String getAttributeType(int i)
      {
          attributeRangeCheck(i);
          return ATTRIBUTE_XML_TYPE;
      }
  
      public String getAttributeValue(int i)
      {
          initAttributes();
          assert attributeHolder != null;
          return attributeHolder.getAttributeValue(i);
      }
  
      public boolean isAttributeSpecified(int i)
      {
          initAttributes();
  
          assert attributeHolder != null;
          return attributeHolder.isAttributeSpecified(i);
      }
  
      public int getNamespaceCount()
      {
          initAttributes();
          return namespaceContext.getCurrentScopeNamespaceCount();
      }
  
  
      public String getNamespacePrefix(int i)
      {
          initAttributes();
          return namespaceContext.getCurrentScopeNamespacePrefix(i);
      }
  
      public String getNamespaceURI(int i)
      {
          initAttributes();
          return namespaceContext.getCurrentScopeNamespaceURI(i);
      }
  
      public NamespaceContext getNamespaceContext()
      {
          return namespaceContext;
      }
  
      protected void bindNamespace(String prefix, String uri)
          throws XmlException
      {
          namespaceContext.bindNamespace(prefix, uri);
      }
  
      protected void addAttribute(String lname,
                                  String value)
          throws XmlException
      {
          addAttribute(null, lname, null, value);
      }
  
      public int getEventType()
      {
          return currentEventType;
      }
  
      public String getText()
      {
          CharSequence seq = currVisitor.getCharData();
          return seq.toString();
      }
  
      public char[] getTextCharacters()
      {
          CharSequence seq = currVisitor.getCharData();
          if (seq instanceof String) {
              return seq.toString().toCharArray();
          }
  
          final int len = seq.length();
          char[] val = new char[len];
          for (int i = 0; i < len; i++) {
              val[i] = seq.charAt(i);
          }
          return val;
      }
  
  
      public int getTextCharacters(int sourceStart,
                                   char[] target,
                                   int targetStart,
                                   int length)
          throws XMLStreamException
      {
          if (length < 0)
              throw new IndexOutOfBoundsException("negative length: " + length);
  
          if (targetStart < 0)
              throw new IndexOutOfBoundsException("negative targetStart: " + targetStart);
  
          final int target_length = target.length;
          if (targetStart >= target_length)
              throw new IndexOutOfBoundsException("targetStart(" + targetStart + ") past end of target(" + target_length + ")");
  
          if ((targetStart + length) > target_length) {
              throw new IndexOutOfBoundsException("insufficient data in target(length is " + target_length + ")");
          }
  
          CharSequence seq = currVisitor.getCharData();
          if (seq instanceof String) {
              final String s = seq.toString();
              s.getChars(sourceStart, sourceStart + length, target, targetStart);
              return length;
          }
  
          //TODO: review this code
          int cnt = 0;
          for (int src_idx = sourceStart, dest_idx = targetStart; cnt < length; cnt++) {
              target[dest_idx++] = seq.charAt(src_idx++);
          }
          return cnt;
      }
  
      public int getTextStart()
      {
          return 0;
      }
  
      public int getTextLength()
      {
          return currVisitor.getCharData().length();
      }
  
      public String getEncoding()
      {
          return null;
      }
  
      public boolean hasText()
      {
          //we'll likely never return some of these but just in case...
          switch (currentEventType) {
              case CHARACTERS:
              case COMMENT:
              case SPACE:
              case ENTITY_REFERENCE:
              case DTD:
                  return true;
              default:
                  return false;
          }
      }
  
      public Location getLocation()
      {
          //TODO: something better than this, like give the object instance
          return EmptyLocation.getInstance();
      }
  
      public QName getName()
      {
          return currVisitor.getName();
      }
  
      public String getLocalName()
      {
          return currVisitor.getLocalPart();
      }
  
      public boolean hasName()
      {
          return ((currentEventType == XMLStreamReader.START_ELEMENT) ||
              (currentEventType == XMLStreamReader.END_ELEMENT));
      }
  
      public String getNamespaceURI()
      {
          return currVisitor.getNamespaceURI();
      }
  
      public String getPrefix()
      {
          return currVisitor.getPrefix();
      }
  
      public String getVersion()
      {
          return null;
      }
  
      public boolean isStandalone()
      {
          return false;
      }
  
      public boolean standaloneSet()
      {
          return false;
      }
  
      public String getCharacterEncodingScheme()
      {
          return null;
      }
  
      public String getPITarget()
      {
          throw new IllegalStateException();
      }
  
      public String getPIData()
      {
          throw new IllegalStateException();
      }
  
      protected void initAttributes()
      {
          if (!initedAttributes) {
              try {
                  if (attributeHolder != null) {
                      attributeHolder.clear();
                  }
                  currVisitor.initAttributes();
              }
              catch (XmlException e) {
                  //public attribute interfaces of XMLStreamReader
                  //force us into this behavior
                  throw new XmlRuntimeException(e);
              }
              initedAttributes = true;
          }
      }
  
      private void attributeRangeCheck(int i)
      {
          final int att_cnt = getAttributeCount();
          if (i >= att_cnt) {
              String msg = "index" + i + " invalid. " +
                  " attribute count is " + att_cnt;
              throw new IndexOutOfBoundsException(msg);
          }
      }
  
  
      public String toString()
      {
          return "org.apache.xmlbeans.impl.marshal.MarshalResult{" +
              "currentEvent=" + XmlStreamUtils.printEvent(this) +
              ", visitorStack=" + (visitorStack == null ? null : "size:" + visitorStack.size() + visitorStack) +
              ", currVisitor=" + currVisitor +
              "}";
      }
  
      protected void addAttribute(String namespaceURI,
                                  String localPart,
                                  String prefix,
                                  String value)
      {
          if (attributeHolder == null) {
              attributeHolder = new AttributeHolder();
          }
          attributeHolder.add(namespaceURI, localPart, prefix, value);
      }
  
      private static final class BindingTypeVisitor
          implements org.apache.xmlbeans.impl.binding.bts.BindingTypeVisitor
      {
          private final PullMarshalResult marshalResult;
  
          private Object parentObject;
          private RuntimeBindingProperty runtimeBindingProperty;
  
          private XmlTypeVisitor xmlTypeVisitor;
  
          public BindingTypeVisitor(PullMarshalResult marshalResult)
          {
              this.marshalResult = marshalResult;
          }
  
          public void setParentObject(Object parentObject)
          {
              this.parentObject = parentObject;
          }
  
          public void setRuntimeBindingProperty(RuntimeBindingProperty runtimeBindingProperty)
          {
              this.runtimeBindingProperty = runtimeBindingProperty;
          }
  
          public XmlTypeVisitor getXmlTypeVisitor()
          {
              return xmlTypeVisitor;
          }
  
          public void visit(BuiltinBindingType builtinBindingType)
              throws XmlException
          {
              xmlTypeVisitor = new SimpleTypeVisitor(runtimeBindingProperty,
                                                     parentObject,
                                                     marshalResult);
          }
  
          public void visit(ByNameBean byNameBean)
              throws XmlException
          {
              xmlTypeVisitor = new ByNameTypeVisitor(runtimeBindingProperty,
                                                     parentObject,
                                                     marshalResult);
          }
  
          public void visit(SimpleContentBean simpleContentBean)
              throws XmlException
          {
              xmlTypeVisitor = new SimpleContentTypeVisitor(runtimeBindingProperty,
                                                            parentObject,
                                                            marshalResult);
          }
  
          public void visit(SimpleBindingType simpleBindingType)
              throws XmlException
          {
              xmlTypeVisitor = new SimpleTypeVisitor(runtimeBindingProperty,
                                                     parentObject,
                                                     marshalResult);
          }
  
          public void visit(JaxrpcEnumType jaxrpcEnumType)
              throws XmlException
          {
              xmlTypeVisitor = new SimpleTypeVisitor(runtimeBindingProperty,
                                                     parentObject,
                                                     marshalResult);
          }
  
          public void visit(SimpleDocumentBinding simpleDocumentBinding)
              throws XmlException
          {
              throw new AssertionError("unexpected type: " + simpleDocumentBinding);
          }
  
          public void visit(WrappedArrayType wrappedArrayType)
              throws XmlException
          {
              xmlTypeVisitor = new WrappedArrayTypeVisitor(runtimeBindingProperty,
                                                           parentObject,
                                                           marshalResult);
          }
  
          public void visit(ListArrayType listArrayType)
              throws XmlException
          {
              xmlTypeVisitor = new SimpleTypeVisitor(runtimeBindingProperty,
                                                     parentObject,
                                                     marshalResult);
          }
  
      }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/PushMarshalResult.java
  
  Index: PushMarshalResult.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  import org.apache.xmlbeans.impl.marshal.util.ArrayUtils;
  
  import javax.xml.namespace.NamespaceContext;
  import javax.xml.namespace.QName;
  import javax.xml.stream.XMLStreamException;
  import javax.xml.stream.XMLStreamWriter;
  import java.util.Iterator;
  
  class PushMarshalResult
      extends MarshalResult
      implements RuntimeTypeVisitor
  {
      //state fields
      private final XMLStreamWriter writer;
      private Object currObject;
      private RuntimeBindingProperty currProp;
  
      public PushMarshalResult(BindingLoader bindingLoader,
                               RuntimeBindingTypeTable typeTable,
                               XMLStreamWriter writer,
                               XmlOptions options)
          throws XmlException
      {
          super(bindingLoader,
                typeTable,
                options);
          this.writer = writer;
      }
  
      //this method can be called recursively
      private void marshalType(final Object obj,
                               final RuntimeBindingProperty prop,
                               final RuntimeBindingType actual_rtt)
          throws XmlException
      {
          try {
              writeStartElement(prop);
              if (obj == null) {
                  addXsiNilAttribute();
              } else if (actual_rtt != prop.getRuntimeBindingType()) {
                  addXsiTypeAttribute(actual_rtt);
              }
              currObject = obj;
              currProp = prop;
              actual_rtt.accept(this);
              writer.writeEndElement();
          }
          catch (XMLStreamException e) {
              throw new XmlException(e);
          }
      }
  
      private void writeStartElement(final RuntimeBindingProperty prop)
          throws XMLStreamException, XmlException
      {
          final QName prop_name = prop.getName();
          final String uri = prop_name.getNamespaceURI();
          if (uri.length() > 0) {
              String prefix = getNamespaceContext().getPrefix(uri);
              final String new_prefix;
              if (prefix == null) {
                  new_prefix = findNextPrefix(uri);
                  prefix = new_prefix;
              } else {
                  new_prefix = null;
              }
              assert prefix != null;
              writer.writeStartElement(prefix,
                                       prop_name.getLocalPart(),
                                       prop_name.getNamespaceURI());
              if (new_prefix != null) {
                  bindNamespace(new_prefix, uri);
              }
          } else {
              writer.writeStartElement(prop_name.getLocalPart());
          }
      }
  
      void marshalType(final Object obj,
                       final RuntimeBindingProperty prop)
          throws XmlException
      {
          final RuntimeBindingType actual_rtt =
              prop.getActualRuntimeType(obj, this);
          marshalType(obj, prop, actual_rtt);
      }
  
  
      public NamespaceContext getNamespaceContext()
      {
          return writer.getNamespaceContext();
      }
  
      protected void bindNamespace(String prefix, String uri)
          throws XmlException
      {
          try {
              writer.writeNamespace(prefix, uri);
          }
          catch (XMLStreamException e) {
              throw new XmlException(e);
          }
      }
  
      protected void addAttribute(String lname,
                                  String value)
          throws XmlException
      {
          try {
              writer.writeAttribute(lname, value);
          }
          catch (XMLStreamException e) {
              throw new XmlException(e);
          }
      }
  
      protected void addAttribute(String uri,
                                  String lname,
                                  String prefix,
                                  String value)
          throws XmlException
      {
          assert uri != null;
          assert lname != null;
          assert prefix != null;
          assert value != null;
  
          try {
              writer.writeAttribute(prefix, uri, lname, value);
          }
          catch (XMLStreamException e) {
              throw new XmlException(e);
          }
      }
  
  
      //====== visitor methods =======
  
      public void visit(BuiltinRuntimeBindingType builtinRuntimeBindingType)
          throws XmlException
      {
          writeCharData();
      }
  
      public void visit(ByNameRuntimeBindingType byNameRuntimeBindingType)
          throws XmlException
      {
          final Object curr_obj = currObject;
  
          writeAttributes(byNameRuntimeBindingType);
  
  
          final int elem_cnt =
              byNameRuntimeBindingType.getElementPropertyCount();
          for (int i = 0; i < elem_cnt; i++) {
              final RuntimeBindingProperty prop =
                  byNameRuntimeBindingType.getElementProperty(i);
  
              if (!prop.isSet(curr_obj, this)) continue;
  
              final Object prop_val = prop.getValue(curr_obj, this);
              if (prop.isMultiple()) {
                  final Iterator itr = ArrayUtils.getCollectionIterator(prop_val);
                  while (itr.hasNext()) {
                      visitProp(itr.next(), prop);
                  }
              } else {
                  visitProp(prop_val, prop);
              }
          }
      }
  
      public void visit(SimpleContentRuntimeBindingType simpleContentRuntimeBindingType)
          throws XmlException
      {
          writeAttributes(simpleContentRuntimeBindingType);
          writeCharData();
      }
  
      public void visit(SimpleRuntimeBindingType simpleRuntimeBindingType)
          throws XmlException
      {
          writeCharData();
      }
  
      public void visit(JaxrpcEnumRuntimeBindingType jaxrpcEnumRuntimeBindingType)
          throws XmlException
      {
          writeCharData();
      }
  
      public void visit(WrappedArrayRuntimeBindingType wrappedArrayRuntimeBindingType)
          throws XmlException
      {
          final RuntimeBindingProperty elem_prop =
              wrappedArrayRuntimeBindingType.getElementProperty();
  
          //REVIEW: consider direct array access
          final Iterator itr = ArrayUtils.getCollectionIterator(currObject);
          while (itr.hasNext()) {
              final Object item = itr.next();
              final RuntimeBindingType actual_rtt =
                  elem_prop.getActualRuntimeType(item, this);
              marshalType(item, elem_prop, actual_rtt);
          }
      }
  
      public void visit(ListArrayRuntimeBindingType listArrayRuntimeBindingType)
          throws XmlException
      {
          writeCharData();
      }
  
      private void writeAttributes(AttributeRuntimeBindingType att_rtt)
          throws XmlException
      {
          final Object curr_obj = currObject;
          final int att_cnt = att_rtt.getAttributePropertyCount();
          for (int i = 0; i < att_cnt; i++) {
              final RuntimeBindingProperty prop =
                  att_rtt.getAttributeProperty(i);
              if (!prop.isSet(curr_obj, this)) continue;
  
              final Object prop_val = prop.getValue(curr_obj, this);
              final CharSequence att_val = prop.getLexical(prop_val,
                                                           this);
  
              if (att_val == null) continue;
              fillAndAddAttribute(prop.getName(), att_val.toString());
          }
      }
  
      private void visitProp(final Object prop_val,
                             final RuntimeBindingProperty prop)
          throws XmlException
      {
          RuntimeBindingType rtt = prop.getActualRuntimeType(prop_val, this);
          marshalType(prop_val, prop, rtt);
      }
  
      private void writeCharData() throws XmlException
      {
          if (currObject == null) return;
  
          final CharSequence lexical = currProp.getLexical(currObject, this);
          try {
              //too bad writer can't take a CharSequence.
              writer.writeCharacters(lexical.toString());
          }
          catch (XMLStreamException e) {
              throw new XmlException(e);
          }
      }
  
  }
  
  
  
  1.5       +31 -4     xml-xmlbeans/v2/test/cases/marshal/com/mytest/MySubClass.java
  
  Index: MySubClass.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/com/mytest/MySubClass.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MySubClass.java	12 Feb 2004 21:18:15 -0000	1.4
  +++ MySubClass.java	6 May 2004 17:47:13 -0000	1.5
  @@ -35,21 +35,48 @@
           setIsSetBigInt(bigInt != null);
       }
   
  -    public boolean isSetBigInt() {
  +    public boolean isSetBigInt()
  +    {
           return issetBigInt;
       }
   
  -    public void setIsSetBigInt(boolean val) {
  +    public void setIsSetBigInt(boolean val)
  +    {
           issetBigInt = val;
       }
   
  +
  +    public boolean equals(Object o)
  +    {
  +        if (this == o) return true;
  +        if (!(o instanceof MySubClass)) return false;
  +        if (!super.equals(o)) return false;
  +
  +        final MySubClass mySubClass = (MySubClass)o;
  +
  +        if (issetBigInt != mySubClass.issetBigInt) return false;
  +        if (bigInt != null ? !bigInt.equals(mySubClass.bigInt) :
  +            mySubClass.bigInt != null)
  +            return false;
  +
  +        return true;
  +    }
  +
  +    public int hashCode()
  +    {
  +        int result = super.hashCode();
  +        result = 29 * result + (bigInt != null ? bigInt.hashCode() : 0);
  +        result = 29 * result + (issetBigInt ? 1 : 0);
  +        return result;
  +    }
  +
       public String toString()
       {
           return "com.mytest.MySubClass{" +
               "super=" + super.toString() +
  -            " bigInt=" + bigInt +
  +            "bigInt=" + bigInt +
  +            ", issetBigInt=" + issetBigInt +
               "}";
       }
  -
   
   }
  
  
  
  1.3       +31 -0     xml-xmlbeans/v2/test/cases/marshal/com/mytest/MySubSubClass.java
  
  Index: MySubSubClass.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/com/mytest/MySubSubClass.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MySubSubClass.java	12 Feb 2004 20:06:30 -0000	1.2
  +++ MySubSubClass.java	6 May 2004 17:47:13 -0000	1.3
  @@ -30,4 +30,35 @@
           this.subsubname = subsubname;
       }
   
  +    public boolean equals(Object o)
  +    {
  +        if (this == o) return true;
  +        if (!(o instanceof MySubSubClass)) return false;
  +        if (!super.equals(o)) return false;
  +
  +        final MySubSubClass mySubSubClass = (MySubSubClass)o;
  +
  +        if (subsubname != null ? !subsubname.equals(mySubSubClass.subsubname) :
  +            mySubSubClass.subsubname != null)
  +            return false;
  +
  +        return true;
  +    }
  +
  +    public int hashCode()
  +    {
  +        int result = super.hashCode();
  +        result = 29 * result + (subsubname != null ? subsubname.hashCode() : 0);
  +        return result;
  +    }
  +
  +    public String toString()
  +    {
  +        return "com.mytest.MySubSubClass{" +
  +            "super=" + super.toString() + 
  +            "subsubname='" + subsubname + "'" +
  +            "}";
  +    }
  +
  +
   }
  
  
  
  1.59      +49 -10    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.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- MarshalTests.java	4 May 2004 21:33:22 -0000	1.58
  +++ MarshalTests.java	6 May 2004 17:47:13 -0000	1.59
  @@ -29,9 +29,12 @@
   import junit.framework.TestSuite;
   import org.apache.xmlbeans.BindingContext;
   import org.apache.xmlbeans.BindingContextFactory;
  +import org.apache.xmlbeans.EncodingStyle;
  +import org.apache.xmlbeans.GDuration;
   import org.apache.xmlbeans.Marshaller;
   import org.apache.xmlbeans.ObjectFactory;
   import org.apache.xmlbeans.SchemaTypeSystem;
  +import org.apache.xmlbeans.SoapMarshaller;
   import org.apache.xmlbeans.Unmarshaller;
   import org.apache.xmlbeans.XmlBeans;
   import org.apache.xmlbeans.XmlCalendar;
  @@ -39,9 +42,6 @@
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlOptions;
  -import org.apache.xmlbeans.GDuration;
  -import org.apache.xmlbeans.EncodingStyle;
  -import org.apache.xmlbeans.SoapMarshaller;
   import org.apache.xmlbeans.impl.binding.compile.Schema2Java;
   import org.apache.xmlbeans.impl.common.XmlReaderToWriter;
   import org.apache.xmlbeans.impl.common.XmlStreamUtils;
  @@ -549,11 +549,20 @@
           myelt.setAttrib(99999.777f);
           myelt.setMyFloat(5555.4444f);
   //        myelt.setMyClass(new com.mytest.MyClass());
  -        myelt.setMyClass(null);
  +//        myelt.setMyClass(new com.mytest.MySubSubClass());
  +        myelt.setMyClass(new com.mytest.MySubClass());
           mc.setMyelt(myelt);
   
  +        myelt.setModeEnum(ModeEnum.Off);
  +        myelt.setQn(new QName("someURI", "somePart"));
  +        final SimpleContentExample sce = new SimpleContentExample();
  +        sce.setFloatAttOne(5.43234f);
  +        sce.setSimpleContent("SIMPLE_CONTENT");
  +        myelt.setSimpleContentExample(sce);
  +
           myelt.setStringArray(new String[]{"one", "two", "three"});
   
  +        myelt.setSimpleStringArray(myelt.getStringArray());
   
           BindingContext bindingContext = getBindingContext(getBindingConfigDocument());
   
  @@ -570,15 +579,36 @@
           Assert.assertNotNull(ctx);
   
   
  +        final QName elem_name = new QName("java:com.mytest", "load");
  +        final QName type_name = new QName("java:com.mytest", "MyClass");
           ctx.marshalType(w, mc,
  -                        new QName("java:com.mytest", "load"),
  -                        new QName("java:com.mytest", "MyClass"),
  +                        elem_name,
  +                        type_name,
                           mc.getClass().getName(), options);
  +        w.close();
  +        sw.close();
   
           inform("=======IN-OBJ: " + mc);
  -        inform("=======OUT-XML: " + PrettyPrinter.indent(sw.getBuffer().toString()));
  +        inform("=======OUT-XML:\n" + PrettyPrinter.indent(sw.getBuffer().toString()));
           reportErrors(errors, "byname-writer");
           Assert.assertTrue(errors.isEmpty());
  +
  +
  +        StringReader sr = new StringReader(sw.getBuffer().toString());
  +        XMLStreamReader rdr =
  +            XMLInputFactory.newInstance().createXMLStreamReader(sr);
  +        while (!rdr.isStartElement()) {
  +            rdr.next();
  +        }
  +        Unmarshaller umctx = bindingContext.createUnmarshaller();
  +        Object out_obj = umctx.unmarshalType(rdr, type_name, mc.getClass().getName(), options);
  +        reportErrors(errors, "byname-doc-writer");
  +        Assert.assertTrue(errors.isEmpty());
  +        if (!mc.equals(out_obj)) {
  +            inform("IN : " + mc, true);
  +            inform("OUT: " + out_obj, true);
  +        }
  +        Assert.assertEquals(mc, out_obj);
       }
   
       public void testByNameDocMarshalViaWriter()
  @@ -630,7 +660,7 @@
           myelt.setAttrib(99999.777f);
           myelt.setMyFloat(5555.4444f);
   //        myelt.setMyClass(new com.mytest.MyClass());
  -        myelt.setMyClass(null);
  +//        myelt.setMyClass(new com.mytest.MySubSubClass());
           mc.setMyelt(myelt);
   
           myelt.setStringArray(new String[]{"one", "two", "three"});
  @@ -681,7 +711,10 @@
           myelt.setAttrib(99999.777f);
           myelt.setMyFloat(5555.4444f);
   //        myelt.setMyClass(new com.mytest.MyClass());
  -        myelt.setMyClass(null);
  +//        myelt.setMyClass(null);
  +//        myelt.setMyClass(new com.mytest.MySubSubClass());
  +        myelt.setMyClass(new com.mytest.MySubClass());
  +
           mc.setMyelt(myelt);
   
           myelt.setStringArray(new String[]{"one", "two", "three"});
  @@ -710,6 +743,10 @@
           final ByteArrayInputStream bais = new ByteArrayInputStream(buf);
           Object out_obj = umctx.unmarshal(bais, options);
           reportErrors(errors, "marsh-outstream");
  +        if (!mc.equals(out_obj)) {
  +            inform("\nIN : " + mc, true);
  +            inform("OUT: " + out_obj, true);
  +        }
           Assert.assertEquals(mc, out_obj);
           Assert.assertTrue(errors.isEmpty());
       }
  @@ -1256,7 +1293,9 @@
           final SchemaDocument xsd_obj =
               (SchemaDocument)XmlObject.Factory.parse(schema);
           final XmlObject[] schemas = new XmlObject[]{xsd_obj};
  -        SchemaTypeSystem sts = XmlBeans.compileXsd(schemas, XmlBeans.getBuiltinTypeSystem(), new XmlOptions());
  +        SchemaTypeSystem sts = XmlBeans.compileXsd(schemas,
  +                                                   XmlBeans.getBuiltinTypeSystem(),
  +                                                   new XmlOptions());
           Schema2Java s2j = new Schema2Java(sts);
           s2j.includeSchema(xsd_obj, schema.getName());
           final File tmpfile = File.createTempFile("marshalTests", "-tylar");
  
  
  

---------------------------------------------------------------------
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