xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkro...@apache.org
Subject cvs commit: xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/validator Validator.java
Date Fri, 19 Nov 2004 00:09:03 GMT
kkrouse     2004/11/18 16:09:02

  Modified:    v2/src/xmlpublic/org/apache/xmlbeans message.properties
               v2/src/typeimpl/org/apache/xmlbeans/impl/validator
                        Validator.java
  Log:
  improved validation error message to skip over missing optional elements
  
  Revision  Changes    Path
  1.8       +2 -2      xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/message.properties
  
  Index: message.properties
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/message.properties,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- message.properties	30 Oct 2004 21:48:46 -0000	1.7
  +++ message.properties	19 Nov 2004 00:09:02 -0000	1.8
  @@ -69,13 +69,13 @@
   Element ''{0}'' with element-only content type cannot have text content.
   
   cvc-complex-type.2.4a = \
  -Expected element ''{0}'' instead of ''{1}'' here
  +Expected element{0,choice,1<s} ''{1}'' instead of ''{2}'' here
   
   cvc-complex-type.2.4b = \
   Element not allowed: {0}
   
   cvc-complex-type.2.4c = \
  -Expected element ''{0}'' at the end of the content
  +Expected element{0,choice,1<s} ''{1}'' at the end of the content
   
   cvc-complex-type.2.4d = \
   Expected element(s)
  
  
  
  1.23      +40 -26    xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java
  
  Index: Validator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Validator.java	29 Sep 2004 18:06:50 -0000	1.22
  +++ Validator.java	19 Nov 2004 00:09:02 -0000	1.23
  @@ -62,11 +62,13 @@
   import org.apache.xmlbeans.XmlString;
   
   import java.math.BigDecimal;
  +import java.math.BigInteger;
   import java.util.Collection;
   import java.util.HashSet;
   import java.util.LinkedList;
   import java.util.List;
   import java.util.ArrayList;
  +import java.util.Iterator;
   import javax.xml.namespace.QName;
   
   public final class Validator
  @@ -884,28 +886,35 @@
   
       private void findDetailedErrorBegin(Event event, State state, QName qName)
       {
  -        boolean found = false;
  +        ArrayList expectedNames = new ArrayList();
  +
           SchemaProperty[] eltProperties = state._type.getElementProperties();
           for (int ii = 0; ii < eltProperties.length; ii++)
           {
               //Get the element from the schema
               SchemaProperty sProp = eltProperties[ii];
   
  -            // test if the element is valid
  -            if (state.test(sProp.getName()))
  -            {
  -                found = true;
  -                ArrayList expectedNames = new ArrayList();
  +            // test if the element is valid and has min occurs > 0
  +            if (state.test(sProp.getName()) && 1 == sProp.getMinOccurs().compareTo(BigInteger.ZERO))
                   expectedNames.add(sProp.getName());
  +        }
   
  -                emitFieldError( event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$EXPECTED_DIFFERENT_ELEMENT,
  -                    new Object[] { QNameHelper.pretty(sProp.getName()), QNameHelper.pretty(qName)
},
  -                    qName, sProp.getType(), expectedNames, XmlValidationError.INCORRECT_ELEMENT,
state._type);
  -
  -                break;
  +        if (expectedNames.size() > 0)
  +        {
  +            StringBuffer buf = new StringBuffer();
  +            for (Iterator iter = expectedNames.iterator(); iter.hasNext();)
  +            {
  +                QName qname = (QName) iter.next();
  +                buf.append(QNameHelper.pretty(qname));
  +                if (iter.hasNext())
  +                    buf.append(" ");
               }
  +
  +            emitFieldError( event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$EXPECTED_DIFFERENT_ELEMENT,
  +                new Object[] { new Integer(expectedNames.size()), buf.toString(), QNameHelper.pretty(qName)
},
  +                qName, null, expectedNames, XmlValidationError.INCORRECT_ELEMENT, state._type);
           }
  -        if (!found)
  +        else
           {
               emitFieldError( event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_NOT_ALLOWED,
                   new Object[] { QNameHelper.pretty(qName) },
  @@ -916,30 +925,35 @@
       private void findDetailedErrorEnd(Event event, State state)
       {
           SchemaProperty[] eltProperties  = state._type.getElementProperties();
  -        boolean found = false;
  +
  +        ArrayList expectedNames = new ArrayList();
   
           for (int ii = 0; ii < eltProperties.length; ii++)
           {
               //Get the element from the schema
               SchemaProperty sProp = eltProperties[ii];
   
  -            // test if the element is valid
  -            if (state.test(sProp.getName()))
  -            {
  -                found = true;
  -
  -                ArrayList expectedNames = new ArrayList();
  +            // test if the element is valid and has min occurs > 0
  +            if (state.test(sProp.getName()) && 1 == sProp.getMinOccurs().compareTo(BigInteger.ZERO))
                   expectedNames.add(sProp.getName());
  +        }
   
  -                emitFieldError( event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_ELEMENT,
  -                    new Object[] { QNameHelper.pretty(sProp.getName()) },
  -                    null, sProp.getType(), expectedNames, XmlValidationError.INCORRECT_ELEMENT,
state._type);
  -
  -                break;
  +        if (expectedNames.size() > 0)
  +        {
  +            StringBuffer buf = new StringBuffer();
  +            for (Iterator iter = expectedNames.iterator(); iter.hasNext();)
  +            {
  +                QName qname = (QName) iter.next();
  +                buf.append(QNameHelper.pretty(qname));
  +                if (iter.hasNext())
  +                    buf.append(" ");
               }
  -        }
   
  -        if (!found)
  +            emitFieldError( event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_ELEMENT,
  +                new Object[] { new Integer(expectedNames.size()), buf.toString() },
  +                null, null, expectedNames, XmlValidationError.INCORRECT_ELEMENT, state._type);
  +        }
  +        else
           {
               emitFieldError( event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$EXPECTED_ELEMENT,
                   null, null, null, null, XmlValidationError.ELEMENT_NOT_ALLOWED, state._type);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org


Mime
View raw message