You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by da...@apache.org on 2004/08/10 01:45:47 UTC

cvs commit: xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans XmlError.java XmlValidationError.java

daveremy    2004/08/09 16:45:47

  Modified:    v2/src/typeimpl/org/apache/xmlbeans/impl/validator
                        Validator.java
               v2/src/xmlpublic/org/apache/xmlbeans XmlError.java
                        XmlValidationError.java
  Log:
  added Location to streaming validation errors
  Contributed by Kevin Krouse
  
  Revision  Changes    Path
  1.14      +19 -4     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Validator.java	7 Aug 2004 01:31:36 -0000	1.13
  +++ Validator.java	9 Aug 2004 23:45:47 -0000	1.14
  @@ -53,6 +53,7 @@
   import org.apache.xmlbeans.SchemaTypeLoader;
   import org.apache.xmlbeans.XmlError;
   import org.apache.xmlbeans.XmlValidationError;
  +import org.apache.xmlbeans.XmlCursor;
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlOptions;
   import org.apache.xmlbeans.SimpleValue;
  @@ -129,10 +130,24 @@
               if (_errorListener != null)
               {
                   assert event != null;
  -                _errorListener.add(
  -                    XmlValidationError.forCursorWithDetails( msg, severity, event.getLocationAsCursor(),
  -                        offendingQName, expectedSchemaType, expectedQNames,
  -                        errorType, badSchemaType));
  +                XmlError error;
  +                XmlCursor curs = event.getLocationAsCursor();
  +                if (curs != null)
  +                {
  +                    // non-streaming validation uses XmlCursor
  +                    error = XmlValidationError.forCursorWithDetails( msg, severity,
  +                        curs, offendingQName, expectedSchemaType, expectedQNames,
  +                        errorType, badSchemaType);
  +                }
  +                else
  +                {
  +                    // streaming validation uses Location
  +                    error = XmlValidationError.forLocationWithDetails( msg, severity,
  +                        event.getLocation(), offendingQName, expectedSchemaType, expectedQNames,
  +                        errorType, badSchemaType);
  +                }
  +
  +                _errorListener.add(error);
               }
           }
       }
  
  
  
  1.6       +43 -2     xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlError.java
  
  Index: XmlError.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlError.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XmlError.java	7 Aug 2004 01:31:37 -0000	1.5
  +++ XmlError.java	9 Aug 2004 23:45:47 -0000	1.6
  @@ -21,6 +21,7 @@
   import java.util.ResourceBundle;
   import java.util.PropertyResourceBundle;
   import java.text.MessageFormat;
  +import javax.xml.stream.Location;
   
   /**
    * Represents a message at a specific XML location.
  @@ -139,8 +140,36 @@
           this(XmlError.formattedMessage(code, args), code, severity, cursor);
       }
       
  -
       /**
  +     * The static factory methods should be used instead of
  +     * this constructor.
  +     */
  +    protected XmlError(String message, String code, int severity, Location loc)
  +    {
  +        String source = null;
  +        int line = -1;
  +        int column = -1;
  +
  +        if (loc != null)
  +        {
  +            line = loc.getLineNumber();
  +            column = loc.getColumnNumber();
  +        }
  +
  +        _message = message;
  +        _code = code;
  +        _severity = severity;
  +        _source = source;
  +        _line = line;
  +        _column = column;
  +    }
  +
  +    protected XmlError(String code, Object[] args, int severity, Location loc)
  +    {
  +        this(XmlError.formattedMessage(code, args), code, severity, loc);
  +    }
  +    
  +     /**
        * Returns an XmlError for the given message, with no location and {@link #SEVERITY_ERROR}.
        * @param message the error message
        */ 
  @@ -184,6 +213,18 @@
        * Returns an XmlError for the given message, located at a specific point in the given file and {@link #SEVERITY_ERROR}.
        * @param message the error message
        * @param sourceName the URL or other name for the file
  +     * @param location the location from an xml stream
  +     */ 
  +    public static XmlError forLocation(String message, String sourceName, Location location)
  +    {
  +        return new XmlError(message, (String)null, SEVERITY_ERROR, sourceName,
  +            location.getLineNumber(), location.getColumnNumber(), -1, null);
  +    }
  +
  +    /**
  +     * Returns an XmlError for the given message, located at a specific point in the given file and {@link #SEVERITY_ERROR}.
  +     * @param message the error message
  +     * @param sourceName the URL or other name for the file
        * @param line the 1-based line number, or -1 if not known
        * @param column the 1-based column number, or -1 if not known
        * @param offset the 0-base file character offset, or -1 if not known
  @@ -534,4 +575,4 @@
                   throw new IllegalArgumentException("unknown severity");
           }
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.3       +27 -1     xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlValidationError.java
  
  Index: XmlValidationError.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/XmlValidationError.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XmlValidationError.java	7 Aug 2004 01:31:37 -0000	1.2
  +++ XmlValidationError.java	9 Aug 2004 23:45:47 -0000	1.3
  @@ -21,6 +21,7 @@
   import java.util.List;
   import org.apache.xmlbeans.XmlError;
   import javax.xml.namespace.QName;
  +import javax.xml.stream.Location;
   
   /**
    * The XmlValidationError class extends the {@link XmlError }XMLError class. The XML Validator contains
  @@ -146,6 +147,23 @@
           setBadSchemaType(badSchemaType);
       }
   
  +    /**
  +     * The static factory methods should be used instead of
  +     * this constructor.
  +     */
  +    private XmlValidationError(String msg, int severity,
  +        Location loc, QName offendingQname, SchemaType expectedSchemaType,
  +        List expectedQNames, int errorType, SchemaType badSchemaType)
  +    {
  +        super(msg, (String)null, severity, loc);
  +
  +        setOffendingQName(offendingQname);
  +        setExpectedSchemaType(expectedSchemaType);
  +        setExpectedQNames(expectedQNames);
  +        setErrorType(errorType);
  +        setBadSchemaType(badSchemaType);
  +    }
  +
       public static XmlValidationError forCursorWithDetails( String msg, int severity,
           XmlCursor cursor, QName offendingQname, SchemaType expectedSchemaType,
           List expectedQNames, int errorType, SchemaType badSchemaType)
  @@ -154,6 +172,14 @@
               expectedSchemaType, expectedQNames, errorType, badSchemaType);
       }
   
  +    public static XmlValidationError forLocationWithDetails( String msg, int severity,
  +        Location location, QName offendingQname, SchemaType expectedSchemaType,
  +        List expectedQNames, int errorType, SchemaType badSchemaType)
  +    {
  +        return new XmlValidationError(msg, severity, location, offendingQname,
  +            expectedSchemaType, expectedQNames, errorType, badSchemaType);
  +    }
  +
       public SchemaType getBadSchemaType()
       {
           return _badSchemaType;
  @@ -203,4 +229,4 @@
       {
           this._expectedSchemaType = _expectedSchemaType;
       }
  -}
  \ No newline at end of file
  +}
  
  
  

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