xml-xmlbeans-cvs 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 Tue, 16 Mar 2004 00:55:01 GMT
zieg        2004/03/15 16:55:01

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        BindingContextFactoryImpl.java
                        BindingContextImpl.java RuntimeBindingType.java
                        UnmarshalResult.java UnmarshallerImpl.java
               v2/src/xmlpublic/org/apache/xmlbeans XmlOptions.java
               v2/test/src/drt/drtcases MarshalTests.java
  Added:       v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        BuiltinSchemaTypeLoaderProvider.java
                        SchemaTypeLoaderProvider.java
                        TylarSchemaTypeLoaderProvider.java
                        UnusedSchemaTypeLoaderProvider.java
  Log:
  first pass at adding validation to unmarshalling (off by default)
  
  Revision  Changes    Path
  1.15      +12 -5     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextFactoryImpl.java
  
  Index: BindingContextFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextFactoryImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- BindingContextFactoryImpl.java	13 Mar 2004 00:33:22 -0000	1.14
  +++ BindingContextFactoryImpl.java	16 Mar 2004 00:55:01 -0000	1.15
  @@ -75,22 +75,27 @@
           // the builtin loader
           BindingLoader loader = tylar.getBindingLoader();
           // finally, glue it all together
  -        return new BindingContextImpl(loader);
  +        TylarSchemaTypeLoaderProvider provider =
  +            new TylarSchemaTypeLoaderProvider(tylar);
  +        return new BindingContextImpl(loader, provider);
       }
   
       public BindingContext createBindingContext()
       {
           BindingFile empty = new BindingFile();
  -        return createBindingContext(empty);
  +        SchemaTypeLoaderProvider provider =
  +            BuiltinSchemaTypeLoaderProvider.getInstance();
  +        return createBindingContext(empty, provider);
       }
   
       // ========================================================================
       // Private methods
   
  -    private static BindingContextImpl createBindingContext(BindingFile bf)
  +    private static BindingContextImpl createBindingContext(BindingFile bf,
  +                                                           SchemaTypeLoaderProvider provider)
       {
           BindingLoader bindingLoader = buildBindingLoader(bf);
  -        return new BindingContextImpl(bindingLoader);
  +        return new BindingContextImpl(bindingLoader, provider);
       }
   
       private static BindingLoader buildBindingLoader(BindingFile bf)
  @@ -111,7 +116,9 @@
           BindingConfigDocument doc =
               BindingConfigDocument.Factory.parse(bindingConfig);
           BindingFile bf = BindingFile.forDoc(doc);
  -        return createBindingContext(bf);
  +        SchemaTypeLoaderProvider provider =
  +            UnusedSchemaTypeLoaderProvider.getInstance();
  +        return createBindingContext(bf, provider);
       }
   
   
  
  
  
  1.11      +6 -2      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BindingContextImpl.java	12 Feb 2004 20:06:16 -0000	1.10
  +++ BindingContextImpl.java	16 Mar 2004 00:55:01 -0000	1.11
  @@ -33,22 +33,26 @@
       private final BindingLoader bindingLoader;
       private final RuntimeTypeFactory runtimeTypeFactory;
       private final RuntimeBindingTypeTable typeTable;
  +    private final SchemaTypeLoaderProvider schemaTypeLoaderProvider;
   
   
       /* package protected -- use the factory */
  -    BindingContextImpl(BindingLoader bindingLoader)
  +    BindingContextImpl(BindingLoader bindingLoader,
  +                       SchemaTypeLoaderProvider provider)
       {
           this.bindingLoader = bindingLoader;
           runtimeTypeFactory = new RuntimeTypeFactory();
           this.typeTable =
               RuntimeBindingTypeTable.createTable(runtimeTypeFactory);
  +        this.schemaTypeLoaderProvider  = provider;
       }
   
   
       public Unmarshaller createUnmarshaller()
           throws XmlException
       {
  -        return new UnmarshallerImpl(bindingLoader, typeTable);
  +        return new UnmarshallerImpl(bindingLoader, typeTable,
  +                                    schemaTypeLoaderProvider);
       }
   
       public Unmarshaller createUnmarshaller(XmlOptions options)
  
  
  
  1.13      +4 -1      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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RuntimeBindingType.java	13 Mar 2004 03:46:57 -0000	1.12
  +++ RuntimeBindingType.java	16 Mar 2004 00:55:01 -0000	1.13
  @@ -115,7 +115,10 @@
       {
           final String xmldoc = "<a>" + value + "</a>";
           try {
  -            final UnmarshallerImpl um = new UnmarshallerImpl(loader, typeTable);
  +            final SchemaTypeLoaderProvider provider =
  +                UnusedSchemaTypeLoaderProvider.getInstance();
  +            final UnmarshallerImpl um =
  +                new UnmarshallerImpl(loader, typeTable, provider);
               final StringReader sr = new StringReader(xmldoc);
               final XMLStreamReader reader =
                   um.getXmlInputFactory().createXMLStreamReader(sr);
  
  
  
  1.11      +60 -11    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- UnmarshalResult.java	3 Mar 2004 18:53:28 -0000	1.10
  +++ UnmarshalResult.java	16 Mar 2004 00:55:01 -0000	1.11
  @@ -20,6 +20,8 @@
   import org.apache.xmlbeans.XmlCalendar;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlOptions;
  +import org.apache.xmlbeans.SchemaTypeLoader;
  +import org.apache.xmlbeans.SchemaType;
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.BindingType;
   import org.apache.xmlbeans.impl.binding.bts.BindingTypeName;
  @@ -29,6 +31,7 @@
   import org.apache.xmlbeans.impl.common.InvalidLexicalValueException;
   import org.apache.xmlbeans.impl.richParser.XMLStreamReaderExt;
   import org.apache.xmlbeans.impl.richParser.XMLStreamReaderExtImpl;
  +import org.apache.xmlbeans.impl.validator.ValidatingXMLStreamReader;
   
   import javax.xml.namespace.QName;
   import javax.xml.stream.Location;
  @@ -55,9 +58,11 @@
       //per binding context objects
       private final BindingLoader bindingLoader;
       private final RuntimeBindingTypeTable typeTable;
  +    private final SchemaTypeLoaderProvider schemaTypeLoaderProvider;
   
       //our state
       private XMLStreamReaderExt baseReader;
  +    private final XmlOptions options;
       private final Collection errors;
       private final XsiAttributeHolder xsiAttributeHolder =
           new XsiAttributeHolder();
  @@ -71,15 +76,18 @@
   
       UnmarshalResult(BindingLoader bindingLoader,
                       RuntimeBindingTypeTable typeTable,
  +                    SchemaTypeLoaderProvider provider,
                       XmlOptions options)
       {
           this.bindingLoader = bindingLoader;
           this.typeTable = typeTable;
  +        this.schemaTypeLoaderProvider = provider;
  +        this.options = options;
           this.errors = BindingContextImpl.extractErrorHandler(options);
       }
   
   
  -    void setXmlStream(XMLStreamReader reader)
  +    private void enrichXmlStream(XMLStreamReader reader)
       {
           assert reader != null;
   
  @@ -98,7 +106,7 @@
       }
   
       //returns null and updates errors if there was a problem.
  -    TypeUnmarshaller getTypeUnmarshaller(QName xsi_type)
  +    private TypeUnmarshaller getTypeUnmarshaller(QName xsi_type)
       {
           XmlTypeName xname = XmlTypeName.forTypeNamed(xsi_type);
           BindingType binding_type =
  @@ -132,12 +140,32 @@
       }
   
   
  -    Object unmarshal(XMLStreamReader reader)
  +    Object unmarshalDocument(XMLStreamReader reader)
           throws XmlException
       {
  -        setXmlStream(reader);
  -        advanceToFirstItemOfInterest();
  +        //TODO: turn on validation before looking at root type
  +        MarshalStreamUtils.advanceToFirstItemOfInterest(reader);
  +        enrichXmlStream(reader);
           BindingType bindingType = determineRootType();
  +
  +        if (isValidating()) {
  +            ValidatingXMLStreamReader vr = new ValidatingXMLStreamReader();
  +            final SchemaTypeLoader schemaTypeLoader =
  +                schemaTypeLoaderProvider.getSchemaTypeLoader();
  +            final XmlTypeName xtype = bindingType.getName().getXmlName();
  +            assert xtype.isSchemaType();
  +            assert xtype.isGlobal();
  +            SchemaType schema_type = schemaTypeLoader.findType(xtype.getQName());
  +            if (schema_type == null) {
  +                throw new XmlException("unable to locate type " + schema_type +
  +                                       " in provided schema type system");
  +            }
  +            //TODO: pass in null instead of schema_type (currently not working)
  +            vr.init(reader, schema_type, schemaTypeLoader, options, errors);
  +            reader = vr; //note changing param
  +        }
  +
  +
           return unmarshalBindingType(bindingType);
       }
   
  @@ -158,7 +186,21 @@
                            String javaType)
           throws XmlException
       {
  -        setXmlStream(reader);
  +        if (isValidating()) {
  +            ValidatingXMLStreamReader vr = new ValidatingXMLStreamReader();
  +            SchemaTypeLoader schemaTypeLoader =
  +                schemaTypeLoaderProvider.getSchemaTypeLoader();
  +            SchemaType schema_type = schemaTypeLoader.findType(schemaType);
  +            if (schema_type == null) {
  +                String e = "unable to locate definition of type " +
  +                    schemaType + " in supplied schema type system";
  +                throw new XmlException(e);
  +            }
  +            vr.init(reader, schema_type, schemaTypeLoader, options, errors);
  +            reader = vr; //note changing param
  +        }
  +
  +        enrichXmlStream(reader);
   
           final QName xsi_type = getXsiType();
   
  @@ -180,6 +222,13 @@
           return unmarshalBindingType(btype);
       }
   
  +    private boolean isValidating()
  +    {
  +        if (options == null) return false;
  +
  +        return options.hasOption(XmlOptions.UNMARSHAL_VALIDATE);
  +    }
  +
       private BindingType determineBindingType(QName schemaType, String javaType)
       {
           XmlTypeName xname = XmlTypeName.forTypeNamed(schemaType);
  @@ -635,7 +684,7 @@
        * return the QName value found for xsi:type
        * or null if neither one was found
        */
  -    QName getXsiType() throws XmlException
  +    private QName getXsiType() throws XmlException
       {
           if (!gotXsiAttributes) {
               getXsiAttributes();
  @@ -644,7 +693,7 @@
           return xsiAttributeHolder.xsiType;
       }
   
  -    boolean hasXsiNil() throws XmlException
  +    private boolean hasXsiNil() throws XmlException
       {
           if (!gotXsiAttributes) {
               getXsiAttributes();
  @@ -679,7 +728,7 @@
       }
   
   
  -    void advanceToFirstItemOfInterest()
  +    private void advanceToFirstItemOfInterest()
           throws XmlException
       {
           assert baseReader != null;
  @@ -736,7 +785,7 @@
           return baseReader.isEndElement();
       }
   
  -    int getAttributeCount()
  +    private int getAttributeCount()
       {
           assert baseReader.isStartElement();
   
  @@ -816,7 +865,7 @@
           return defaultAttributeBits.get(att_idx);
       }
   
  -    void setNextElementDefault(String lexical_default)
  +    private void setNextElementDefault(String lexical_default)
           throws XmlException
       {
           try {
  
  
  
  1.21      +9 -4      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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- UnmarshallerImpl.java	19 Feb 2004 22:02:12 -0000	1.20
  +++ UnmarshallerImpl.java	16 Mar 2004 00:55:01 -0000	1.21
  @@ -30,18 +30,21 @@
   {
       private final BindingLoader bindingLoader;
       private final RuntimeBindingTypeTable typeTable;
  +    private final SchemaTypeLoaderProvider schemaTypeLoaderProvider;
   
       private static final XMLInputFactory XML_INPUT_FACTORY =
           XMLInputFactory.newInstance();
   
       public UnmarshallerImpl(BindingLoader loader,
  -                            RuntimeBindingTypeTable typeTable)
  +                            RuntimeBindingTypeTable typeTable,
  +                            SchemaTypeLoaderProvider provider)
       {
           assert loader != null;
           assert typeTable != null;
   
           this.bindingLoader = loader;
           this.typeTable = typeTable;
  +        this.schemaTypeLoaderProvider = provider;
       }
   
       public Object unmarshal(XMLStreamReader reader)
  @@ -54,9 +57,10 @@
           throws XmlException
       {
           final UnmarshalResult result =
  -            new UnmarshalResult(bindingLoader, typeTable, options);
  +            new UnmarshalResult(bindingLoader, typeTable,
  +                                schemaTypeLoaderProvider, options);
   
  -        return result.unmarshal(reader);
  +        return result.unmarshalDocument(reader);
       }
   
       public Object unmarshal(InputStream doc)
  @@ -102,7 +106,8 @@
           }
   
           final UnmarshalResult result =
  -            new UnmarshalResult(bindingLoader, typeTable, options);
  +            new UnmarshalResult(bindingLoader, typeTable,
  +                                schemaTypeLoaderProvider, options);
   
           return result.unmarshalType(reader, schemaType, javaType);
       }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BuiltinSchemaTypeLoaderProvider.java
  
  Index: BuiltinSchemaTypeLoaderProvider.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.SchemaTypeLoader;
  import org.apache.xmlbeans.XmlBeans;
  
  final class BuiltinSchemaTypeLoaderProvider
      implements SchemaTypeLoaderProvider
  {
      private final SchemaTypeLoader builtinLoader;
  
      private BuiltinSchemaTypeLoaderProvider()
      {
          builtinLoader = XmlBeans.getBuiltinTypeSystem();
      }
  
      private static final BuiltinSchemaTypeLoaderProvider INSTANCE =
          new BuiltinSchemaTypeLoaderProvider();
  
      static SchemaTypeLoaderProvider getInstance()
      {
          return INSTANCE;
      }
  
      public SchemaTypeLoader getSchemaTypeLoader()
      {
          return builtinLoader;
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/SchemaTypeLoaderProvider.java
  
  Index: SchemaTypeLoaderProvider.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.SchemaTypeLoader;
  
  interface SchemaTypeLoaderProvider
  {
      /**
       * get the SchemaTypeLoader
       *
       * @return the SchemaTypeLoader
       * @throws IllegalStateException  if schema type system not available
       */
      SchemaTypeLoader getSchemaTypeLoader();
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/TylarSchemaTypeLoaderProvider.java
  
  Index: TylarSchemaTypeLoaderProvider.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.SchemaTypeLoader;
  import org.apache.xmlbeans.impl.binding.tylar.Tylar;
  
  final class TylarSchemaTypeLoaderProvider
      implements SchemaTypeLoaderProvider
  {
      private final Tylar tylar;
      private SchemaTypeLoader schemaTypeLoader; //cached result
  
      TylarSchemaTypeLoaderProvider(Tylar tylar)
      {
          this.tylar = tylar;
      }
  
      public SchemaTypeLoader getSchemaTypeLoader()
      {
          if (schemaTypeLoader == null) {
              schemaTypeLoader = tylar.getSchemaTypeSystem();
          }
          assert schemaTypeLoader != null;
          return schemaTypeLoader;
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnusedSchemaTypeLoaderProvider.java
  
  Index: UnusedSchemaTypeLoaderProvider.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.SchemaTypeLoader;
  
  final class UnusedSchemaTypeLoaderProvider
      implements SchemaTypeLoaderProvider
  {
      private UnusedSchemaTypeLoaderProvider()
      {
      }
  
      private static final UnusedSchemaTypeLoaderProvider INSTANCE =
          new UnusedSchemaTypeLoaderProvider();
  
      static SchemaTypeLoaderProvider getInstance()
      {
          return INSTANCE;
      }
  
  
      public SchemaTypeLoader getSchemaTypeLoader()
      {
          throw new IllegalStateException("schema type system not available");
      }
  }
  
  
  
  1.4       +12 -0     xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java
  
  Index: XmlOptions.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XmlOptions.java	12 Feb 2004 20:06:27 -0000	1.3
  +++ XmlOptions.java	16 Mar 2004 00:55:01 -0000	1.4
  @@ -413,6 +413,15 @@
       }
   
       /**
  +     * If this option is set, then schema validation will be performed during
  +     * unmarshalling.  Errors will be added to error collection supplied
  +     * in this options instance
  +     */
  +    public XmlOptions setUnmarshalValidate () {
  +        return set( UNMARSHAL_VALIDATE );
  +    }
  +
  +    /**
        * Sets the name of the variable that represents
        * the current node in a query expression.
        * 
  @@ -601,6 +610,9 @@
       public static final String LOAD_ADDITIONAL_NAMESPACES      =  "LOAD_ADDITIONAL_NAMESPACES";
       /** @exclude */
       public static final String LOAD_MESSAGE_DIGEST             =  "LOAD_MESSAGE_DIGEST";
  +
  +    /** @exclude */
  +    public static final String UNMARSHAL_VALIDATE              =  "UNMARSHAL_VALIDATE";
   
       /** @exclude */
       public static final String XQUERY_CURRENT_NODE_VAR         =  "XQUERY_CURRENT_NODE_VAR";
  
  
  
  1.44      +11 -3     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.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- MarshalTests.java	13 Mar 2004 03:46:58 -0000	1.43
  +++ MarshalTests.java	16 Mar 2004 00:55:01 -0000	1.44
  @@ -141,7 +141,6 @@
           final byte[] bytes = new byte[]{1, 2, 3, 4, 5, 6};
           testSimpleTypeUnmarshal(bytes, "AQIDBAUG", "base64Binary");
           testSimpleTypeUnmarshal(bytes, "010203040506", "hexBinary");
  -
       }
   
       private void testStringTypeUnmarshal(String xsd_type)
  @@ -189,9 +188,10 @@
                                           String xsd_type)
           throws Exception
       {
  -        BindingContext bindingContext = getBindingContext(getBindingConfigDocument());
  +        BindingContext bindingContext = getBuiltinBindingContext();
   
  -        String xmldoc = "<a xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
  +         String xmldoc = "<a" +
  +            " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
               " xmlns:xs='http://www.w3.org/2001/XMLSchema' xsi:type='xs:" +
               xsd_type + "' >" + lexval + "</a>";
   
  @@ -202,6 +202,7 @@
           final XmlOptions options = new XmlOptions();
           Collection errors = new LinkedList();
           options.setErrorListener(errors);
  +        options.setUnmarshalValidate();
   
           Unmarshaller umctx =
               bindingContext.createUnmarshaller();
  @@ -968,6 +969,7 @@
           final XmlOptions xmlOptions = new XmlOptions();
           Collection errors = new LinkedList();
           xmlOptions.setErrorListener(errors);
  +
           Unmarshaller ctx = bindingContext.createUnmarshaller();
   
           //this is not very safe but it should work...
  @@ -1055,6 +1057,12 @@
       public static void main(String args[])
       {
           junit.textui.TestRunner.run(suite());
  +    }
  +
  +    private static BindingContext getBuiltinBindingContext()
  +        throws XmlException, IOException
  +    {
  +        return BindingContextFactory.newInstance().createBindingContext();
       }
   
       private static BindingContext getBindingContext(File bcdoc)
  
  
  

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