com.saxonica.schema
Class ElementParticle

java.lang.Object
  extended bycom.saxonica.schema.SchemaStructure
      extended bycom.saxonica.schema.SimpleComponentReference
          extended bycom.saxonica.schema.ElementParticle
All Implemented Interfaces:
ComponentReference, Particle, SchemaComponent, java.io.Serializable, javax.xml.transform.SourceLocator, UserSchemaComponent

public class ElementParticle
extends SimpleComponentReference
implements UserSchemaComponent, Particle

A reference to an element declaration within the content model of a complex type. This corresponds to an <xs:element ref="x"> element in the XML representation of a schema. Where a local element declaration appears in a content model, using the form <xs:element name="x">, both an element declaration and an element particle are created.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.saxonica.schema.SimpleComponentReference
nameCode, symbolSpace, target
 
Fields inherited from interface net.sf.saxon.type.SchemaComponent
FIXED_UP, INCOMPLETE, INVALID, UNVALIDATED, VALIDATED, VALIDATING
 
Constructor Summary
ElementParticle(PreparedSchema schema, javax.xml.transform.SourceLocator locator)
          Creates a new element particle
 
Method Summary
 void compile(PreparedSchema schema, UserComplexType subjectType)
          Compile this local element declaration, considered as a particle of some complex type, by compiling its own complex type definition.
static int computeParticleCardinality(int minOccurs, int maxOccurs)
          Compute an XPath cardinality (e.g.
 boolean fixup(PreparedSchema schema)
          Check references from this component to other components
 ElementDecl getDeclaration()
          Returns the ElementDecl that this element definition references.
 java.lang.String getDisplayName()
          Returns the display name of this Element particle.
 int getElementParticleCardinality(int fingerprint)
          Find an element particle within this complex type definition having a given element name (identified by fingerprint), and return the cardinality associated with that element particle, that is, the number of times the element can occur within this complex type.
 SchemaType getElementParticleType(int fingerprint)
          Find an element particle within this complex type definition having a given element name (identified by fingerprint), and return the schema type associated with that element particle.
 int getMaxOccurs()
          Returns the maximum number of occurrences that this Particle may appear in the containing content model
 int getMinOccurs()
          Returns the minimum number of occurrences that this Particle must appear in the containing content model
 java.lang.String getName()
          Returns the local name of this Element particle.
 java.lang.String getNamespaceURI()
          Get the namespace URI of this element particle
 Term getTerm()
          Get the term corresponding to this particle
 boolean isEmptiable()
          Determine if this particle can be empty
 void rewrite()
          Rewrite a particle prior to compiling it
 void setMaxOccurs(int maxOccurs)
          Sets the maximum number of occurrences for this Particle within the containing content model
 void setMinOccurs(int minOccurs)
          Sets the minimum number of occurrences for this Particle within the containing content model
 void setReference(ElementDecl declaration)
          Set the reference to a specific (typically non-global) element declaration
 java.lang.String toString()
           
 boolean validate(PreparedSchema schema)
          Check the validity (consistency) of this element definition.
 
Methods inherited from class com.saxonica.schema.SimpleComponentReference
getFingerprint, getNameCode, getSymbolSpace, getTarget, isResolved, setNameCode, setTarget, tryToResolve
 
Methods inherited from class com.saxonica.schema.SchemaStructure
getColumnNumber, getFixupStatus, getLineNumber, getPublicId, getSchema, getSystemId, getValidationStatus, lookForCycles, setFixupStatus, setLineNumber, setLocator, setSchema, setSystemId, setValidationStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.saxonica.schema.UserSchemaComponent
lookForCycles
 
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getValidationStatus
 
Methods inherited from interface com.saxonica.schema.ComponentReference
getSchema
 
Methods inherited from interface javax.xml.transform.SourceLocator
getColumnNumber, getLineNumber, getPublicId, getSystemId
 

Constructor Detail

ElementParticle

public ElementParticle(PreparedSchema schema,
                       javax.xml.transform.SourceLocator locator)
Creates a new element particle

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

getDisplayName

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

Returns:
the local name of this element declaration

getNamespaceURI

public java.lang.String getNamespaceURI()
Get the namespace URI of this element particle


getName

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

Returns:
the name of this element declaration

getDeclaration

public ElementDecl getDeclaration()
                           throws UnresolvedReferenceException
Returns the ElementDecl that this element definition references.

Returns:
the ElementDecl that this element definition references.
Throws:
UnresolvedReferenceException

setReference

public void setReference(ElementDecl declaration)
Set the reference to a specific (typically non-global) element declaration


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.

fixup

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

Specified by:
fixup in interface UserSchemaComponent
Parameters:
schema - The schema is used for reporting errors
Returns:
true if all is well, false if errors found
Throws:
SchemaException
UnresolvedReferenceException

validate

public boolean validate(PreparedSchema schema)
                 throws SchemaException,
                        ValidationException
Check the validity (consistency) of this element definition.

Specified by:
validate in interface UserSchemaComponent
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:
SchemaException - if an error is found and the error listener decides that the error is fatal
ValidationException

rewrite

public void rewrite()
Rewrite a particle prior to compiling it

Specified by:
rewrite in interface Particle

compile

public void compile(PreparedSchema schema,
                    UserComplexType subjectType)
             throws SchemaException,
                    ValidationException
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.
ValidationException

getMaxOccurs

public final int getMaxOccurs()
Returns the maximum number of occurrences that this Particle may appear in the containing content model

Specified by:
getMaxOccurs in interface Particle
Returns:
the maximum number of occurrences that this Particle may appear. A negative (n < 0) value indicates that the value is unspecified (ie. unbounded).

getMinOccurs

public final int getMinOccurs()
Returns the minimum number of occurrences that this Particle must appear in the containing content model

Specified by:
getMinOccurs in interface Particle
Returns:
the minimum number of occurrences that this Particle must appear A negative (n < 0) value indicates that the value is unspecified.

setMaxOccurs

public final void setMaxOccurs(int maxOccurs)
Sets the maximum number of occurrences for this Particle within the containing content model

Parameters:
maxOccurs - the maximum number of occurrences for this Particle, or -1 to indicate that the maximum is unbounded

setMinOccurs

public final void setMinOccurs(int minOccurs)
Sets the minimum number of occurrences for this Particle within the containing content model

Specified by:
setMinOccurs in interface Particle
Parameters:
minOccurs - the minimum number of occurrences for this Particle

getTerm

public Term getTerm()
Get the term corresponding to this particle

Specified by:
getTerm in interface Particle
Returns:
the corresponding term

getElementParticleType

public SchemaType getElementParticleType(int fingerprint)
Find an element particle within this complex type definition having a given element name (identified by fingerprint), and return the schema type associated with that element particle. If there is no such particle, return null. If the fingerprint matches an element wildcard, return the type of the global element declaration with the given name if one exists, or AnyType if none exists and lax validation is permitted by the wildcard.

Specified by:
getElementParticleType in interface Particle
Parameters:
fingerprint - Identifies the name of the child element within this content model

getElementParticleCardinality

public int getElementParticleCardinality(int fingerprint)
                                  throws SchemaException,
                                         ValidationException
Find an element particle within this complex type definition having a given element name (identified by fingerprint), and return the cardinality associated with that element particle, that is, the number of times the element can occur within this complex type. The value is one of StaticProperty.EXACTLY_ONE, StaticProperty.ALLOWS_ZERO_OR_ONE, StaticProperty.ALLOWS_ZERO_OR_MORE, StaticProperty.ALLOWS_ONE_OR_MORE, If there is no such particle, return zero.

Specified by:
getElementParticleCardinality in interface Particle
Parameters:
fingerprint - Identifies the name of the child element within this content model
Throws:
SchemaException
ValidationException

computeParticleCardinality

public static int computeParticleCardinality(int minOccurs,
                                             int maxOccurs)
Compute an XPath cardinality (e.g. ONE_OR_MORE) from an XML Schema cardinality

Parameters:
minOccurs - Minimum occurrences
maxOccurs - Maximum occurrences (-1 = unbounded)
Returns:
The XPath cardinality

toString

public java.lang.String toString()