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

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2 SchemaValidator.java SchemaParserConfiguration.java SAXParser.java

sandygao    01/08/27 13:57:05

  Added:       java/src/org/apache/xerces/impl/v2 SchemaValidator.java
                        SchemaParserConfiguration.java SAXParser.java
  Log:
  A new parser configuration for schema validation.
  This is a temprory configuration for the new schema design. It will be merged to the standard configuration when schema support is ready.
  Currently the SchemaValidator does nothing but to pass the events to the next component.
  A SAX parser is created to use this new configuration. To try the schema validator, simply replace "org.apache.xerces.parsers.SAXParser" with "org.apache.xerces.impl.v2.SAXParser" in your application. (for example, sax.Counter).
  
  Revision  Changes    Path
  1.1                  xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaValidator.java
  
  Index: SchemaValidator.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999,2000,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) 1999, 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 org.apache.xerces.impl.v2.datatypes.*;
  
  import org.apache.xerces.impl.Constants;
  import org.apache.xerces.impl.XMLErrorReporter;
  import org.apache.xerces.impl.msg.XMLMessageFormatter;
  
  import org.apache.xerces.util.SymbolTable;
  import org.apache.xerces.util.XMLChar;
  
  import org.apache.xerces.xni.QName;
  import org.apache.xerces.xni.XMLString;
  import org.apache.xerces.xni.XMLAttributes;
  import org.apache.xerces.xni.XMLDocumentHandler;
  import org.apache.xerces.xni.XMLDTDHandler;
  import org.apache.xerces.xni.XMLDTDContentModelHandler;
  import org.apache.xerces.xni.XMLLocator;
  import org.apache.xerces.xni.XNIException;
  import org.apache.xerces.xni.parser.XMLComponent;
  import org.apache.xerces.xni.parser.XMLComponentManager;
  import org.apache.xerces.xni.parser.XMLConfigurationException;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.Vector;
  import java.util.StringTokenizer;
  
  /**
   * The DTD validator. The validator implements a document
   * filter: receiving document events from the scanner; validating
   * the content and structure; augmenting the InfoSet, if applicable;
   * and notifying the parser of the information resulting from the
   * validation process.
   * <p>
   * This component requires the following features and properties from the
   * component manager that uses it:
   * <ul>
   *  <li>http://xml.org/sax/features/namespaces</li>
   *  <li>http://xml.org/sax/features/validation</li>
   *  <li>http://apache.org/xml/features/validation/dynamic</li>
   *  <li>http://apache.org/xml/properties/internal/symbol-table</li>
   *  <li>http://apache.org/xml/properties/internal/error-reporter</li>
   *  <li>http://apache.org/xml/properties/internal/grammar-pool</li>
   *  <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
   * </ul>
   *
   * @author Eric Ye, IBM
   * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
   * @author Andy Clark, IBM
   * @author Jeffrey Rodriguez IBM
   *
   * @version $Id: SchemaValidator.java,v 1.1 2001/08/27 20:57:05 sandygao Exp $
   */
  public class SchemaValidator
      implements XMLComponent, XMLDocumentHandler {
  
      //
      // Constants
      //
  
      // feature identifiers
  
      /** Feature identifier: namespaces. */
      protected static final String NAMESPACES =
          Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
  
      /** Feature identifier: validation. */
      protected static final String VALIDATION =
          Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
  
      /** Feature identifier: dynamic validation. */
      protected static final String DYNAMIC_VALIDATION =
          Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;
  
      // property identifiers
  
      /** Property identifier: symbol table. */
      protected static final String SYMBOL_TABLE =
          Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
  
      /** Property identifier: error reporter. */
      protected static final String ERROR_REPORTER =
          Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
  
      // recognized features and properties
  
      /** Recognized features. */
      protected static final String[] RECOGNIZED_FEATURES = {
          NAMESPACES,
          VALIDATION,
          DYNAMIC_VALIDATION,
      };
  
      /** Recognized properties. */
      protected static final String[] RECOGNIZED_PROPERTIES = {
          SYMBOL_TABLE,
          ERROR_REPORTER,
      };
  
      //
      // Data
      //
  
      // features
  
      /** Namespaces. */
      protected boolean fNamespaces;
  
      /** Validation. */
      protected boolean fValidation;
  
      /**
       * Dynamic validation. This state of this feature is only useful when
       * the validation feature is set to <code>true</code>.
       */
      protected boolean fDynamicValidation;
  
      // properties
  
      /** Symbol table. */
      protected SymbolTable fSymbolTable;
  
      /** Error reporter. */
      protected XMLErrorReporter fErrorReporter;
  
      // handlers
  
      /** Document handler. */
      protected XMLDocumentHandler fDocumentHandler;
  
      // state
  
      /** Schema grammar. */
      private SchemaGrammar fSchemaGrammar;
  
      /** Schema grammar. */
      private XSGrammarResolver fGrammarResolver;
  
      /** Perform validation. */
      private boolean fPerformValidation;
  
      /** Skip validation. */
      private boolean fSkipValidation;
  
      // information regarding the current element
  
      /** Current element name. */
      private final QName fCurrentElement = new QName();
  
      /** Current element index. */
      private int fCurrentElementIndex = -1;
  
      /** Current content model. */
      //???private ContentModel fCurrentContentModel = null;
  
      /** The root element name. */
      private final QName fRootElement = new QName();
  
      // element stack
  
      /** Element index stack. */
      private int[] fElementIndexStack = new int[8];
  
      /** Content spec type stack. */
      //???private ContentModel[] fContentModelStack = new int[8];
  
      /** Element name stack. */
      private QName[] fElementQNamePartsStack = new QName[8];
  
      // children list and offset stack
  
      /**
       * Element children. This data structure is a growing stack that
       * holds the children of elements from the root to the current
       * element depth. This structure never gets "deeper" than the
       * deepest element. Space is re-used once each element is closed.
       * <p>
       * <strong>Note:</strong> This is much more efficient use of memory
       * than creating new arrays for each element depth.
       * <p>
       * <strong>Note:</strong> The use of this data structure is for
       * validation "on the way out". If the validation model changes to
       * "on the way in", then this data structure is not needed.
       */
      private QName[] fElementChildren = new QName[32];
  
      /** Element children count. */
      private int fElementChildrenLength = 0;
  
      /**
       * Element children offset stack. This stack refers to offsets
       * into the <code>fElementChildren</code> array.
       * @see #fElementChildren
       */
      private int[] fElementChildrenOffsetStack = new int[32];
  
      /** Element depth. */
      private int fElementDepth = -1;
  
      // validation states
  
      /** Validation of a standalone document. */
      private boolean fStandaloneIsYes = false;
  
      /** True if seen the root element. */
      private boolean fSeenRootElement = false;
  
      /** True if inside of element content. */
      private boolean fInElementContent = false;
  
      /** Mixed. */
      private boolean fMixed;
  
      // temporary variables
  
      /** Temporary element declaration. */
      private XSElementDecl fTempElementDecl = new XSElementDecl();
  
      /** Temporary atribute declaration. */
      //private XSAttributeDecl fTempAttDecl = new XSAttributeDecl();
  
      /** Temporary qualified name. */
      private QName fTempQName = new QName();
  
      /** Temporary string buffer for buffering datatype value. */
      //private StringBuffer fDatatypeBuffer = new StringBuffer();
  
      /** Notation declaration hash. */
      private Hashtable fNDataDeclNotations = new Hashtable();
  
      /** Mixed element type "hash". */
      private Vector fMixedElementTypes = new Vector();
  
      /** Temporary string buffers. */
      private StringBuffer fBuffer = new StringBuffer();
  
      /**
       * This table has to be own by instance of XMLValidator and shared
       * among ID, IDREF and IDREFS.
       * <p>
       * <strong>Note:</strong> Only ID has read/write access.
       * <p>
       * <strong>Note:</strong> Should revisit and replace with a ligther
       * structure.
       */
      private Hashtable fTableOfIDs;
      private Hashtable fTableOfIDRefs;
  
      // to check for duplicate ID or ANNOTATION attribute declare in
      // ATTLIST, and misc VCs
  
      /** ID attribute names. */
      private Hashtable fTableOfIDAttributeNames;
  
      /** NOTATION attribute names. */
      private Hashtable fTableOfNOTATIONAttributeNames;
  
      /** NOTATION enumeration values. */
      private Hashtable fNotationEnumVals;
  
      //
      // Constructors
      //
  
      /** Default constructor. */
      public SchemaValidator() {
  
          // initialize data
          for (int i = 0; i < fElementQNamePartsStack.length; i++) {
              fElementQNamePartsStack[i] = new QName();
          }
  
      } // <init>()
  
      //
      // XMLComponent methods
      //
  
      /*
       * Resets the component. The component can query the component manager
       * about any features and properties that affect the operation of the
       * component.
       *
       * @param componentManager The component manager.
       *
       * @throws SAXException Thrown by component on finitialization error.
       *                      For example, if a feature or property is
       *                      required for the operation of the component, the
       *                      component manager may throw a
       *                      SAXNotRecognizedException or a
       *                      SAXNotSupportedException.
       */
      public void reset(XMLComponentManager componentManager)
          throws XMLConfigurationException {
  
          // clear grammars
          fSchemaGrammar = null;
  
          // initialize state
          fStandaloneIsYes = false;
          fSeenRootElement = false;
          fInElementContent = false;
          fCurrentElementIndex = -1;
          //???fCurrentContentModel = null;
          fSkipValidation=false;
  
          fRootElement.clear();
  
          fNDataDeclNotations.clear();
  
          // sax features
          try {
              fNamespaces = componentManager.getFeature(NAMESPACES);
          }
          catch (XMLConfigurationException e) {
              fNamespaces = true;
          }
          try {
              fValidation = componentManager.getFeature(VALIDATION);
          }
          catch (XMLConfigurationException e) {
              fValidation = false;
          }
  
          // Xerces features
          try {
              fDynamicValidation = componentManager.getFeature(DYNAMIC_VALIDATION);
          }
          catch (XMLConfigurationException e) {
              fDynamicValidation = false;
          }
  
          // get needed components
          fErrorReporter = (XMLErrorReporter)componentManager.getProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.ERROR_REPORTER_PROPERTY);
          fSymbolTable = (SymbolTable)componentManager.getProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.SYMBOL_TABLE_PROPERTY);
  
          fElementDepth = -1;
          init();
  
      } // reset(XMLComponentManager)
  
      /**
       * Returns a list of feature identifiers that are recognized by
       * this component. This method may return null if no features
       * are recognized by this component.
       */
      public String[] getRecognizedFeatures() {
          return RECOGNIZED_FEATURES;
      } // getRecognizedFeatures():String[]
  
      /**
       * Sets the state of a feature. This method is called by the component
       * manager any time after reset when a feature changes state.
       * <p>
       * <strong>Note:</strong> Components should silently ignore features
       * that do not affect the operation of the component.
       *
       * @param featureId The feature identifier.
       * @param state     The state of the feature.
       *
       * @throws SAXNotRecognizedException The component should not throw
       *                                   this exception.
       * @throws SAXNotSupportedException The component should not throw
       *                                  this exception.
       */
      public void setFeature(String featureId, boolean state)
          throws XMLConfigurationException {
      } // setFeature(String,boolean)
  
      /**
       * Returns a list of property identifiers that are recognized by
       * this component. This method may return null if no properties
       * are recognized by this component.
       */
      public String[] getRecognizedProperties() {
          return RECOGNIZED_PROPERTIES;
      } // getRecognizedProperties():String[]
  
      /**
       * Sets the value of a property. This method is called by the component
       * manager any time after reset when a property changes value.
       * <p>
       * <strong>Note:</strong> Components should silently ignore properties
       * that do not affect the operation of the component.
       *
       * @param propertyId The property identifier.
       * @param value      The value of the property.
       *
       * @throws SAXNotRecognizedException The component should not throw
       *                                   this exception.
       * @throws SAXNotSupportedException The component should not throw
       *                                  this exception.
       */
      public void setProperty(String propertyId, Object value)
          throws XMLConfigurationException {
      } // setProperty(String,Object)
  
      //
      // XMLDocumentSource methods
      //
  
      /**
       * Sets the document handler to receive information about the document.
       *
       * @param documentHandler The document handler.
       */
      public void setDocumentHandler(XMLDocumentHandler documentHandler) {
          fDocumentHandler = documentHandler;
      } // setDocumentHandler(XMLDocumentHandler)
  
      //
      // XMLDTDSource methods
      //
  
      /**
       * Sets the DTD handler.
       *
       * @param dtdHandler The DTD handler.
       */
      //public void setDTDHandler(XMLDTDHandler dtdHandler) {
      //    fDTDHandler = dtdHandler;
      //} // setDTDHandler(XMLDTDHandler)
  
      //
      // XMLDTDContentModelSource methods
      //
  
      //
      // XMLDocumentHandler methods
      //
  
      /**
       * The start of the document.
       *
       * @param systemId The system identifier of the entity if the entity
       *                 is external, null otherwise.
       * @param encoding The auto-detected IANA encoding name of the entity
       *                 stream. This value will be null in those situations
       *                 where the entity encoding is not auto-detected (e.g.
       *                 internal entities or a document entity that is
       *                 parsed from a java.io.Reader).
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void startDocument(XMLLocator locator, String encoding)
          throws XNIException {
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.startDocument(locator, encoding);
          }
  
      } // startDocument(XMLLocator,String)
  
      /**
       * Notifies of the presence of an XMLDecl line in the document. If
       * present, this method will be called immediately following the
       * startDocument call.
       *
       * @param version    The XML version.
       * @param encoding   The IANA encoding name of the document, or null if
       *                   not specified.
       * @param standalone The standalone value, or null if not specified.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void xmlDecl(String version, String encoding, String standalone)
          throws XNIException {
  
          // save standalone state
          fStandaloneIsYes = standalone != null && standalone.equals("yes");
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.xmlDecl(version, encoding, standalone);
          }
  
      } // xmlDecl(String,String,String)
  
      /**
       * Notifies of the presence of the DOCTYPE line in the document.
       *
       * @param rootElement The name of the root element.
       * @param publicId    The public identifier if an external DTD or null
       *                    if the external DTD is specified using SYSTEM.
       * @param systemId    The system identifier if an external DTD, null
       *                    otherwise.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void doctypeDecl(String rootElement, String publicId, String systemId)
          throws XNIException {
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.doctypeDecl(rootElement, publicId, systemId);
          }
  
      } // doctypeDecl(String,String,String)
  
      /**
       * The start of a namespace prefix mapping. This method will only be
       * called when namespace processing is enabled.
       *
       * @param prefix The namespace prefix.
       * @param uri    The URI bound to the prefix.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void startPrefixMapping(String prefix, String uri)
          throws XNIException {
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.startPrefixMapping(prefix, uri);
          }
  
      } // startPrefixMapping(String,String)
  
      /**
       * The start of an element.
       *
       * @param element    The name of the element.
       * @param attributes The element attributes.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void startElement(QName element, XMLAttributes attributes)
          throws XNIException {
  
          //???handleStartElement(element, attributes, false);
          System.out.println("startElement: " + element.rawname);
          if (fDocumentHandler != null) {
              fDocumentHandler.startElement(element, attributes);
          }
  
      } // startElement(QName,XMLAttributes)
  
      /**
       * An empty element.
       *
       * @param element    The name of the element.
       * @param attributes The element attributes.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void emptyElement(QName element, XMLAttributes attributes)
          throws XNIException {
  
          //???handleStartElement(element, attributes, true);
          //???handleEndElement(element, true);
          System.out.println("start/endElement: " + element.rawname);
          if (fDocumentHandler != null) {
              fDocumentHandler.emptyElement(element, attributes);
          }
  
      } // emptyElement(QName,XMLAttributes)
  
      /**
       * Character content.
       *
       * @param text The content.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void characters(XMLString text) throws XNIException {
          boolean callNextCharacters = true;
  
          // REVISIT: [Q] Is there a more efficient way of doing this?
          //          Perhaps if the scanner told us so we don't have to
          //          look at the characters again. -Ac
          boolean allWhiteSpace = true;
          for (int i=text.offset; i< text.offset+text.length; i++) {
              if (!XMLChar.isSpace(text.ch[i])) {
                  allWhiteSpace = false;
                  break;
              }
          }
  
          // call the ignoreableWhiteSpace callback
          if (fInElementContent && allWhiteSpace) {
              if (fDocumentHandler != null) {
                  fDocumentHandler.ignorableWhitespace(text);
                  callNextCharacters = false;
              }
          }
  
          // validate
  
          // call handlers
          if (callNextCharacters && fDocumentHandler != null) {
              fDocumentHandler.characters(text);
          }
  
      } // characters(XMLString)
  
      /**
       * Ignorable whitespace. For this method to be called, the document
       * source must have some way of determining that the text containing
       * only whitespace characters should be considered ignorable. For
       * example, the validator can determine if a length of whitespace
       * characters in the document are ignorable based on the element
       * content model.
       *
       * @param text The ignorable whitespace.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void ignorableWhitespace(XMLString text) throws XNIException {
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.ignorableWhitespace(text);
          }
  
      } // ignorableWhitespace(XMLString)
  
      /**
       * The end of an element.
       *
       * @param element The name of the element.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void endElement(QName element) throws XNIException {
  
          //???handleEndElement(element, false);
          System.out.println("endElement: " + element.rawname);
          if (fDocumentHandler != null) {
              fDocumentHandler.endElement(element);
          }
  
      } // endElement(QName)
  
      /**
       * The end of a namespace prefix mapping. This method will only be
       * called when namespace processing is enabled.
       *
       * @param prefix The namespace prefix.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void endPrefixMapping(String prefix) throws XNIException {
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.endPrefixMapping(prefix);
          }
  
      } // endPrefixMapping(String)
  
      /**
       * The start of a CDATA section.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void startCDATA() throws XNIException {
  
          if (fPerformValidation && fInElementContent) {
              //???charDataInContent();
          }
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.startCDATA();
          }
  
      } // startCDATA()
  
      /**
       * The end of a CDATA section.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void endCDATA() throws XNIException {
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.endCDATA();
          }
  
      } // endCDATA()
  
      /**
       * The end of the document.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void endDocument() throws XNIException {
  
          // call handlers
          if (fDocumentHandler != null) {
              fDocumentHandler.endDocument();
          }
  
      } // endDocument()
  
      //
      // XMLDocumentHandler and XMLDTDHandler methods
      //
  
      /**
       * This method notifies of the start of an entity. The DTD has the
       * pseudo-name of "[dtd]; parameter entity names start with '%'; and
       * general entity names are just the entity name.
       * <p>
       * <strong>Note:</strong> Since the DTD is an entity, the handler
       * will be notified of the start of the DTD entity by calling the
       * startEntity method with the entity name "[dtd]" <em>before</em> calling
       * the startDTD method.
       * <p>
       * <strong>Note:</strong> This method is not called for entity references
       * appearing as part of attribute values.
       *
       * @param name     The name of the entity.
       * @param publicId The public identifier of the entity if the entity
       *                 is external, null otherwise.
       * @param systemId The system identifier of the entity if the entity
       *                 is external, null otherwise.
       * @param baseSystemId The base system identifier of the entity if
       *                     the entity is external, null otherwise.
       * @param encoding The auto-detected IANA encoding name of the entity
       *                 stream. This value will be null in those situations
       *                 where the entity encoding is not auto-detected (e.g.
       *                 internal parameter entities).
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void startEntity(String name,
                              String publicId, String systemId,
                              String baseSystemId,
                              String encoding) throws XNIException {
  
          if (fDocumentHandler != null) {
              fDocumentHandler.startEntity(name, publicId, systemId,
                                           baseSystemId, encoding);
          }
  
      } // startEntity(String,String,String,String,String)
  
      /**
       * Notifies of the presence of a TextDecl line in an entity. If present,
       * this method will be called immediately following the startEntity call.
       * <p>
       * <strong>Note:</strong> This method will never be called for the
       * document entity; it is only called for external general entities
       * referenced in document content.
       * <p>
       * <strong>Note:</strong> This method is not called for entity references
       * appearing as part of attribute values.
       *
       * @param version  The XML version, or null if not specified.
       * @param encoding The IANA encoding name of the entity.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void textDecl(String version, String encoding) throws XNIException {
  
          if (fDocumentHandler != null) {
              fDocumentHandler.textDecl(version, encoding);
          }
  
      } // textDecl(String,String)
  
      /**
       * A comment.
       *
       * @param text The text in the comment.
       *
       * @throws XNIException Thrown by application to signal an error.
       */
      public void comment(XMLString text) throws XNIException {
  
          if (fDocumentHandler != null) {
              fDocumentHandler.comment(text);
          }
  
      } // comment(XMLString)
  
      /**
       * A processing instruction. Processing instructions consist of a
       * target name and, optionally, text data. The data is only meaningful
       * to the application.
       * <p>
       * Typically, a processing instruction's data will contain a series
       * of pseudo-attributes. These pseudo-attributes follow the form of
       * element attributes but are <strong>not</strong> parsed or presented
       * to the application as anything other than text. The application is
       * responsible for parsing the data.
       *
       * @param target The target.
       * @param data   The data or null if none specified.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void processingInstruction(String target, XMLString data)
          throws XNIException {
  
          if (fDocumentHandler != null) {
              fDocumentHandler.processingInstruction(target, data);
          }
  
      } // processingInstruction(String,XMLString)
  
      /**
       * This method notifies the end of an entity. The DTD has the pseudo-name
       * of "[dtd]; parameter entity names start with '%'; and general entity
       * names are just the entity name.
       * <p>
       * <strong>Note:</strong> Since the DTD is an entity, the handler
       * will be notified of the end of the DTD entity by calling the
       * endEntity method with the entity name "[dtd]" <em>after</em> calling
       * the endDTD method.
       * <p>
       * <strong>Note:</strong> This method is not called for entity references
       * appearing as part of attribute values.
       *
       * @param name The name of the entity.
       *
       * @throws XNIException Thrown by handler to signal an error.
       */
      public void endEntity(String name) throws XNIException {
  
          if (fDocumentHandler != null) {
              fDocumentHandler.endEntity(name);
          }
  
      } // endEntity(String)
  
      /**
       * Check that the content of an element is valid.
       * <p>
       * This is the method of primary concern to the validator. This method is called
       * upon the scanner reaching the end tag of an element. At that time, the
       * element's children must be structurally validated, so it calls this method.
       * The index of the element being checked (in the decl pool), is provided as
       * well as an array of element name indexes of the children. The validator must
       * confirm that this element can have these children in this order.
       * <p>
       * This can also be called to do 'what if' testing of content models just to see
       * if they would be valid.
       * <p>
       * Note that the element index is an index into the element decl pool, whereas
       * the children indexes are name indexes, i.e. into the string pool.
       * <p>
       * A value of -1 in the children array indicates a PCDATA node. All other
       * indexes will be positive and represent child elements. The count can be
       * zero, since some elements have the EMPTY content model and that must be
       * confirmed.
       *
       * @param elementIndex The index within the <code>ElementDeclPool</code> of this
       *                     element.
       * @param childCount The number of entries in the <code>children</code> array.
       * @param children The children of this element.
       *
       * @return The value -1 if fully valid, else the 0 based index of the child
       *         that first failed. If the value returned is equal to the number
       *         of children, then additional content is required to reach a valid
       *         ending state.
       *
       * @exception Exception Thrown on error.
       */
      /*private int checkContent(int elementIndex,
                               QName[] children,
                               int childOffset,
                               int childCount) throws XNIException {
  
          fSchemaGrammar.getElementDecl(elementIndex, fTempElementDecl);
  
          int typeIdx = fTempElementDecl.fXSTypeDecl;
          XSType type = fSchemaGrammar.getTypeDecl(typeIdx, fTempTypeDecl);
  
          int result = -1;
          if (type.getXSType() == XSType.COMPLEX_TYPE) {
              ContentModel cmElem = ((XSComplexTypeInfo)fTempTypeDecl).fContentModel;
              result = cmElem.validate(children, childOffset, childCount);
          } else {
              result = ((XSSimpleTypeInfo)fTempTypeDecl).validate();
          }
  
          return result;
      } // checkContent(int,int,QName[]):int
  
      /** Character data in content. */
      /*private void charDataInContent() {
  
          if (fElementChildren.length == fElementChildrenLength) {
              QName[] newarray = new QName[fElementChildrenLength * 2];
              System.arraycopy(fElementChildren, 0, newarray, 0, fElementChildrenLength);
              fElementChildren = newarray;
              for (int i = fElementChildrenLength; i < fElementChildren.length; i++) {
                  fElementChildren[i] = new QName();
              }
          } else {
              fElementChildren[fElementChildrenLength].clear();
          }
          fElementChildrenLength++;
  
      } // charDataInCount()
  
      /** intialization */
      private void init() {
  
          //Initialize ID, IDREF, IDREFS validators
          if (fTableOfIDs == null) {
              fTableOfIDs = new Hashtable();
              fTableOfIDRefs = new Hashtable();
              fNotationEnumVals = new Hashtable();
              fTableOfIDAttributeNames = new Hashtable();
              fTableOfNOTATIONAttributeNames = new Hashtable();
          }
  
          fTableOfIDs.clear();
          fTableOfIDRefs.clear();
          fNotationEnumVals.clear();
          fTableOfIDAttributeNames.clear();
          fTableOfNOTATIONAttributeNames.clear();
  
      } // init()
  
      /** ensure element stack capacity */
      /*private void ensureStackCapacity ( int newElementDepth) {
  
          if (newElementDepth == fElementQNamePartsStack.length) {
  
              QName[] newQNameStack = new QName[newElementDepth * 2];
              System.arraycopy(fElementQNamePartsStack, 0,
                               newQNameStack, 0, newElementDepth );
              fElementQNamePartsStack = newQNameStack;
  
              for (int i = newElementDepth; i < newElementDepth * 2; i++) {
                  fElementQNamePartsStack[i] = new QName();
              }
  
              int[] newIntStack = new int[newElementDepth * 2];
              System.arraycopy(fElementIndexStack, 0, newIntStack, 0, newElementDepth);
              fElementIndexStack = newIntStack;
  
              ContentModel[] newCMStack = new ContentModel[newElementDepth * 2];
              System.arraycopy(fContentModelStack, 0, newCMStack, 0, newElementDepth);
              fContentModelStack = newCMStack;
          }
      } // ensureStackCapacity
  
      //
      // Protected methods
      //
  
      /** Handle element. */
      /*protected void handleStartElement(QName element, XMLAttributes attributes,
                                        boolean isEmpty) throws XNIException {
  
          // set wether we're performing validation
          fPerformValidation = fValidation && !fDynamicValidation;
  
          if (fSchemaGrammar == null && !fSkipValidation){
  
              if  (!fPerformValidation) {
                  fCurrentElementIndex = -1;
                  fCurrentContentModel = null;
                  fInElementContent = false;
              }
              if (fPerformValidation) {
                  fSkipValidation = true;
                  fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                             "MSG_GRAMMAR_NOT_FOUND",
                                             new Object[]{ element.rawname},
                                             XMLErrorReporter.SEVERITY_ERROR);
              }
          }
          else {
              //  resolve the element
              fCurrentElementIndex = fSchemaGrammar.getElementDeclIndex(element, -1);
  
              fCurrentContentModel = getContentSpecType(fCurrentElementIndex);
              if (fCurrentElementIndex == -1 && fPerformValidation) {
                  fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                             "MSG_ELEMENT_NOT_DECLARED",
                                             new Object[]{ element.rawname},
                                             XMLErrorReporter.SEVERITY_ERROR);
              }
          }
  
          // set element content state
          fInElementContent = fCurrentContentModel.childrenCount() > 0;
  
          // increment the element depth, add this element's
          // QName to its enclosing element 's children list
          fElementDepth++;
          if (fPerformValidation) {
              // push current length onto stack
              if (fElementChildrenOffsetStack.length < fElementDepth) {
                  int newarray[] = new int[fElementChildrenOffsetStack.length * 2];
                  System.arraycopy(fElementChildrenOffsetStack, 0, newarray, 0, fElementChildrenOffsetStack.length);
                  fElementChildrenOffsetStack = newarray;
              }
              fElementChildrenOffsetStack[fElementDepth] = fElementChildrenLength;
  
              // add this element to children
              if (fElementChildren.length <= fElementChildrenLength) {
                  QName[] newarray = new QName[fElementChildrenLength * 2];
                  System.arraycopy(fElementChildren, 0, newarray, 0, fElementChildren.length);
                  fElementChildren = newarray;
              }
              QName qname = fElementChildren[fElementChildrenLength];
              if (qname == null) {
                  for (int i = fElementChildrenLength; i < fElementChildren.length; i++) {
                      fElementChildren[i] = new QName();
                  }
                  qname = fElementChildren[fElementChildrenLength];
              }
              qname.setValues(element);
              fElementChildrenLength++;
          }
  
          // save current element information
          fCurrentElement.setValues(element);
          ensureStackCapacity(fElementDepth);
          fElementQNamePartsStack[fElementDepth].setValues(fCurrentElement);
          fElementIndexStack[fElementDepth] = fCurrentElementIndex;
          fContentModelStack[fElementDepth] = fCurrentContentModel;
  
          // call handlers
          if (fDocumentHandler != null) {
              if (isEmpty) {
                  fDocumentHandler.emptyElement(element, attributes);
              }
              else {
                  fDocumentHandler.startElement(element, attributes);
              }
          }
  
      } // handleStartElement(QName,XMLAttributes,boolean)
  
      /** Handle end element. */
      /*protected void handleEndElement(QName element, boolean isEmpty)
          throws XNIException {
  
          // decrease element depth
          fElementDepth--;
  
          // validate
          if (fPerformValidation) {
              int elementIndex = fCurrentElementIndex;
              if (elementIndex != -1 && fCurrentContentModel != null) {
                  QName children[] = fElementChildren;
                  int childrenOffset = fElementChildrenOffsetStack[fElementDepth + 1] + 1;
                  int childrenLength = fElementChildrenLength - childrenOffset;
                  int result = checkContent(elementIndex,
                                            children, childrenOffset, childrenLength);
  
                  if (result != -1) {
                      fSchemaGrammar.getElementDecl(elementIndex, fTempElementDecl);
                      if (fTempElementDecl.type.contentModel.childrenCount() == 0) {
                          fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                                     "MSG_CONTENT_INVALID",
                                                     new Object[]{ element.rawname, "EMPTY"},
                                                     XMLErrorReporter.SEVERITY_ERROR);
                      }
                      else {
                          String messageKey = result != childrenLength ?
                                              "MSG_CONTENT_INVALID" : "MSG_CONTENT_INCOMPLETE";
                          fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                                     messageKey,
                                                     new Object[]{ element.rawname,
                                                         fTempElementDecl.type.contentModel.toString()},
                                                     XMLErrorReporter.SEVERITY_ERROR);
                      }
                  }
              }
              fElementChildrenLength = fElementChildrenOffsetStack[fElementDepth + 1] + 1;
          }
  
          // call handlers
          if (fDocumentHandler != null && !isEmpty) {
              // NOTE: The binding of the element doesn't actually happen
              //       yet because the namespace binder does that. However,
              //       if it does it before this point, then the endPrefix-
              //       Mapping calls get made too soon! As long as the
              //       rawnames match, we know it'll have a good binding,
              //       so we can just use the current element. -Ac
              fDocumentHandler.endElement(fCurrentElement);
          }
  
          // now pop this element off the top of the element stack
          if (fElementDepth < -1) {
              throw new RuntimeException("FWK008 Element stack underflow");
          }
          if (fElementDepth < 0) {
              fCurrentElement.clear();
              fCurrentElementIndex = -1;
              fCurrentContentModel = null;
              fInElementContent = false;
  
              // TO DO : fix this
              //
              // Check after document is fully parsed
              // (1) check that there was an element with a matching id for every
              //   IDREF and IDREFS attr (V_IDREF0)
              //
              if (fPerformValidation) {
                  try {
                      //Do final validation of IDREFS against IDs
                      IDREFDatatypeValidator.checkIDREF(fTableOfIDs, fTableOfIDRefs);
                  }
                  catch (InvalidDatatypeValueException ex) {
                      String  key = ex.getKeyIntoReporter();
  
                      fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN,
                                                  key,
                                                  new Object[]{ ex.getMessage()},
                                                  XMLErrorReporter.SEVERITY_ERROR );
                  }
                  fTableOfIDs.clear();//Clear table of IDs
              }
              return;
          }
  
          // If Namespace enable then localName != rawName
          fCurrentElement.setValues(fElementQNamePartsStack[fElementDepth]);
  
          fCurrentElementIndex = fElementIndexStack[fElementDepth];
          fCurrentContentModel = fElementContentModelStack[fElementDepth];
          fInElementContent = fCurrentContentModel.childrenCount() > 0;
  
      } // handleEndElement(QName,boolean)*/
  
  } // class XMLDTDValidator
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaParserConfiguration.java
  
  Index: SchemaParserConfiguration.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) 1999, 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 org.apache.xerces.impl.v2.SchemaValidator;
  
  import org.apache.xerces.impl.Constants;
  import org.apache.xerces.impl.validation.GrammarPool;
  import org.apache.xerces.parsers.StandardParserConfiguration;
  import org.apache.xerces.util.SymbolTable;
  
  /**
   * A temprory configuration for schema validation
   * Eventhing here will be merged to StardardParserConfiguration when
   * schema support is ready. - sandygao
   *
   * @version $Id: SchemaParserConfiguration.java,v 1.1 2001/08/27 20:57:05 sandygao Exp $
   */
  public class SchemaParserConfiguration extends StandardParserConfiguration {
  
      /** Property identifier: XML Schema validator. */
      protected static final String SCHEMA_VALIDATOR =
          Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
  
      /** XML Schema Validator. */
      protected SchemaValidator fSchemaValidator;
  
      //
      // Constructors
      //
  
      /**
       * Constructs a document parser using the default symbol table and grammar
       * pool or the ones specified by the application (through the properties).
       */
      public SchemaParserConfiguration() {
          this(null, null);
      } // <init>()
  
      /**
       * Constructs a document parser using the specified symbol table.
       */
      public SchemaParserConfiguration(SymbolTable symbolTable) {
          this(symbolTable, null);
      } // <init>(SymbolTable)
  
      /**
       * Constructs a document parser using the specified symbol table and
       * grammar pool.
       */
      public SchemaParserConfiguration(SymbolTable symbolTable,
                                       GrammarPool grammarPool) {
          super(symbolTable, grammarPool);
  
          fSchemaValidator = createSchemaValidator();
          if (fSchemaValidator != null) {
              fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
              addComponent(fSchemaValidator);
          }
  
      } // <init>(SymbolTable,GrammarPool)
  
      //
      // Public methods
      //
  
      /** Configures the pipeline. */
      protected void configurePipeline() {
  
          super.configurePipeline();
  
          if (fSchemaValidator != null) {
              fNamespaceBinder.setDocumentHandler(fSchemaValidator);
              fSchemaValidator.setDocumentHandler(fDocumentHandler);
          }
  
      } // configurePipeline()
  
      /** Create a Schema validator. */
      protected SchemaValidator createSchemaValidator() {
          return new SchemaValidator();
      } // createSchemaValidator():XMLSchemaValidator
  
  } // class StandardParserConfiguration
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/impl/v2/SAXParser.java
  
  Index: SAXParser.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 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) 1999, 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 org.apache.xerces.parsers.AbstractSAXParser;
  import org.apache.xerces.impl.validation.GrammarPool;
  import org.apache.xerces.util.SymbolTable;
  import org.apache.xerces.xni.parser.XMLParserConfiguration;
  
  /**
   * This is the main Xerces SAX parser class. It uses the abstract SAX
   * parser with a document scanner, a dtd scanner, and a validator, as
   * well as a grammar pool.
   *
   * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
   * @author Arnaud  Le Hors, IBM
   * @author Andy Clark, IBM
   *
   * @version $Id: SAXParser.java,v 1.1 2001/08/27 20:57:05 sandygao Exp $
   */
  public class SAXParser
      extends AbstractSAXParser {
  
      //
      // Constructors
      //
  
      /**
       * Constructs a SAX parser using the default basic parser configuration.
       */
      public SAXParser() {
          super(new SchemaParserConfiguration());
      } // <init>
  
      /**
       * Constructs a SAX parser using the specified symbol table.
       */
      public SAXParser(SymbolTable symbolTable) {
          super(new SchemaParserConfiguration(symbolTable));
      } // <init>(SymbolTable)
  
      /**
       * Constructs a SAX parser using the specified symbol table and
       * grammar pool.
       */
      public SAXParser(SymbolTable symbolTable, GrammarPool grammarPool) {
          super(new SchemaParserConfiguration(symbolTable, grammarPool));
      }
  
  } // class SAXParser
  
  
  

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