org.biojava.bio
Interface Annotatable

All Superinterfaces:
Changeable
All Known Subinterfaces:
Alphabet, AtomicSymbol, BasisSymbol, ComponentFeature, DotState, EmissionState, Feature, FeatureTypes.Repository, FeatureTypes.Type, FiniteAlphabet, FramedFeature, GappedSequence, HomologyFeature, ModelInState, RemoteFeature, RestrictionSite, SeqSimilaritySearchHit, SeqSimilaritySearchResult, SeqSimilaritySearchSubHit, Sequence, SimilarityPairFeature, State, StrandedFeature, Symbol, SymbolTokenization, Taxon, UnigeneCluster
All Known Implementing Classes:
AbstractAlphabet, AbstractSymbol, AbstractTaxon, CharacterTokenization, DoubleAlphabet, DoubleAlphabet.DoubleRange, DoubleAlphabet.DoubleSymbol, DoubleAlphabet.SubDoubleAlphabet, DummySequence, FeatureTypes.RepositoryImpl, FundamentalAtomicSymbol, IntegerAlphabet, IntegerAlphabet.IntegerSymbol, ProjectedFeature, ProjectedStrandedFeature, org.biojava.bio.seq.ragbag.RagbagAbstractSequence, SequenceDBSearchHit, SequenceDBSearchResult, SequenceDBSearchSubHit, SimpleAssembly, SimpleAtomicSymbol, org.biojava.bio.symbol.SimpleBasisSymbol, SimpleDotState, SimpleEmissionState, SimpleFeature, SimpleFramedFeature, SimpleGappedSequence, SimpleHomologyFeature, SimpleModelInState, SimpleRemoteFeature, SimpleRestrictionSite, SimpleSeqSimilaritySearchHit, SimpleSeqSimilaritySearchResult, SimpleSeqSimilaritySearchSubHit, SimpleSequence, SimpleSimilarityPairFeature, SimpleStrandedFeature, org.biojava.bio.symbol.SimpleSymbol, SingletonAlphabet, SubSequence, ViewSequence, WordTokenization

public interface Annotatable
extends Changeable

Indicates that an object has an associated annotation.

Many BioJava objects will have associated unstructured data. This should be stored in an Annotation instance. However, the BioJava object itself will probably not want to extend the Annotation interface directly, but rather delegate off that functionality to an Annotation property. The Annotatable interface indicates that there is an Annoation porperty. It also provides an inner class called AnnotationForwarder. When implementing Annotatable, you should always create a protected or private field containing an instance of AnnotationForwarder, and register it as a ChangeListener with the associated Annotation delegate instance.

 public class Foo extends AbstractChangeable implements Annotatable {
   private Annotation ann; // the associated annotation delegate
   protected ChangeListener annFor; // the event forwarder

   public Foo() {
     // make the ann delegate
     ann = new SimpleAnnotation();

     annFor = new Annotatable.AnnotationForwarder(
       this, // this is the source of the new events
       getChangeSupport(Annotatable.ANNOTATION) // the type of the events
     );

     // add the forwarder to our ann delegate
     ann.addChangeListener(annFor, Annotatable.ANNOTATION);
   }

   public Annotation getAnnotation() {
     return ann;
   }
 }
 

Author:
Matthew Pocock, Keith James (docs).
For general use:
Check if BioJava classes and interfaces extend Annotatable. This will tell you if you should look for associated annotation
For advanced users:
If an object implements Annotatable, it may well propogate ChangeEvent notifications from the associated Annotation. You may need to track these to maintain the state of your applications.
For developers:
Be careful to hook up the appropreate event forwarders.

The getAnnotation() method can be implemented lazily (instantiate the Annotation instance and event forwarders when the first request comes in). It can also be implemented by returning throw-away immutable Annotatoin instances that are built from scratch each time.

Nested Class Summary
static class Annotatable.AnnotationForwarder
          A helper class so that you don't have to worry about forwarding events from the Annotation object to the Annotatable one.
 
Field Summary
static ChangeType ANNOTATION
          Signals that the associated Annotation has altered in some way.
 
Method Summary
 Annotation getAnnotation()
          Should return the associated annotation object.
 
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
 

Field Detail

ANNOTATION

public static final ChangeType ANNOTATION
Signals that the associated Annotation has altered in some way. The chainedEvent property should refer back to the event fired by the Annotation object.

Method Detail

getAnnotation

public Annotation getAnnotation()
Should return the associated annotation object.

Returns:
an Annotation object, never null