Package com.saxonica.ee.schema
Class ModelGroup
- java.lang.Object
-
- com.saxonica.ee.schema.SchemaStructure
-
- com.saxonica.ee.schema.ModelGroup
-
- All Implemented Interfaces:
Term
,UserSchemaComponent
,javax.xml.transform.SourceLocator
,Location
,SchemaComponent
,org.xml.sax.Locator
- Direct Known Subclasses:
AllModelGroup
,ChoiceModelGroup
,ModelGroupDefinition
,SequenceModelGroup
public abstract class ModelGroup extends SchemaStructure implements UserSchemaComponent, Term
An XML Schema Model Group. This corresponds to a sequence, choice, or all in the schema document representation. The model group is typically referenced by a ModelGroupParticle, which links it into some containing content model. Named model groups, corresponding to global xs:group elements in a schema document, are represented by the subclassModelGroupDefinition
.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Particle>
contentModel
The list of particles making up the content model of this ModelGroup.protected java.util.List<Particle>
simplifiedContentModel
The reduced list of particles.
-
Constructor Summary
Constructors Constructor Description ModelGroup()
Creates a new ModelGroup, with no name
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addParticle(Particle particle)
Adds a given Particle to the content model defined by this model groupprotected boolean
checkElements(IntHashMap<ElementDecl> map, SchemaCompiler compiler)
Check that the elements defined as particles in this model group are consistentvoid
compile(SchemaCompiler compiler)
Compile this Compositor by compiling each of the particles contained in its content model.boolean
containsAll(boolean simplified)
Test whether this model group contains an xs:all compositorboolean
containsElementWildcard()
Ask whether the model group contains an element wildcardboolean
fixup(SchemaCompiler compiler)
Check references from this component to other componentsvoid
gatherAllPermittedElements(IntHashSet result, boolean ignoreWildcards)
Find the set of all element particles allowed within the content model of this particle, identified by their integer fingerprints.FunctionItem
getComponentAsFunction()
Get the schema component in the form of a function item.abstract java.lang.String
getCompositorName()
Get the name of the compositor used in this model groupint
getContentModelSize()
Get the number of particles in the (unsimplified) content modelint
getElementParticleCardinality(int elementName)
Find an element particle within this complex type definition having a given element name (identified by elementName), 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 elementName)
Find an element particle within this complex type definition having a given element name (identified by elementName), and return the schema type associated with that element particle.java.util.List<Particle>
getParticles()
Get the (unsimplified list of) Particles of the content model defined by this model group.java.util.List<Particle>
getSimplifiedContentModel()
Remove pointless particles from this content model (recursively), and replace group references by the content of the identified groupTerm
getTerm()
Get the term corresponding to this particleabstract boolean
isEmptiable()
Determine if empty content is allowedboolean
isEmpty()
Return true if the content model is emptyboolean
isPointless(ModelGroup container)
Test whether the particle is pointless, as described in XML Schema Part 1 Schema Component Constraint: Particle Valid (Restriction)void
lookForCycles(java.util.Stack<SchemaComponent> references, SchemaCompiler compiler)
This method is called to look for cycles.void
markVulnerableSubParticles(boolean isRepeatable)
Mark contained particles as vulnerable.void
serialize(SchemaModelSerializer serializer)
Serialize the schema componentvoid
setContentModel(java.util.List<Particle> particles)
Set the entire content modelboolean
validate(SchemaCompiler compiler)
Checks the validity of this model group.-
Methods inherited from class com.saxonica.ee.schema.SchemaStructure
elaborate, getColumnNumber, getConfiguration, getFixupStatus, getGeneratedId, getLineNumber, getPublicId, getRedefinitionLevel, getSchemaDocumentURI, getSystemId, getValidationStatus, hasSameLocation, isValidationNeeded, makeXPathExpressionPropertyRecord, saveLocation, setConfiguration, setFixupStatus, setGeneratedId, setLineNumber, setLocator, setRedefinitionLevel, setSchemaDocumentURI, setSystemId, setValidationStatus
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.type.SchemaComponent
getRedefinitionLevel, getValidationStatus
-
Methods inherited from interface com.saxonica.ee.schema.UserSchemaComponent
elaborate
-
-
-
-
Field Detail
-
contentModel
protected java.util.List<Particle> contentModel
The list of particles making up the content model of this ModelGroup. In this list, group references are not expanded: that is, the particles can be real particles, or group references. In an AllModelGroup, this list does not include wildcard particles
-
simplifiedContentModel
protected java.util.List<Particle> simplifiedContentModel
The reduced list of particles. Pointless particles are removed, and group references are expanded. The list is evaluated lazily.
-
-
Method Detail
-
getCompositorName
public abstract java.lang.String getCompositorName()
Get the name of the compositor used in this model group- Returns:
- one of "sequence", "choice", or "all"
-
addParticle
public void addParticle(Particle particle)
Adds a given Particle to the content model defined by this model group- Parameters:
particle
- the Particle to be added. Note that the particle is ignored (and is not added to the content model) if it has minOccurs=maxOccurs=0.
-
setContentModel
public void setContentModel(java.util.List<Particle> particles)
Set the entire content model- Parameters:
particles
- a List whose members are Particle objects
-
isEmptiable
public abstract boolean isEmptiable() throws MissingComponentException
Determine if empty content is allowed- Returns:
- true if the content model of the model group allows empty content
- Throws:
MissingComponentException
- if the schema contains unresolved references to required components
-
isPointless
public boolean isPointless(ModelGroup container) throws MissingComponentException
Test whether the particle is pointless, as described in XML Schema Part 1 Schema Component Constraint: Particle Valid (Restriction)- Parameters:
container
- not used- Returns:
- true if the particle is pointless (which effectively means it can't match anything)
- Throws:
MissingComponentException
-
getParticles
public java.util.List<Particle> getParticles()
Get the (unsimplified list of) Particles of the content model defined by this model group.- Returns:
- the immediately contained particles in the content model. Note that the iteration may return group references as well as "true" particles.
-
getContentModelSize
public int getContentModelSize()
Get the number of particles in the (unsimplified) content model- Returns:
- the number of particles in the (unsimplified) content model
-
isEmpty
public boolean isEmpty()
Return true if the content model is empty- Returns:
- true if the content model is empty
-
containsAll
public boolean containsAll(boolean simplified) throws MissingComponentException
Test whether this model group contains an xs:all compositor- Parameters:
simplified
- set to false if we want to look at the original unsimplified content model, to true if we want the model after removing pointless particles- Returns:
- true if this model group contains an xs:all compositor
- Throws:
MissingComponentException
- if the schema contains unresolved references to required components
-
getSimplifiedContentModel
public java.util.List<Particle> getSimplifiedContentModel() throws MissingComponentException
Remove pointless particles from this content model (recursively), and replace group references by the content of the identified group- Returns:
- the simplified content model
- Throws:
MissingComponentException
-
markVulnerableSubParticles
public void markVulnerableSubParticles(boolean isRepeatable) throws MissingComponentException
Mark contained particles as vulnerable. A particle is marked as vulnerable if everything both before and after it in the content model is optional. This is used in deciding whether to use counting states in a finite state machine.- Parameters:
isRepeatable
- true if this particle repeats within the content model- Throws:
MissingComponentException
-
lookForCycles
public void lookForCycles(java.util.Stack<SchemaComponent> references, SchemaCompiler compiler) throws SchemaException
This method is called to look for cycles. The object implementing this method is required (a) to raise an exception if the object itself appears in the list of references, (b) to add itself to the list of references, and (c) to call the lookForCycles method on all the objects that it references.- Specified by:
lookForCycles
in interfaceUserSchemaComponent
- Overrides:
lookForCycles
in classSchemaStructure
- Parameters:
references
- A list of objects that contain direct or indirect references to this object, and that must therefore not be referred to from this object.compiler
- used for error reporting- Throws:
SchemaException
- if cycles are found
-
validate
public boolean validate(SchemaCompiler compiler) throws SchemaException
Checks the validity of this model group.- Specified by:
validate
in interfaceUserSchemaComponent
- Overrides:
validate
in classSchemaStructure
- Parameters:
compiler
- the schema compiler- Returns:
- true when this Schema definition is valid, otherwise false.
- Throws:
SchemaException
- when the error listener decides an error is fatal
-
checkElements
protected boolean checkElements(IntHashMap<ElementDecl> map, SchemaCompiler compiler) throws SchemaException, MissingComponentException
Check that the elements defined as particles in this model group are consistent- Parameters:
map
- a HashMap that maps integers to ElementDecl'scompiler
- used for error reporting- Returns:
- true of the elements are consistent
- Throws:
SchemaException
- if the schema is invalidMissingComponentException
- if the schema contains unresolved references to required components
-
getElementParticleType
public SchemaType getElementParticleType(int elementName) throws MissingComponentException
Find an element particle within this complex type definition having a given element name (identified by elementName), and return the schema type associated with that element particle. If there is no such particle, return null. If the elementName 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.- Parameters:
elementName
- Identifies the name of the child element within this content model- Returns:
- the type associated with the element particle, if found
- Throws:
MissingComponentException
-
getElementParticleCardinality
public int getElementParticleCardinality(int elementName) throws MissingComponentException
Find an element particle within this complex type definition having a given element name (identified by elementName), 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 ofStaticProperty.EXACTLY_ONE
,StaticProperty.ALLOWS_ZERO_OR_ONE
,StaticProperty.ALLOWS_ZERO_OR_MORE
,StaticProperty.ALLOWS_ONE_OR_MORE
, If there is no such particle, returnStaticProperty.EMPTY
.- Parameters:
elementName
- Identifies the name of the child element within this content model- Returns:
- the cardinality of the element particle within this content model
- Throws:
MissingComponentException
-
containsElementWildcard
public boolean containsElementWildcard() throws MissingComponentException
Ask whether the model group contains an element wildcard- Returns:
- true if the model group contains an element wildcard,
- Throws:
MissingComponentException
-
gatherAllPermittedElements
public void gatherAllPermittedElements(IntHashSet result, boolean ignoreWildcards) throws SchemaException
Find the set of all element particles allowed within the content model of this particle, identified by their integer fingerprints. Ignore wildcards.- Parameters:
result
- an initially-empty integer set in which the results are accumulatedignoreWildcards
- if true, wildcards are ignored. If false, the result will be an integer set containing the value XS_INVALID_NAME, meaning that it is not possible to enumerate the elements that can appear in the content.- Throws:
SchemaException
- if the schema is found to be invalid
-
compile
public void compile(SchemaCompiler compiler) throws SchemaException
Compile this Compositor by compiling each of the particles contained in its content model.- Parameters:
compiler
- used for error reporting- Throws:
SchemaException
- if compilation fails.
-
fixup
public boolean fixup(SchemaCompiler compiler) throws SchemaException, MissingComponentException
Check references from this component to other components- Specified by:
fixup
in interfaceUserSchemaComponent
- Overrides:
fixup
in classSchemaStructure
- Parameters:
compiler
- is used for reporting errors- Returns:
- true if all is well, false if errors found
- Throws:
SchemaException
MissingComponentException
-
getTerm
public Term getTerm()
Get the term corresponding to this particle- Returns:
- the corresponding term
-
serialize
public void serialize(SchemaModelSerializer serializer) throws XPathException, MissingComponentException
Serialize the schema component- Parameters:
serializer
- used to receive the serialized output- Throws:
XPathException
- if serialization failsMissingComponentException
-
getComponentAsFunction
public FunctionItem getComponentAsFunction()
Description copied from interface:SchemaComponent
Get the schema component in the form of a function item. This allows schema information to be made visible to XSLT or XQuery code. The function makes available the contents of the schema component as defined in the XSD specification. The function takes a string as argument representing a property name, and returns the corresponding property of the schema component. There is also a property "class" which returns the kind of schema component, for example "Attribute Declaration".- Specified by:
getComponentAsFunction
in interfaceSchemaComponent
- Overrides:
getComponentAsFunction
in classSchemaStructure
- Returns:
- the schema component represented as a function from property names to property values.
-
-