xsdsimpletypetraverser.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 501 行 · 第 1/2 页

JAVA
501
字号
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001-2003 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) 2001, International * Business Machines, Inc., http://www.apache.org.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package com.sun.org.apache.xerces.internal.impl.xs.traversers;import java.util.Vector;import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeFacetException;import com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory;import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;import com.sun.org.apache.xerces.internal.impl.dv.xs.SchemaDVFactoryImpl;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.xs.XSConstants;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.XSObjectListImpl;import com.sun.org.apache.xerces.internal.impl.xs.util.XInt;import com.sun.org.apache.xerces.internal.util.DOMUtil;import com.sun.org.apache.xerces.internal.xni.QName;import org.w3c.dom.Element;/** * The simple type definition schema component traverser. * * <simpleType *   final = (#all | (list | union | restriction)) *   id = ID *   name = NCName *   {any attributes with non-schema namespace . . .}> *   Content: (annotation?, (restriction | list | union)) * </simpleType> * * <restriction *   base = QName *   id = ID *   {any attributes with non-schema namespace . . .}> *   Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)) * </restriction> * * <list *   id = ID *   itemType = QName *   {any attributes with non-schema namespace . . .}> *   Content: (annotation?, (simpleType?)) * </list> * * <union *   id = ID *   memberTypes = List of QName *   {any attributes with non-schema namespace . . .}> *   Content: (annotation?, (simpleType*)) * </union> * * @author Elena Litani, IBM * @author Neeraj Bajaj, Sun Microsystems, Inc. * @author Sandy Gao, IBM *  * @version $Id: XSDSimpleTypeTraverser.java,v 1.26 2003/11/11 20:15:00 sandygao Exp $ */class XSDSimpleTypeTraverser extends XSDAbstractTraverser {    // the factory used to query/create simple types    private final SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance();    // whether the type being parsed is a S4S built-in type.    private boolean fIsBuiltIn = false;    XSDSimpleTypeTraverser (XSDHandler handler,                            XSAttributeChecker gAttrCheck) {        super(handler, gAttrCheck);        if (schemaFactory instanceof SchemaDVFactoryImpl) {            ((SchemaDVFactoryImpl)schemaFactory).setDeclPool(handler.fDeclPool);        }    }    //return qualified name of simpleType or empty string if error occured    XSSimpleType traverseGlobal(Element elmNode,                                XSDocumentInfo schemaDoc,                                SchemaGrammar grammar) {        // General Attribute Checking        Object[] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc);        String nameAtt = (String)attrValues[XSAttributeChecker.ATTIDX_NAME];        XSSimpleType type = traverseSimpleTypeDecl(elmNode, attrValues, schemaDoc, grammar);        fAttrChecker.returnAttrArray(attrValues, schemaDoc);        // if it's a global type without a name, return null        if (nameAtt == null) {            reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, SchemaSymbols.ATT_NAME}, elmNode);            type = null;        }        // don't add global components without name to the grammar        if (type != null) {            grammar.addGlobalTypeDecl(type);        }        return type;    }    XSSimpleType traverseLocal(Element elmNode,                               XSDocumentInfo schemaDoc,                               SchemaGrammar grammar) {        // General Attribute Checking        Object[] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc);        XSSimpleType type = traverseSimpleTypeDecl (elmNode, attrValues, schemaDoc, grammar);        fAttrChecker.returnAttrArray(attrValues, schemaDoc);        return type;    }    private XSSimpleType traverseSimpleTypeDecl(Element simpleTypeDecl,                                                Object[] attrValues,                                                XSDocumentInfo schemaDoc,                                                SchemaGrammar grammar) {        // get name and final values        String name = (String)attrValues[XSAttributeChecker.ATTIDX_NAME];        XInt finalAttr = (XInt)attrValues[XSAttributeChecker.ATTIDX_FINAL];        int finalProperty = finalAttr == null ? schemaDoc.fFinalDefault : finalAttr.intValue();        // annotation?,(list|restriction|union)        Element child = DOMUtil.getFirstChildElement(simpleTypeDecl);        XSAnnotationImpl [] annotations = null;        if (child != null) {            // traverse annotation if any            if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {                XSAnnotationImpl annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);                if (annotation != null)                    annotations = new XSAnnotationImpl [] {annotation};                child = DOMUtil.getNextSiblingElement(child);            }        }        // (list|restriction|union)        if (child == null) {            reportSchemaError("s4s-elt-must-match.2", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, "(annotation?, (restriction | list | union))"}, simpleTypeDecl);            return errorType(name, schemaDoc.fTargetNamespace, XSConstants.DERIVATION_RESTRICTION);        }        // derivation type: restriction/list/union        String varietyProperty = DOMUtil.getLocalName(child);        short refType = XSConstants.DERIVATION_RESTRICTION;        boolean restriction = false, list = false, union = false;        if (varietyProperty.equals(SchemaSymbols.ELT_RESTRICTION)) {            refType = XSConstants.DERIVATION_RESTRICTION;            restriction = true;        }        else if (varietyProperty.equals(SchemaSymbols.ELT_LIST)) {            refType = XSConstants.DERIVATION_LIST;            list = true;        }        else if (varietyProperty.equals(SchemaSymbols.ELT_UNION)) {            refType = XSConstants.DERIVATION_UNION;            union = true;        }        else {            reportSchemaError("s4s-elt-must-match.1", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, "(annotation?, (restriction | list | union))", varietyProperty}, simpleTypeDecl);            return errorType(name, schemaDoc.fTargetNamespace, XSConstants.DERIVATION_RESTRICTION);        }        // nothing should follow this element        Element nextChild = DOMUtil.getNextSiblingElement(child);        if (nextChild != null) {            reportSchemaError("s4s-elt-must-match.1", new Object[]{SchemaSymbols.ELT_SIMPLETYPE, "(annotation?, (restriction | list | union))", DOMUtil.getLocalName(nextChild)}, nextChild);        }                // General Attribute Checking: get base/item/member types        Object[] contentAttrs = fAttrChecker.checkAttributes(child, false, schemaDoc);        QName baseTypeName = (QName)contentAttrs[restriction ?                                                 XSAttributeChecker.ATTIDX_BASE :                                                 XSAttributeChecker.ATTIDX_ITEMTYPE];        Vector memberTypes = (Vector)contentAttrs[XSAttributeChecker.ATTIDX_MEMBERTYPES];        //content = {annotation?,simpleType?...}        Element content = DOMUtil.getFirstChildElement(child);        //check content (annotation?, ...)        if (content != null) {            // traverse annotation if any            if (DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {                XSAnnotationImpl annotation = traverseAnnotationDecl(content, contentAttrs, false, schemaDoc);                if(annotation != null ) {                    if(annotations == null)                         annotations = new XSAnnotationImpl [] {annotation};                    else {                        XSAnnotationImpl [] tempArray = new XSAnnotationImpl[2];                        tempArray[0] = annotations[0];                        annotations = tempArray;                        annotations[1] = annotation;                    }                }                content = DOMUtil.getNextSiblingElement(content);            }

⌨️ 快捷键说明

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