⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsdabstracttraverser.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xerces.internal.impl.xs.traversers;import java.util.Vector;import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;import com.sun.org.apache.xerces.internal.impl.dv.XSFacets;import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;import com.sun.org.apache.xerces.internal.impl.validation.ValidationState;import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeUseImpl;import com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl;import com.sun.org.apache.xerces.internal.xs.XSObjectList;import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;import com.sun.org.apache.xerces.internal.impl.xs.util.XInt;import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl;import com.sun.org.apache.xerces.internal.util.DOMUtil;import com.sun.org.apache.xerces.internal.util.NamespaceSupport;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.xni.QName;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.Text;/** * Class <code>XSDAbstractTraverser</code> serves as the base class for all * other <code>XSD???Traverser</code>s. It holds the common data and provide * a unified way to initialize these data. * * @xerces.internal  * * @author Elena Litani, IBM * @author Rahul Srivastava, Sun Microsystems Inc. * @author Neeraj Bajaj, Sun Microsystems Inc. * * @version $Id: XSDAbstractTraverser.java,v 1.2.6.1 2005/09/08 12:01:12 sunithareddy Exp $ */abstract class XSDAbstractTraverser {        protected static final String NO_NAME      = "(no name)";        // Flags for checkOccurrences to indicate any special    // restrictions on minOccurs and maxOccurs relating to "all".    //    NOT_ALL_CONTEXT    - not processing an <all>    //    PROCESSING_ALL_EL  - processing an <element> in an <all>    //    GROUP_REF_WITH_ALL - processing <group> reference that contained <all>    //    CHILD_OF_GROUP     - processing a child of a model group definition    //    PROCESSING_ALL_GP  - processing an <all> group itself        protected static final int NOT_ALL_CONTEXT    = 0;    protected static final int PROCESSING_ALL_EL  = 1;    protected static final int GROUP_REF_WITH_ALL = 2;    protected static final int CHILD_OF_GROUP     = 4;    protected static final int PROCESSING_ALL_GP  = 8;        //Shared data    protected XSDHandler            fSchemaHandler = null;    protected SymbolTable           fSymbolTable = null;    protected XSAttributeChecker    fAttrChecker = null;    protected boolean               fValidateAnnotations = false;        // used to validate default/fixed attribute values    ValidationState fValidationState = new ValidationState();        XSDAbstractTraverser (XSDHandler handler,            XSAttributeChecker attrChecker) {        fSchemaHandler = handler;        fAttrChecker = attrChecker;    }        void reset(SymbolTable symbolTable, boolean validateAnnotations) {        fSymbolTable = symbolTable;        fValidateAnnotations = validateAnnotations;        fValidationState.setExtraChecking(false);        fValidationState.setSymbolTable(symbolTable);    }        // traverse the annotation declaration    // REVISIT: how to pass the parentAttrs? as DOM attributes?    //          as name/value pairs (string)? in parsed form?    // @return XSAnnotationImpl object    XSAnnotationImpl traverseAnnotationDecl(Element annotationDecl, Object[] parentAttrs,            boolean isGlobal, XSDocumentInfo schemaDoc) {        // General Attribute Checking        Object[] attrValues = fAttrChecker.checkAttributes(annotationDecl, isGlobal, schemaDoc);        fAttrChecker.returnAttrArray(attrValues, schemaDoc);                String contents = null;        Element child = DOMUtil.getFirstChildElement(annotationDecl);        if (child != null) {            do {                String name = DOMUtil.getLocalName(child);                                // the only valid children of "annotation" are                // "appinfo" and "documentation"                if (!((name.equals(SchemaSymbols.ELT_APPINFO)) ||                        (name.equals(SchemaSymbols.ELT_DOCUMENTATION)))) {                    reportSchemaError("src-annotation", new Object[]{name}, child);                } else { // the annotation, as we currently know it, is a Text child                    Node textContent = child.getFirstChild();                    if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) {                        contents = ((Text)textContent).getData();                    }                }                                // General Attribute Checking                // There is no difference between global or local appinfo/documentation,                // so we assume it's always global.                attrValues = fAttrChecker.checkAttributes(child, true, schemaDoc);                fAttrChecker.returnAttrArray(attrValues, schemaDoc);                                child = DOMUtil.getNextSiblingElement(child);            }            while (child != null);        }        // REVISIT: When an annotation has no <documentation> or        // <appinfo> children the text child is stored on the first child of its        // parent. Only if the annotation is the first child will we find the        // text node there. See SchemaDOM. We need to store the string representation        // in a consistent place so it can be reliably retrieved, perhaps as         // user data. -- mrglavas        else {            Node textContent = annotationDecl.getFirstChild();            if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) {                contents = ((Text)textContent).getData();            }        }        // if contents was null, must have been some kind of error;        // nothing to contribute to PSVI        if (contents == null) return null;                // find the grammar; fSchemaHandler must be known!        SchemaGrammar grammar = fSchemaHandler.getGrammar(schemaDoc.fTargetNamespace);        // fish out local attributes passed from parent        Vector annotationLocalAttrs = (Vector)parentAttrs[XSAttributeChecker.ATTIDX_NONSCHEMA];        // optimize for case where there are no local attributes        if(annotationLocalAttrs != null && !annotationLocalAttrs.isEmpty()) {            StringBuffer localStrBuffer = new StringBuffer(64);            localStrBuffer.append(" ");            // Vector should contain rawname value pairs            int i = 0;            while (i < annotationLocalAttrs.size()) {                String rawname = (String)annotationLocalAttrs.elementAt(i++);                int colonIndex = rawname.indexOf(':');                String prefix, localpart;                if (colonIndex == -1) {                    prefix = "";                    localpart = rawname;                }                else {                    prefix = rawname.substring(0,colonIndex);                    localpart = rawname.substring(colonIndex+1);                }                String uri = schemaDoc.fNamespaceSupport.getURI(prefix.intern());                if (!annotationDecl.getAttributeNS(uri, localpart).equals("")) {                    i++; // skip the next value, too                    continue;                }                localStrBuffer.append(rawname)                .append("=\"");                String value = (String)annotationLocalAttrs.elementAt(i++);                // search for pesky "s and >s within attr value:                value = processAttValue(value);                localStrBuffer.append(value)                .append("\" ");            }            // and now splice it into place; immediately after the annotation token, for simplicity's sake            StringBuffer contentBuffer = new StringBuffer(contents.length() + localStrBuffer.length());            int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION);            // annotation must occur somewhere or we're in big trouble...            if(annotationTokenEnd == -1) return null;            annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length();            contentBuffer.append(contents.substring(0,annotationTokenEnd));            contentBuffer.append(localStrBuffer.toString());            contentBuffer.append(contents.substring(annotationTokenEnd, contents.length()));            final String annotation = contentBuffer.toString();            if (fValidateAnnotations) {                schemaDoc.addAnnotation(new XSAnnotationInfo(annotation, annotationDecl));            }            return new XSAnnotationImpl(annotation, grammar);        } else {            if (fValidateAnnotations) {                schemaDoc.addAnnotation(new XSAnnotationInfo(contents, annotationDecl));            }            return new XSAnnotationImpl(contents, grammar);        }            }        XSAnnotationImpl traverseSyntheticAnnotation(Element annotationParent, String initialContent,            Object[] parentAttrs, boolean isGlobal, XSDocumentInfo schemaDoc) {                String contents = initialContent;                // find the grammar; fSchemaHandler must be known!        SchemaGrammar grammar = fSchemaHandler.getGrammar(schemaDoc.fTargetNamespace);        // fish out local attributes passed from parent        Vector annotationLocalAttrs = (Vector)parentAttrs[XSAttributeChecker.ATTIDX_NONSCHEMA];        // optimize for case where there are no local attributes        if (annotationLocalAttrs != null && !annotationLocalAttrs.isEmpty()) {            StringBuffer localStrBuffer = new StringBuffer(64);            localStrBuffer.append(" ");            // Vector should contain rawname value pairs            int i = 0;            while (i < annotationLocalAttrs.size()) {                String rawname = (String)annotationLocalAttrs.elementAt(i++);                int colonIndex = rawname.indexOf(':');                String prefix, localpart;                if (colonIndex == -1) {                    prefix = "";                    localpart = rawname;                }                else {                    prefix = rawname.substring(0,colonIndex);                    localpart = rawname.substring(colonIndex+1);                }                String uri = schemaDoc.fNamespaceSupport.getURI(prefix.intern());                localStrBuffer.append(rawname)                .append("=\"");                String value = (String)annotationLocalAttrs.elementAt(i++);                // search for pesky "s and >s within attr value:                value = processAttValue(value);                localStrBuffer.append(value)                .append("\" ");            }            // and now splice it into place; immediately after the annotation token, for simplicity's sake            StringBuffer contentBuffer = new StringBuffer(contents.length() + localStrBuffer.length());            int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION);            // annotation must occur somewhere or we're in big trouble...            if(annotationTokenEnd == -1) return null;            annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length();            contentBuffer.append(contents.substring(0,annotationTokenEnd));            contentBuffer.append(localStrBuffer.toString());            contentBuffer.append(contents.substring(annotationTokenEnd, contents.length()));            final String annotation = contentBuffer.toString();            if (fValidateAnnotations) {                schemaDoc.addAnnotation(new XSAnnotationInfo(annotation, annotationParent));            }            return new XSAnnotationImpl(annotation, grammar);        } else {            if (fValidateAnnotations) {                schemaDoc.addAnnotation(new XSAnnotationInfo(contents, annotationParent));            }            return new XSAnnotationImpl(contents, grammar);        }    }        // the QName simple type used to resolve qnames    private static final XSSimpleType fQNameDV = (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME);

⌨️ 快捷键说明

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