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 Wed, 14 Apr 2004 23:03:51 GMT
zieg        2004/04/14 16:03:51

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        BindingContextImpl.java MarshallerImpl.java
                        RuntimeBindingTypeTable.java
                        RuntimeTypeFactory.java
                        SimpleContentUnmarshaller.java UnmarshalResult.java
                        UnmarshallerImpl.java
               v2/src/xmlpublic/org/apache/xmlbeans BindingContext.java
                        Marshaller.java Unmarshaller.java
               v2/test/cases/marshal doc2.xml example_config.xml
               v2/test/cases/marshal/com/mytest YourClass.java
               v2/test/src/drt/drtcases MarshalTests.java
  Added:       v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        SoapMarshallerImpl.java
               v2/src/xmlpublic/org/apache/xmlbeans EncodingStyle.java
                        SoapMarshaller.java
  Log:
  add element based marshal and unmarshal methods
  stub out soap marshal methods
  
  Revision  Changes    Path
  1.13      +17 -8     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextImpl.java
  
  Index: BindingContextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BindingContextImpl.java	18 Mar 2004 23:25:35 -0000	1.12
  +++ BindingContextImpl.java	14 Apr 2004 23:03:50 -0000	1.13
  @@ -16,7 +16,9 @@
   package org.apache.xmlbeans.impl.marshal;
   
   import org.apache.xmlbeans.BindingContext;
  +import org.apache.xmlbeans.EncodingStyle;
   import org.apache.xmlbeans.Marshaller;
  +import org.apache.xmlbeans.SoapMarshaller;
   import org.apache.xmlbeans.Unmarshaller;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlOptions;
  @@ -31,7 +33,6 @@
   final class BindingContextImpl implements BindingContext
   {
       private final BindingLoader bindingLoader;
  -    private final RuntimeTypeFactory runtimeTypeFactory;
       private final RuntimeBindingTypeTable typeTable;
       private final SchemaTypeLoaderProvider schemaTypeLoaderProvider;
   
  @@ -41,9 +42,7 @@
                          SchemaTypeLoaderProvider provider)
       {
           this.bindingLoader = bindingLoader;
  -        runtimeTypeFactory = new RuntimeTypeFactory();
  -        this.typeTable =
  -            RuntimeBindingTypeTable.createTable(runtimeTypeFactory);
  +        this.typeTable = RuntimeBindingTypeTable.createTable();
           this.schemaTypeLoaderProvider = provider;
       }
   
  @@ -69,9 +68,7 @@
       public Marshaller createMarshaller()
           throws XmlException
       {
  -        return new MarshallerImpl(bindingLoader,
  -                                  typeTable,
  -                                  runtimeTypeFactory);
  +        return new MarshallerImpl(bindingLoader, typeTable);
       }
   
   
  @@ -79,10 +76,22 @@
           throws XmlException
       {
           if (options == null) {
  -            throw new IllegalArgumentException("options must not be null");
  +            throw new IllegalArgumentException("null options");
           }
   
           return createMarshaller();
  +    }
  +
  +    public SoapMarshaller createSoapMarshaller(EncodingStyle encodingStyle)
  +        throws XmlException
  +    {
  +        if (encodingStyle == null) {
  +            throw new IllegalArgumentException("null encodingStyle");
  +        }
  +
  +        return new SoapMarshallerImpl(bindingLoader,
  +                                      typeTable,
  +                                      encodingStyle);
       }
   
       static Collection extractErrorHandler(XmlOptions options)
  
  
  
  1.25      +119 -11   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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- MarshallerImpl.java	8 Apr 2004 19:03:44 -0000	1.24
  +++ MarshallerImpl.java	14 Apr 2004 23:03:50 -0000	1.25
  @@ -24,6 +24,7 @@
   import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
   import org.apache.xmlbeans.impl.binding.bts.JavaTypeName;
   import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
  +import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
   import org.apache.xmlbeans.impl.common.XmlReaderToWriter;
   
   import javax.xml.namespace.NamespaceContext;
  @@ -41,7 +42,6 @@
       //per binding context constants
       private final BindingLoader loader;
       private final RuntimeBindingTypeTable typeTable;
  -    private final RuntimeTypeFactory runtimeTypeFactory;
   
       private static final XMLOutputFactory XML_OUTPUT_FACTORY =
           XMLOutputFactory.newInstance();
  @@ -49,12 +49,10 @@
       private static final String XML_VERSION = "1.0";
   
       public MarshallerImpl(BindingLoader loader,
  -                          RuntimeBindingTypeTable typeTable,
  -                          RuntimeTypeFactory runtimeTypeFactory)
  +                          RuntimeBindingTypeTable typeTable)
       {
           this.loader = loader;
           this.typeTable = typeTable;
  -        this.runtimeTypeFactory = runtimeTypeFactory;
       }
   
       public XMLStreamReader marshal(Object obj,
  @@ -95,8 +93,19 @@
                                                 Object obj)
           throws XmlException
       {
  +        assert btype != null;
  +
           final RuntimeBindingType runtime_type =
  -            runtimeTypeFactory.createRuntimeType(btype, typeTable, loader);
  +            typeTable.getRuntimeTypeFactory().createRuntimeType(btype,
  +                                                                typeTable,
  +                                                                loader);
  +
  +        if (obj != null && !runtime_type.getJavaType().isAssignableFrom(obj.getClass()))
{
  +            String m = "instance type: " + obj.getClass() +
  +                " not an instance of expected type: " +
  +                runtime_type.getJavaType();
  +            throw new XmlException(m);
  +        }
   
           RuntimeGlobalProperty prop =
               new RuntimeGlobalProperty(elem_qn, runtime_type);
  @@ -111,7 +120,8 @@
           throws XmlException
       {
           //TODO: actually use the options!
  -        return marshal(obj, EmptyNamespaceContext.getInstance());
  +        NamespaceContext nscontext = getNamespaceContextFromOptions(options);
  +        return marshal(obj, nscontext);
       }
   
       private static JavaTypeName determineJavaType(Object obj)
  @@ -187,7 +197,8 @@
                                  XmlOptions options)
           throws XmlException
       {
  -        XMLStreamReader rdr = marshal(obj, EmptyNamespaceContext.getInstance());
  +        NamespaceContext nscontext = getNamespaceContextFromOptions(options);
  +        XMLStreamReader rdr = marshal(obj, nscontext);
           XmlObject xobj = XmlObject.Factory.parse(rdr);
           try {
               xobj.save(out, options);
  @@ -216,7 +227,7 @@
       }
   
       private static XMLStreamWriter createXmlStreamWriter(OutputStream out,
  -                                                  final String encoding)
  +                                                         final String encoding)
           throws XMLStreamException
       {
           XMLStreamWriter writer;
  @@ -284,6 +295,27 @@
           }
       }
   
  +    public void marshalElement(XMLStreamWriter writer,
  +                               Object obj,
  +                               QName elementName,
  +                               String javaType,
  +                               XmlOptions options)
  +        throws XmlException
  +    {
  +        if (writer == null)
  +            throw new IllegalArgumentException("null writer");
  +
  +        final XMLStreamReader rdr =
  +            marshalElement(obj, elementName, javaType, options);
  +
  +        try {
  +            XmlReaderToWriter.writeAll(rdr, writer);
  +        }
  +        catch (XMLStreamException e) {
  +            throw new XmlException(e);
  +        }
  +    }
  +
       public void marshalType(XMLStreamWriter writer,
                               Object obj,
                               QName elementName,
  @@ -292,7 +324,6 @@
                               XmlOptions options)
           throws XmlException
       {
  -        //TODO: actually use the options!!
           marshalType(writer, obj, elementName, schemaType, javaType);
       }
   
  @@ -303,9 +334,86 @@
                                          XmlOptions options)
           throws XmlException
       {
  -        //TODO: actually use the options!!
  -        return marshalType(obj, elementName, schemaType, javaType, EmptyNamespaceContext.getInstance());
  +        NamespaceContext nscontext = getNamespaceContextFromOptions(options);
  +
  +        return marshalType(obj, elementName, schemaType, javaType,
  +                           nscontext);
  +    }
  +
  +    public XMLStreamReader marshalElement(Object obj,
  +                                          QName elementName,
  +                                          String javaType,
  +                                          XmlOptions options)
  +        throws XmlException
  +    {
  +        if (elementName == null)
  +            throw new IllegalArgumentException("null elementName");
  +
  +        //TODO: we could allow javaType to be null in which case we could
  +        //use our usual lookup methods (as in plain marshal)
  +        if (javaType == null)
  +            throw new IllegalArgumentException("null javaType");
  +
  +
  +        final SimpleDocumentBinding doc_binding =
  +            determineDocumentType(elementName);
  +
  +        final XmlTypeName elem_type = doc_binding.getTypeOfElement();
  +        final BindingType type =
  +            loadBindingType(elem_type,
  +                            JavaTypeName.forClassName(javaType),
  +                            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);
  +    }
  +
  +    private static NamespaceContext getNamespaceContextFromOptions(XmlOptions options)
  +    {
  +        //TODO: do this properly
  +        return EmptyNamespaceContext.getInstance();
  +    }
  +
  +    private SimpleDocumentBinding determineDocumentType(QName global_element)
  +        throws XmlException
  +    {
  +        final XmlTypeName type_name =
  +            XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, global_element);
  +        BindingType doc_binding_type = getPojoBindingType(type_name);
  +        return (SimpleDocumentBinding)doc_binding_type;
       }
  +
  +
  +    private BindingType getPojoBindingType(final XmlTypeName type_name)
  +        throws XmlException
  +    {
  +        final BindingTypeName btName = loader.lookupPojoFor(type_name);
  +        if (btName == null) {
  +            final String msg = "failed to load java type corresponding " +
  +                "to " + type_name;
  +            throw new XmlException(msg);
  +        }
  +
  +        BindingType bt = loader.getBindingType(btName);
  +
  +        if (bt == null) {
  +            final String msg = "failed to load BindingType for " + btName;
  +            throw new XmlException(msg);
  +        }
  +
  +        return bt;
  +    }
  +
  +
   
   
       //TODO: refine this algorithm to deal better
  
  
  
  1.27      +2 -4      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingTypeTable.java
  
  Index: RuntimeBindingTypeTable.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingTypeTable.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- RuntimeBindingTypeTable.java	8 Apr 2004 19:03:44 -0000	1.26
  +++ RuntimeBindingTypeTable.java	14 Apr 2004 23:03:50 -0000	1.27
  @@ -63,14 +63,12 @@
           BUILTIN_MARSHALLER_MAP = (ConcurrentReaderHashMap)tbl.marshallerMap;
       }
   
  -    static RuntimeBindingTypeTable createTable(RuntimeTypeFactory factory)
  +    static RuntimeBindingTypeTable createTable()
       {
  -        assert factory != null;
  -
           final RuntimeBindingTypeTable tbl =
               new RuntimeBindingTypeTable((Map)BUILTIN_UNMARSHALLER_MAP.clone(),
                                           (Map)BUILTIN_MARSHALLER_MAP.clone(),
  -                                        factory);
  +                                        new RuntimeTypeFactory());
           return tbl;
       }
   
  
  
  
  1.16      +1 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeTypeFactory.java
  
  Index: RuntimeTypeFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeTypeFactory.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- RuntimeTypeFactory.java	6 Apr 2004 00:53:09 -0000	1.15
  +++ RuntimeTypeFactory.java	14 Apr 2004 23:03:50 -0000	1.16
  @@ -58,6 +58,7 @@
                                                   BindingLoader binding_loader)
           throws XmlException
       {
  +        assert type != null;
           RuntimeBindingType rtype = (RuntimeBindingType)initedTypeMap.get(type);
           if (rtype != null) return rtype;
   
  
  
  
  1.3       +1 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentUnmarshaller.java
  
  Index: SimpleContentUnmarshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SimpleContentUnmarshaller.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleContentUnmarshaller.java	25 Mar 2004 03:19:28 -0000	1.2
  +++ SimpleContentUnmarshaller.java	14 Apr 2004 23:03:50 -0000	1.3
  @@ -17,7 +17,7 @@
   
   import org.apache.xmlbeans.XmlException;
   
  -public final class SimpleContentUnmarshaller
  +final class SimpleContentUnmarshaller
       extends AttributeUnmarshaller
   {
   
  
  
  
  1.17      +55 -7     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalResult.java
  
  Index: UnmarshalResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalResult.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- UnmarshalResult.java	9 Apr 2004 21:54:16 -0000	1.16
  +++ UnmarshalResult.java	14 Apr 2004 23:03:51 -0000	1.17
  @@ -213,6 +213,32 @@
                            String javaType)
           throws XmlException
       {
  +        doctorStream(schemaType, reader);
  +
  +        final QName xsi_type = getXsiType();
  +
  +        BindingType btype = null;
  +
  +        if (xsi_type != null) {
  +            btype = getPojoTypeFromXsiType(xsi_type);
  +        }
  +
  +        if (btype == null) {
  +            btype = determineBindingType(schemaType, javaType);
  +        }
  +
  +        if (btype == null) {
  +            final String msg = "unable to find binding type for " +
  +                schemaType + " : " + javaType;
  +            throw new XmlException(msg);
  +        }
  +        return unmarshalBindingType(btype);
  +    }
  +
  +    private void doctorStream(QName schemaType,
  +                              XMLStreamReader reader)
  +        throws XmlException
  +    {
           if (isValidating()) {
               ValidatingXMLStreamReader vr = new ValidatingXMLStreamReader();
               SchemaTypeLoader schemaTypeLoader =
  @@ -228,6 +254,21 @@
           }
   
           enrichXmlStream(reader);
  +    }
  +
  +
  +    Object unmarshalElement(XMLStreamReader reader,
  +                            QName globalElement,
  +                            String javaType)
  +        throws XmlException
  +    {
  +        final BindingType binding_type =
  +            determineTypeForGlobalElement(globalElement);
  +        final XmlTypeName type_name = binding_type.getName().getXmlName();
  +        assert type_name.isGlobal();
  +        assert type_name.isSchemaType();
  +        final QName schema_type = type_name.getQName();
  +        doctorStream(schema_type, reader);
   
           final QName xsi_type = getXsiType();
   
  @@ -238,17 +279,18 @@
           }
   
           if (btype == null) {
  -            btype = determineBindingType(schemaType, javaType);
  +            btype = determineBindingType(schema_type, javaType);
           }
   
           if (btype == null) {
               final String msg = "unable to find binding type for " +
  -                schemaType + " : " + javaType;
  +                schema_type + " : " + javaType;
               throw new XmlException(msg);
           }
           return unmarshalBindingType(btype);
       }
   
  +
       private boolean isValidating()
       {
           if (options == null) return false;
  @@ -277,14 +319,20 @@
           if (retval == null) {
               QName root_elem_qname = new QName(this.getNamespaceURI(),
                                                 this.getLocalName());
  -            final XmlTypeName type_name =
  -                XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, root_elem_qname);
  -            BindingType doc_binding_type = getPojoBindingType(type_name, true);
  -            SimpleDocumentBinding sd = (SimpleDocumentBinding)doc_binding_type;
  -            retval = getPojoBindingType(sd.getTypeOfElement(), true);
  +            retval = determineTypeForGlobalElement(root_elem_qname);
           }
   
           return retval;
  +    }
  +
  +    private BindingType determineTypeForGlobalElement(QName elem)
  +        throws XmlException
  +    {
  +        final XmlTypeName type_name =
  +            XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, elem);
  +        BindingType doc_binding_type = getPojoBindingType(type_name, true);
  +        SimpleDocumentBinding sd = (SimpleDocumentBinding)doc_binding_type;
  +        return getPojoBindingType(sd.getTypeOfElement(), true);
       }
   
       //will return null on error and log errors
  
  
  
  1.22      +23 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshallerImpl.java
  
  Index: UnmarshallerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshallerImpl.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- UnmarshallerImpl.java	16 Mar 2004 00:55:01 -0000	1.21
  +++ UnmarshallerImpl.java	14 Apr 2004 23:03:51 -0000	1.22
  @@ -112,6 +112,29 @@
           return result.unmarshalType(reader, schemaType, javaType);
       }
   
  +    public Object unmarshalElement(XMLStreamReader reader,
  +                                   QName globalElement,
  +                                   String javaType,
  +                                   XmlOptions options)
  +        throws XmlException
  +    {
  +        if (reader == null)
  +            throw new IllegalArgumentException("null reader");
  +        if (globalElement == null)
  +            throw new IllegalArgumentException("null globalElement");
  +        if (javaType == null)
  +            throw new IllegalArgumentException("null javaType");
  +        if (!reader.isStartElement()) {
  +            throw new IllegalStateException("reader must be positioned on a start element");
  +        }
  +
  +        final UnmarshalResult result =
  +            new UnmarshalResult(bindingLoader, typeTable,
  +                                schemaTypeLoaderProvider, options);
  +
  +        return result.unmarshalElement(reader, globalElement, javaType);
  +    }
  +
       XMLInputFactory getXmlInputFactory()
       {
           return XML_INPUT_FACTORY;
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SoapMarshallerImpl.java
  
  Index: SoapMarshallerImpl.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.SoapMarshaller;
  import org.apache.xmlbeans.EncodingStyle;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  
  import javax.xml.stream.XMLStreamReader;
  import javax.xml.namespace.QName;
  
  class SoapMarshallerImpl implements SoapMarshaller
  {
      SoapMarshallerImpl(BindingLoader loader,
                         RuntimeBindingTypeTable typeTable,
                         EncodingStyle encodingStyle)
      {
      }
  
      public XMLStreamReader marshalType(Object obj,
                                         QName elementName,
                                         QName schemaType,
                                         String javaType,
                                         XmlOptions options)
          throws XmlException
      {
          throw new AssertionError("UNIMP: this=" + this);
      }
  
      public XMLStreamReader marshalReferenced(Object obj,
                                               QName elementName,
                                               QName schemaType,
                                               String javaType,
                                               XmlOptions options)
          throws XmlException
      {
          throw new AssertionError("UNIMP: this=" + this);
      }
  }
  
  
  
  1.7       +12 -0     xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/BindingContext.java
  
  Index: BindingContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/BindingContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BindingContext.java	12 Feb 2004 20:06:27 -0000	1.6
  +++ BindingContext.java	14 Apr 2004 23:03:51 -0000	1.7
  @@ -66,4 +66,16 @@
       Marshaller createMarshaller(XmlOptions options)
           throws XmlException;
   
  +
  +    /**
  +     * Create an Marshaller object capable of marshalling types
  +     * known by this context
  +     *
  +     * @return Marshaller object
  +     * @throws XmlException
  +     */
  +    SoapMarshaller createSoapMarshaller(EncodingStyle encodingStyle)
  +        throws XmlException;
  +
  +
   }
  
  
  
  1.12      +59 -5     xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/Marshaller.java
  
  Index: Marshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/Marshaller.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Marshaller.java	3 Mar 2004 18:53:28 -0000	1.11
  +++ Marshaller.java	14 Apr 2004 23:03:51 -0000	1.12
  @@ -23,9 +23,7 @@
   
   /**
    * A Marshaller object is used to convert Java objects to XML documents.
  - * The object is not thread safe and should not be shared between threads.
  - * It can however be shared across different invocations of
  - * Marshaller.marshalType() for a given document.
  + * The object is thread safe and stateless.
    */
   public interface Marshaller
   {
  @@ -121,7 +119,7 @@
        * compilation, as described in {@link XmlOptions#setErrorListener}.</li>
        * <li>The encoding for the document, as described in
        * {@link XmlOptions#setCharacterEncoding}.</li>
  -     * </ul>
  +     * </ul>B
        *
        *
        * @param obj
  @@ -231,7 +229,6 @@
           throws XmlException;
   
   
  -
       /**
        * Get an XMLStreamReader object that represents the given java type.
   
  @@ -262,6 +259,35 @@
                                   XmlOptions options)
           throws XmlException;
   
  +
  +    /**
  +     * Get an XMLStreamReader object that represents the given java type.
  +
  +     * It is the responsibility of the caller to ensure that
  +     * obj is an instanceof javaType
  +
  +     * As of this writing (11/22/2003), the returned reader will NOT contain
  +     * a START_DOCUMENT or END_DOCUMENT element.
  +     * The reader's first event is a START_ELEMENT event.
  +     *
  +     * <ul>
  +     * <li>A collection instance that should be used as an error listener during
  +     * compilation, as described in {@link XmlOptions#setErrorListener}.</li>
  +     * </ul>
  +     *
  +     * @param obj
  +     * @param elementName  name of global element from a known schema
  +     * @param javaType the java type in the format returned by Class.getName()
  +     * @param options
  +     * @return
  +     * @throws XmlException
  +     */
  +    XMLStreamReader marshalElement(Object obj,
  +                                   QName elementName,
  +                                   String javaType,
  +                                   XmlOptions options)
  +        throws XmlException;
  +
       /**
        * Write an XML representation of the Java object to the provided output.
        *
  @@ -317,5 +343,33 @@
                        XmlOptions options)
           throws XmlException;
   
  +
  +    /**
  +     * Write an XML representation of the Java object to the provided output.
  +     *
  +     * It is the responsibility of the caller to ensure that
  +     * obj is an instanceof javaType
  +     *
  +     * As of this writing (11/22/2003), this method will NOT write
  +     * a START_DOCUMENT or END_DOCUMENT element.
  +     * The first event written will be a START_ELEMENT event.
  +     *
  +     * <ul>
  +     * <li>A collection instance that should be used as an error listener during
  +     * compilation, as described in {@link XmlOptions#setErrorListener}.</li>
  +     * </ul>
  +     *
  +     * @param writer
  +     * @param obj
  +     * @param elementName  name of global element from a known schema
  +     * @param javaType the java type in the format returned by Class.getName()
  +     * @throws XmlException
  +     */
  +    void marshalElement(XMLStreamWriter writer,
  +                        Object obj,
  +                        QName elementName,
  +                        String javaType,
  +                        XmlOptions options)
  +        throws XmlException;
   
   }
  
  
  
  1.8       +31 -0     xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/Unmarshaller.java
  
  Index: Unmarshaller.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/Unmarshaller.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Unmarshaller.java	3 Mar 2004 18:53:28 -0000	1.7
  +++ Unmarshaller.java	14 Apr 2004 23:03:51 -0000	1.8
  @@ -162,4 +162,35 @@
                            String javaType,
                            XmlOptions options)
           throws XmlException;
  +
  +    /**
  +     * unmarshal an xml instance of a given schema element
  +     *
  +     * PRECONDITIONS:
  +     * reader.isStartElement() must return true
  +     * reader is positioned on an element matching globalElement
  +     *   (or on a a valid substitution for that element).
  +     *
  +     * POSTCONDITIONS:
  +     * reader will be positioned immediately after the end element
  +     * corresponding to the start element from the precondition
  +     *
  +     * <p>Use the <em>options</em> parameter to specify the following:</p>
  +     *
  +     * <ul>
  +     * <li>A collection instance that should be used as an error listener during
  +     * compilation, as described in {@link XmlOptions#setErrorListener}.</li>
  +     * </ul>
  +     *
  +     *
  +     * @param globalElement  name of a global element
  +     * @param javaType the java type in the format returned by Class.getName()
  +     * @return
  +     * @throws org.apache.xmlbeans.XmlException
  +     */
  +    Object unmarshalElement(XMLStreamReader reader,
  +                            QName globalElement,
  +                            String javaType,
  +                            XmlOptions options)
  +        throws XmlException;
   }
  
  
  
  1.1                  xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/EncodingStyle.java
  
  Index: EncodingStyle.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans;
  
  public final class EncodingStyle
  {
      public static final EncodingStyle SOAP11 = new EncodingStyle("SOAP11");
      public static final EncodingStyle SOAP12 = new EncodingStyle("SOAP12");
  
      private final String myName;
  
      private EncodingStyle(String name)
      {
          myName = name;
      }
  
      public String toString()
      {
          return myName;
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/SoapMarshaller.java
  
  Index: SoapMarshaller.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;
  
  import javax.xml.namespace.QName;
  import javax.xml.stream.XMLStreamReader;
  
  /**
   * A SoapMarshaller object is used to convert Java objects to SOAP encoded XML documents.
   * The object is not thread safe and should not be shared between threads.
   * It can however be shared across different invocations of
   * Marshaller.marshalType() for a given document.
   */
  public interface SoapMarshaller
  {
  
      /**
       * Get an XMLStreamReader object that represents the given java type.
  
       * It is the responsibility of the caller to ensure that
       * obj is an instanceof javaType
  
       * As of this writing (11/22/2003), the returned reader will NOT contain
       * a START_DOCUMENT or END_DOCUMENT element.
       * The reader's first event is a START_ELEMENT event.
       *
       * <ul>
       * <li>A collection instance that should be used as an error listener during
       * compilation, as described in {@link XmlOptions#setErrorListener}.</li>
       * </ul>
       *
       * @param obj
       * @param elementName
       * @param schemaType
       * @param javaType the java type in the format returned by Class.getName()
       * @param options
       * @return
       * @throws XmlException
       */
      XMLStreamReader marshalType(Object obj,
                                  QName elementName,
                                  QName schemaType,
                                  String javaType,
                                  XmlOptions options)
          throws XmlException;
  
  
      /**
       * 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.
       *
       * <ul>
       * <li>A collection instance that should be used as an error listener during
       * compilation, as described in {@link XmlOptions#setErrorListener}.</li>
       * </ul>
       *
       * @param obj
       * @param elementName
       * @param schemaType
       * @param javaType the java type in the format returned by Class.getName()
       * @param options
       * @return
       * @throws XmlException
       */
      XMLStreamReader marshalReferenced(Object obj,
                                        QName elementName,
                                        QName schemaType,
                                        String javaType,
                                        XmlOptions options)
          throws XmlException;
  
  
  }
  
  
  
  1.9       +5 -0      xml-xmlbeans/v2/test/cases/marshal/doc2.xml
  
  Index: doc2.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/doc2.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- doc2.xml	29 Mar 2004 07:02:48 -0000	1.8
  +++ doc2.xml	14 Apr 2004 23:03:51 -0000	1.9
  @@ -35,6 +35,11 @@
           </n1:BooleanArray>
           <n1:BooleanArray>1</n1:BooleanArray>
   
  +<!--        test bad xsi type TODO: handle better-->
  +<!--        <n1:SomeDate xsi:type='xsd:string'>2002-03-06T08:04:39.265Z</n1:SomeDate>-->
  +        <n1:SomeDate>2002-03-06T08:04:39.265Z</n1:SomeDate>
  +
  +
       </n1:Myelt>
   
       <n1:Myatt>attval</n1:Myatt>
  
  
  
  1.28      +12 -0     xml-xmlbeans/v2/test/cases/marshal/example_config.xml
  
  Index: example_config.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/example_config.xml,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- example_config.xml	6 Apr 2004 00:53:09 -0000	1.27
  +++ example_config.xml	14 Apr 2004 23:03:51 -0000	1.28
  @@ -290,6 +290,18 @@
                   <bin:qname>java:simpleLongArray</bin:qname>
               </bin:qname-property>
   
  +            <bin:qname-property>
  +                <bin:xmlcomponent>t=dateTime@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
  +                <bin:javatype>java.util.Date</bin:javatype>
  +                <bin:getter>
  +                    <bin:method-name>getSomeDate</bin:method-name>
  +                </bin:getter>
  +                <bin:setter>
  +                    <bin:method-name>setSomeDate</bin:method-name>
  +                    <bin:param-type>java.util.Date</bin:param-type>
  +                </bin:setter>
  +                <bin:qname>java:SomeDate</bin:qname>
  +            </bin:qname-property>
   
   
           </bin:binding-type>
  
  
  
  1.18      +12 -0     xml-xmlbeans/v2/test/cases/marshal/com/mytest/YourClass.java
  
  Index: YourClass.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/com/mytest/YourClass.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- YourClass.java	6 Apr 2004 00:53:09 -0000	1.17
  +++ YourClass.java	14 Apr 2004 23:03:51 -0000	1.18
  @@ -23,6 +23,7 @@
   import java.util.List;
   import java.util.Random;
   import java.util.Arrays;
  +import java.util.Date;
   
   public class YourClass
       implements ObjectFactory
  @@ -63,6 +64,7 @@
       private long[] simpleLongArray = {RND.nextLong(),
                                         RND.nextLong()};
   
  +    private Date someDate;
   
       //hack alert
       static final Random RND = new Random();
  @@ -331,6 +333,16 @@
       public void setSimpleLongArray(long[] simpleLongArray)
       {
           this.simpleLongArray = simpleLongArray;
  +    }
  +
  +    public Date getSomeDate()
  +    {
  +        return someDate;
  +    }
  +
  +    public void setSomeDate(Date someDate)
  +    {
  +        this.someDate = someDate;
       }
   
       public boolean equals(Object o)
  
  
  
  1.52      +49 -1     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.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- MarshalTests.java	12 Apr 2004 22:39:46 -0000	1.51
  +++ MarshalTests.java	14 Apr 2004 23:03:51 -0000	1.52
  @@ -480,7 +480,8 @@
           Assert.assertNotNull(ctx);
   
   
  -        ctx.marshalType(w, mc, new QName("java:com.mytest", "load"),
  +        ctx.marshalType(w, mc,
  +                        new QName("java:com.mytest", "load"),
                           new QName("java:com.mytest", "MyClass"),
                           mc.getClass().getName(), options);
   
  @@ -523,6 +524,53 @@
               XMLInputFactory.newInstance().createXMLStreamReader(sr);
           Unmarshaller umctx = bindingContext.createUnmarshaller();
           Object out_obj = umctx.unmarshal(rdr, options);
  +        Assert.assertEquals(mc, out_obj);
  +        Assert.assertTrue(errors.isEmpty());
  +    }
  +
  +    public void testByNameMarshalElementViaWriter()
  +        throws Exception
  +    {
  +        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);
  +//        myelt.setMyClass(new com.mytest.MyClass());
  +        myelt.setMyClass(null);
  +        mc.setMyelt(myelt);
  +
  +        myelt.setStringArray(new String[]{"one", "two", "three"});
  +
  +
  +        BindingContext bindingContext = getBindingContext(getBindingConfigDocument());
  +
  +        StringWriter sw = new StringWriter();
  +        XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
  +
  +        final XmlOptions options = new XmlOptions();
  +        Collection errors = new LinkedList();
  +        options.setErrorListener(errors);
  +        Marshaller ctx =
  +            bindingContext.createMarshaller();
  +        Assert.assertNotNull(ctx);
  +
  +        final QName elem_name = new QName("java:com.mytest", "load");
  +        ctx.marshalElement(w,
  +                           mc,
  +                           elem_name,
  +                           mc.getClass().getName(),
  +                           options);
  +
  +        //now unmarshall from String and compare objects...
  +        StringReader sr = new StringReader(sw.getBuffer().toString());
  +        XMLStreamReader rdr =
  +            XMLInputFactory.newInstance().createXMLStreamReader(sr);
  +        Unmarshaller umctx = bindingContext.createUnmarshaller();
  +        while(!rdr.isStartElement()) {rdr.next();}
  +        Object out_obj = umctx.unmarshalElement(rdr, elem_name,
  +                                                mc.getClass().getName(),
  +                                                options);
           Assert.assertEquals(mc, out_obj);
           Assert.assertTrue(errors.isEmpty());
       }
  
  
  

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