org.biojava.bio.program.tagvalue
Class AnnotationBuilder

java.lang.Object
  extended by org.biojava.bio.program.tagvalue.AnnotationBuilder
All Implemented Interfaces:
TagValueListener

public class AnnotationBuilder
extends Object
implements TagValueListener

Builds an Annotation tree from TagValue events using an AnnotationType to work out which fields are of what type.

Since:
1.2
Author:
Matthew Pocock

Constructor Summary
AnnotationBuilder(AnnotationType type)
           Make a new AnnotationBuilder that will build Annotation instances of a given type.
 
Method Summary
 void endRecord()
          The current record has ended.
 void endTag()
          End the current tag.
 Annotation getLast()
           Get the last complete annotation built.
 void startRecord()
          A new record is about to start.
 void startTag(Object tag)
          Start a new tag.
 void value(TagValueContext ctxt, Object value)
          A value has been seen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationBuilder

public AnnotationBuilder(AnnotationType type)

Make a new AnnotationBuilder that will build Annotation instances of a given type.

The type is used to provide appropriate accessors for properties. As tag -value events stream through this TagValueListener, they will be matched against the properties of the annotation type. As sub-trees of events are pushed, child annotation bundles will be pushed into the appropriate properties. If any of the tag-value events are of a type that are not accepted by the annotation type, a ClassCastException will be thrown.

Parameters:
type - the AnnotationType stating what will be built and how
Throws:
ClassCastException - if any of the tag-value events are of inappropriate type
Method Detail

getLast

public Annotation getLast()

Get the last complete annotation built.

The value of this is undefined before the first annotation has been built and during the parsing of an event stream.

Returns:
the Annotation that was last built

startRecord

public void startRecord()
Description copied from interface: TagValueListener
A new record is about to start.

Specified by:
startRecord in interface TagValueListener

endRecord

public void endRecord()
Description copied from interface: TagValueListener
The current record has ended.

Specified by:
endRecord in interface TagValueListener

startTag

public void startTag(Object tag)
Description copied from interface: TagValueListener
Start a new tag.

Specified by:
startTag in interface TagValueListener
Parameters:
tag - the Object representing the new tag

value

public void value(TagValueContext ctxt,
                  Object value)
Description copied from interface: TagValueListener
A value has been seen.

Specified by:
value in interface TagValueListener
Parameters:
ctxt - a TagValueContext that could be used to push a sub-document
value - the value Object observed

endTag

public void endTag()
Description copied from interface: TagValueListener
End the current tag.

Specified by:
endTag in interface TagValueListener