xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ce...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases ValidatingXMLStreamReaderTests.java
Date Mon, 03 May 2004 13:03:21 GMT
cezar       2004/05/03 06:03:21

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        UnmarshalResult.java
               v2/src/typeimpl/org/apache/xmlbeans/impl/validator
                        ValidatingXMLStreamReader.java
               v2/src/xmlcomp/org/apache/xmlbeans/impl/tool
                        StreamInstanceValidator.java
               v2/test/src/drt/drtcases ValidatingXMLStreamReaderTests.java
  Log:
  Enabled ValidatingXMLStreamReader to start validating from both current and next event in
the XMLStreamReader.
  
  CR: Scott
  DRT: pass
  
  Revision  Changes    Path
  1.23      +2 -2      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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- UnmarshalResult.java	3 May 2004 05:48:15 -0000	1.22
  +++ UnmarshalResult.java	3 May 2004 13:03:20 -0000	1.23
  @@ -151,7 +151,7 @@
               ValidatingXMLStreamReader vr = new ValidatingXMLStreamReader();
               final SchemaTypeLoader schemaTypeLoader =
                   schemaTypeLoaderProvider.getSchemaTypeLoader();
  -            vr.init(reader, null, schemaTypeLoader, options, errors);
  +            vr.init(reader, false, null, schemaTypeLoader, options, errors);
               enrichXmlStream(vr);
           } else {
               enrichXmlStream(reader);
  @@ -241,7 +241,7 @@
                       schemaType + " in supplied schema type system";
                   throw new XmlException(e);
               }
  -            vr.init(reader, schema_type, schemaTypeLoader, options, errors);
  +            vr.init(reader, false, schema_type, schemaTypeLoader, options, errors);
               reader = vr; //note changing param
           }
   
  
  
  
  1.4       +23 -9     xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/validator/ValidatingXMLStreamReader.java
  
  Index: ValidatingXMLStreamReader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/validator/ValidatingXMLStreamReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ValidatingXMLStreamReader.java	23 Mar 2004 02:42:45 -0000	1.3
  +++ ValidatingXMLStreamReader.java	3 May 2004 13:03:21 -0000	1.4
  @@ -34,7 +34,7 @@
   import java.util.List;
   
   /**
  - * This class is a wrapper over a generic XMLInputStream that provides validation.
  + * This class is a wrapper over a generic XMLStreamReader that provides validation.
    * There are 3 cases:
    * <br/> 1) the XMLStreamReader represents a document, it contains only one element
document
    *          - in this case the user schema type should be null or it should be a document
SchemaType
  @@ -43,6 +43,7 @@
    * <br/>     b) it doesn't have xsi:type - user must provide a schema type
    *         otherwise will error and will not do validation
    * <br/> 3) the XMLStreamReader represents a global attribute - i.e. user schema
type is null and only one attribute
  + * <br/>
    *
    * @author Cezar Andrei (cezar.andrei at bea.com)
    * Date: Feb 13, 2004
  @@ -91,13 +92,14 @@
       /**
        * Used in case of reusing the same ValidatinXMLStreamReader object
        * @param xsr The stream to be validated
  +     * @param startWithCurrentEvent Validation will start if true with the current event
or if false with the next event in the stream
        * @param contentType The schemaType of the content. This can be null for document
and global Att validation
        * @param stl SchemaTypeLoader context of validation
        * @param options Validator options
        * @param errorListener Errors and warnings listener
        */
  -    public void init(XMLStreamReader xsr, SchemaType contentType, SchemaTypeLoader stl,
  -                     XmlOptions options, Collection errorListener)
  +    public void init(XMLStreamReader xsr, boolean startWithCurrentEvent, SchemaType contentType,
  +                     SchemaTypeLoader stl, XmlOptions options, Collection errorListener)
       {
           setParent(xsr);
           _contentType = contentType;
  @@ -115,6 +117,12 @@
               _attValuesList.clear();
           }
           _xsiType = null;
  +
  +        if (startWithCurrentEvent)
  +        {
  +            int evType = getEventType();
  +            validate_event(evType);
  +        }
       }
   
       private static class ElementEventImpl
  @@ -402,7 +410,8 @@
               return _xmlStream.getNamespaceURI(prefix);
           }
       }
  -    /* public methods */
  +
  +    /* public methods in XMLStreamReader */
   
       public Object getProperty(String s) throws IllegalArgumentException
       {
  @@ -414,8 +423,15 @@
           int evType = super.next();
           //debugEvent(evType);
   
  +        validate_event(evType);
  +
  +        return evType;
  +    }
  +
  +    private void validate_event(int evType)
  +    {
           if (_state==STATE_ERROR)
  -            return evType;
  +            return;
   
           switch(evType)
           {
  @@ -534,8 +550,6 @@
           default:
               throw new IllegalStateException("Unknown event type.");
           }
  -
  -        return evType;
       }
   
       private void pushBufferedAttributes()
  @@ -645,8 +659,8 @@
       }
   
       /**
  -     * @return Returns the validation state up to this point
  -     * NOTE: At least on START ELEMENT should have been consumed for a valid value to be
returned.
  +     * @return Returns the validation state up to this point.
  +     * NOTE: At least one START ELEMENT should have been consumed for a valid value to
be returned.
        */
       public boolean isValid()
       {
  
  
  
  1.3       +5 -4      xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/StreamInstanceValidator.java
  
  Index: StreamInstanceValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/StreamInstanceValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StreamInstanceValidator.java	30 Mar 2004 00:09:49 -0000	1.2
  +++ StreamInstanceValidator.java	3 May 2004 13:03:21 -0000	1.3
  @@ -128,11 +128,12 @@
                       XML_INPUT_FACTORY.createXMLStreamReader(path, fis);
   
                   //advance to first start element.
  -//                while(!rdr.isStartElement()) {
  -//                    rdr.next();
  -//                }
  +                while(!rdr.isStartElement()) {
  +                    rdr.next();
  +                }
   
  -                vsr.init(rdr, null, sLoader, options, errors);
  +                vsr.init(rdr, true, null, sLoader, options, errors);
  +                
                   while (vsr.hasNext()) {
                       vsr.next();
                   }
  
  
  
  1.2       +22 -17    xml-xmlbeans/v2/test/src/drt/drtcases/ValidatingXMLStreamReaderTests.java
  
  Index: ValidatingXMLStreamReaderTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/ValidatingXMLStreamReaderTests.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidatingXMLStreamReaderTests.java	29 Feb 2004 16:38:25 -0000	1.1
  +++ ValidatingXMLStreamReaderTests.java	3 May 2004 13:03:21 -0000	1.2
  @@ -77,7 +77,7 @@
           XMLStreamReader xsr = XMLInputFactory.newInstance().
               createXMLStreamReader(new FileInputStream(file));
   
  -        valXsr.init(xsr, null /* validate an entire document */ ,
  +        valXsr.init(xsr, false, null /* validate an entire document */ ,
               XmlBeans.typeLoaderForClassLoader(ValidatingXMLStreamReader.class.getClassLoader()),
               null,
               errors);
  @@ -118,17 +118,28 @@
           Collection errors = new ArrayList();
   
           ValidatingXMLStreamReader valXsr = new ValidatingXMLStreamReader();
  -        valXsr.init(xsr,
  -            null,
  +        valXsr.init(xsr, false, null,
               XmlBeans.typeLoaderForClassLoader(ValidatingXMLStreamReader.class.getClassLoader()),
  -            null,
  -            errors);
  +            null, errors);
   
           while(valXsr.hasNext())
           {
               valXsr.next();
           }
  +
  +        if (!valXsr.isValid())
  +        {
  +            System.out.println("---------------\n");
  +            Iterator i = errors.iterator();
  +            while (i.hasNext())
  +            {
  +                XmlError xmlError = (XmlError) i.next();
  +                System.out.println(xmlError.getSeverity() + " " + xmlError.getMessage());
  +            }
  +        }
  +
           Assert.assertTrue("Global attribute validation is broken.", valXsr.isValid());
  +
       }
   
       public void testValidateGlobalAtt2() throws XMLStreamException
  @@ -138,11 +149,9 @@
           Collection errors = new ArrayList();
   
           ValidatingXMLStreamReader valXsr = new ValidatingXMLStreamReader();
  -        valXsr.init(xsr,
  -            null,
  +        valXsr.init(xsr, false, null,
               XmlBeans.typeLoaderForClassLoader(ValidatingXMLStreamReader.class.getClassLoader()),
  -            null,
  -            errors);
  +            null, errors);
   
           while(valXsr.hasNext())
           {
  @@ -431,11 +440,9 @@
           Collection errors = new ArrayList();
   
           ValidatingXMLStreamReader valXsr = new ValidatingXMLStreamReader();
  -        valXsr.init(xsr,
  -            DocDocument.Doc.type,
  +        valXsr.init(xsr, false, DocDocument.Doc.type,
               XmlBeans.typeLoaderForClassLoader(ValidatingXMLStreamReader.class.getClassLoader()),
  -            null,
  -            errors);
  +            null, errors);
   
           while(valXsr.hasNext())
           {
  @@ -454,11 +461,9 @@
           Collection errors = new ArrayList();
   
           ValidatingXMLStreamReader valXsr = new ValidatingXMLStreamReader();
  -        valXsr.init(xsr,
  -            DocDocument.Doc.type,
  +        valXsr.init(xsr, false, DocDocument.Doc.type,
               XmlBeans.typeLoaderForClassLoader(ValidatingXMLStreamReader.class.getClassLoader()),
  -            null,
  -            errors);
  +            null, errors);
   
           int depth = 0;
   
  
  
  

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