FileDocCategorySizeDatePackage
XSComplexTypeDecl.javaAPI DocApache Xerces 3.0.126584Fri Sep 14 20:33:54 BST 2007org.apache.xerces.impl.xs

XSComplexTypeDecl

public class XSComplexTypeDecl extends Object implements TypeInfo, XSComplexTypeDefinition
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 573322 2007-09-06 16:48:47Z peterjm $

Fields Summary
String
fName
String
fTargetNamespace
XSTypeDefinition
fBaseType
short
fDerivedBy
short
fFinal
short
fBlock
short
fMiscFlags
XSAttributeGroupDecl
fAttrGrp
short
fContentType
org.apache.xerces.impl.dv.XSSimpleType
fXSSimpleType
XSParticleDecl
fParticle
org.apache.xerces.impl.xs.models.XSCMValidator
fCMValidator
org.apache.xerces.impl.xs.models.XSCMValidator
fUPACMValidator
org.apache.xerces.impl.xs.util.XSObjectListImpl
fAnnotations
static final int
DERIVATION_ANY
static final int
DERIVATION_RESTRICTION
static final int
DERIVATION_EXTENSION
static final int
DERIVATION_UNION
static final int
DERIVATION_LIST
private static final short
CT_IS_ABSTRACT
private static final short
CT_HAS_TYPE_ID
private static final short
CT_IS_ANONYMOUS
Constructors Summary
public XSComplexTypeDecl()

    
      
        // do-nothing constructor for now.
    
Methods Summary
voidappendTypeInfo(java.lang.StringBuffer str)

        String contentType[] = {"EMPTY", "SIMPLE", "ELEMENT", "MIXED"};
        String derivedBy[] = {"EMPTY", "EXTENSION", "RESTRICTION"};

        str.append("Complex type name='").append(fTargetNamespace).append(",").append(getTypeName()).append("', ");
        if (fBaseType != null) {
            str.append(" base type name='").append(fBaseType.getName()).append("', ");
        }
        str.append(" content type='").append(contentType[fContentType]).append("', ");
        str.append(" isAbstract='").append(getAbstract()).append("', ");
        str.append(" hasTypeId='").append(containsTypeID()).append("', ");
        str.append(" final='").append(fFinal).append("', ");
        str.append(" block='").append(fBlock).append("', ");
        if (fParticle != null) {
            str.append(" particle='").append(fParticle.toString()).append("', ");
        }
        str.append(" derivedBy='").append(derivedBy[fDerivedBy]).append("'. ");

    
public booleancontainsTypeID()


    // methods to get/set misc flag

        
        return((fMiscFlags & CT_HAS_TYPE_ID) != 0);
    
public booleanderivedFrom(java.lang.String ancestorNS, java.lang.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;
    
public booleanderivedFromType(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 booleangetAbstract()
{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.

        return((fMiscFlags & CT_IS_ABSTRACT) != 0);
    
public XSObjectListgetAnnotations()
Optional. Annotation.

        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
    
public booleangetAnonymous()
A boolean that specifies if the type definition is anonymous. Convenience attribute. This is a field is not part of XML Schema component model.

        return((fMiscFlags & CT_IS_ANONYMOUS) != 0);
    
public XSAttributeGroupDeclgetAttrGrp()

        return fAttrGrp;
    
public XSAttributeUsegetAttributeUse(java.lang.String namespace, java.lang.String name)

         return fAttrGrp.getAttributeUse(namespace, name);
    
public XSObjectListgetAttributeUses()
{attribute uses} A set of attribute uses.

        return fAttrGrp.getAttributeUses();
    
public XSWildcardgetAttributeWildcard()
{attribute wildcard} Optional. A wildcard.

        return fAttrGrp.getAttributeWildcard();
    
public XSTypeDefinitiongetBaseType()
{base type definition} Either a simple type definition or a complex type definition.

        return fBaseType;
    
public org.apache.xerces.impl.xs.models.XSCMValidatorgetContentModel(org.apache.xerces.impl.xs.models.CMBuilder cmBuilder)

        return getContentModel(cmBuilder, false);
    
public synchronized org.apache.xerces.impl.xs.models.XSCMValidatorgetContentModel(org.apache.xerces.impl.xs.models.CMBuilder cmBuilder, boolean forUPA)

        if (fCMValidator == null) {
            if (forUPA) {
                if (fUPACMValidator == null) {
                    fUPACMValidator = cmBuilder.getContentModel(this, true);

                    if (fUPACMValidator != null && !fUPACMValidator.isCompactedForUPA()) {
                        fCMValidator = fUPACMValidator;
                    }
                }
                return fUPACMValidator;
            }
            else {
                fCMValidator = cmBuilder.getContentModel(this, false);
            }
        }

        return fCMValidator;
    
public shortgetContentType()
{content type} One of empty, a simple type definition (see simpleType, or mixed, element-only (see cmParticle).

        return fContentType;
    
public shortgetDerivationMethod()
{derivation method} Either extension or restriction. The valid constant value for this XSConstants EXTENTION, RESTRICTION.

        return fDerivedBy;
    
public shortgetFinal()
{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;

        return fFinal;
    
public shortgetFinalSet()

        return fFinal;
    
public java.lang.StringgetName()
The name of this XSObject depending on the XSObject type.

        return getAnonymous() ? null : fName;
    
public java.lang.StringgetNamespace()
The namespace URI of this node, or null if it is unspecified. defines how a namespace URI is attached to schema components.

        return fTargetNamespace;
    
public XSNamespaceItemgetNamespaceItem()

see
org.apache.xerces.xs.XSObject#getNamespaceItem()

        // REVISIT: implement
		return null;
	
public XSParticlegetParticle()
A particle for mixed or element-only content model, otherwise null

        return fParticle;
    
public shortgetProhibitedSubstitutions()
{prohibited substitutions}

return
A bit flag corresponding to prohibited substitutions

        return fBlock;
    
public XSSimpleTypeDefinitiongetSimpleType()
A simple type definition corresponding to simple content model, otherwise null

        return fXSSimpleType;
    
public java.lang.StringgetTargetNamespace()

        return fTargetNamespace;
    
public shortgetType()
Get the type of the object, i.e ELEMENT_DECLARATION.

        return XSConstants.TYPE_DEFINITION;
    
public shortgetTypeCategory()

        return COMPLEX_TYPE;
    
public java.lang.StringgetTypeName()

        return fName;
    
public java.lang.StringgetTypeNamespace()

        return getNamespace();
    
public booleanisDOMDerivedFrom(java.lang.String ancestorNS, java.lang.String ancestorName, int derivationMethod)
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
derivationMethod The derivation method
return
boolean True if the ancestor type is derived from the reference type by the specifiied derivation method.

        // 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;
    
private booleanisDerivedByAny(java.lang.String ancestorNS, java.lang.String ancestorName, int derivationMethod, XSTypeDefinition type)
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

        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
            if (isDerivedByRestriction(ancestorNS, ancestorName,
                    derivationMethod, type)) {
                return true;
            } else if (!isDerivedByExtension(ancestorNS, ancestorName,
                    derivationMethod, type)) {
                return true;
            }
            oldType = type;
            type = type.getBaseType();
        }
        
        return derivedFrom;
    
private booleanisDerivedByExtension(java.lang.String ancestorNS, java.lang.String ancestorName, int derivationMethod, XSTypeDefinition type)
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

        
        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;
    
private booleanisDerivedByRestriction(java.lang.String ancestorNS, java.lang.String ancestorName, int derivationMethod, XSTypeDefinition type)
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

        
        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;
    
public booleanisDerivedFrom(java.lang.String typeNamespaceArg, java.lang.String typeNameArg, int derivationMethod)

        return isDOMDerivedFrom(typeNamespaceArg, typeNameArg, derivationMethod);
    
public booleanisFinal(short derivation)
{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 XSConstants).
return
True if derivation is in the final set, otherwise false.

        return (fFinal & derivation) != 0;
    
public booleanisProhibitedSubstitution(short prohibited)
{prohibited substitutions} A subset of {extension, restriction}.

param
prohibited extention or restriction constants (defined in XSConstants).
return
True if prohibited is a prohibited substitution, otherwise false.

        return (fBlock & prohibited) != 0;
    
public voidreset()

        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;
        fUPACMValidator = null;
        if(fAnnotations != null) {
            // help out the garbage collector
            fAnnotations.clear();
        }
        fAnnotations = null;
    
public voidsetContainsTypeID()

        fMiscFlags |= CT_HAS_TYPE_ID;
    
public voidsetIsAbstractType()

        fMiscFlags |= CT_IS_ABSTRACT;
    
public voidsetIsAnonymous()

        fMiscFlags |= CT_IS_ANONYMOUS;
    
public voidsetName(java.lang.String name)

        fName = name;
   
public voidsetValues(java.lang.String name, java.lang.String targetNamespace, XSTypeDefinition baseType, short derivedBy, short schemaFinal, short block, short contentType, boolean isAbstract, XSAttributeGroupDecl attrGrp, org.apache.xerces.impl.dv.XSSimpleType simpleType, XSParticleDecl particle, org.apache.xerces.impl.xs.util.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 java.lang.StringtoString()

        StringBuffer str = new StringBuffer();
        appendTypeInfo(str);
        return str.toString();