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

📄 xsdattributetraverser.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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 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.XSAnnotationImpl;import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeDecl;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.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 com.sun.org.apache.xerces.internal.xs.XSConstants;import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;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> * * @xerces.internal  * * @author Sandy Gao, IBM * @author Neeraj Bajaj, Sun Microsystems, inc. * @version $Id: XSDAttributeTraverser.java,v 1.2.6.1 2005/09/08 14:08:22 sunithareddy 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;            }        }                //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);                }            }        }                fAttrChecker.returnAttrArray(attrValues, schemaDoc);        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);        return attribute;            }        /**     * Traverse a globally declared attribute.     *     * @param  attrDecl     * @param  attrValues     * @param  schemaDoc     * @param  grammar     * @param  isGlobal     * @return the attribute declaration index     */    XSAttributeDecl traverseNamedAttr(Element attrDecl,            Object[] attrValues,            XSDocumentInfo schemaDoc,            SchemaGrammar grammar,            boolean isGlobal,            XSComplexTypeDecl enclosingCT) {                String  defaultAtt = (String) attrValues[XSAttributeChecker.ATTIDX_DEFAULT];

⌨️ 快捷键说明

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