FileDocCategorySizeDatePackage
DOMParser.javaAPI DocJava SE 5 API11586Fri Aug 26 14:55:50 BST 2005com.sun.org.apache.xerces.internal.impl.xs.dom

DOMParser

public class DOMParser extends DOMParser
A dom parser used to parse schema documents into DOM trees
author
Sandy Gao, IBM
version
$Id: DOMParser.java,v 1.9 2002/12/11 16:01:18 sandygao Exp $

Fields Summary
protected static final String
ENTITY_MANAGER
Property identifier: entity manager.
protected static final String
DOCUMENT_CLASS
Property identifier: DOM document class name.
protected static final String
DEFER_EXPANSION
Feature identifier: DOM Defer node expansion.
public static final String
ERROR_REPORTER
Property identifier: error reporter.
protected XMLLocator
fLocator
public DocumentImpl
fDocumentImpl
private DOMNodePool
fNodePool
private int
fAnnotationDepth
private int
fDepth
XMLErrorReporter
fErrorReporter
Constructors Summary
public DOMParser()
Constructs a DOM parser using the dtd/xml schema parser configuration.

    
    //
    // Constructors
    //

                   
      
        // REVISIT: should we use a new configuration with scannerNS->dom API with 
        //          no dtd scanners/valitors..?
        //
        super(new NonValidatingConfiguration());
        try {
            // use our own document implementation
            setProperty(DOCUMENT_CLASS, "com.sun.org.apache.xerces.internal.impl.xs.dom.DocumentImpl");
            // don't defer DOM expansion
            setFeature(DEFER_EXPANSION, false);

        }
        catch (Exception e) {
        }
        fNodePool = new DOMNodePool();
    
Methods Summary
public voidcharacters(com.sun.org.apache.xerces.internal.xni.XMLString text, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        // when it's not within xs:appinfo or xs:documentation
        if (fAnnotationDepth == -1) {
            for (int i=text.offset; i<text.offset+text.length; i++) {
                // and there is a non-whitespace character
                if (!XMLChar.isSpace(text.ch[i])) {
                    // only get the error reporter when reporting an error
                    if (fErrorReporter == null) {
                        try {
                            fErrorReporter = (XMLErrorReporter)getProperty(ERROR_REPORTER);
                        } catch (Exception e) {
                            //ignore the excpetion
                        }
                        if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
                            XSMessageFormatter xmft = new XSMessageFormatter();
                            fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
                        }
                    }
                    // the string we saw: starting from the first non-whitespace character.
                    String txt = new String(text.ch, i, text.length+text.offset-i);
                    // report an error
                    fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
                                               "s4s-elt-character",
                                               new Object[]{txt},
                                               XMLErrorReporter.SEVERITY_ERROR);
                    break;
                }
            }
            // don't call super.characters() when it's not within one of the 2
            // annotation elements: the traversers ignore them anyway. We can
            // save time/memory creating the text nodes.
        }
        // when it's not within either of the 2 elements, characters are allowed
        // and we need to call super.characters().
        else {
            super.characters(text, augs);
        }
    
protected org.w3c.dom.ElementcreateElementNode(com.sun.org.apache.xerces.internal.xni.QName element)

        // create an element containing line/column information
        return fDocumentImpl.createElementNS(element.uri, element.rawname,
                                             element.localpart,
                                             fLocator.getLineNumber(),
                                             fLocator.getColumnNumber());
    
public voidendElement(com.sun.org.apache.xerces.internal.xni.QName element, com.sun.org.apache.xerces.internal.xni.Augmentations augs)

        super.endElement(element, augs);
        // when we reach the endElement of xs:appinfo or xs:documentation,
        // change fAnnotationDepth to -1
        if (fAnnotationDepth == fDepth)
            fAnnotationDepth = -1;
        fDepth--;
    
public voidresetNodePool()
Resets the node pool.

        fNodePool.reset();
    
public voidstartDocument(com.sun.org.apache.xerces.internal.xni.XMLLocator locator, java.lang.String encoding, com.sun.org.apache.xerces.internal.xni.NamespaceContext namespaceContext, com.sun.org.apache.xerces.internal.xni.Augmentations augs)
The start of the document.

param
locator 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).
param
namespaceContext The namespace context in effect at the start of this document. This object represents the current context. Implementors of this class are responsible for copying the namespace bindings from the the current context (and its parent contexts) if that information is important.
param
augs Additional information that may include infoset augmentations
throws
XNIException Thrown by handler to signal an error.


        super.startDocument(locator, encoding, namespaceContext, augs);
        // get a handle to the document created
        fDocumentImpl = (DocumentImpl)super.fDocumentImpl;
        fDocumentImpl.fNodePool=fNodePool;
        fLocator = locator;

    
public voidstartElement(com.sun.org.apache.xerces.internal.xni.QName element, com.sun.org.apache.xerces.internal.xni.XMLAttributes attributes, com.sun.org.apache.xerces.internal.xni.Augmentations augs)


    // override startElement method to check whether it's one of
    // xs:appinfo or xs:documentation
           
          
        super.startElement(element, attributes, augs);
        fDepth++;
        // if it's not within either element, check whether it's one of them
        // if so, record the current depth, so that any element with larger
        // depth is allowed to have character data.
        if (fAnnotationDepth == -1) {
            if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA &&
                (element.localpart == SchemaSymbols.ELT_APPINFO ||
                 element.localpart == SchemaSymbols.ELT_DOCUMENTATION)) {
                fAnnotationDepth = fDepth;
            }
        }