schemadomparser.java

来自「JAVA 所有包」· Java 代码 · 共 600 行 · 第 1/2 页

JAVA
600
字号
        //   schemaDOM.endAnnotationElement (if applicable)        //   schemaDOM.endElementElement        // Thus, we can see that the order of events isn't the same.  However, it doesn't        // seem to matter.  -- PJM        if (fAnnotationDepth == -1) {            // this is messed up, but a case to consider:            if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA &&                    element.localpart == SchemaSymbols.ELT_ANNOTATION) {                schemaDOM.startAnnotation(element, attributes, fNamespaceContext);            }        } else {            schemaDOM.startAnnotationElement(element, attributes);        }                schemaDOM.emptyElement(element, attributes,                 fLocator.getLineNumber(),                fLocator.getColumnNumber(),                fLocator.getCharacterOffset());                if (fAnnotationDepth == -1) {            // this is messed up, but a case to consider:            if (element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA &&                    element.localpart == SchemaSymbols.ELT_ANNOTATION) {                schemaDOM.endAnnotationElement(element, true);            }        } else {            schemaDOM.endAnnotationElement(element, false);        }     }            /**     * The end of an element.     *      * @param element The name of the element.     * @param augs    Additional information that may include infoset augmentations     *                     * @exception XNIException     *                   Thrown by handler to signal an error.     */    public void endElement(QName element, Augmentations augs) throws XNIException {                // when we reach the endElement of xs:appinfo or xs:documentation,        // change fInnerAnnotationDepth to -1        if(fAnnotationDepth > -1) {            if (fInnerAnnotationDepth == fDepth) {                fInnerAnnotationDepth = -1;                schemaDOM.endAnnotationElement(element, false);                schemaDOM.endElement();            } else if (fAnnotationDepth == fDepth) {                fAnnotationDepth = -1;                schemaDOM.endAnnotationElement(element, true);                schemaDOM.endElement();            } else { // inside a child of annotation                schemaDOM.endAnnotationElement(element, false);            }        } else { // not in an annotation at all            if(element.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA && fGenerateSyntheticAnnotation) {                boolean value = fHasNonSchemaAttributes.pop();                boolean sawann = fSawAnnotation.pop();                if (value && !sawann) {                    String schemaPrefix = fNamespaceContext.getPrefix(SchemaSymbols.URI_SCHEMAFORSCHEMA);                    QName annQName = new QName(schemaPrefix, SchemaSymbols.ELT_ANNOTATION, schemaPrefix + (schemaPrefix.length() == 0?"":":") + SchemaSymbols.ELT_ANNOTATION, SchemaSymbols.URI_SCHEMAFORSCHEMA);                    schemaDOM.startAnnotation(annQName, fEmptyAttr, fNamespaceContext);                    QName elemQName = new QName(schemaPrefix, SchemaSymbols.ELT_DOCUMENTATION, schemaPrefix + (schemaPrefix.length() == 0?"":":") + SchemaSymbols.ELT_DOCUMENTATION, SchemaSymbols.URI_SCHEMAFORSCHEMA);                    schemaDOM.startAnnotationElement(elemQName, fEmptyAttr);                    schemaDOM.characters(new XMLString("SYNTHETIC_ANNOTATION".toCharArray(), 0, 20 ));                         schemaDOM.endSyntheticAnnotationElement(elemQName, false);                    schemaDOM.endSyntheticAnnotationElement(annQName, true);                }            }            schemaDOM.endElement();        }        fDepth--;            }        /**     * @param attributes     * @return     */    private boolean hasNonSchemaAttributes(QName element, XMLAttributes attributes) {        final int length = attributes.getLength();        for (int i = 0; i < length; ++i) {            String uri = attributes.getURI(i);            if (uri != null && uri != SchemaSymbols.URI_SCHEMAFORSCHEMA &&                     uri != NamespaceContext.XMLNS_URI &&                    !(uri == NamespaceContext.XML_URI &&                             attributes.getQName(i) == SchemaSymbols.ATT_XML_LANG && element.localpart == SchemaSymbols.ELT_SCHEMA)) {                return true;            }        }        return false;    }        /**     * 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.     * @param augs   Additional information that may include infoset augmentations     *                    * @exception XNIException     *                   Thrown by handler to signal an error.     */    public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {        // unlikely to be called, but you never know...        if (fAnnotationDepth != -1 ) {            schemaDOM.characters(text);        }    }        /**     * The start of a CDATA section.     *      * @param augs   Additional information that may include infoset augmentations     *                    * @exception XNIException     *                   Thrown by handler to signal an error.     */    public void startCDATA(Augmentations augs) throws XNIException {        // only deal with CDATA boundaries within an annotation.        if (fAnnotationDepth != -1) {            schemaDOM.startAnnotationCDATA();        }    }        /**     * The end of a CDATA section.     *      * @param augs   Additional information that may include infoset augmentations     *                    * @exception XNIException     *                   Thrown by handler to signal an error.     */    public void endCDATA(Augmentations augs) throws XNIException {        // only deal with CDATA boundaries within an annotation.        if (fAnnotationDepth != -1) {            schemaDOM.endAnnotationCDATA();        }    }            //    // other methods    //        /**     * Returns the DOM document object.     */    public Document getDocument() {        return schemaDOM;    }        /**     * Delegates to SchemaParsingConfig.setFeature     * @param featureId     * @param state     */    public void setFeature(String featureId, boolean state){    	config.setFeature(featureId, state);    }        /**     * Delegates to SchemaParsingConfig.getFeature     * @param featureId     * @return boolean     */    public boolean getFeature(String featureId){        return config.getFeature(featureId);    }        /**     * Delegates to SchemaParsingConfig.setProperty.     * @param propertyId     * @param value     */    public void setProperty(String propertyId, Object value){        config.setProperty(propertyId, value);    }        /**     * Delegates to SchemaParsingConfig.getProperty.     * @param propertyId     * @return Object     */    public Object getProperty(String propertyId){        return config.getProperty(propertyId);    }        /**     * Delegates to SchemaParsingConfig.setEntityResolver.     * @param er XMLEntityResolver     */    public void setEntityResolver(XMLEntityResolver er) {    	config.setEntityResolver(er);    }        /**     * Delegates parsing to SchemaParsingConfig     *      * @param inputSource     * @throws IOException     */    public void parse(XMLInputSource inputSource) throws IOException {        config.parse(inputSource);    }        /**     * Gets the document from SchemaParsingConfig     * @return Document     */    public Document getDocument2() {    	return ((SchemaParsingConfig)config).getDocument();    }        /**     * Reset SchemaParsingConfig     */    public void reset() {    	((SchemaParsingConfig)config).reset();    }        /**     * ResetNodePool on SchemaParsingConfig     */    public void resetNodePool() {    	((SchemaParsingConfig)config).resetNodePool();    }        /**     * A simple boolean based stack.     *      * @xerces.internal     */    private static final class BooleanStack {        //        // Data        //        /** Stack depth. */        private int fDepth;        /** Stack data. */        private boolean[] fData;                //        // Constructor        //                public BooleanStack () {}        //        // Public methods        //        /** Returns the size of the stack. */        public int size() {            return fDepth;        }        /** Pushes a value onto the stack. */        public void push(boolean value) {            ensureCapacity(fDepth + 1);            fData[fDepth++] = value;        }        /** Pops a value off of the stack. */        public boolean pop() {            return fData[--fDepth];        }        /** Clears the stack. */        public void clear() {            fDepth = 0;        }        //        // Private methods        //        /** Ensures capacity. */        private void ensureCapacity(int size) {            if (fData == null) {                fData = new boolean[32];            }            else if (fData.length <= size) {                boolean[] newdata = new boolean[fData.length * 2];                System.arraycopy(fData, 0, newdata, 0, fData.length);                fData = newdata;            }        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?