Class StateMachine
- java.lang.Object
-
- org.biojava.bio.program.tagvalue.StateMachine
-
- All Implemented Interfaces:
TagValueListener,TagValueWrapper
public class StateMachine extends Object implements TagValueWrapper
This class implements a state machine for parsing events from the Parser class.Each State can be specified to deliver events to a particular TagValueListener.
Transitions can be specified to occur between States when specific events are encountered. These events can be Tags delivered by startTag as well as the endTag/endRecord events. Events that result in exit from the current State can be specified to be notifiable to the State listener.
In addition, tables of transitions can be defined and specified as the fallback when the a corresponding Transition cannot be found for the tag. This is useful for specifying the destination States that are globally applicable for particular tags. As the fallbacks can be chained, you can end up with a hierarchy of Transition Tables, some being State-specific, others applicable to groups of States and finally one being global.
- Author:
- David Huen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classStateMachine.BasicStateImplementation of a State in a state machinestatic interfaceStateMachine.ExitNotificationInterface implemented by State listeners that want notification when a transition leaves the State.classStateMachine.SimpleStateListenera basic listener for a State.static interfaceStateMachine.StateInterface for a State within this StateMachineclassStateMachine.Transitionclass to represent a State TransitionclassStateMachine.TransitionTableTable of Transition destination States and their corresponding Tags.
-
Field Summary
Fields Modifier and Type Field Description protected TagValueListenerdelegateprotected static StringEND_RECORD_TAGprotected static StringEND_TAGprotected static StringMAGICAL_STATEprotected static StringSTART_RECORD_TAG
-
Constructor Summary
Constructors Constructor Description StateMachine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StateMachine.BasicStatecreateState(String label)StateMachine.TransitionTablecreateTransitionTable()voidendRecord()The current record has ended.voidendTag()End the current tag.TagValueListenergetDelegate()get listener to which all calls will be delegatedStateMachine.BasicStategetMagicalState()StateMachine.StategetState(String label)voidsetDelegate(TagValueListener delegate)TagValueWrapper interfacevoidstartRecord()A new record is about to start.voidstartTag(Object tag)TagValueListener interfacevoidvalue(TagValueContext ctxt, Object value)A value has been seen.
-
-
-
Field Detail
-
START_RECORD_TAG
protected static final String START_RECORD_TAG
- See Also:
- Constant Field Values
-
END_RECORD_TAG
protected static final String END_RECORD_TAG
- See Also:
- Constant Field Values
-
END_TAG
protected static final String END_TAG
- See Also:
- Constant Field Values
-
MAGICAL_STATE
protected static final String MAGICAL_STATE
- See Also:
- Constant Field Values
-
delegate
protected TagValueListener delegate
-
-
Constructor Detail
-
StateMachine
public StateMachine()
-
-
Method Detail
-
getMagicalState
public StateMachine.BasicState getMagicalState()
-
createState
public StateMachine.BasicState createState(String label)
-
getState
public StateMachine.State getState(String label)
-
createTransitionTable
public StateMachine.TransitionTable createTransitionTable()
-
setDelegate
public void setDelegate(TagValueListener delegate)
TagValueWrapper interface- Specified by:
setDelegatein interfaceTagValueWrapper
-
getDelegate
public TagValueListener getDelegate()
Description copied from interface:TagValueWrapperget listener to which all calls will be delegated- Specified by:
getDelegatein interfaceTagValueWrapper
-
startTag
public void startTag(Object tag) throws ParserException
TagValueListener interface- Specified by:
startTagin interfaceTagValueListener- Parameters:
tag- the Object representing the new tag- Throws:
ParserException- if the tag could not be started
-
endTag
public void endTag() throws ParserException
Description copied from interface:TagValueListenerEnd the current tag.- Specified by:
endTagin interfaceTagValueListener- Throws:
ParserException- if the tag could not be ended
-
startRecord
public void startRecord() throws ParserException
Description copied from interface:TagValueListenerA new record is about to start.- Specified by:
startRecordin interfaceTagValueListener- Throws:
ParserException- if the record can not be started
-
endRecord
public void endRecord() throws ParserException
Description copied from interface:TagValueListenerThe current record has ended.- Specified by:
endRecordin interfaceTagValueListener- Throws:
ParserException- if the record can not be ended
-
value
public void value(TagValueContext ctxt, Object value) throws ParserException
Description copied from interface:TagValueListenerA value has been seen.- Specified by:
valuein interfaceTagValueListener- Parameters:
ctxt- a TagValueContext that could be used to push a sub-documentvalue- the value Object observed- Throws:
ParserException- if the value could not be processed
-
-