xscomplextypedecl.java

来自「JAVA 所有包」· Java 代码 · 共 695 行 · 第 1/2 页

JAVA
695
字号
/* * Copyright 2001-2005 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;import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;import com.sun.org.apache.xerces.internal.xs.*;import com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator;import com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder;import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl;import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl;import org.w3c.dom.TypeInfo;/** * The XML representation for a complexType * schema component is a <complexType> element information item * * @xerces.internal  * * @author Elena Litani, IBM * @author Sandy Gao, IBM * @version $Id: XSComplexTypeDecl.java,v 1.2.6.1 2005/09/09 07:30:55 sunithareddy Exp $ */public class XSComplexTypeDecl implements XSComplexTypeDefinition, TypeInfo {    // name of the complexType    String fName = null;    // target namespace of the complexType    String fTargetNamespace = null;    // base type of the complexType    XSTypeDefinition fBaseType = null;    // derivation method of the complexType    short fDerivedBy = XSConstants.DERIVATION_RESTRICTION;    // final set of the complexType    short fFinal = XSConstants.DERIVATION_NONE;    // block set (prohibited substitution) of the complexType    short fBlock = XSConstants.DERIVATION_NONE;    // flags: whether is abstract; whether contains ID type;    //        whether it's an anonymous tpye    short fMiscFlags = 0;    // the attribute group that holds the attribute uses and attribute wildcard    XSAttributeGroupDecl fAttrGrp = null;    // the content type of the complexType    short fContentType = CONTENTTYPE_EMPTY;    // if the content type is simple, then the corresponding simpleType    XSSimpleType fXSSimpleType = null;    // if the content type is element or mixed, the particle    XSParticleDecl fParticle = null;    // if there is a particle, the content model corresponding to that particle    XSCMValidator fCMValidator = null;    // list of annotations affiliated with this type    XSObjectListImpl fAnnotations = null;    // DOM Level 3 TypeInfo Derivation Method constants    static final int DERIVATION_ANY = 0;    static final int DERIVATION_RESTRICTION = 1;    static final int DERIVATION_EXTENSION = 2;    static final int DERIVATION_UNION = 4;    static final int DERIVATION_LIST = 8;        public XSComplexTypeDecl() {        // do-nothing constructor for now.    }    public void setValues(String name, String targetNamespace,            XSTypeDefinition baseType, short derivedBy, short schemaFinal,             short block, short contentType,            boolean isAbstract, XSAttributeGroupDecl attrGrp,             XSSimpleType simpleType, XSParticleDecl particle,            XSObjectListImpl annotations) {        fTargetNamespace = targetNamespace;        fBaseType = baseType;        fDerivedBy = derivedBy;        fFinal = schemaFinal;        fBlock = block;        fContentType = contentType;        if(isAbstract)            fMiscFlags |= CT_IS_ABSTRACT;        fAttrGrp = attrGrp;        fXSSimpleType = simpleType;        fParticle = particle;        fAnnotations = annotations;   }   public void setName(String name) {        fName = name;   }    public short getTypeCategory() {        return COMPLEX_TYPE;    }    public String getTypeName() {        return fName;    }    public short getFinalSet(){        return fFinal;    }    public String getTargetNamespace(){        return fTargetNamespace;    }    // flags for the misc flag    private static final short CT_IS_ABSTRACT = 1;    private static final short CT_HAS_TYPE_ID = 2;    private static final short CT_IS_ANONYMOUS = 4;    // methods to get/set misc flag    public boolean containsTypeID () {        return((fMiscFlags & CT_HAS_TYPE_ID) != 0);    }    public void setIsAbstractType() {        fMiscFlags |= CT_IS_ABSTRACT;    }    public void setContainsTypeID() {        fMiscFlags |= CT_HAS_TYPE_ID;    }    public void setIsAnonymous() {        fMiscFlags |= CT_IS_ANONYMOUS;    }    public synchronized XSCMValidator getContentModel(CMBuilder cmBuilder) {        if (fCMValidator == null)            fCMValidator = cmBuilder.getContentModel(this);        return fCMValidator;    }    // some utility methods:    // return the attribute group for this complex type    public XSAttributeGroupDecl getAttrGrp() {        return fAttrGrp;    }    public String toString() {        StringBuffer str = new StringBuffer();        appendTypeInfo(str);        return str.toString();    }    void appendTypeInfo(StringBuffer str) {        String contentType[] = {"EMPTY", "SIMPLE", "ELEMENT", "MIXED"};        String derivedBy[] = {"EMPTY", "EXTENSION", "RESTRICTION"};        str.append("Complex type name='" + fTargetNamespace + "," + getTypeName() + "', ");        if (fBaseType != null)            str.append(" base type name='" + fBaseType.getName() + "', ");        str.append(" content type='" + contentType[fContentType] + "', ");        str.append(" isAbstract='" + getAbstract() + "', ");        str.append(" hasTypeId='" + containsTypeID() + "', ");        str.append(" final='" + fFinal + "', ");        str.append(" block='" + fBlock + "', ");        if (fParticle != null)            str.append(" particle='" + fParticle.toString() + "', ");        str.append(" derivedBy='" + derivedBy[fDerivedBy] + "'. ");    }    public boolean derivedFromType(XSTypeDefinition ancestor, short derivationMethod) {        // ancestor is null, retur false        if (ancestor == null)            return false;        // ancestor is anyType, return true        if (ancestor == SchemaGrammar.fAnyType)            return true;        // recursively get base, and compare it with ancestor        XSTypeDefinition type = this;        while (type != ancestor &&                     // compare with ancestor               type != SchemaGrammar.fAnySimpleType &&  // reached anySimpleType               type != SchemaGrammar.fAnyType) {        // reached anyType            type = type.getBaseType();        }        return type == ancestor;    }    public boolean derivedFrom(String ancestorNS, String ancestorName, short derivationMethod) {        // ancestor is null, retur false        if (ancestorName == null)            return false;        // ancestor is anyType, return true        if (ancestorNS != null &&            ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) &&            ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) {            return true;        }        // recursively get base, and compare it with ancestor        XSTypeDefinition type = this;        while (!(ancestorName.equals(type.getName()) &&                 ((ancestorNS == null && type.getNamespace() == null) ||                  (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) &&   // compare with ancestor               type != SchemaGrammar.fAnySimpleType &&  // reached anySimpleType               type != SchemaGrammar.fAnyType) {        // reached anyType            type = (XSTypeDefinition)type.getBaseType();        }        return type != SchemaGrammar.fAnySimpleType &&        type != SchemaGrammar.fAnyType;    }    /**     * Checks if a type is derived from another given the the name, namespace     * and derivation method. See:     * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom     *      * @param ancestorNS     *            The namspace of the ancestor type declaration     * @param ancestorName     *            The name of the ancestor type declaration     * @param derivation     *            The derivation method     *      * @return boolean True if the ancestor type is derived from the reference     *         type by the specifiied derivation method.     */    public boolean isDOMDerivedFrom(String ancestorNS, String ancestorName,            int derivationMethod) {        // ancestor is null, retur false        if (ancestorName == null)            return false;                // ancestor is anyType, return true        if (ancestorNS != null                && ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)                && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)                && (derivationMethod == DERIVATION_RESTRICTION                 && derivationMethod == DERIVATION_EXTENSION)) {            return true;        }                // restriction        if ((derivationMethod & DERIVATION_RESTRICTION) != 0) {            if (isDerivedByRestriction(ancestorNS, ancestorName,                    derivationMethod, this)) {                return true;            }        }                // extension        if ((derivationMethod & DERIVATION_EXTENSION) != 0) {            if (isDerivedByExtension(ancestorNS, ancestorName,                    derivationMethod, this)) {                return true;            }        }                // list or union        if ((((derivationMethod & DERIVATION_LIST) != 0) || ((derivationMethod & DERIVATION_UNION) != 0))                && ((derivationMethod & DERIVATION_RESTRICTION) == 0)                && ((derivationMethod & DERIVATION_EXTENSION) == 0)) {            if (ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)                    && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) {                ancestorName = SchemaSymbols.ATTVAL_ANYSIMPLETYPE;            }            if(!(fName.equals(SchemaSymbols.ATTVAL_ANYTYPE)                             && fTargetNamespace.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA))){                if (fBaseType != null && fBaseType instanceof XSSimpleTypeDecl) {                                        return ((XSSimpleTypeDecl) fBaseType).isDOMDerivedFrom(ancestorNS,                            ancestorName, derivationMethod);                } else if (fBaseType != null                        && fBaseType instanceof XSComplexTypeDecl) {                    return ((XSComplexTypeDecl) fBaseType).isDOMDerivedFrom(                            ancestorNS, ancestorName, derivationMethod);                }            }        }                // If the value of the parameter is 0 i.e. no bit (corresponding to        // restriction, list, extension or union) is set to 1 for the         // derivationMethod parameter.           if (((derivationMethod  & DERIVATION_EXTENSION) == 0)                && (((derivationMethod & DERIVATION_RESTRICTION) == 0)                        && ((derivationMethod & DERIVATION_LIST) == 0)                         && ((derivationMethod & DERIVATION_UNION) == 0))) {            return isDerivedByAny(ancestorNS, ancestorName, derivationMethod, this);        }        return false;    }        /**     * Checks if a type is derived from another by any combination of     * restriction, list ir union. See:     * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom     *      * @param ancestorNS     *            The namspace of the ancestor type declaration     * @param ancestorName     *            The name of the ancestor type declaration     * @param derivationMethod     *            A short indication the method of derivation     * @param type     *            The reference type definition     *      * @return boolean True if the type is derived by any method for the     *         reference type     */    private boolean isDerivedByAny(String ancestorNS, String ancestorName,            int derivationMethod, XSTypeDefinition type) {        XSTypeDefinition oldType = null;        boolean derivedFrom = false;        while (type != null && type != oldType) {                        // If the ancestor type is reached or is the same as this type.            if ((ancestorName.equals(type.getName()))                    && ((ancestorNS == null && type.getNamespace() == null)                         || (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) {                derivedFrom = true;                break;            }                        // Check if this type is derived from the base by restriction or            // extension

⌨️ 快捷键说明

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