xsdattributetraverser.java

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

JAVA
445
字号
/* * 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.InvalidDatatypeValueException;import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;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.XSAttributeDecl;import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;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.xs.XSConstants;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.util.DOMUtil;import com.sun.org.apache.xerces.internal.util.XMLSymbols;import com.sun.org.apache.xerces.internal.xni.QName;import org.w3c.dom.Element;/** * The attribute declaration schema component traverser. * * <attribute *   default = string *   fixed = string *   form = (qualified | unqualified) *   id = ID *   name = NCName *   ref = QName *   type = QName *   use = (optional | prohibited | required) : optional *   {any attributes with non-schema namespace . . .}> *   Content: (annotation?, (simpleType?)) * </attribute> * * @author Sandy Gao, IBM * @author Neeraj Bajaj, Sun Microsystems, inc. * @version $Id: XSDAttributeTraverser.java,v 1.27 2003/11/11 20:15:00 sandygao Exp $ */class XSDAttributeTraverser extends XSDAbstractTraverser {    public XSDAttributeTraverser (XSDHandler handler,                                  XSAttributeChecker gAttrCheck) {        super(handler, gAttrCheck);    }    protected XSAttributeUseImpl traverseLocal(Element attrDecl,                                               XSDocumentInfo schemaDoc,                                               SchemaGrammar grammar,                                               XSComplexTypeDecl enclosingCT) {        // General Attribute Checking        Object[] attrValues = fAttrChecker.checkAttributes(attrDecl, false, schemaDoc);        String defaultAtt = (String) attrValues[XSAttributeChecker.ATTIDX_DEFAULT];        String fixedAtt   = (String) attrValues[XSAttributeChecker.ATTIDX_FIXED];        String nameAtt    = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];        QName  refAtt     = (QName)  attrValues[XSAttributeChecker.ATTIDX_REF];        XInt   useAtt     = (XInt)   attrValues[XSAttributeChecker.ATTIDX_USE];        // get 'attribute declaration'        XSAttributeDecl attribute = null;        if (attrDecl.getAttributeNode(SchemaSymbols.ATT_REF) != null) {            if (refAtt != null) {                attribute = (XSAttributeDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ATTRIBUTE_TYPE, refAtt, attrDecl);                Element child = DOMUtil.getFirstChildElement(attrDecl);                if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {                    // REVISIT:  put this somewhere                    traverseAnnotationDecl(child, attrValues, false, schemaDoc);                    child = DOMUtil.getNextSiblingElement(child);                }                if (child != null) {                    reportSchemaError("src-attribute.3.2", new Object[]{refAtt.rawname}, child);                }                // for error reporting                nameAtt = refAtt.localpart;            } else {                attribute = null;            }        } else {            attribute = traverseNamedAttr(attrDecl, attrValues, schemaDoc, grammar, false, enclosingCT);        }        // get 'value constraint'        short consType = XSConstants.VC_NONE;        if (defaultAtt != null) {            consType = XSConstants.VC_DEFAULT;        } else if (fixedAtt != null) {            consType = XSConstants.VC_FIXED;            defaultAtt = fixedAtt;            fixedAtt = null;        }        XSAttributeUseImpl attrUse = null;        if (attribute != null) {            if (fSchemaHandler.fDeclPool !=null) {                attrUse = fSchemaHandler.fDeclPool.getAttributeUse();            } else {                attrUse = new XSAttributeUseImpl();            }            attrUse.fAttrDecl = attribute;            attrUse.fUse = useAtt.shortValue();            attrUse.fConstraintType = consType;            if (defaultAtt != null) {                attrUse.fDefault = new ValidatedInfo();                attrUse.fDefault.normalizedValue = defaultAtt;            }        }        fAttrChecker.returnAttrArray(attrValues, schemaDoc);        //src-attribute        // 1 default and fixed must not both be present.        if (defaultAtt != null && fixedAtt != null) {            reportSchemaError("src-attribute.1", new Object[]{nameAtt}, attrDecl);        }        // 2 If default and use are both present, use must have the actual value optional.        if (consType == XSConstants.VC_DEFAULT &&            useAtt != null && useAtt.intValue() != SchemaSymbols.USE_OPTIONAL) {            reportSchemaError("src-attribute.2", new Object[]{nameAtt}, attrDecl);        }        // a-props-correct        if (defaultAtt != null && attrUse != null) {            // 2 if there is a {value constraint}, the canonical lexical representation of its value must be valid with respect to the {type definition} as defined in String Valid (3.14.4).            fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport);            try {                checkDefaultValid(attrUse);            }            catch (InvalidDatatypeValueException ide) {                reportSchemaError (ide.getKey(), ide.getArgs(), attrDecl);                reportSchemaError ("a-props-correct.2", new Object[]{nameAtt, defaultAtt}, attrDecl);            }            // 3 If the {type definition} is or is derived from ID then there must not be a {value constraint}.            if (((XSSimpleType)attribute.getTypeDefinition()).isIDType() ) {                reportSchemaError ("a-props-correct.3", new Object[]{nameAtt}, attrDecl);            }            // check 3.5.6 constraint            // Attribute Use Correct            // 2 If the {attribute declaration} has a fixed {value constraint}, then if the attribute use itself has a {value constraint}, it must also be fixed and its value must match that of the {attribute declaration}'s {value constraint}.            if (attrUse.fAttrDecl.getConstraintType() == XSConstants.VC_FIXED &&                attrUse.fConstraintType != XSConstants.VC_NONE) {                if (attrUse.fConstraintType != XSConstants.VC_FIXED ||                    !attrUse.fAttrDecl.getValInfo().actualValue.equals(attrUse.fDefault.actualValue)) {                    reportSchemaError ("au-props-correct.2", new Object[]{nameAtt, attrUse.fAttrDecl.getValInfo().stringValue()}, attrDecl);                }            }        }        return attrUse;    }    protected XSAttributeDecl traverseGlobal(Element attrDecl,                                             XSDocumentInfo schemaDoc,                                             SchemaGrammar grammar) {        // General Attribute Checking        Object[] attrValues = fAttrChecker.checkAttributes(attrDecl, true, schemaDoc);        XSAttributeDecl attribute = traverseNamedAttr(attrDecl, attrValues, schemaDoc, grammar, true, null);        fAttrChecker.returnAttrArray(attrValues, schemaDoc);

⌨️ 快捷键说明

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