Free Trial - Stylus Studio, The World's Best XML IDE!


com.saxonica.schema
Class ElementDecl

java.lang.Object
  |
  +--com.saxonica.schema.SchemaElement
        |
        +--com.saxonica.schema.AbstractParticle
              |
              +--com.saxonica.schema.ElementDecl
All Implemented Interfaces:
Particle, SchemaComponent, SchemaDeclaration, java.io.Serializable, javax.xml.transform.SourceLocator, Term

public class ElementDecl
extends AbstractParticle
implements SchemaComponent, Term

The object represents an element declaration in the schema. It may be a global element declaration, a local element declaration, or a reference to an element declaration (xs:element with a ref attribute)

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.saxonica.schema.AbstractParticle
UNBOUNDED
 
Fields inherited from class com.saxonica.schema.SchemaElement
ANNOTATION, ANYTYPE, APPINFO, ATTRIBUTE, ATTRIBUTE_GROUP, COMPLEX_CONTENT, COMPLEX_TYPE, COMPOSITOR, DOCUMENTATION, ELEMENT, FACET, GROUP, IDENTITY_FIELD, IDENTITY_SELECTOR, KEY, KEYREF, LIST, REDEFINE, SCHEMA, SIMPLE_CONTENT, SIMPLE_TYPE, UNION, UNIQUE, UNKNOWN, WILDCARD_ATTRIBUTE, WILDCARD_ELEMENT
 
Constructor Summary
ElementDecl(Schema schema, javax.xml.transform.SourceLocator locator)
          Creates a new element declaration
 
Method Summary
 void addIdentityConstraint(IdentityConstraint constraint)
          Adds the given IdentityConstraint to this element definition.
 void addSubstitutionGroupMember(ElementDecl member)
          Add a member of the substitution group that has this element as its head.
 boolean allowsDerivation(int derivation)
          Determines whether derivation (of a particular kind) from this type is allowed, based on the "final" property
 void compile(Schema schema, UserComplexType subjectType)
          Compile this local element declaration, considered as a particle of some complex type, by compiling its own complex type definition.
 boolean fixup(Schema schema)
          Fix up references.
protected  void fixupSubstitutionGroup(NamePool pool)
          Fix up the reference to the head of the substitition group
 int getBlock()
          Returns the value of the 'block' attribute for this element
 ValidationContext getContainedValidationContext()
          Get the validation context for validating the children of this element.
 java.lang.String getDefaultValue()
          Returns the default value defined for this element definition.
 int getFingerprint()
          Get the fingerprint of the name of this element declation in the namePool
 java.lang.String getFixedValue()
          Returns the 'fixed' value defined for this element declaration.
 java.lang.String getForm()
          Returns the 'form' for this element definition.
 java.lang.String getId()
          Returns the 'id' value for for this element definition.
 java.util.Iterator getIdentityConstraints()
          Returns an Iterator over the identity constrains defined within this element definition.
 java.lang.String getLocalName()
          Returns the local name of this Element declaration.
 java.lang.String getName(boolean ignoreRef)
          Returns the name of this Element declaration.
 ElementDecl getReference()
          If this is an element reference, returns the ElementDecl that this element definition references.
 Schema getSchema()
          Returns the Schema to which this element declaration belongs.
 short getStructureType()
          Returns the type of this SchemaElement
 int getSubstitutionGroupHead()
          Returns the head of the substitutionGroup for this element declaration, or -1 if there is none.
 java.util.Set getSubstitutionGroupMembers()
          Get the known members of the substitution group of this element, as a Set containing the ElementDecl objects.
 SchemaType getType()
          Returns the Schema Type (ComplexType or SimpleType) of this Element Declaration.
 int getTypeFingerprint()
          Get the namepool fingerprint of the name of the element's type.
 boolean isAbstract()
          Returns true if this element definition is abstract
 boolean isEmptiable()
          Determine if this particle can be empty
 boolean isNillable()
          Determine whether or not instances of this element definition permit xsi:nil to be set to "yes".
 boolean isReference()
          Determine whether this ElementDecl represents an element reference, that is, an xs:element element with a 'ref' attribute.
 java.util.Iterator iterateSubstitutionGroup()
          Iterate over all the elements contained in the substitution group of which this element is the head.
 void registerComplexTypeUsingThisElement(UserComplexType type)
          Register a complex type that contains this element as a particle.
 void setAbstract(boolean isAbstract)
          Sets whether or not this element definition is abstract.
 void setBlock(int block)
          Sets the value of the 'block' attribute for this element For internal use only.
 void setDefaultValue(java.lang.String value)
          Sets the 'default' value for this element declaration.
 void setFinalProhibitions(int finalValue)
          Sets the value of the 'final' property, indicating which types of derivation are not allowed.
 void setFingerprint(int fingerprint)
          Set the fingerprint of the name of this element declaration in the namePool
 void setFixedValue(java.lang.String value)
          Sets the fixed value for this element definition.
 void setForm(java.lang.String form)
          Sets the 'form' for this element declaration.
 void setId(java.lang.String id)
          Sets the id for this element definition.
 void setName(java.lang.String name)
          Sets the name of the element that this Element definition defines.
 void setNillable(boolean nillable)
          Sets whether or not instances of this element definition may set xsi:nil='true'.
 void setReference(java.lang.String reference)
          Sets the value of the 'ref' attribute for this element reference.
 void setSubstitutionGroupHead(int substitutionGroupHead)
          Sets the fingerprint of the name of the head of the substitutionGroup for this element definition.
 void setType(SchemaType type)
          Sets the schema type for this element declaration.
 void setTypeFingerprint(int fingerprint)
          Set the namepool fingerprint of the name of the element's type.
 boolean validate(Schema schema)
          Check the validity (consistency) of this element definition.
 
Methods inherited from class com.saxonica.schema.AbstractParticle
getMaxOccurs, getMinOccurs, getTerm, setMaxOccurs, setMinOccurs
 
Methods inherited from class com.saxonica.schema.SchemaElement
getColumnNumber, getLineNumber, getPublicId, getSystemId, setLocator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementDecl

public ElementDecl(Schema schema,
                   javax.xml.transform.SourceLocator locator)
Creates a new element declaration

Parameters:
schema - the XML Schema to which this element declaration belongs
locator - identifies the location of the element declaration in the source schema
Method Detail

addIdentityConstraint

public void addIdentityConstraint(IdentityConstraint constraint)
Adds the given IdentityConstraint to this element definition. For internal use only.

Parameters:
constraint - the IdentityConstraint to add.

getBlock

public int getBlock()
Returns the value of the 'block' attribute for this element

Returns:
the value of the block attribute, as a bit-significant integer using constants such as SchemaType.DERIVE_BY_SUBSTITUTION, indicating which kinds of derivation from this element declaration are blocked.

getDefaultValue

public java.lang.String getDefaultValue()
Returns the default value defined for this element definition.

Returns:
the default value of this element definition, or null if no default was specified.

allowsDerivation

public boolean allowsDerivation(int derivation)
Determines whether derivation (of a particular kind) from this type is allowed, based on the "final" property

Parameters:
derivation - the kind of derivation, e.g. SchemaType.DERIVE_BY_LIST
Returns:
true if this kind of derivation is allowed

getFixedValue

public java.lang.String getFixedValue()
Returns the 'fixed' value defined for this element declaration.

Returns:
the fixed value for this element declaration, or null if no fixed value was specified.

getForm

public java.lang.String getForm()
Returns the 'form' for this element definition. The 'form' species whether or not names are qualified or unqualified in the scope of this element definition.

Returns:
the form for this element declaration, as a string "qualified" or "unqualified". The value will be taken from the schema-level default if no explicit value is set for this element declaration.

getId

public java.lang.String getId()
Returns the 'id' value for for this element definition.

Returns:
the 'id' for this element definition, or null if none was defined.

getIdentityConstraints

public java.util.Iterator getIdentityConstraints()
Returns an Iterator over the identity constrains defined within this element definition.

Returns:
an Iterator of IdentityConstraint objects contained within this element definition.

getLocalName

public java.lang.String getLocalName()
Returns the local name of this Element declaration. The name of the referenced element is returned if the 'ref' attribute was used. The name returned will be an NCName (no namespace prefix will be included with the name).

Returns:
the local name of this element declaration

getName

public java.lang.String getName(boolean ignoreRef)
Returns the name of this Element declaration. The name returned, if not null, will be an NCName.

Parameters:
ignoreRef - if false the name of the referenced element (if specified) is returned, otherwise the localname (may be null).
Returns:
the name of this element declaration

getTypeFingerprint

public int getTypeFingerprint()
Get the namepool fingerprint of the name of the element's type.

Returns:
the fingerprint of the type, or -1 if none is available.

setTypeFingerprint

public void setTypeFingerprint(int fingerprint)
Set the namepool fingerprint of the name of the element's type.


getType

public SchemaType getType()
Returns the Schema Type (ComplexType or SimpleType) of this Element Declaration.

Returns:
the Schema Type of this Element Declaration. Returns null if there is no associated type (which only happens if an element reference can't be resolved)

getReference

public ElementDecl getReference()
If this is an element reference, returns the ElementDecl that this element definition references. Otherwise, return null.

Returns:
the ElementDecl that this element definition references, if any. May return null during validation if the schema is invalid

getSchema

public Schema getSchema()
Returns the Schema to which this element declaration belongs.

Returns:
the Schema to which this element declaration belongs.

getSubstitutionGroupHead

public int getSubstitutionGroupHead()
Returns the head of the substitutionGroup for this element declaration, or -1 if there is none.

Returns:
the fingerprint of the name of the head of the substitution group for this element declaration, or -1 if none is defined. This is the immediate parent in the substitution group hierarchy.

getSubstitutionGroupMembers

public java.util.Set getSubstitutionGroupMembers()
Get the known members of the substitution group of this element, as a Set containing the ElementDecl objects. This includes all applicable element declarations in schemas compiled within the same Configuration as this schema.


addSubstitutionGroupMember

public void addSubstitutionGroupMember(ElementDecl member)
                                throws SchemaException
Add a member of the substitution group that has this element as its head. For internal use only. This method may be called at any time, for example when a new schema is loaded as a result of validating an instance document. The method is therefore synchronized, since the schema may be used in several threads concurrently. Adding a new member to a substitution group means that all complex type definitions that include this element in their content model must be recompiled.

Parameters:
member - The element declaration to be added to the substitution group of which this element declaration is the head. Elements are added to each ancestor in the substitution group hierarchy.
SchemaException

registerComplexTypeUsingThisElement

public void registerComplexTypeUsingThisElement(UserComplexType type)
Register a complex type that contains this element as a particle. If new elements are added to the substitution group headed by this element, these complex types will need to be recompiled to permit the new substititution group members. For internal use only.

Parameters:
type - A complex type that contains this element as a particle.

isAbstract

public boolean isAbstract()
Returns true if this element definition is abstract

Returns:
true if this element definition is abstract

isNillable

public boolean isNillable()
Determine whether or not instances of this element definition permit xsi:nil to be set to "yes".

Returns:
true if instances conforming to this element definition may be nilled, and false otherwise.

isReference

public boolean isReference()
Determine whether this ElementDecl represents an element reference, that is, an xs:element element with a 'ref' attribute.

Returns:
true if this element definition is a reference

setAbstract

public void setAbstract(boolean isAbstract)
Sets whether or not this element definition is abstract. For internal use only.

Parameters:
isAbstract - a boolean: when true indicates that this element definition is abstract

setBlock

public void setBlock(int block)
Sets the value of the 'block' attribute for this element For internal use only.

Parameters:
block - the value of the block attribute for this element definition, indicating the types of derivation that are not allowed, as a bit-significant integer, using constants such as SchemaType.DERIVE_BY_EXTENSION

setDefaultValue

public void setDefaultValue(java.lang.String value)
Sets the 'default' value for this element declaration. For internal use only.

Parameters:
value - the default value for this element declaration.

setFinalProhibitions

public void setFinalProhibitions(int finalValue)
Sets the value of the 'final' property, indicating which types of derivation are not allowed. For internal use only.

Parameters:
finalValue - the bit-significant code representing the final property, made up of values such as SchemaType.DERIVE_BY_SUBSTITUTION

setFixedValue

public void setFixedValue(java.lang.String value)
Sets the fixed value for this element definition. For internal use only.

Parameters:
value - the fixed value for this element definition.

setForm

public void setForm(java.lang.String form)
Sets the 'form' for this element declaration. The value species whether or not names are qualified or unqualified for instances of this element declaration. If null, the Form is to be obtained from the parent Schema. For internal use only.

Parameters:
form - the form for this element declaration, as a string, "qualified" or "unqualified". The caller is responsible for validating the value.

setId

public void setId(java.lang.String id)
Sets the id for this element definition. For internal use only.

Parameters:
id - the id for this element definition.

setName

public void setName(java.lang.String name)
Sets the name of the element that this Element definition defines. This is the actual value of the 'name' attribute of the xs:element element. The value must be validated by the caller. For internal use only.

Parameters:
name - the name of the element declaration.

setNillable

public void setNillable(boolean nillable)
Sets whether or not instances of this element definition may set xsi:nil='true'. For internal use only.

Parameters:
nillable - the flag when true indicates that instances of this element definition may be nilled

setReference

public void setReference(java.lang.String reference)
Sets the value of the 'ref' attribute for this element reference. For internal use only. Validation is the responsibility of the caller.

Parameters:
reference - the name of the element definition that this definition references, as set in the 'ref' attribute

setFingerprint

public void setFingerprint(int fingerprint)
Set the fingerprint of the name of this element declaration in the namePool

Parameters:
fingerprint - the fingerprint of the element name

getFingerprint

public int getFingerprint()
Get the fingerprint of the name of this element declation in the namePool

Returns:
the fingerprint of the element name

setSubstitutionGroupHead

public void setSubstitutionGroupHead(int substitutionGroupHead)
Sets the fingerprint of the name of the head of the substitutionGroup for this element definition. For internal use only.

Parameters:
substitutionGroupHead - the fingerprint of the name of the head of the substitutionGroup of this element definition.

iterateSubstitutionGroup

public java.util.Iterator iterateSubstitutionGroup()
Iterate over all the elements contained in the substitution group of which this element is the head. If this object represents an element reference, the iterator is over the substitution group of the referenced global element.

Returns:
an iterator giving access to the ElementDecl objects defining the members of the substitution group. This gives access to all the descendants in the substitution group hierarchy, not only the elements that explicitly name this element as their substitution group head.

setType

public void setType(SchemaType type)
Sets the schema type for this element declaration. For internal use only.

Parameters:
type - the schema type for this element declaration.

getStructureType

public short getStructureType()
Returns the type of this SchemaElement

Specified by:
getStructureType in class SchemaElement
Returns:
the type of this SchemaElement (always SchemaElement.ELEMENT)

isEmptiable

public boolean isEmptiable()
Determine if this particle can be empty

Specified by:
isEmptiable in interface Particle
Returns:
true if this element, considered as a particle in a content model, can be matched by empty content (which is true if the minOccurs value is zero). The result is undefined for a global element declaration.

getContainedValidationContext

public ValidationContext getContainedValidationContext()
Get the validation context for validating the children of this element. This method is intended for use by the validator (when validating instance documents against this schema)

Returns:
a ValidationContext object suitable for use by the validator.

fixup

public boolean fixup(Schema schema)
Fix up references. For internal use only. This implementation of the method does nothing.

Specified by:
fixup in interface SchemaComponent
Parameters:
schema - Not used
Returns:
true (always)

validate

public boolean validate(Schema schema)
                 throws javax.xml.transform.TransformerException
Check the validity (consistency) of this element definition.

Specified by:
validate in interface SchemaComponent
Parameters:
schema - the containing schema - used for reporting errors. Any errors will be reported to the error listener.
Returns:
true if validation succeeded, false if errors were found.
Throws:
javax.xml.transform.TransformerException - if an error is found and the error listener decides that the error is fatal

fixupSubstitutionGroup

protected void fixupSubstitutionGroup(NamePool pool)
                               throws SchemaException
Fix up the reference to the head of the substitition group

Parameters:
pool - the name pool
Throws:
SchemaException - if any error occurs, for example a name that is referenced but not declared

compile

public void compile(Schema schema,
                    UserComplexType subjectType)
             throws SchemaException
Compile this local element declaration, considered as a particle of some complex type, by compiling its own complex type definition.

Specified by:
compile in interface Particle
Parameters:
schema - The containing schema (used to generate error messages)
subjectType - The containing complex type (used so that this can be registered with any elements appearing as particles in the content model, so that the complex type can be recompiled if the substitution group membership of the element declaration subsequently changes)
Throws:
SchemaException - if compilation fails.


Stylus Studio features integrated development and debugging support for Saxon in the XQuery editor and XSLT editor.