com.saxonica.schema.fsa
Class AutomatonState

java.lang.Object
  extended by com.saxonica.schema.fsa.AutomatonState
All Implemented Interfaces:
State, Serializable
Direct Known Subclasses:
DeterminizedState, NonDeterminizedState

public abstract class AutomatonState
extends Object
implements State

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.

See Also:
Serialized Form

Field Summary
static Edge[] EMPTY_EDGE_ARRAY
           
protected  Edge[] wildcardEdges
           
 
Constructor Summary
AutomatonState(FiniteStateMachine machine)
          Create a new state
 
Method Summary
 void 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 displayLambdaTransitions()
          Display the lambda transitions available from this state
 void displayState(PrintStream err)
          Display the finite state machine reachable from this state.
 Iterator<Edge> getEdges()
          Get an iterator over all the transitions (edges) allowed from this state
 Edge getMaxTransition()
          Get the transition to be used when the maxOccurs value is reached for a counting state.
 int getStateNumber()
          Get the state number
 Edge getTransition(int token, UserComplexType type)
          Find the edge representing the transition from this state to another state, that is triggered by a given input token
 Edge[] getWildcardEdges()
          Get an iterator over the wildcard transitions (edges) allowed from this state.
 boolean isConditionallyFinalState()
          Test whether this state is a final state assuming the counter has reached its minimum value
 boolean isFinalState()
          Test whether this state is a final state
 CharSequence listAllowedElements()
          List the allowed elements in this state as a string, for use in error messages
 boolean requiresCounter()
          Ask whether this is a counting state
 void serialize(SchemaModelSerializer serializer)
          Serialize this state as part of the serialization of a schema component model
 void setFinalState(boolean finalState)
          Set this state to be (or not to be) a final state
 void setLimits(int min, int max)
          Set the counter limits
 void setMaxTransition(Edge edge)
          A counting state may have a special Edge that is used when the maxOccurs value is reached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wildcardEdges

protected Edge[] wildcardEdges

EMPTY_EDGE_ARRAY

public static final Edge[] EMPTY_EDGE_ARRAY
Constructor Detail

AutomatonState

public AutomatonState(FiniteStateMachine machine)
Create a new state

Parameters:
machine - the finite state machine to which this State belongs
Method Detail

isFinalState

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

Specified by:
isFinalState in interface State
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

public void addSpecificTransition(Edge edge,
                                  SchemaCompiler compiler)
                           throws SchemaException
Add a specific transition from this state to another state. This transition accepts a specific element name only.

Parameters:
edge - the transition to be added
compiler - the schema compiler
Throws:
SchemaException - if there are two transitions for the same element declaration, that is, if the content model is ambiguous

addWildcardTransition

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

Parameters:
compiler - the schema compiler
transition - 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 used
max - 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

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

Specified by:
getTransition in interface State
Parameters:
token - the input token, specifically the fingerprint of an element name
type - 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

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

Specified by:
listAllowedElements in interface State
Returns:
the list of permitted elements as a string containing comma-separated element names

getWildcardEdges

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

Specified by:
getWildcardEdges in interface State
Returns:
an Iterator over the edges that represent element wildcards. The objects returned by this Iterator are Edge objects.

getEdges

public Iterator<Edge> getEdges()
Get an iterator over all the transitions (edges) allowed from this state

Specified by:
getEdges in interface State
Returns:
an Iterator over all the edges from this state. The objects returned by this Iterator are Edge objects.

display

public void display(HashMap<AutomatonState,Integer> 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.

displayState

public void displayState(PrintStream err)
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

public void setMaxTransition(Edge edge)
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

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

public void serialize(SchemaModelSerializer serializer)
               throws XPathException
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


Copyright (c) 2004-2011 Saxonica Limited. All rights reserved.