xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases MarshalTests.java
Date Fri, 30 Apr 2004 21:31:49 GMT
zieg        2004/04/30 14:31:49

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        BuiltinRuntimeBindingType.java
                        ByNameRuntimeBindingType.java
                        JaxrpcEnumRuntimeBindingType.java
                        ListArrayRuntimeBindingType.java MarshalResult.java
                        MarshallerImpl.java RuntimeBindingType.java
                        SimpleContentRuntimeBindingType.java
                        SimpleRuntimeBindingType.java
                        SoapMarshallerImpl.java
                        WrappedArrayRuntimeBindingType.java
               v2/src/xmlpublic/org/apache/xmlbeans SoapMarshaller.java
               v2/test/src/drt/drtcases MarshalTests.java
  Added:       v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        LiteralMarshalResult.java ObjectRefTable.java
                        RefdObjectVisitor.java RuntimeTypeVisitor.java
                        Soap11MarshalResult.java
                        Soap11RefdObjectVisitor.java SoapMarshalResult.java
  Log:
  creating soap 1.1 msgs, phase one
  
  Revision  Changes    Path
  1.5       +11 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BuiltinRuntimeBindingType.java
  
  Index: BuiltinRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BuiltinRuntimeBindingType.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BuiltinRuntimeBindingType.java	27 Apr 2004 02:36:14 -0000	1.4
  +++ BuiltinRuntimeBindingType.java	30 Apr 2004 21:31:48 -0000	1.5
  @@ -25,10 +25,21 @@
           builtinBindingType = type;
       }
   
  +    void accept(RuntimeTypeVisitor visitor)
  +        throws XmlException
  +    {
  +        visitor.visit(this);
  +    }
  +
       public void initialize(RuntimeBindingTypeTable typeTable,
                              BindingLoader bindingLoader)
           throws XmlException
       {
  +    }
  +
  +    boolean hasElementChildren()
  +    {
  +        return false;
       }
   
   
  
  
  
  1.39      +11 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java
  
  Index: ByNameRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ByNameRuntimeBindingType.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- ByNameRuntimeBindingType.java	27 Apr 2004 02:36:14 -0000	1.38
  +++ ByNameRuntimeBindingType.java	30 Apr 2004 21:31:48 -0000	1.39
  @@ -63,6 +63,12 @@
       }
   
   
  +    void accept(RuntimeTypeVisitor visitor)
  +        throws XmlException
  +    {
  +        visitor.visit(this);
  +    }
  +
       Object getObjectFromIntermediate(Object inter)
       {
           if (hasMulti()) {
  @@ -71,6 +77,11 @@
           } else {
               return inter;
           }
  +    }
  +
  +    boolean hasElementChildren()
  +    {
  +        return true;
       }
   
   
  
  
  
  1.5       +11 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/JaxrpcEnumRuntimeBindingType.java
  
  Index: JaxrpcEnumRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/JaxrpcEnumRuntimeBindingType.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JaxrpcEnumRuntimeBindingType.java	27 Apr 2004 02:36:14 -0000	1.4
  +++ JaxrpcEnumRuntimeBindingType.java	30 Apr 2004 21:31:48 -0000	1.5
  @@ -37,6 +37,12 @@
           jaxrpcEnumType = type;
       }
   
  +    void accept(RuntimeTypeVisitor visitor)
  +        throws XmlException
  +    {
  +        visitor.visit(this);
  +    }
  +
       public void initialize(RuntimeBindingTypeTable typeTable,
                              BindingLoader bindingLoader
                              )
  @@ -44,6 +50,11 @@
       {
           itemInfo = new ItemInfo(jaxrpcEnumType, getJavaType(), typeTable,
                                   bindingLoader);
  +    }
  +
  +    boolean hasElementChildren()
  +    {
  +        return false;
       }
   
       CharSequence print(Object value,
  
  
  
  1.7       +11 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ListArrayRuntimeBindingType.java
  
  Index: ListArrayRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ListArrayRuntimeBindingType.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ListArrayRuntimeBindingType.java	28 Apr 2004 00:01:38 -0000	1.6
  +++ ListArrayRuntimeBindingType.java	30 Apr 2004 21:31:48 -0000	1.7
  @@ -39,6 +39,12 @@
           listArrayType = binding_type;
       }
   
  +    void accept(RuntimeTypeVisitor visitor)
  +        throws XmlException
  +    {
  +        visitor.visit(this);
  +    }
  +
       public void initialize(RuntimeBindingTypeTable typeTable,
                              BindingLoader bindingLoader
                              )
  @@ -58,6 +64,11 @@
               typeTable.createRuntimeType(item_type, bindingLoader);
   
           itemProperty = new LAProperty(this, item_rtt);
  +    }
  +
  +    boolean hasElementChildren()
  +    {
  +        return false;
       }
   
   
  
  
  
  1.30      +34 -8     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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- MarshalResult.java	28 Apr 2004 00:01:38 -0000	1.29
  +++ MarshalResult.java	30 Apr 2004 21:31:48 -0000	1.30
  @@ -44,7 +44,7 @@
   import java.util.Stack;
   
   
  -final class MarshalResult implements XMLStreamReader
  +abstract class MarshalResult implements XMLStreamReader
   {
   
       //per binding context constants
  @@ -57,6 +57,7 @@
       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;
  @@ -84,7 +85,29 @@
           namespaceContext = new ScopedNamespaceContext(root_nsctx);
           namespaceContext.openScope();
           errors = BindingContextImpl.extractErrorHandler(options);
  -        currVisitor = createVisitor(property, obj);
  +        currVisitor = createInitialVisitor(property, obj);
  +    }
  +
  +    //reset to initial state but with new property and object
  +    protected void reset(RuntimeBindingProperty property, Object obj)
  +        throws XmlException
  +    {
  +        namespaceContext.clear();
  +        namespaceContext.openScope();
  +        visitorStack.clear();
  +        currVisitor = createInitialVisitor(property, obj);
  +        currentEventType = XMLStreamReader.START_ELEMENT;
  +        initedAttributes = false;
  +        if (attributeHolder != null) attributeHolder.clear();
  +        prefixCnt = 0;
  +        currIndex = 0;
  +    }
  +
  +    protected XmlTypeVisitor createInitialVisitor(RuntimeBindingProperty property,
  +                                                  Object obj)
  +        throws XmlException
  +    {
  +        return createVisitor(property, obj);
       }
   
       protected XmlTypeVisitor createVisitor(RuntimeBindingProperty property,
  @@ -94,19 +117,22 @@
           assert property != null;
   
           BindingType btype = property.getRuntimeBindingType().getBindingType();
  -        bindingTypeVisitor.setParentObject(obj);
  -        bindingTypeVisitor.setRuntimeBindingProperty(property);
  -        btype.accept(bindingTypeVisitor);
  -        return bindingTypeVisitor.getXmlTypeVisitor();
  +        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
  +    public int next()
  +        throws XMLStreamException
       {
           switch (currVisitor.getState()) {
               case XmlTypeVisitor.START:
  @@ -551,7 +577,7 @@
           throw new IllegalStateException();
       }
   
  -    private void initAttributes()
  +    protected void initAttributes()
       {
           if (!initedAttributes) {
               try {
  
  
  
  1.29      +33 -25    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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- MarshallerImpl.java	28 Apr 2004 00:01:38 -0000	1.28
  +++ MarshallerImpl.java	30 Apr 2004 21:31:48 -0000	1.29
  @@ -98,20 +98,13 @@
           final RuntimeBindingType runtime_type =
               typeTable.createRuntimeType(btype, loader);
   
  -        if (obj != null &&
  -            !runtime_type.isJavaPrimitive() &&
  -            !runtime_type.getJavaType().isInstance(obj)) {
  -            String m = "instance type: " + obj.getClass() +
  -                " not an instance of expected type: " +
  -                runtime_type.getJavaType();
  -            throw new XmlException(m);
  -        }
  +        runtime_type.checkInstance(obj);
   
           RuntimeGlobalProperty prop =
               new RuntimeGlobalProperty(elem_qn, runtime_type);
   
  -        return new MarshalResult(loader, typeTable,
  -                                 nscontext, prop, obj, null);
  +        return new LiteralMarshalResult(loader, typeTable,
  +                                        nscontext, prop, obj, null);
       }
   
   
  @@ -260,8 +253,33 @@
                                          NamespaceContext namespaceContext)
           throws XmlException
       {
  +        BindingType type = lookupBindingType(schemaType, javaType,
  +                                             elementName, obj, loader);
  +
  +        return createMarshalResult(type, elementName, namespaceContext, obj);
  +    }
  +
  +    static BindingType lookupBindingType(QName schemaType,
  +                                         String javaType,
  +                                         QName elementName,
  +                                         Object obj,
  +                                         BindingLoader loader)
  +        throws XmlException
  +    {
  +        return lookupBindingType(XmlTypeName.forTypeNamed(schemaType),
  +                                 javaType,
  +                                 elementName, obj, loader);
  +    }
  +
  +    static BindingType lookupBindingType(XmlTypeName schema_type,
  +                                         String javaType,
  +                                         QName elementName,
  +                                         Object obj,
  +                                         BindingLoader loader)
  +        throws XmlException
  +    {
           final BindingType type =
  -            loadBindingType(XmlTypeName.forTypeNamed(schemaType),
  +            loadBindingType(schema_type,
                               JavaTypeName.forClassName(javaType),
                               loader);
   
  @@ -269,12 +287,11 @@
               final String msg = "failed to find a suitable binding type for" +
                   " use in marshalling \"" + elementName + "\". " +
                   " using java type: " + javaType +
  -                " schema type: " + schemaType +
  +                " schema type: " + schema_type +
                   " instance type: " + obj.getClass().getName();
               throw new XmlException(msg);
           }
  -
  -        return createMarshalResult(type, elementName, namespaceContext, obj);
  +        return type;
       }
   
       public void marshalType(XMLStreamWriter writer,
  @@ -359,19 +376,10 @@
               determineDocumentType(elementName);
   
           final XmlTypeName elem_type = doc_binding.getTypeOfElement();
  +
           final BindingType type =
  -            loadBindingType(elem_type,
  -                            JavaTypeName.forClassName(javaType),
  -                            loader);
  +            lookupBindingType(elem_type, javaType, elementName, obj, loader);
   
  -        if (type == null) {
  -            final String msg = "failed to find a suitable binding type for" +
  -                " use in marshalling \"" + elementName + "\" " +
  -                " using java type: " + javaType +
  -                " schema type: " + elem_type +
  -                " instance type: " + obj.getClass().getName();
  -            throw new XmlException(msg);
  -        }
           NamespaceContext nscontext = getNamespaceContextFromOptions(options);
           return createMarshalResult(type, elementName,
                                      nscontext, obj);
  
  
  
  1.20      +19 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingType.java
  
  Index: RuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingType.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- RuntimeBindingType.java	28 Apr 2004 00:01:38 -0000	1.19
  +++ RuntimeBindingType.java	30 Apr 2004 21:31:48 -0000	1.20
  @@ -75,6 +75,11 @@
           marshaller = m;
       }
   
  +
  +    abstract void accept(RuntimeTypeVisitor visitor)
  +        throws XmlException;
  +
  +
       Object getObjectFromIntermediate(Object inter)
       {
           return inter;
  @@ -208,6 +213,20 @@
               "}";
       }
   
  +    protected void checkInstance(Object obj)
  +        throws XmlException
  +    {
  +        final Class java_type = getJavaType();
  +        if (obj != null &&
  +            !isJavaPrimitive() &&
  +            !java_type.isInstance(obj)) {
  +            String m = "instance type: " + obj.getClass() +
  +                " not an instance of expected type: " + java_type;
  +            throw new XmlException(m);
  +        }
  +    }
  +
  +    abstract boolean hasElementChildren();
   
       protected abstract static class BeanRuntimeProperty
           extends RuntimeBindingProperty
  
  
  
  1.4       +12 -2     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentRuntimeBindingType.java
  
  Index: SimpleContentRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentRuntimeBindingType.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleContentRuntimeBindingType.java	27 Apr 2004 02:36:14 -0000	1.3
  +++ SimpleContentRuntimeBindingType.java	30 Apr 2004 21:31:48 -0000	1.4
  @@ -36,10 +36,15 @@
           super(simpleContentBean);
       }
   
  +    void accept(RuntimeTypeVisitor visitor)
  +        throws XmlException
  +    {
  +        visitor.visit(this);
  +    }
  +
       //prepare internal data structures for use
       public final void initialize(RuntimeBindingTypeTable typeTable,
  -                                 BindingLoader loader
  -                                 )
  +                                 BindingLoader loader)
           throws XmlException
       {
           super.initialize(typeTable, loader);
  @@ -50,6 +55,11 @@
               new SimpleContentRuntimeProperty(getJavaType(),
                                                simpleContentProperty, this,
                                                typeTable, loader);
  +    }
  +
  +    boolean hasElementChildren()
  +    {
  +        return false;
       }
   
       private SimpleContentBean getSimpleContentBean()
  
  
  
  1.4       +11 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleRuntimeBindingType.java
  
  Index: SimpleRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleRuntimeBindingType.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleRuntimeBindingType.java	27 Apr 2004 02:36:14 -0000	1.3
  +++ SimpleRuntimeBindingType.java	30 Apr 2004 21:31:48 -0000	1.4
  @@ -31,11 +31,22 @@
           simpleBindingType = type;
       }
   
  +    void accept(RuntimeTypeVisitor visitor)
  +        throws XmlException
  +    {
  +        visitor.visit(this);
  +    }
  +
       public void initialize(RuntimeBindingTypeTable typeTable,
                              BindingLoader bindingLoader
                              )
           throws XmlException
       {
  +    }
  +
  +    boolean hasElementChildren()
  +    {
  +        return false;
       }
   
   }
  
  
  
  1.5       +272 -4    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SoapMarshallerImpl.java	28 Apr 2004 00:01:38 -0000	1.4
  +++ SoapMarshallerImpl.java	30 Apr 2004 21:31:48 -0000	1.5
  @@ -19,12 +19,18 @@
   import org.apache.xmlbeans.SoapMarshaller;
   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.marshal.util.ArrayUtils;
  +import org.apache.xmlbeans.impl.marshal.util.collections.EmptyIterator;
   
   import javax.xml.namespace.NamespaceContext;
   import javax.xml.namespace.QName;
   import javax.xml.stream.XMLStreamReader;
  +import java.util.Iterator;
   
  +//this class is not thread safe and doesn't have to be per javadocs
   class SoapMarshallerImpl
       implements SoapMarshaller
   {
  @@ -32,6 +38,9 @@
       private final BindingLoader loader;
       private final RuntimeBindingTypeTable typeTable;
       private final EncodingStyle encodingStyle;
  +    private final InstanceVisitor instanceVisitor = new InstanceVisitor();
  +
  +    private ObjectRefTable objectRefTable;
   
   
       SoapMarshallerImpl(BindingLoader loader,
  @@ -50,17 +59,276 @@
                                          XmlOptions options)
           throws XmlException
       {
  -        NamespaceContext nscontext =
  +        final NamespaceContext nscontext =
               MarshallerImpl.getNamespaceContextFromOptions(options);
  +        final BindingType btype =
  +            MarshallerImpl.lookupBindingType(schemaType, javaType,
  +                                             elementName, obj, loader);
  +
  +        assert btype != null;
  +
  +        final RuntimeBindingType runtime_type =
  +            typeTable.createRuntimeType(btype, loader);
  +
  +        runtime_type.checkInstance(obj);
  +
  +        RuntimeGlobalProperty prop =
  +            new RuntimeGlobalProperty(elementName, runtime_type);
  +
  +        if (runtime_type.hasElementChildren()) {
  +            objectRefTable = new ObjectRefTable();
  +        }
  +
  +        final MarshalResult retval =
  +            createMarshalResult(nscontext, prop, obj, options, false);
  +
  +        addObjectGraphToRefTable(obj, runtime_type, prop, retval);
  +
  +        return retval;
  +    }
  +
  +    private SoapMarshalResult createMarshalResult(final NamespaceContext nscontext,
  +                                                  RuntimeBindingProperty prop,
  +                                                  Object obj,
  +                                                  XmlOptions options,
  +                                                  boolean doing_id_parts)
  +        throws XmlException
  +    {
  +        final SoapMarshalResult retval;
  +
  +        if (EncodingStyle.SOAP11.equals(encodingStyle)) {
  +            retval = new Soap11MarshalResult(loader, typeTable,
  +                                             nscontext, prop, obj, options,
  +                                             objectRefTable, doing_id_parts);
  +        } else if (EncodingStyle.SOAP12.equals(encodingStyle)) {
  +            throw new AssertionError("UNIMP");
  +        } else {
  +            throw new AssertionError("UNKNOWN ENCODING: " + encodingStyle);
  +        }
  +        return retval;
  +    }
   
  -        throw new AssertionError("UNIMP");
  +    private void addObjectGraphToRefTable(Object obj,
  +                                          RuntimeBindingType runtime_type,
  +                                          RuntimeBindingProperty prop,
  +                                          MarshalResult result)
  +        throws XmlException
  +    {
  +        if (objectRefTable == null) return;
   
  +        //traverse graph...
  +        instanceVisitor.setCurrObject(obj, prop);
  +        instanceVisitor.setMarshalResult(result);
  +        runtime_type.accept(instanceVisitor);
   
       }
   
  -    public XMLStreamReader marshalReferenced(XmlOptions options)
  +    public Iterator marshalReferenced(XmlOptions options)
           throws XmlException
       {
  -        throw new AssertionError("UNIMP: this=" + this);
  +        if (objectRefTable == null || !objectRefTable.hasMultiplyRefdObjects())
  +            return EmptyIterator.getInstance();
  +
  +        return new ReaderIterator(options);
  +    }
  +
  +    private final class ReaderIterator
  +        implements Iterator
  +    {
  +        private final XmlOptions options;
  +        private final NamespaceContext nscontext;
  +        private final Iterator tblItr = objectRefTable.getMultipleRefTableEntries();
  +        private SoapMarshalResult marshalResult;
  +
  +        public ReaderIterator(XmlOptions options)
  +        {
  +            this.options = options;
  +            nscontext = MarshallerImpl.getNamespaceContextFromOptions(options);
  +        }
  +
  +        public boolean hasNext()
  +        {
  +            return tblItr.hasNext();
  +        }
  +
  +        public Object next()
  +        {
  +            final ObjectRefTable.Value cur_val =
  +                (ObjectRefTable.Value)tblItr.next();
  +            assert cur_val.getCnt() > 1;
  +
  +            try {
  +                if (marshalResult == null) {
  +                    marshalResult = createMarshalResult(nscontext,
  +                                                        cur_val.getProp(),
  +                                                        cur_val.object,
  +                                                        options, true);
  +                } else {
  +                    marshalResult.reset(cur_val.getProp(), cur_val.object, true);
  +                }
  +                return marshalResult;
  +            }
  +            catch (XmlException e) {
  +                //TODO: REVIEW: is there a better way to do this?
  +                //maybe write out own typesafe iterator...
  +                throw new XmlRuntimeException(e);
  +            }
  +
  +        }
  +
  +        public void remove()
  +        {
  +            throw new UnsupportedOperationException();
  +        }
  +
       }
  +
  +
  +    private final class InstanceVisitor
  +        implements RuntimeTypeVisitor
  +    {
  +        private Object currObject;
  +        private RuntimeBindingProperty currProp;
  +        private MarshalResult marshalResult;
  +
  +        public Object getCurrObject()
  +        {
  +            return currObject;
  +        }
  +
  +        public void setCurrObject(Object obj,
  +                                  RuntimeBindingProperty prop)
  +        {
  +            this.currObject = obj;
  +            this.currProp = prop;
  +        }
  +
  +        public MarshalResult getMarshalResult()
  +        {
  +            return marshalResult;
  +        }
  +
  +        public void setMarshalResult(MarshalResult marshalResult)
  +        {
  +            this.marshalResult = marshalResult;
  +        }
  +
  +        public void visit(BuiltinRuntimeBindingType builtinRuntimeBindingType)
  +            throws XmlException
  +        {
  +            initialVisit(currObject, currProp);
  +            //no element children so we are finished.
  +        }
  +
  +        public void visit(ByNameRuntimeBindingType byNameRuntimeBindingType)
  +            throws XmlException
  +        {
  +            final Object curr_obj = currObject;
  +            final RuntimeBindingProperty curr_prop = currProp;
  +
  +            if (initialVisit(curr_obj, curr_prop)) {
  +                return;
  +            }
  +
  +            final int elem_cnt =
  +                byNameRuntimeBindingType.getElementPropertyCount();
  +            for (int i = 0; i < elem_cnt; i++) {
  +                final RuntimeBindingProperty prop =
  +                    byNameRuntimeBindingType.getElementProperty(i);
  +
  +                if (prop.getRuntimeBindingType().isJavaPrimitive()) continue;
  +                if (!prop.isSet(curr_obj, marshalResult)) continue;
  +
  +                final Object prop_val = prop.getValue(curr_obj, marshalResult);
  +                if (prop.isMultiple()) {
  +                    //NOTE: we don't add the array itself becuase there is no
  +                    //actual element on which to put the id or href attribute.
  +                    final Iterator itr = ArrayUtils.getCollectionIterator(prop_val);
  +                    while (itr.hasNext()) {
  +                        visitProp(itr.next(), prop, curr_obj, curr_prop);
  +                    }
  +                } else {
  +                    visitProp(prop_val, prop, curr_obj, curr_prop);
  +                }
  +            }
  +        }
  +
  +        private void visitProp(final Object prop_val,
  +                               final RuntimeBindingProperty prop,
  +                               final Object curr_obj,
  +                               final RuntimeBindingProperty curr_prop)
  +            throws XmlException
  +        {
  +            setCurrObject(prop_val, prop);
  +            RuntimeBindingType rtt = prop.getRuntimeBindingType();
  +            if (rtt.hasElementChildren()) {
  +                prop.getActualRuntimeType(prop_val, marshalResult).accept(this);
  +            } else {
  +                rtt.accept(this);
  +            }
  +            setCurrObject(curr_obj, curr_prop);
  +        }
  +
  +        public void visit(SimpleContentRuntimeBindingType simpleContentRuntimeBindingType)
  +            throws XmlException
  +        {
  +            initialVisit(currObject, currProp);
  +            //no element children so we are finished.
  +        }
  +
  +        public void visit(SimpleRuntimeBindingType simpleRuntimeBindingType)
  +            throws XmlException
  +        {
  +            initialVisit(currObject, currProp);
  +            //no element children so we are finished.
  +        }
  +
  +        public void visit(JaxrpcEnumRuntimeBindingType jaxrpcEnumRuntimeBindingType)
  +            throws XmlException
  +        {
  +            initialVisit(currObject, currProp);
  +            //no element children so we are finished.
  +        }
  +
  +        public void visit(WrappedArrayRuntimeBindingType wrappedArrayRuntimeBindingType)
  +            throws XmlException
  +        {
  +            final Object curr_obj = currObject;
  +            final RuntimeBindingProperty curr_prop = currProp;
  +
  +            if (initialVisit(curr_obj, curr_prop)) {
  +                return;
  +            }
  +
  +            final RuntimeBindingProperty elem_prop =
  +                wrappedArrayRuntimeBindingType.getElementProperty();
  +
  +            if (elem_prop.getRuntimeBindingType().isJavaPrimitive()) return;
  +
  +
  +            //REVIEW: consider direct array access
  +            final Iterator itr = ArrayUtils.getCollectionIterator(curr_obj);
  +            while (itr.hasNext()) {
  +                final Object item = itr.next();
  +                setCurrObject(item, elem_prop);
  +                elem_prop.getActualRuntimeType(item, marshalResult).accept(this);
  +            }
  +            setCurrObject(curr_obj, curr_prop);
  +        }
  +
  +        public void visit(ListArrayRuntimeBindingType listArrayRuntimeBindingType)
  +            throws XmlException
  +        {
  +            initialVisit(currObject, currProp);
  +            //no element children so we are finished.
  +        }
  +
  +        //return true if we should stop processing!
  +        private boolean initialVisit(Object obj,
  +                                     RuntimeBindingProperty property)
  +        {
  +            return objectRefTable.incrementRefCount(obj, property) > 1;
  +        }
  +    }
  +
   }
  
  
  
  1.9       +11 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayRuntimeBindingType.java
  
  Index: WrappedArrayRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayRuntimeBindingType.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WrappedArrayRuntimeBindingType.java	28 Apr 2004 00:01:38 -0000	1.8
  +++ WrappedArrayRuntimeBindingType.java	30 Apr 2004 21:31:48 -0000	1.9
  @@ -40,6 +40,12 @@
           wrappedArrayType = binding_type;
       }
   
  +    void accept(RuntimeTypeVisitor visitor)
  +        throws XmlException
  +    {
  +        visitor.visit(this);
  +    }
  +
       public void initialize(RuntimeBindingTypeTable typeTable,
                              BindingLoader bindingLoader)
           throws XmlException
  @@ -63,6 +69,11 @@
                              wrappedArrayType.isItemNillable());
   
   
  +    }
  +
  +    boolean hasElementChildren()
  +    {
  +        return true;
       }
   
       RuntimeBindingProperty getElementProperty()
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/LiteralMarshalResult.java
  
  Index: LiteralMarshalResult.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.impl.binding.bts.BindingLoader;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xmlbeans.XmlException;
  
  import javax.xml.namespace.NamespaceContext;
  
  final class LiteralMarshalResult
      extends MarshalResult
  {
  
      //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)
          throws XmlException
      {
          super(loader, tbl, root_nsctx, property, obj, options);
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ObjectRefTable.java
  
  Index: ObjectRefTable.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.impl.marshal.RuntimeBindingProperty;
  
  import java.util.IdentityHashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  public final class ObjectRefTable
  {
      private final IdentityHashMap table = new IdentityHashMap();
      private boolean haveMultiplyRefdObj = false;
      private int idcnt;
  
  
      public boolean hasMultiplyRefdObjects()
      {
          return haveMultiplyRefdObj;
      }
  
      public Iterator getMultipleRefTableEntries()
      {
          return new MultiRefIterator();
      }
  
      private final class MultiRefIterator
          implements Iterator
      {
          private final Iterator base_itr = table.entrySet().iterator();
          private Value nextValue = null;
  
          MultiRefIterator()
          {
              updateNext();
          }
  
          public boolean hasNext()
          {
              return (nextValue != null);
          }
  
          public Object next()
          {
              final Value retval = this.nextValue;
  
  
              assert retval.getCnt() > 1;
  
  
              updateNext();
  
              assert (nextValue == null || nextValue.getCnt() > 1);
  
              return retval;
          }
  
          private void updateNext()
          {
              while (base_itr.hasNext()) {
                  final Map.Entry map_entry = (Map.Entry)base_itr.next();
                  final ObjectRefTable.Value val =
                      (ObjectRefTable.Value)map_entry.getValue();
                  if (val.cnt > 1) {
                      nextValue = val;
                      return;
                  }
              }
              nextValue = null;
          }
  
  
          public void remove()
          {
              throw new UnsupportedOperationException();
          }
  
      }
  
      //returns new count
      public int incrementRefCount(final Object keyobj,
                                   RuntimeBindingProperty property)
      {
          if (keyobj == null) return 0;
  
          Value val = (Value)table.get(keyobj);
          if (val == null) {
              val = new Value(keyobj, ++idcnt, property);
              table.put(keyobj, val);
          } else {
              assert val.cnt > 0;
              haveMultiplyRefdObj = true;
              //System.out.println("MULTI: " + System.identityHashCode(keyobj) + ": " + keyobj.getClass().getName());
          }
  
          assert table.get(keyobj) == val;
  
          return (++val.cnt);
      }
  
      public int getRefCount(Object obj)
      {
          if (obj == null) return 0;
  
          Value val = (Value)table.get(obj);
          if (val == null) {
              return 0;
          }
          return val.cnt;
      }
  
  
      /**
       * Returns -1 if ref count for obj is <= 1
       *
       * @param obj
       * @return
       */
      public int getId(Object obj)
      {
          int retval = -1;
  
          if (obj != null) {
              Value val = (Value)table.get(obj);
              if (val != null && val.cnt > 1) {
                  retval = val.id;
              }
          }
          return retval;
      }
  
  
      public static final class Value
      {
          final Object object;
          final int id;
          final RuntimeBindingProperty prop;
          int cnt;
  
          public int getId()
          {
              return id;
          }
  
          public int getCnt()
          {
              return cnt;
          }
  
          public RuntimeBindingProperty getProp()
          {
              return prop;
          }
  
          public Value(Object obj, int id, RuntimeBindingProperty prop)
          {
              this.object = obj;
              this.id = id;
              this.prop = prop;
          }
  
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RefdObjectVisitor.java
  
  Index: RefdObjectVisitor.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 javax.xml.namespace.QName;
  import java.lang.AssertionError;
  
  abstract class RefdObjectVisitor
      extends NamedXmlTypeVisitor
  {
      protected final int id;
  
      private int state = START;
  
  
      public RefdObjectVisitor(RuntimeBindingProperty property,
                               Object obj,
                               MarshalResult result,
                               int id)
          throws XmlException
      {
          super(obj, property, result);
          assert obj != null;  //cannot have multiple refs to null
          assert id >= 0 ;
          this.id = id;
      }
  
      protected int getState()
      {
          return state;
      }
  
      protected int advance()
          throws XmlException
      {
          if (state == START) {
              return (state = END);
          } else {
              throw new AssertionError("invalid state: " + state);
          }
      }
  
      protected void initAttributes()
          throws XmlException
      {
          marshalResult.fillAndAddAttribute(getRefQName(), getRefValue());
      }
  
      protected abstract QName getRefQName();
      protected abstract String getRefValue();
  
      public XmlTypeVisitor getCurrentChild()
          throws XmlException
      {
          throw new AssertionError("no children");
      }
  
      protected CharSequence getCharData()
      {
          throw new AssertionError("no char data");
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeTypeVisitor.java
  
  Index: RuntimeTypeVisitor.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;
  
  public interface RuntimeTypeVisitor
  {
      void visit(BuiltinRuntimeBindingType builtinRuntimeBindingType)
          throws XmlException;
  
      void visit(ByNameRuntimeBindingType byNameRuntimeBindingType)
          throws XmlException;
  
      void visit(SimpleContentRuntimeBindingType simpleContentRuntimeBindingType)
          throws XmlException;
  
      void visit(SimpleRuntimeBindingType simpleRuntimeBindingType)
          throws XmlException;
  
      void visit(JaxrpcEnumRuntimeBindingType jaxrpcEnumRuntimeBindingType)
          throws XmlException;
  
      void visit(WrappedArrayRuntimeBindingType wrappedArrayRuntimeBindingType)
          throws XmlException;
  
      void visit(ListArrayRuntimeBindingType listArrayRuntimeBindingType)
          throws XmlException;
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Soap11MarshalResult.java
  
  Index: Soap11MarshalResult.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 javax.xml.namespace.NamespaceContext;
  import javax.xml.namespace.QName;
  
  final class Soap11MarshalResult
      extends SoapMarshalResult
  {
  
      private static final QName ID_NAME = new QName("id");
  
      //TODO: REVIEW: consider ways to reduce the number of parameters here
      Soap11MarshalResult(BindingLoader loader,
                          RuntimeBindingTypeTable tbl,
                          NamespaceContext root_nsctx,
                          RuntimeBindingProperty property,
                          Object obj,
                          XmlOptions options,
                          ObjectRefTable object_ref_table,
                          boolean writingMultiRefdObjs)
          throws XmlException
      {
          super(loader, tbl, root_nsctx, property, obj,
                options, object_ref_table, writingMultiRefdObjs);
      }
  
      protected XmlTypeVisitor createRefdObjectVisitor(RuntimeBindingProperty property,
                                                       Object obj,
                                                       int id)
          throws XmlException
      {
          return new Soap11RefdObjectVisitor(property, obj, this, id);
      }
  
      protected QName getIdAttributeName()
      {
          return ID_NAME;
      }
  
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Soap11RefdObjectVisitor.java
  
  Index: Soap11RefdObjectVisitor.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 javax.xml.namespace.QName;
  
  class Soap11RefdObjectVisitor
      extends RefdObjectVisitor
  {
  
      private static final QName HREF_NAME = new QName("href");
      private static final String REF_PREFIX = '#' + SoapMarshalResult.ID_PREFIX;
  
      public Soap11RefdObjectVisitor(RuntimeBindingProperty property,
                               Object obj,
                               MarshalResult result,
                               int id)
          throws XmlException
      {
          super(property, obj, result, id);
      }
  
      protected QName getRefQName()
      {
          return HREF_NAME;
      }
  
      protected String getRefValue()
      {
          return REF_PREFIX + Integer.toString(id);
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SoapMarshalResult.java
  
  Index: SoapMarshalResult.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 javax.xml.namespace.NamespaceContext;
  import javax.xml.namespace.QName;
  
  abstract class SoapMarshalResult
      extends MarshalResult
  {
      private final ObjectRefTable objectRefTable;
      private final boolean writingMultiRefdObjs;
  
      protected static final String ID_PREFIX = "i";
  
  
      //TODO: REVIEW: consider ways to reduce the number of parameters here
      SoapMarshalResult(BindingLoader loader,
                        RuntimeBindingTypeTable tbl,
                        NamespaceContext root_nsctx,
                        RuntimeBindingProperty property,
                        Object obj,
                        XmlOptions options,
                        ObjectRefTable object_ref_table,
                        boolean writingMultiRefdObjs)
          throws XmlException
      {
          super(loader, tbl, root_nsctx, property, obj, options);
  
          this.objectRefTable = object_ref_table;
          this.writingMultiRefdObjs = writingMultiRefdObjs;
          if (writingMultiRefdObjs) topLevelIdInit(obj);
      }
  
  
      protected void reset(RuntimeBindingProperty property,
                           Object obj,
                           boolean writingMultiRefdObjs)
          throws XmlException
      {
          reset(property, obj);
          if (writingMultiRefdObjs) topLevelIdInit(obj);
      }
  
      private void topLevelIdInit(Object top_lvl_obj)
      {
          initAttributes();
  
          if (objectRefTable != null) {
              int id = objectRefTable.getId(top_lvl_obj);
              if (id >= 0) {
                  fillAndAddAttribute(getIdAttributeName(), ID_PREFIX + id);
              }
          }
  
      }
  
  
      //somewhat ugly way to "un-override" our createVisitor override, since
      //we don't want the special behavior when writing top lvl id parts.
      protected XmlTypeVisitor createInitialVisitor(RuntimeBindingProperty property,
                                                    Object obj)
          throws XmlException
      {
          if (writingMultiRefdObjs)
              return super.createVisitor(property, obj);
          else
              return createVisitor(property, obj);
      }
  
  
      protected XmlTypeVisitor createVisitor(RuntimeBindingProperty property,
                                             Object obj)
          throws XmlException
      {
          if (objectRefTable != null) {
              final int id = objectRefTable.getId(obj);
              if (id >= 0) {
                  return createRefdObjectVisitor(property, obj, id);
              }
          }
  
          return super.createVisitor(property, obj);
  
      }
  
      protected abstract XmlTypeVisitor createRefdObjectVisitor(RuntimeBindingProperty property,
                                                                Object obj,
                                                                int id)
          throws XmlException;
  
      protected abstract QName getIdAttributeName();
  }
  
  
  
  1.3       +5 -3      xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/SoapMarshaller.java
  
  Index: SoapMarshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/SoapMarshaller.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SoapMarshaller.java	27 Apr 2004 02:36:15 -0000	1.2
  +++ SoapMarshaller.java	30 Apr 2004 21:31:48 -0000	1.3
  @@ -17,6 +17,7 @@
   
   import javax.xml.namespace.QName;
   import javax.xml.stream.XMLStreamReader;
  +import java.util.Iterator;
   
   /**
    * A SoapMarshaller object is used to convert Java objects to SOAP encoded XML documents.
  @@ -61,8 +62,9 @@
       /**
        * Get the multiply referenced objects, usually written after the other parts.
        *
  -     * Note that the returned reader is not a full xml document,
  -     * but rather a forest of parts.
  +     * Returns an Iterator of XMLStreamReader objects, each reader 
  +     * represting an object that has been referred to more than once.
  +     *
        *
        * <ul>
        * <li>A collection instance that should be used as an error listener during
  @@ -73,7 +75,7 @@
        * @return
        * @throws XmlException
        */
  -    XMLStreamReader marshalReferenced(XmlOptions options)
  +    Iterator marshalReferenced(XmlOptions options)
           throws XmlException;
   
   
  
  
  
  1.57      +103 -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.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- MarshalTests.java	23 Apr 2004 18:52:31 -0000	1.56
  +++ MarshalTests.java	30 Apr 2004 21:31:49 -0000	1.57
  @@ -40,6 +40,8 @@
   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;
  @@ -234,7 +236,7 @@
               bindingContext.createUnmarshaller();
   
           Object obj = umctx.unmarshal(xrdr, options);
  -        reportErrors(errors, "SimpleType error. lexical="+lexval);
  +        reportErrors(errors, "SimpleType error. lexical=" + lexval);
           Assert.assertTrue(errors.isEmpty());
   
   
  @@ -420,6 +422,82 @@
       }
   
   
  +    public void testByNameMarshalSoap()
  +        throws Exception
  +    {
  +        final boolean verbose = false;
  +
  +        com.mytest.MyClass mc = new com.mytest.MyClass();
  +        mc.setMyatt("attval");
  +        com.mytest.YourClass myelt = new com.mytest.YourClass();
  +        myelt.setAttrib(99999.777f);
  +        myelt.setMyFloat(5555.4444f);
  +
  +        QName qn = new QName("foo", "bar");
  +        myelt.setQn(qn);
  +        myelt.setQn2(qn);
  +
  +        myelt.setWrappedArrayOne(new String[]{"a", "a", "b"});
  +
  +        MySubClass sub = new MySubClass();
  +        sub.setBigInt(new BigInteger("23522352235223522352"));
  +
  +        myelt.setMySubClass(sub);
  +        myelt.setMyClass(sub);
  +        sub.setMyelt(myelt);  //cycle
  +
  +        myelt.setMyBoss(myelt); //cycle: self reference
  +
  +        SimpleContentExample se = new SimpleContentExample();
  +        se.setFloatAttOne(44.33f);
  +        se.setSimpleContent("someSimpleContentOkay");
  +        myelt.setSimpleContentExample(se);
  +
  +        myelt.setModeEnum(ModeEnum.On);
  +
  +        mc.setMyelt(myelt);
  +
  +        myelt.setStringArray(new String[]{"a", "b", "c"});
  +
  +        myelt.setMyClassArray(new MyClass[]{sub, new MyClass(),
  +                                            //this type is not in our binding file,
  +                                            //but we should then treat is as its the parent type
  +                                            new MySubSubClass(),
  +                                            sub});
  +
  +
  +        BindingContext bindingContext = getBindingContext(getBindingConfigDocument());
  +
  +        final XmlOptions options = new XmlOptions();
  +        Collection errors = new LinkedList();
  +        options.setErrorListener(errors);
  +
  +        final SoapMarshaller ctx =
  +            bindingContext.createSoapMarshaller(EncodingStyle.SOAP11);
  +
  +        Assert.assertNotNull(ctx);
  +
  +
  +        final XMLStreamReader reader =
  +            ctx.marshalType(mc, new QName("java:com.mytest", "load"),
  +                            new QName("java:com.mytest", "MyClass"),
  +                            mc.getClass().getName(), options);
  +
  +        dumpReader(reader, verbose);
  +        reportErrors(errors, "byname-marshal-soap");
  +        Assert.assertTrue(errors.isEmpty());
  +
  +        inform("===========final id objs coming next===========", verbose);
  +        final Iterator itr = ctx.marshalReferenced(options);
  +        while (itr.hasNext()) {
  +            final XMLStreamReader rdr = (XMLStreamReader)itr.next();
  +            inform("got rdr: " + System.identityHashCode(rdr), verbose);
  +            dumpReader(rdr, verbose);
  +            rdr.close();
  +        }
  +    }
  +
  +
       public void testWrappedArray()
           throws Exception
       {
  @@ -965,6 +1043,12 @@
       private static void dumpReader(final XMLStreamReader reader)
           throws XMLStreamException, XmlException, IOException
       {
  +        dumpReader(reader, VERBOSE);
  +    }
  +
  +    private static void dumpReader(final XMLStreamReader reader, boolean verbose)
  +        throws XMLStreamException, XmlException, IOException
  +    {
           final boolean write_doc = true;
           if (write_doc) {
               StringWriter sw = new StringWriter();
  @@ -977,22 +1061,21 @@
   
               xsw.close();
   
  -            if (VERBOSE) {
  +            if (verbose) {
                   final String xmldoc = sw.getBuffer().toString();
  -                inform("DOC:");
  -                inform(PrettyPrinter.indent(xmldoc));
  -                inform((xmldoc));
  +                inform("DOC:", verbose);
  +                inform(PrettyPrinter.indent(xmldoc), verbose);
               }
           } else {
               int i = 0;
  -            if (VERBOSE)
  +            if (verbose)
                   inform((i++) + "\tSTATE: " +
  -                       XmlStreamUtils.printEvent(reader));
  +                       XmlStreamUtils.printEvent(reader), verbose);
               while (reader.hasNext()) {
                   final int state = reader.next();
  -                if (VERBOSE)
  +                if (verbose)
                       inform((i++) + "\tSTATE: " +
  -                           XmlStreamUtils.printEvent(reader));
  +                           XmlStreamUtils.printEvent(reader), verbose);
               }
           }
       }
  @@ -1304,7 +1387,17 @@
   
       private static void inform(String msg)
       {
  -        if (VERBOSE) System.out.println(msg);
  +        inform(msg, VERBOSE);
  +    }
  +
  +    private static void inform(String msg, boolean verbose)
  +    {
  +        if (verbose) System.out.println(msg);
  +    }
  +
  +    private static void say(String msg)
  +    {
  +        System.out.println(msg);
       }
   
       private static void error(String msg)
  
  
  

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