xsdcomplextypetraverser.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,218 行 · 第 1/4 页
JAVA
1,218 行
/* * 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 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.XSFacets;import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;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.XSConstraints;import com.sun.org.apache.xerces.internal.impl.xs.XSModelGroupImpl;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.XSAttributeUse;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.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.xni.QName;import org.w3c.dom.Element;/** * A complex type definition schema component traverser. * * <complexType * abstract = boolean : false * block = (#all | List of (extension | restriction)) * final = (#all | List of (extension | restriction)) * id = ID * mixed = boolean : false * name = NCName * {any attributes with non-schema namespace . . .}> * Content: (annotation?, (simpleContent | complexContent | * ((group | all | choice | sequence)?, * ((attribute | attributeGroup)*, anyAttribute?)))) * </complexType> * @version $Id: XSDComplexTypeTraverser.java,v 1.41 2003/11/11 20:15:00 sandygao Exp $ */class XSDComplexTypeTraverser extends XSDAbstractParticleTraverser { // size of stack to hold globals: private final static int GLOBAL_NUM = 11; // globals for building XSComplexTypeDecls private String fName = null; private String fTargetNamespace = null; private short fDerivedBy = XSConstants.DERIVATION_RESTRICTION; private short fFinal = XSConstants.DERIVATION_NONE; private short fBlock = XSConstants.DERIVATION_NONE; private short fContentType = XSComplexTypeDecl.CONTENTTYPE_EMPTY; private XSTypeDefinition fBaseType = null; private XSAttributeGroupDecl fAttrGrp = null; private XSSimpleType fXSSimpleType = null; private XSParticleDecl fParticle = null; private boolean fIsAbstract = false; private XSComplexTypeDecl fComplexTypeDecl = null; private XSAnnotationImpl [] fAnnotations = null; private XSParticleDecl fEmptyParticle = null; // our own little stack to retain state when getGlobalDecls is called: private Object [] fGlobalStore = null; private int fGlobalStorePos = 0; XSDComplexTypeTraverser (XSDHandler handler, XSAttributeChecker gAttrCheck) { super(handler, gAttrCheck); } private static final boolean DEBUG=false; private SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance(); private class ComplexTypeRecoverableError extends Exception { Object[] errorSubstText=null; Element errorElem = null; ComplexTypeRecoverableError() { super(); } ComplexTypeRecoverableError(String msgKey, Object[] args, Element e) { super(msgKey); errorSubstText=args; errorElem = e; } } /** * Traverse local complexType declarations * * @param Element * @param XSDocumentInfo * @param SchemaGrammar * @return XSComplexTypeDecl */ XSComplexTypeDecl traverseLocal(Element complexTypeNode, XSDocumentInfo schemaDoc, SchemaGrammar grammar) { Object[] attrValues = fAttrChecker.checkAttributes(complexTypeNode, false, schemaDoc); String complexTypeName = genAnonTypeName(complexTypeNode); contentBackup(); XSComplexTypeDecl type = traverseComplexTypeDecl (complexTypeNode, complexTypeName, attrValues, schemaDoc, grammar); contentRestore(); // need to add the type to the grammar for later constraint checking grammar.addComplexTypeDecl(type, fSchemaHandler.element2Locator(complexTypeNode)); type.setIsAnonymous(); fAttrChecker.returnAttrArray(attrValues, schemaDoc); return type; } /** * Traverse global complexType declarations * * @param Element * @param XSDocumentInfo * @param SchemaGrammar * @return XSComplexTypeDecXSComplexTypeDecl */ XSComplexTypeDecl traverseGlobal (Element complexTypeNode, XSDocumentInfo schemaDoc, SchemaGrammar grammar) { Object[] attrValues = fAttrChecker.checkAttributes(complexTypeNode, true, schemaDoc); String complexTypeName = (String) attrValues[XSAttributeChecker.ATTIDX_NAME]; contentBackup(); XSComplexTypeDecl type = traverseComplexTypeDecl (complexTypeNode, complexTypeName, attrValues, schemaDoc, grammar); contentRestore(); if (complexTypeName == null) { reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_COMPLEXTYPE, SchemaSymbols.ATT_NAME}, complexTypeNode); } else { grammar.addGlobalTypeDecl(type); } // need to add the type to the grammar for later constraint checking grammar.addComplexTypeDecl(type, fSchemaHandler.element2Locator(complexTypeNode)); fAttrChecker.returnAttrArray(attrValues, schemaDoc); return type; } private XSComplexTypeDecl traverseComplexTypeDecl(Element complexTypeDecl, String complexTypeName, Object[] attrValues, XSDocumentInfo schemaDoc, SchemaGrammar grammar) { fComplexTypeDecl = new XSComplexTypeDecl(); fAttrGrp = new XSAttributeGroupDecl(); Boolean abstractAtt = (Boolean) attrValues[XSAttributeChecker.ATTIDX_ABSTRACT]; XInt blockAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_BLOCK]; Boolean mixedAtt = (Boolean) attrValues[XSAttributeChecker.ATTIDX_MIXED]; XInt finalAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_FINAL]; fName = complexTypeName; fComplexTypeDecl.setName(fName); fTargetNamespace = schemaDoc.fTargetNamespace; fBlock = blockAtt == null ? schemaDoc.fBlockDefault : blockAtt.shortValue(); fFinal = finalAtt == null ? schemaDoc.fFinalDefault : finalAtt.shortValue(); //discard valid Block/Final 'Default' values that are invalid for Block/Final fBlock &= (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION); fFinal &= (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION); if (abstractAtt != null && abstractAtt.booleanValue()) fIsAbstract = true; Element child = null; try { // --------------------------------------------------------------- // First, handle any ANNOTATION declaration and get next child // --------------------------------------------------------------- child = DOMUtil.getFirstChildElement(complexTypeDecl); if (child != null) { // traverse annotation if any if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { addAnnotation(traverseAnnotationDecl(child, attrValues, false, schemaDoc)); child = DOMUtil.getNextSiblingElement(child); } if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", new Object[]{fName,SchemaSymbols.ELT_ANNOTATION}, child); } } // --------------------------------------------------------------- // Process the content of the complex type definition // --------------------------------------------------------------- if (child==null) { // // EMPTY complexType with complexContent // // set the base to the anyType fBaseType = SchemaGrammar.fAnyType; processComplexContent(child, mixedAtt.booleanValue(), false, schemaDoc, grammar); } else if (DOMUtil.getLocalName(child).equals (SchemaSymbols.ELT_SIMPLECONTENT)) { // // SIMPLE CONTENT // traverseSimpleContent(child, schemaDoc, grammar); Element elemTmp = DOMUtil.getNextSiblingElement(child); if (elemTmp != null) { String siblingName = DOMUtil.getLocalName(elemTmp); throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", new Object[]{fName,siblingName}, elemTmp); } } else if (DOMUtil.getLocalName(child).equals (SchemaSymbols.ELT_COMPLEXCONTENT)) { traverseComplexContent(child, mixedAtt.booleanValue(), schemaDoc, grammar); Element elemTmp = DOMUtil.getNextSiblingElement(child); if (elemTmp != null) { String siblingName = DOMUtil.getLocalName(elemTmp); throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", new Object[]{fName,siblingName}, elemTmp); } } else { // // We must have .... // GROUP, ALL, SEQUENCE or CHOICE, followed by optional attributes // Note that it's possible that only attributes are specified. // // set the base to the anyType
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?