com.saxonica.schema
Class ElementDecl

java.lang.Object
  extended by com.saxonica.schema.SchemaStructure
      extended by com.saxonica.schema.ElementDecl
All Implemented Interfaces:
SerializableSchemaComponent, Term, UserSchemaComponent, Serializable, SourceLocator, SchemaComponent, SchemaDeclaration

public class ElementDecl
extends SchemaStructure
implements UserSchemaComponent, SerializableSchemaComponent, SchemaDeclaration, Term

The object represents an element declaration in the schema. It may be a global element declaration, or a local element declaration.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface net.sf.saxon.type.SchemaComponent
FIXED_UP, INCOMPLETE, INVALID, UNVALIDATED, VALIDATED, VALIDATING
 
Constructor Summary
ElementDecl(SchemaAwareConfiguration config, String targetNamespace, boolean global, SourceLocator locator)
          Creates a new element declaration
 
Method Summary
 void addIdentityConstraint(IdentityConstraint constraint)
          Adds the given IdentityConstraint to this element definition.
 boolean addSubstitutionGroupMember(ElementDecl member, SchemaCompiler compiler)
          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 (that is, the {substitution group exclusions} in the component model
 boolean fixup(SchemaCompiler compiler)
          Check references from this component to other components
 int getBlock()
          Returns the value of the 'block' attribute for this element.
 UserComplexType getContainingComplexType()
          Get the containing complex type.
 String getDefaultValue()
          Returns the default value defined for this element definition.
 String getDisplayName()
          Returns the display name of this Element declaration.
 int getFingerprint()
          Get the fingerprint of the name of this element declaration in the namePool
 Value getFixedValue()
          Returns the 'fixed' value defined for this element declaration.
 Iterator getIdentityConstraints()
          Returns an Iterator over the identity constrains defined within this element definition.
 String getName()
          Returns the local name of this Element declaration.
 int getNameCode()
          Get the nameCode of the name of this element declaration in the namePool
 String getNamespaceURI()
          Deprecated. since 9.0: use the renamed method getTargetNamespace()
 int getSubstitutionGroupExclusions()
          Get the substitution group exclusions of this element, that is, the value of the applcable final or finalDefault attributes.
 int getSubstitutionGroupHead()
          Returns the fingerprint of the name of the head of the substitutionGroup for this element declaration, or -1 if there is none.
 Set getSubstitutionGroupMembers()
          Get the known members of the substitution group of this element, as a Set containing the ElementDecl objects.
 ElementDecl getSubstitutionGroupOwner()
          Returns the head of the substitutionGroup for this element declaration, or null if there is none.
 ComponentReference getSubstitutionGroupOwnerReference()
          Get the component reference pointing to the owner of the substitution group.
 String getTargetNamespace()
          Get the namespace URI of this element declaration.
 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 isGlobal()
          Determine whether this element declaration is global.
 boolean isNillable()
          Determine whether or not instances of this element definition permit xsi:nil to be set to "yes".
 boolean isSameDeclaration(ElementDecl other)
          Test whether this is the same declaration as another declaration.
 Iterator iterateSubstitutionGroup()
          Iterate over all the elements contained in the substitution group of which this element is the head.
 NodeTest makeSchemaNodeTest()
          Create a NodeTest that implements the semantics of schema-element(name) or schema-attribute(name) applied to this element or attribute declaration.
 void registerComplexTypeUsingThisElement(UserComplexType type)
          Register a complex type that contains this element as a particle.
 void serialize(SchemaModelSerializer serializer)
          Serialize the schema component
 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 setContainingComplexType(UserComplexType type)
          Sets the containing complex type definition.
 void setDefaultValue(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 setFixedValue(Value value)
          Sets the fixed value for this element definition.
 void setNameCode(int nameCode)
          Set the name of this element declaration
 void setNamespaceResolver(NamespaceResolver resolver)
          Set the namespace resolver to be used
 void setNillable(boolean nillable)
          Sets whether or not instances of this element definition may set xsi:nil='true'.
 void setSubstitutionGroupHead(int nameCode)
          Sets the fingerprint of the name of the head of the substitutionGroup for this element definition.
 void setTypeReference(TypeReference type)
          Sets the schema type for this element declaration.
 boolean validate(SchemaCompiler compiler)
          Check the validity (consistency) of this element definition.
 
Methods inherited from class com.saxonica.schema.SchemaStructure
elaborate, getColumnNumber, getConfiguration, getFixupStatus, getLineNumber, getPublicId, getSystemId, getValidationStatus, lookForCycles, setConfiguration, setFixupStatus, setLineNumber, setLocator, setSystemId, setValidationStatus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.saxonica.schema.UserSchemaComponent
elaborate, lookForCycles
 
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getValidationStatus
 

Constructor Detail

ElementDecl

public ElementDecl(SchemaAwareConfiguration config,
                   String targetNamespace,
                   boolean global,
                   SourceLocator locator)
Creates a new element declaration

Parameters:
config - the Configuration to which this element declaration belongs
targetNamespace - the targetNamespace of the schema document
global - true if the element declaration is top-level
locator - identifies the location of the element declaration in the
Method Detail

setNamespaceResolver

public void setNamespaceResolver(NamespaceResolver resolver)
Set the namespace resolver to be used

Parameters:
resolver - the namespace resolver

addIdentityConstraint

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

Parameters:
constraint - the IdentityConstraint to add.

setContainingComplexType

public void setContainingComplexType(UserComplexType type)
Sets the containing complex type definition. For internal use only.

Parameters:
type - the complex type containing this local element declaration

getBlock

public int getBlock()
Returns the value of the 'block' attribute for this element. This corresponds to the value of the {disallowed substitutions} property in the schema component model.

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 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.

getSubstitutionGroupExclusions

public int getSubstitutionGroupExclusions()
Get the substitution group exclusions of this element, that is, the value of the applcable final or finalDefault attributes. Corresponds to the property {substitution group exclusions} in the schema component model.

Returns:
the substitution group exclusions, represented as a bit-significant integer, the relevant bits being SchemaType.DERIVATION_EXTENSION and SchemaType.DERIVATION_RESTRICTION

allowsDerivation

public boolean allowsDerivation(int derivation)
Determines whether derivation (of a particular kind) from this type is allowed, based on the "final" property (that is, the {substitution group exclusions} in the component model

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

getContainingComplexType

public UserComplexType getContainingComplexType()
Get the containing complex type. This represents one aspect of the {scope} property defined in the schema component model. If the element is a local element declaration and is defined as part of a complex type (and not as part of a named model group), returns the complex type definition. Otherwise, returns null.

Returns:
the containing complex type definition if there is one, otherwise null

getFixedValue

public Value 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.

getIdentityConstraints

public Iterator getIdentityConstraints()
Returns an Iterator over the identity constrains defined within this element definition. This corresponds to the {identity-constraint definitions} property in the schema component model.

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

getDisplayName

public String getDisplayName()
Returns the display name of this Element declaration. This will be in the form of a lexical QName typically using the original prefix

Returns:
the local name of this element declaration

getName

public String getName()
Returns the local name of this Element declaration. The name returned, if not null, will be an NCName. This corresponds to the {name} property defined in the schema component model.

Returns:
the local name of this element declaration, if it is global, or null if it is anonymous

getTargetNamespace

public String getTargetNamespace()
Get the namespace URI of this element declaration. This corresponds to the {targetNamespace} property defined in the schema component model.

Returns:
the target namespace if the element declaration is global and the target namespace is not "absent". Return null for a local element declaration or for a global element in a no-namespace schema.

getNamespaceURI

public String getNamespaceURI()
Deprecated. since 9.0: use the renamed method getTargetNamespace()

Get the namespace URI of this element declaration. This corresponds to the {targetNamespace} property defined in the schema component model.

Returns:
the target namespace

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.

getType

public SchemaType getType()
                   throws UnresolvedReferenceException
Returns the Schema Type (ComplexType or SimpleType) of this Element Declaration. This corresponds to the {typeDefinition} property in the schema component model.

Specified by:
getType in interface SchemaDeclaration
Returns:
the Schema Type of this Element Declaration.
Throws:
UnresolvedReferenceException - if the reference from the element declaration to its type cannot be resolved.

getSubstitutionGroupHead

public int getSubstitutionGroupHead()
Returns the fingerprint of the name of 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.

getSubstitutionGroupOwnerReference

public ComponentReference getSubstitutionGroupOwnerReference()
Get the component reference pointing to the owner of the substitution group.

Returns:
the owner of the substitution group; return null if not defined.

getSubstitutionGroupOwner

public ElementDecl getSubstitutionGroupOwner()
                                      throws UnresolvedReferenceException
Returns the head of the substitutionGroup for this element declaration, or null if there is none. This corresponds to the {substitution group affiliation} property in the schema component model.

Returns:
the element declaration representing the head of the substitution group for this element declaration, or null if none is defined. This is the immediate parent in the substitution group hierarchy.
Throws:
UnresolvedReferenceException - if the element is a member of a substitution group but no declaration of the referenced element is (yet) available

getSubstitutionGroupMembers

public 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.

Returns:
a set containing all the substitution group members, expanded transtively

addSubstitutionGroupMember

public boolean addSubstitutionGroupMember(ElementDecl member,
                                          SchemaCompiler compiler)
                                   throws SchemaException,
                                          ValidationException
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.

It is not possible to add to a substitution group once the element declaration has been used, either for validating a source document or for compiling stylesheets or schemas.

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.
compiler - used for error reporting
Returns:
true if the element was added to the substitution group or was already a member; false if it was not added because substitution was blocked (in which case it will not be added to any containing substitution groups either)
Throws:
SchemaException
ValidationException

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. This corresponds to the {abstract} property in the schema component model.

Specified by:
isAbstract in interface SchemaDeclaration
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". This corresponds to the {nillable} property in the schema component model.

Specified by:
isNillable in interface SchemaDeclaration
Returns:
true if instances conforming to this element definition may be nilled, and false otherwise.

isGlobal

public boolean isGlobal()
Determine whether this element declaration is global. This represents one aspect of the {scope} property defined in the schema data model.

Returns:
true if the element declaration is global, false if it is local

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.DERIVATION_EXTENSION

setDefaultValue

public void setDefaultValue(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(Value value)
Sets the fixed value for this element definition. For internal use only.

Parameters:
value - the fixed value for this element definition. This is stored initially as the string value initially specified in the schema document; once the type of the element is known (during schema validation) this is replaced by the typed value.

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

setNameCode

public void setNameCode(int nameCode)
Set the name of this element declaration

Parameters:
nameCode - the nameCode of the element name in the namePool

getFingerprint

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

Returns:
the fingerprint of the element name

getNameCode

public int getNameCode()
Get the nameCode of the name of this element declaration in the namePool

Returns:
the nameCode of the element name

setSubstitutionGroupHead

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

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

iterateSubstitutionGroup

public 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.

setTypeReference

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

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

fixup

public boolean fixup(SchemaCompiler compiler)
              throws SchemaException,
                     UnresolvedReferenceException
Check references from this component to other components

Specified by:
fixup in interface UserSchemaComponent
Overrides:
fixup in class SchemaStructure
Parameters:
compiler - used for error reporting
Returns:
true if all is well, false if errors found
Throws:
SchemaException
UnresolvedReferenceException

makeSchemaNodeTest

public NodeTest makeSchemaNodeTest()
Create a NodeTest that implements the semantics of schema-element(name) or schema-attribute(name) applied to this element or attribute declaration.

Specified by:
makeSchemaNodeTest in interface SchemaDeclaration

validate

public boolean validate(SchemaCompiler compiler)
                 throws SchemaException
Check the validity (consistency) of this element definition.

Specified by:
validate in interface UserSchemaComponent
Parameters:
compiler - used for error reporting
Returns:
true if validation succeeded, false if errors were found.
Throws:
SchemaException - if an error is found and the error listener decides that the error is fatal

isSameDeclaration

public boolean isSameDeclaration(ElementDecl other)
Test whether this is the same declaration as another declaration. They are considered to be the same declaration if they are derived from the same definition in the original XML representation (which can happen when there are multiple includes of the same file)

Parameters:
other - the declaration with which to compare this one
Returns:
true if the two declarations are the same

serialize

public void serialize(SchemaModelSerializer serializer)
               throws XPathException
Serialize the schema component

Specified by:
serialize in interface SerializableSchemaComponent
Throws:
XPathException


Copyright (C) Michael H. Kay. All rights reserved.