Fixing NPE for the new schemaDOMParser.


git-svn-id: https://svn.apache.org/repos/asf/xerces/java/branches/jaxp-ri-1_2_0-fcs-branch@318640 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/org/apache/xerces/impl/xs/opti/DefaultXMLDocumentHandler.java b/src/org/apache/xerces/impl/xs/opti/DefaultXMLDocumentHandler.java
index e959675..56cd690 100644
--- a/src/org/apache/xerces/impl/xs/opti/DefaultXMLDocumentHandler.java
+++ b/src/org/apache/xerces/impl/xs/opti/DefaultXMLDocumentHandler.java
@@ -62,7 +62,9 @@
 import org.apache.xerces.xni.XMLLocator;
 import org.apache.xerces.xni.Augmentations;
 import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLDTDHandler;
 import org.apache.xerces.xni.XMLDocumentHandler;
+import org.apache.xerces.xni.XMLDTDContentModelHandler;
 import org.apache.xerces.xni.XMLResourceIdentifier;
 
 import org.apache.xerces.xni.XNIException;
@@ -73,7 +75,9 @@
  *
  * @version $Id$
  */
-public class DefaultXMLDocumentHandler implements XMLDocumentHandler {
+public class DefaultXMLDocumentHandler implements XMLDocumentHandler, 
+                                                  XMLDTDHandler, 
+                                                  XMLDTDContentModelHandler {
     
     /** Default Constructor */
     public DefaultXMLDocumentHandler() {
@@ -364,4 +368,498 @@
     public void endDocument(Augmentations augs) throws XNIException {
     }
 
+
+    //
+    // XMLDTDHandler methods
+    //
+
+    /**
+     * The start of the DTD.
+     *
+     * @param locator  The document locator, or null if the document
+     *                 location cannot be reported during the parsing of 
+     *                 the document DTD. However, it is <em>strongly</em>
+     *                 recommended that a locator be supplied that can 
+     *                 at least report the base system identifier of the
+     *                 DTD.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void startDTD(XMLLocator locator, Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * This method notifies of the start of a parameter entity. The parameter
+     * entity name start with a '%' character.
+     * 
+     * @param name     The name of the parameter entity.
+     * @param identifier The resource identifier.
+     * @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).
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void startParameterEntity(String name, 
+                                     XMLResourceIdentifier identifier,
+                                     String encoding,
+                                     Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * 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 is only called for external
+     * parameter entities referenced in the DTD.
+     * 
+     * @param version  The XML version, or null if not specified.
+     * @param encoding The IANA encoding name of the entity.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+/*
+    public void textDecl(String version, String encoding,
+                         Augmentations augmentations) throws XNIException {
+    }
+*/
+
+    /**
+     * This method notifies the end of a parameter entity. Parameter entity
+     * names begin with a '%' character.
+     * 
+     * @param name The name of the parameter entity.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void endParameterEntity(String name, Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * The start of the DTD external subset.
+     * 
+     * @param identifier The resource identifier.
+     * @param augmentations
+     *                   Additional information that may include infoset
+     *                   augmentations.
+     * @exception XNIException
+     *                   Thrown by handler to signal an error.
+     */
+    public void startExternalSubset(Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * The end of the DTD external subset.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void endExternalSubset(Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * A comment.
+     * 
+     * @param text The text in the comment.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by application to signal an error.
+     */
+/*
+    public void comment(XMLString text, Augmentations augmentations) 
+        throws XNIException {
+    }
+*/
+
+    /**
+     * 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.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+/*
+    public void processingInstruction(String target, XMLString data,
+                                      Augmentations augmentations)
+        throws XNIException {
+    }
+*/
+
+
+    /**
+     * An element declaration.
+     * 
+     * @param name         The name of the element.
+     * @param contentModel The element content model.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void elementDecl(String name, String contentModel,
+                            Augmentations augmentations)
+        throws XNIException {
+    }
+
+    /**
+     * The start of an attribute list.
+     * 
+     * @param elementName The name of the element that this attribute
+     *                    list is associated with.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void startAttlist(String elementName,
+                             Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * An attribute declaration.
+     * 
+     * @param elementName   The name of the element that this attribute
+     *                      is associated with.
+     * @param attributeName The name of the attribute.
+     * @param type          The attribute type. This value will be one of
+     *                      the following: "CDATA", "ENTITY", "ENTITIES",
+     *                      "ENUMERATION", "ID", "IDREF", "IDREFS", 
+     *                      "NMTOKEN", "NMTOKENS", or "NOTATION".
+     * @param enumeration   If the type has the value "ENUMERATION" or
+     *                      "NOTATION", this array holds the allowed attribute
+     *                      values; otherwise, this array is null.
+     * @param defaultType   The attribute default type. This value will be
+     *                      one of the following: "#FIXED", "#IMPLIED",
+     *                      "#REQUIRED", or null.
+     * @param defaultValue  The attribute default value, or null if no
+     *                      default value is specified.
+     * @param nonNormalizedDefaultValue  The attribute default value with no normalization 
+     *                      performed, or null if no default value is specified.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void attributeDecl(String elementName, String attributeName, 
+                              String type, String[] enumeration, 
+                              String defaultType, XMLString defaultValue,
+                              XMLString nonNormalizedDefaultValue, Augmentations augmentations)
+        throws XNIException {
+    }
+
+    /**
+     * The end of an attribute list.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void endAttlist(Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * An internal entity declaration.
+     * 
+     * @param name The name of the entity. Parameter entity names start with
+     *             '%', whereas the name of a general entity is just the 
+     *             entity name.
+     * @param text The value of the entity.
+     * @param nonNormalizedText The non-normalized value of the entity. This
+     *             value contains the same sequence of characters that was in 
+     *             the internal entity declaration, without any entity
+     *             references expanded.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void internalEntityDecl(String name, XMLString text, 
+                                   XMLString nonNormalizedText,
+                                   Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * An external entity declaration.
+     * 
+     * @param name     The name of the entity. Parameter entity names start
+     *                 with '%', whereas the name of a general entity is just
+     *                 the entity name.
+     * @param identifier    An object containing all location information 
+     *                      pertinent to this external entity.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void externalEntityDecl(String name, 
+                                   XMLResourceIdentifier identifier,
+                                   Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * An unparsed entity declaration.
+     * 
+     * @param name     The name of the entity.
+     * @param identifier    An object containing all location information 
+     *                      pertinent to this unparsed entity declaration.
+     * @param notation The name of the notation.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void unparsedEntityDecl(String name, 
+                                   XMLResourceIdentifier identifier, 
+                                   String notation, Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * A notation declaration
+     * 
+     * @param name     The name of the notation.
+     * @param identifier    An object containing all location information 
+     *                      pertinent to this notation.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void notationDecl(String name, XMLResourceIdentifier identifier,
+                             Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * The start of a conditional section.
+     * 
+     * @param type The type of the conditional section. This value will
+     *             either be CONDITIONAL_INCLUDE or CONDITIONAL_IGNORE.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     *
+     * @see #CONDITIONAL_INCLUDE
+     * @see #CONDITIONAL_IGNORE
+     */
+    public void startConditional(short type, Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * Characters within an IGNORE conditional section.
+     *
+     * @param text The ignored text.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void ignoredCharacters(XMLString text, Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * The end of a conditional section.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void endConditional(Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * The end of the DTD.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void endDTD(Augmentations augmentations) throws XNIException {
+    }
+
+
+    //
+    // XMLDTDContentModelHandler methods
+    //
+
+    /**
+     * The start of a content model. Depending on the type of the content
+     * model, specific methods may be called between the call to the
+     * startContentModel method and the call to the endContentModel method.
+     * 
+     * @param elementName The name of the element.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void startContentModel(String elementName, Augmentations augmentations)
+        throws XNIException {
+    }
+
+    /** 
+     * A content model of ANY. 
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     *
+     * @see #empty
+     * @see #startGroup
+     */
+    public void any(Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * A content model of EMPTY.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @see #any
+     * @see #startGroup
+     */
+    public void empty(Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * A start of either a mixed or children content model. A mixed
+     * content model will immediately be followed by a call to the
+     * <code>pcdata()</code> method. A children content model will
+     * contain additional groups and/or elements.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     *
+     * @see #any
+     * @see #empty
+     */
+    public void startGroup(Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * The appearance of "#PCDATA" within a group signifying a
+     * mixed content model. This method will be the first called
+     * following the content model's <code>startGroup()</code>.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *     
+     * @throws XNIException Thrown by handler to signal an error.
+     *
+     * @see #startGroup
+     */
+    public void pcdata(Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * A referenced element in a mixed or children content model.
+     * 
+     * @param elementName The name of the referenced element.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void element(String elementName, Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * The separator between choices or sequences of a mixed or children
+     * content model.
+     * 
+     * @param separator The type of children separator.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     *
+     * @see #SEPARATOR_CHOICE
+     * @see #SEPARATOR_SEQUENCE
+     */
+    public void separator(short separator, Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * The occurrence count for a child in a children content model or
+     * for the mixed content model group.
+     * 
+     * @param occurrence The occurrence count for the last element
+     *                   or group.
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     *
+     * @see #OCCURS_ZERO_OR_ONE
+     * @see #OCCURS_ZERO_OR_MORE
+     * @see #OCCURS_ONE_OR_MORE
+     */
+    public void occurrence(short occurrence, Augmentations augmentations) 
+        throws XNIException {
+    }
+
+    /**
+     * The end of a group for mixed or children content models.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void endGroup(Augmentations augmentations) throws XNIException {
+    }
+
+    /**
+     * The end of a content model.
+     *
+     * @param augmentations Additional information that may include infoset
+     *                      augmentations.
+     *
+     * @throws XNIException Thrown by handler to signal an error.
+     */
+    public void endContentModel(Augmentations augmentations) throws XNIException {
+    }
+
 }
\ No newline at end of file
diff --git a/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java b/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
index 577e9f6..bc2ba83 100644
--- a/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
+++ b/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
@@ -78,8 +78,7 @@
  *
  * @version $Id$
  */
-public class SchemaDOMParser extends DefaultXMLDocumentHandler
-                             implements XMLComponent, XMLDocumentSource {
+public class SchemaDOMParser extends DefaultXMLDocumentHandler {
 
     //
     // Data
@@ -87,9 +86,7 @@
     
     SchemaDOM schemaDOM;
     
-    /** Document handler. */
-    protected XMLDocumentHandler fDocumentHandler;
-    
+
 
     //
     // Constructors
@@ -97,95 +94,10 @@
 
     /** Default constructor. */
     public SchemaDOMParser() {
+        schemaDOM = new SchemaDOM();
     }
 
 
-    //
-    // 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 initialization 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 XNIException {
-
-        schemaDOM = new SchemaDOM();
-
-    } // 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 null;
-    } // 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 null;
-    } // getRecognizedProperties():String[]
-
-    /**
-     * Sets the value of a property during parsing.
-     *
-     * @param propertyId
-     * @param value
-     */
-    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)
 
     //
     // XMLDocumentHandler methods
diff --git a/src/org/apache/xerces/impl/xs/opti/SchemaParsingConfig.java b/src/org/apache/xerces/impl/xs/opti/SchemaParsingConfig.java
index 4a6bc6c..a8703f3 100644
--- a/src/org/apache/xerces/impl/xs/opti/SchemaParsingConfig.java
+++ b/src/org/apache/xerces/impl/xs/opti/SchemaParsingConfig.java
@@ -322,8 +322,7 @@
             NAMESPACE_BINDER,
             XMLGRAMMAR_POOL,   
             DATATYPE_VALIDATOR_FACTORY,
-            VALIDATION_MANAGER,
-            "SchemaDOMParser"
+            VALIDATION_MANAGER
         };
         addRecognizedProperties(recognizedProperties);
 	
@@ -361,11 +360,6 @@
             addComponent(fNamespaceBinder);
         }
 
-        fSchemaDOMParser = createSchemaDOMParser();
-        if (fSchemaDOMParser != null) {
-            setProperty("SchemaDOMParser", fSchemaDOMParser);
-            addComponent(fSchemaDOMParser);
-        }
 
         fDatatypeValidatorFactory = createDatatypeValidatorFactory();
         if (fDatatypeValidatorFactory != null) {
@@ -589,6 +583,12 @@
      */
     public void reset() throws XNIException {
 
+        // set handlers
+        fSchemaDOMParser = createSchemaDOMParser();
+        fDocumentHandler = fSchemaDOMParser;
+        fDTDHandler = fSchemaDOMParser;
+        fDTDContentModelHandler = fSchemaDOMParser;
+
         // configure the pipeline and initialize the components
         configurePipeline();
         super.reset();
@@ -607,10 +607,9 @@
 
         // setup document pipeline
         fScanner.setDocumentHandler(fNamespaceBinder);
-        fNamespaceBinder.setDocumentHandler(fSchemaDOMParser);
-        //fSchemaDOMParser.setDocumentHandler(fDocumentHandler);
+        fNamespaceBinder.setDocumentHandler(fDocumentHandler);
 
-        //fLastComponent = fSchemaDOMParser;
+        fLastComponent = fNamespaceBinder;
 
         // setup dtd pipeline