xscomplextypedecl.java

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

JAVA
695
字号
            if (isDerivedByRestriction(ancestorNS, ancestorName,                    derivationMethod, type)) {                return true;            } else if (!isDerivedByExtension(ancestorNS, ancestorName,                    derivationMethod, type)) {                return true;            }            oldType = type;            type = type.getBaseType();        }                return derivedFrom;    }        /**     * Checks if a type is derived from another by restriction. 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 restriciton for the     *         reference type     */    private boolean isDerivedByRestriction(String ancestorNS,            String ancestorName, int derivationMethod, XSTypeDefinition type) {                XSTypeDefinition oldType = null;        while (type != null && type != oldType) {                        // ancestor is anySimpleType, return false            if (ancestorNS != null                    && ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)                    && ancestorName.equals(SchemaSymbols.ATTVAL_ANYSIMPLETYPE)) {                return false;            }                        // if the name and namespace of this type is the same as the            // ancestor return true            if ((ancestorName.equals(type.getName()))                    && (ancestorNS != null && ancestorNS.equals(type.getNamespace()))                             || ((type.getNamespace() == null && ancestorNS == null))) {                                return true;            }                        // If the base type is a complexType with simpleContent            if (type instanceof XSSimpleTypeDecl) {                if (ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)                        && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) {                    ancestorName = SchemaSymbols.ATTVAL_ANYSIMPLETYPE;                }                return ((XSSimpleTypeDecl) type).isDOMDerivedFrom(ancestorNS,                        ancestorName, derivationMethod);            } else {                // If the base type is a complex type                // Every derivation step till the base type should be                // restriction. If not return false                if (((XSComplexTypeDecl) type).getDerivationMethod() != XSConstants.DERIVATION_RESTRICTION) {                    return false;                }            }            oldType = type;            type = type.getBaseType();                    }                return false;    }        /**     * Checks if a type is derived from another by extension. 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 extension for the     *         reference type     */    private boolean isDerivedByExtension(String ancestorNS,            String ancestorName, int derivationMethod, XSTypeDefinition type) {                boolean extension = false;        XSTypeDefinition oldType = null;        while (type != null && type != oldType) {            // If ancestor is anySimpleType return false.            if (ancestorNS != null                    && ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)                    && ancestorName.equals(SchemaSymbols.ATTVAL_ANYSIMPLETYPE)                    && SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(type.getNamespace())                            && SchemaSymbols.ATTVAL_ANYTYPE.equals(type.getName())) {                break;            }                        if ((ancestorName.equals(type.getName()))                    && ((ancestorNS == null && type.getNamespace() == null)                         || (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) {                // returns true if atleast one derivation step was extension                return extension;            }                        // If the base type is a complexType with simpleContent            if (type instanceof XSSimpleTypeDecl) {                if (ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)                        && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) {                    ancestorName = SchemaSymbols.ATTVAL_ANYSIMPLETYPE;                }                                // derivationMethod extension will always return false for a                // simpleType,                // we treat it like a restriction                if ((derivationMethod & DERIVATION_EXTENSION) != 0) {                    return extension                    & ((XSSimpleTypeDecl) type).isDOMDerivedFrom(                            ancestorNS, ancestorName,                            (derivationMethod & DERIVATION_RESTRICTION));                } else {                    return extension                    & ((XSSimpleTypeDecl) type).isDOMDerivedFrom(                            ancestorNS, ancestorName, derivationMethod);                }                            } else {                // If the base type is a complex type                // At least one derivation step upto the ancestor type should be                // extension.                if (((XSComplexTypeDecl) type).getDerivationMethod() == XSConstants.DERIVATION_EXTENSION) {                    extension = extension | true;                }            }            oldType = type;            type = type.getBaseType();        }                return false;    }                public void reset(){        fName = null;        fTargetNamespace = null;        fBaseType = null;        fDerivedBy = XSConstants.DERIVATION_RESTRICTION;        fFinal = XSConstants.DERIVATION_NONE;        fBlock = XSConstants.DERIVATION_NONE;        fMiscFlags = 0;        // reset attribute group        fAttrGrp.reset();        fContentType = CONTENTTYPE_EMPTY;        fXSSimpleType = null;        fParticle = null;        fCMValidator = null;        if(fAnnotations != null) {            // help out the garbage collector            fAnnotations.clear();        }        fAnnotations = null;    }    /**     * Get the type of the object, i.e ELEMENT_DECLARATION.     */    public short getType() {        return XSConstants.TYPE_DEFINITION;    }    /**     * The <code>name</code> of this <code>XSObject</code> depending on the     * <code>XSObject</code> type.     */    public String getName() {        return getAnonymous() ? null : fName;    }    /**     * A boolean that specifies if the type definition is anonymous.     * Convenience attribute. This is a field is not part of     * XML Schema component model.     */    public boolean getAnonymous() {        return((fMiscFlags & CT_IS_ANONYMOUS) != 0);    }    /**     * The namespace URI of this node, or <code>null</code> if it is     * unspecified.  defines how a namespace URI is attached to schema     * components.     */    public String getNamespace() {        return fTargetNamespace;    }    /**     * {base type definition} Either a simple type definition or a complex     * type definition.     */    public XSTypeDefinition getBaseType() {        return fBaseType;    }    /**     * {derivation method} Either extension or restriction. The valid constant     * value for this <code>XSConstants</code> EXTENTION, RESTRICTION.     */    public short getDerivationMethod() {        return fDerivedBy;    }    /**     * {final} For complex type definition it is a subset of {extension,     * restriction}. For simple type definition it is a subset of     * {extension, list, restriction, union}.     * @param derivation  Extension, restriction, list, union constants     *   (defined in <code>XSConstants</code>).     * @return True if derivation is in the final set, otherwise false.     */    public boolean isFinal(short derivation) {        return (fFinal & derivation) != 0;    }    /**     * {final} For complex type definition it is a subset of {extension, restriction}.     *     * @return A bit flag that represents:     *         {extension, restriction) or none for complexTypes;     *         {extension, list, restriction, union} or none for simpleTypes;     */    public short getFinal() {        return fFinal;    }    /**     * {abstract} A boolean. Complex types for which {abstract} is true must     * not be used as the {type definition} for the validation of element     * information items.     */    public boolean getAbstract() {        return((fMiscFlags & CT_IS_ABSTRACT) != 0);    }    /**     *  {attribute uses} A set of attribute uses.     */    public XSObjectList getAttributeUses() {        return fAttrGrp.getAttributeUses();    }    /**     * {attribute wildcard} Optional. A wildcard.     */    public XSWildcard getAttributeWildcard() {        return fAttrGrp.getAttributeWildcard();    }    /**     * {content type} One of empty, a simple type definition (see     * <code>simpleType</code>, or mixed, element-only (see     * <code>cmParticle</code>).     */    public short getContentType() {        return fContentType;    }    /**     * A simple type definition corresponding to simple content model,     * otherwise <code>null</code>     */    public XSSimpleTypeDefinition getSimpleType() {        return fXSSimpleType;    }    /**     * A particle for mixed or element-only content model, otherwise     * <code>null</code>     */    public XSParticle getParticle() {        return fParticle;    }    /**     * {prohibited substitutions} A subset of {extension, restriction}.     * @param prohibited  extention or restriction constants (defined in     *   <code>XSConstants</code>).     * @return True if prohibited is a prohibited substitution, otherwise     *   false.     */    public boolean isProhibitedSubstitution(short prohibited) {        return (fBlock & prohibited) != 0;    }    /**     * {prohibited substitutions}     *     * @return A bit flag corresponding to prohibited substitutions     */    public short getProhibitedSubstitutions() {        return fBlock;    }    /**     * Optional. Annotation.     */    public XSObjectList getAnnotations() {        return fAnnotations;    }    	/**	 * @see com.sun.org.apache.xerces.internal.xs.XSObject#getNamespaceItem()	 */	public XSNamespaceItem getNamespaceItem() {        // REVISIT: implement		return null;	}    /* (non-Javadoc)     * @see com.sun.org.apache.xerces.internal.xs.XSComplexTypeDefinition#getAttributeUse(java.lang.String, java.lang.String)     */    public XSAttributeUse getAttributeUse(String namespace, String name) {         return fAttrGrp.getAttributeUse(namespace, name);    }    public String getTypeNamespace() {        return getNamespace();    }    public boolean isDerivedFrom(String typeNamespaceArg, String typeNameArg, int derivationMethod) {        return isDOMDerivedFrom(typeNamespaceArg, typeNameArg, derivationMethod);    }} // class XSComplexTypeDecl

⌨️ 快捷键说明

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