Package com.saxonica.ee.schema.fsa
Class AutomatonState
java.lang.Object
com.saxonica.ee.schema.fsa.AutomatonState
- All Implemented Interfaces:
State
- Direct Known Subclasses:
DeterminizedState
,NonDeterminizedState
Defines a state of a finite state machine used when validating an instance against
a complex type. Each State knows about the possible
transitions to other states, and knows whether it is a final state. The initial
state is referenced from the FiniteStateMachine object, which is itself a property
of the UserComplexType against which validation is being performed.
This class is designed for internal use only.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSpecificTransition
(Edge edge, SchemaCompiler compiler) Add a specific transition from this state to another state.void
addWildcardTransition
(SchemaCompiler compiler, Edge transition) Add a wildcard transition from this state to another state.void
display
(HashMap<AutomatonState, Integer> map) Display the finite state machine reachable from this state.void
Display the lambda transitions available from this statevoid
displayState
(Logger err) Display the finite state machine reachable from this state.getEdges()
Get an iterator over all the transitions (edges) allowed from this stateGet the transition to be used when the maxOccurs value is reached for a counting state.int
Get the state numbergetTransition
(int token, UserComplexType type) Find the edge representing the transition from this state to another state, that is triggered by a given input tokenEdge[]
Get an iterator over the wildcard transitions (edges) allowed from this state.boolean
Test whether this state is a final state assuming the counter has reached its minimum valueboolean
Test whether this state is a final stateList the allowed elements in this state as a string, for use in error messagesboolean
Ask whether this is a counting statevoid
serialize
(SchemaModelSerializer serializer) Serialize this state as part of the serialization of a schema component modelvoid
setFinalState
(boolean finalState) Set this state to be (or not to be) a final statevoid
setLimits
(int min, int max) Set the counter limitsvoid
setMaxTransition
(Edge edge) A counting state may have a special Edge that is used when the maxOccurs value is reached.
-
Field Details
-
wildcardEdges
-
EMPTY_EDGE_ARRAY
-
-
Constructor Details
-
AutomatonState
Create a new state- Parameters:
machine
- the finite state machine to which this State belongs
-
-
Method Details
-
isFinalState
public boolean isFinalState()Test whether this state is a final state- Specified by:
isFinalState
in interfaceState
- Returns:
- true if this is a final state
-
isConditionallyFinalState
public boolean isConditionallyFinalState()Test whether this state is a final state assuming the counter has reached its minimum value- Returns:
- true if this state is a final state when the minimum number of occurrences is reached
-
setFinalState
public void setFinalState(boolean finalState) Set this state to be (or not to be) a final state- Parameters:
finalState
- true if this state is final
-
getStateNumber
public int getStateNumber()Get the state number- Returns:
- the state number
-
addSpecificTransition
Add a specific transition from this state to another state. This transition accepts a specific element name only.- Parameters:
edge
- the transition to be addedcompiler
- the schema compiler- Throws:
SchemaException
- if there are two transitions for the same element declaration, that is, if the content model is ambiguous
-
addWildcardTransition
Add a wildcard transition from this state to another state.- Parameters:
compiler
- the schema compilertransition
- the edge representing the transition- Throws:
SchemaException
- if the transition cannot be added because it would generate an inconsistency
-
setLimits
public void setLimits(int min, int max) Set the counter limits- Parameters:
min
- the minimum number of occurrences of counting edges before a non-counting edge is usedmax
- the maximum number of occurrences of counting edges before a non-counting edge is used; the value -1 means unbounded
-
requiresCounter
public boolean requiresCounter()Ask whether this is a counting state- Returns:
- true if this state requires a counter to be maintained
-
getTransition
Find the edge representing the transition from this state to another state, that is triggered by a given input token- Specified by:
getTransition
in interfaceState
- Parameters:
token
- the input token, specifically the fingerprint of an element nametype
- the complex type we are validating against- Returns:
- the Edge representing the selected transition of the finite state machine, or null if this token is not accepted when in this State (which implies a validation error).
-
listAllowedElements
List the allowed elements in this state as a string, for use in error messages- Specified by:
listAllowedElements
in interfaceState
- Returns:
- the list of permitted elements as a string containing comma-separated element names
-
getWildcardEdges
Get an iterator over the wildcard transitions (edges) allowed from this state.- Specified by:
getWildcardEdges
in interfaceState
- Returns:
- an Iterator over the edges that represent element wildcards. The objects
returned by this Iterator are
Edge
objects.
-
getEdges
Get an iterator over all the transitions (edges) allowed from this state -
display
Display the finite state machine reachable from this state. This is a diagnostic method for internal use. Output is written to System.err. At present, wildcard transitions are not shown.- Parameters:
map
- a Hashmap mapping states already processed to the integer values used to represent that state. The method should be called initially with an empty map.
-
displayState
Display the finite state machine reachable from this state. This is a diagnostic method for internal use. Output is written to System.err. At present, wildcard transitions are not shown.- Parameters:
err
- the output destination destination
-
displayLambdaTransitions
public void displayLambdaTransitions()Display the lambda transitions available from this state -
setMaxTransition
A counting state may have a special Edge that is used when the maxOccurs value is reached. This method sets this edge.- Parameters:
edge
- the transition to be used when the maxOccurs value is reached
-
getMaxTransition
Get the transition to be used when the maxOccurs value is reached for a counting state.- Returns:
- the max transition if there is one, else null.
-
serialize
Serialize this state as part of the serialization of a schema component model- Parameters:
serializer
- used to output the model- Throws:
XPathException
- if any failure occurs
-