You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by kk...@apache.org on 2004/11/19 03:16:27 UTC

cvs commit: xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/validator Validator.java

kkrouse     2004/11/18 18:16:27

  Modified:    v1/src/typeimpl/org/apache/xmlbeans/impl/validator
                        Validator.java
  Log:
  improved validation error message to print list missing elements
  
  Revision  Changes    Path
  1.6       +48 -5     xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java
  
  Index: Validator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Validator.java	30 Sep 2004 00:23:14 -0000	1.5
  +++ Validator.java	19 Nov 2004 02:16:26 -0000	1.6
  @@ -60,11 +60,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
  @@ -801,6 +803,9 @@
           String message = null;
           SchemaProperty[] eltProperties = state._type.getElementProperties();
   
  +        ArrayList expectedNames = new ArrayList();
  +        ArrayList optionalNames = new ArrayList();
  +
           for (int ii = 0; ii < eltProperties.length; ii++)
           {
               //Get the element from the schema
  @@ -809,10 +814,28 @@
               // test if the element is valid
               if (state.test(sProp.getName()))
               {
  -                message = "Expected element " + QNameHelper.pretty(sProp.getName()) + " instead of " + QNameHelper.pretty(qName) + " here";
  -                break;
  +                if (0 == BigInteger.ZERO.compareTo(sProp.getMinOccurs()))
  +                    optionalNames.add(sProp.getName());
  +                else
  +                    expectedNames.add(sProp.getName());
  +            }
  +        }
  +
  +        List names = (expectedNames.size() > 0 ? expectedNames : optionalNames);
  +
  +        if (names.size() > 0)
  +        {
  +            StringBuffer buf = new StringBuffer();
  +            for (Iterator iter = names.iterator(); iter.hasNext(); )
  +            {
  +                buf.append(QNameHelper.pretty((QName)iter.next()));
  +                buf.append(" ");
               }
  +
  +            message = "Expected element" + (names.size()>1 ? "s " : " ") +
  +                      buf.toString() + "at the end of the content";
           }
  +
           return message;
       }
   
  @@ -821,6 +844,9 @@
           SchemaProperty[] eltProperties  = state._type.getElementProperties();
           String message = null;
   
  +        ArrayList expectedNames = new ArrayList();
  +        ArrayList optionalNames = new ArrayList();
  +
           for (int ii = 0; ii < eltProperties.length; ii++)
           {
               //Get the element from the schema
  @@ -829,11 +855,28 @@
               // test if the element is valid
               if (state.test(sProp.getName()))
               {
  -                message = "Expected element " + QNameHelper.pretty(sProp.getName()) +
  -                          " at the end of the content";
  -                break;
  +                if (0 == BigInteger.ZERO.compareTo(sProp.getMinOccurs()))
  +                    optionalNames.add(sProp.getName());
  +                else
  +                    expectedNames.add(sProp.getName());
  +            }
  +        }
  +
  +        List names = (expectedNames.size() > 0 ? expectedNames : optionalNames);
  +
  +        if (names.size() > 0)
  +        {
  +            StringBuffer buf = new StringBuffer();
  +            for (Iterator iter = names.iterator(); iter.hasNext(); )
  +            {
  +                buf.append(QNameHelper.pretty((QName)iter.next()));
  +                buf.append(" ");
               }
  +
  +            message = "Expected element" + (names.size()>1 ? "s " : " ") +
  +                      buf.toString() + "at the end of the content";
           }
  +
           return message;
       }
   
  
  
  

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