com.saxonica.schema
Class AutomatonState

java.lang.Object
  extended bycom.saxonica.schema.AutomatonState

public class AutomatonState
extends java.lang.Object

Defines a state of a finite state machine used when validating an instance against a complex type. There is no object (other than the UserComplexType object) that represents the entire finite state machine. 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 UserComplexType object against which validation is being performed.

This class is designed for internal use only.


Nested Class Summary
static class AutomatonState.Edge
          Internal class to represent the data associated with a transition: the element that triggers the transition, and the new state that results from the transition.
 
Field Summary
static AutomatonState.Edge[] EMPTY_EDGE_ARRAY
           
 
Constructor Summary
AutomatonState()
          Create a new state
 
Method Summary
 void addLambdaTransition(AutomatonState newState)
          Add a lambda transition from this state to another state.
 void addWildcardTransition(AutomatonState.Edge transition)
          Add a wildcard transition from this state to another state.
static AutomatonState compileParticle(Particle particle, AutomatonState endState, UserComplexType subjectType)
          Static method to translate a particle to a Finite State Automaton, returning the start state of the FSA.
 void determinize()
          Determinize the tree: that is, ensure that there are no ambiguous transitions from this state.
 void display(java.util.HashMap map)
          Display the finite state machine reachable from this state.
 java.util.Iterator getEdges()
          Get an iterator over all the transitions (edges) allowed from this state
 AutomatonState.Edge getTransition(int token, NamePool pool)
          Find the edge representing the transition from this state to another state, that is triggered by a given input token
 AutomatonState.Edge[] getWildcardEdges()
          Get an iterator over the wildcard transitions (edges) allowed from this state.
 boolean isFinalState()
          Test whether this state is a final state
 java.lang.CharSequence listAllowedElements()
          List the allowed elements in this state as a string, for use in error messages
 void setFinalState(boolean finalState)
          Set this state to be (or not to be) a final state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_EDGE_ARRAY

public static final AutomatonState.Edge[] EMPTY_EDGE_ARRAY
Constructor Detail

AutomatonState

public AutomatonState()
Create a new state

Method Detail

compileParticle

public static AutomatonState compileParticle(Particle particle,
                                             AutomatonState endState,
                                             UserComplexType subjectType)
                                      throws SchemaException,
                                             UnresolvedReferenceException
Static method to translate a particle to a Finite State Automaton, returning the start state of the FSA. This precisely follows Henry Thompson's and Richard Tobin's algorithm, published here

Parameters:
particle - the particle to be compiled, which is either an ElementDeclaration, a WildCard, a choice, or a sequence
endState - the State representing the final state of the automaton
subjectType - the complex type to which this particle belongs
Returns:
the initial state of the new Automaton
Throws:
SchemaException
UnresolvedReferenceException

isFinalState

public boolean isFinalState()
Test whether this state is a final state

Returns:
true if this is a final state

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

addLambdaTransition

public void addLambdaTransition(AutomatonState newState)
Add a lambda transition from this state to another state. This is a transition that can take place when no symbol is read.

Parameters:
newState - the state that results from this event

addWildcardTransition

public void addWildcardTransition(AutomatonState.Edge transition)
                           throws SchemaException
Add a wildcard transition from this state to another state.

Parameters:
transition - the edge representing the transition
Throws:
SchemaException

determinize

public void determinize()
                 throws SchemaException
Determinize the tree: that is, ensure that there are no ambiguous transitions from this state. When presented with an input token, the FSA can then examine the specific transitions from this state and either choose one of them, or throw an error.

Throws:
SchemaException - if while determinizing the finite state machine it is found to contain non-deterministic transitions.

getTransition

public AutomatonState.Edge getTransition(int token,
                                         NamePool pool)
Find the edge representing the transition from this state to another state, that is triggered by a given input token

Parameters:
token - the input token, specifically the fingerprint of an element name
Returns:
the new State of the finite state machine, or null if this token is not accepted when in this State (which implies a validation error).

listAllowedElements

public java.lang.CharSequence listAllowedElements()
List the allowed elements in this state as a string, for use in error messages

Returns:
the list of permitted elements as a string containing comma-separated element names

getWildcardEdges

public AutomatonState.Edge[] getWildcardEdges()
Get an iterator over the wildcard transitions (edges) allowed from this state.

Returns:
an Iterator over the edges that represent element wildcards. The objects returned by this Iterator are AutomatonState.Edge objects.

getEdges

public java.util.Iterator getEdges()
Get an iterator over all the transitions (edges) allowed from this state

Returns:
an Iterator over all the edges from this state. The objects returned by this Iterator are AutomatonState.Edge objects.

display

public void display(java.util.HashMap map)
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.