You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2001/08/28 22:21:16 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2 XSMessageFormatter.java XSDAbstractTraverser.java XSDSimpleTypeTraverser.java

elena       01/08/28 13:21:16

  Modified:    java/src/org/apache/xerces/impl/v2 XSDAbstractTraverser.java
                        XSDSimpleTypeTraverser.java
  Added:       java/src/org/apache/xerces/impl/v2 XSMessageFormatter.java
  Log:
  Trying to sync error reporting for *Traversers
  
  Revision  Changes    Path
  1.7       +3 -7      xml-xerces/java/src/org/apache/xerces/impl/v2/XSDAbstractTraverser.java
  
  Index: XSDAbstractTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDAbstractTraverser.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSDAbstractTraverser.java	2001/08/28 18:50:48	1.6
  +++ XSDAbstractTraverser.java	2001/08/28 20:21:15	1.7
  @@ -68,7 +68,7 @@
    * other <code>XSD???Traverser</code>s. It holds the common data and provide
    * a unified way to initialize these data.
    *
  - * @version $Id: XSDAbstractTraverser.java,v 1.6 2001/08/28 18:50:48 neilg Exp $
  + * @version $Id: XSDAbstractTraverser.java,v 1.7 2001/08/28 20:21:15 elena Exp $
    */
   abstract class XSDAbstractTraverser {
   
  @@ -76,13 +76,13 @@
       protected XSDHandler            fSchemaHandler = null;
       protected SymbolTable           fSymbolTable = null;
       protected XSAttributeChecker    fAttrChecker = null;
  -    private XMLErrorReporter        fErrorReporter = null;
  +    protected XMLErrorReporter      fErrorReporter = null;
   
       //REVISIT: should we add global fSchemaGrammar field
   
       XSDAbstractTraverser (XSDHandler handler,
                             XMLErrorReporter errorReporter,
  -                          XSAttributeChecker attrChecker) {
  +                          XSAttributeChecker attrChecker) {        
           fSchemaHandler = handler;
           fErrorReporter = errorReporter;
           fAttrChecker = attrChecker;
  @@ -129,11 +129,7 @@
       }
   
       // REVISIT: is it how we want to handle error reporting?
  -    //REVISIT: Implement
       void reportGenericSchemaError (String error) {
  -    }
  -    //REVISIT: Implement
  -    void reportSchemaError(String key, Object args[]) {
       }
   
       //
  
  
  
  1.7       +60 -43    xml-xerces/java/src/org/apache/xerces/impl/v2/XSDSimpleTypeTraverser.java
  
  Index: XSDSimpleTypeTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDSimpleTypeTraverser.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSDSimpleTypeTraverser.java	2001/08/28 18:50:48	1.6
  +++ XSDSimpleTypeTraverser.java	2001/08/28 20:21:15	1.7
  @@ -77,7 +77,7 @@
   
   /**
    * The simple type definition schema component traverser.
  - *
  + * 
    * <simpleType
    *   final = (#all | (list | union | restriction))
    *   id = ID
  @@ -85,28 +85,31 @@
    *   {any attributes with non-schema namespace . . .}>
    *   Content: (annotation?, (restriction | list | union))
    * </simpleType>
  - *
  + * 
    * <restriction
    *   base = QName
    *   id = ID
    *   {any attributes with non-schema namespace . . .}>
    *   Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*))
    * </restriction>
  - *
  + * 
    * <list
    *   id = ID
    *   itemType = QName
    *   {any attributes with non-schema namespace . . .}>
    *   Content: (annotation?, (simpleType?))
    * </list>
  - *
  + * 
    * <union
    *   id = ID
    *   memberTypes = List of QName
    *   {any attributes with non-schema namespace . . .}>
    *   Content: (annotation?, (simpleType*))
    * </union>
  - * @version $Id: XSDSimpleTypeTraverser.java,v 1.6 2001/08/28 18:50:48 neilg Exp $
  + * 
  + * @author Elena Litani
  + * @author IBM
  + * @version $Id: XSDSimpleTypeTraverser.java,v 1.7 2001/08/28 20:21:15 elena Exp $
    */
   class XSDSimpleTypeTraverser extends XSDAbstractTraverser {
   
  @@ -154,7 +157,6 @@
           String nameProperty  =  DOMUtil.getAttrValue(simpleTypeDecl, SchemaSymbols.ATT_NAME);
           String qualifiedName = nameProperty;
   
  -
           //---------------------------------------------------
           // set qualified name
           //---------------------------------------------------
  @@ -270,10 +272,10 @@
               dTValidators = new Vector (size, 2);
           }
           else {
  -            //REVISIT: port SchemaMessageProvider
  -            //reportSchemaError(SchemaMessageProvider.FeatureUnsupported,
  -            //          new Object [] { varietyProperty });
  -            //          return fSchemaHandler.EMPTY_STRING;
  +            Object[] args = { varietyProperty};
  +            fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, 
  +                                       "FeatureUnsupported",
  +                                       args, XMLErrorReporter.SEVERITY_ERROR);
           }
           if (DOMUtil.getNextSiblingElement(content) != null) {
               // REVISIT: Localize
  @@ -304,17 +306,20 @@
                       }
                   }
                   if (baseValidator == null) {
  -                    //REVISIT:
  -                    // reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
  -                    //                      new Object [] { content.getAttribute( SchemaSymbols.ATT_BASE ),
  -                    //                          content.getAttribute(SchemaSymbols.ATT_NAME) });
  +                    Object[] args = {content.getAttribute( SchemaSymbols.ATT_BASE )};
  +                    fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                               "UnknownBaseDatatype",
  +                                               args,
  +                                               XMLErrorReporter.SEVERITY_ERROR);
                       return resetSimpleTypeNameStack(fSchemaHandler.EMPTY_STRING);
                   }
               }
               else {
  -                //REVISIT
  -                //reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
  -                //       new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
  +                Object[] args = { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )};
  +                fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                           "ListUnionRestrictionError",
  +                                           args,
  +                                           XMLErrorReporter.SEVERITY_ERROR);
                   return resetSimpleTypeNameStack(fSchemaHandler.EMPTY_STRING);
               }
           } //end - must see simpleType?
  @@ -401,10 +406,11 @@
                       }
                   }
                   if (baseValidator == null) {
  -                    //REVISIT: 
  -                    //reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
  -                    //                  new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_BASE ),
  -                    //                      simpleTypeDecl.getAttribute(SchemaSymbols.ATT_NAME)});
  +                    Object[] args = { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_BASE ), simpleTypeDecl.getAttribute(SchemaSymbols.ATT_NAME)};
  +                    fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                               "UnknownBaseDatatype",
  +                                               args,
  +                                               XMLErrorReporter.SEVERITY_ERROR);
                       return fSchemaHandler.EMPTY_STRING;
                   }
                   content   = DOMUtil.getNextSiblingElement( content );
  @@ -465,9 +471,13 @@
                           checkContent(simpleTypeDecl, DOMUtil.getFirstChildElement( content ), true);
                       }
                       else if (facet.equals(SchemaSymbols.ELT_ANNOTATION) || facet.equals(SchemaSymbols.ELT_SIMPLETYPE)) {
  -                        //REVISIT:      
  -                        //reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
  -                        //new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
  +                        //REVISIT: 
  +                        Object[] args = { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )};
  +                        fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                                   "ListUnionRestrictionError",
  +                                                   args,
  +                                                   XMLErrorReporter.SEVERITY_ERROR);
  +
                       }
                       else if (facet.equals(SchemaSymbols.ELT_PATTERN)) {
                           if (fPattern == null) {
  @@ -485,10 +495,11 @@
                       }
                       else {
                           if (fFacetData.containsKey(facet))
  -                            //REVISIT:
  -                            //reportSchemaError(SchemaMessageProvider.DatatypeError,
  -                            //                  new Object [] {"The facet '" + facet + "' is defined more than once."} );
  -                            fFacetData.put(facet,content.getAttribute( SchemaSymbols.ATT_VALUE ));
  +                            fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                                       "DatatypeError",
  +                                                       new Object[]{"The facet '" + facet + "' is defined more than once."},
  +                                                       XMLErrorReporter.SEVERITY_ERROR);
  +                        fFacetData.put(facet,content.getAttribute( SchemaSymbols.ATT_VALUE ));
   
                           if (content.getAttribute( SchemaSymbols.ATT_FIXED).equals(SchemaSymbols.ATTVAL_TRUE) ||
                               content.getAttribute( SchemaSymbols.ATT_FIXED).equals(SchemaSymbols.ATTVAL_TRUE_1)) {
  @@ -542,23 +553,26 @@
               }
               fPattern.setLength(0);
           }
  -
  -
           else if (list && content!=null) {
               // report error - must not have any children!
               if (baseTypeQNameProperty.length() != 0) {
                   content = checkContent(simpleTypeDecl, content, true);
                   if (content!=null) {
                       //REVISIT:
  -                    //reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
  -                    //                  new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
  +                    Object[] args = { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )};
  +                    fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                               "ListUnionRestrictionError",
  +                                               args,
  +                                               XMLErrorReporter.SEVERITY_ERROR);
  +
                   }
               }
               else {
  -                //REVISIT
  -                //reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
  -                //                  new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
  -                //REVISIT: should we return?
  +                Object[] args = { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )};
  +                fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                           "ListUnionRestrictionError",
  +                                           args,
  +                                           XMLErrorReporter.SEVERITY_ERROR);
               }
           }
           else if (union && content!=null) {
  @@ -566,16 +580,19 @@
               if (baseTypeQNameProperty.length() != 0) {
                   content = checkContent(simpleTypeDecl, content, true);
                   if (content!=null) {
  -                    //REVISIT
  -                    //reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
  -                    //                  new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
  +                    Object[] args = { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )};
  +                    fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                               "ListUnionRestrictionError",
  +                                               args,
  +                                               XMLErrorReporter.SEVERITY_ERROR);
                   }
               }
               else {
  -                //REVISIT
  -                //reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
  -                //                  new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
  -                //REVISIT: should we return?
  +                Object[] args = { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )};
  +                fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                           "ListUnionRestrictionError",
  +                                           args,
  +                                           XMLErrorReporter.SEVERITY_ERROR);
               }
           }
   
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/impl/v2/XSMessageFormatter.java
  
  Index: XSMessageFormatter.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 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 "Xerces" 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",
   *    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) 2001, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.impl.v2;
  
  import java.util.Locale;
  import java.util.MissingResourceException;
  import java.util.ResourceBundle;
  import java.util.PropertyResourceBundle;
  import org.apache.xerces.util.MessageFormatter;
  
  
  /**
   * SchemaMessageProvider implements an XMLMessageProvider that
   * provides localizable error messages for the W3C XML Schema Language
   * 
   * @author Elena Litani, IBM
   */
  public class XSMessageFormatter implements MessageFormatter {
      /**
       * The domain of messages concerning the XML Schema: Structures specification.
       */
      public static final String SCHEMA_DOMAIN = "http://www.w3.org/TR/xml-schema-1";
  
  
      // private objects to cache the locale and resource bundle
      private Locale fLocale = null;
      private ResourceBundle fResourceBundle = null;
  
      /**
       * Formats a message with the specified arguments using the given
       * locale information.
       * 
       * @param locale    The locale of the message.
       * @param key       The message key.
       * @param arguments The message replacement text arguments. The order
       *                  of the arguments must match that of the placeholders
       *                  in the actual message.
       * 
       * @return Returns the formatted message.
       *
       * @throws MissingResourceException Thrown if the message with the
       *                                  specified key cannot be found.
       */
       public String formatMessage(Locale locale, String key, Object[] arguments)
          throws MissingResourceException {
          
          if (fResourceBundle == null || locale != fLocale) {
              if (locale != null) {
                  fResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.SchemaMessages", locale);
                  // memorize the most-recent locale
                  fLocale = locale;
              }
              if (fResourceBundle == null)
                  fResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.SchemaMessages");
          }
          
          String msg = fResourceBundle.getString(key);
          if (arguments != null) {
              try {
                  msg = java.text.MessageFormat.format(msg, arguments);
              } catch (Exception e) {
                  msg = fResourceBundle.getString("FormatFailed");
                  msg += " " + fResourceBundle.getString(key);
              }
          } 
  
          if (msg == null) {
              msg = fResourceBundle.getString("BadMessageKey");
              throw new MissingResourceException(msg, "org.apache.xerces.impl.msg.SchemaMessages", key);
          }
  
          return msg;
      }
  }
  
  
  

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