001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021 022package org.biojava.ontology; 023 024import org.biojava.bio.Annotatable; 025import org.biojava.bio.Annotation; 026import org.biojava.bio.BioRuntimeException; 027import org.biojava.utils.AbstractChangeable; 028import org.biojava.utils.ChangeEvent; 029import org.biojava.utils.ChangeForwarder; 030import org.biojava.utils.ChangeSupport; 031import org.biojava.utils.ChangeType; 032 033/** 034 * Abstract implementation of term 035 * 036 * This provides basic change-forwarding functionality from 037 * the annotation and ontology properties. 038 * 039 * @author Thomas Down 040 * @since 1.4 041 */ 042 043public abstract class AbstractTerm extends AbstractChangeable implements Term { 044 private transient ChangeForwarder forwarder; 045 protected String description; 046 047 public ChangeSupport getChangeSupport(ChangeType ct) { 048 ChangeSupport cs = super.getChangeSupport(ct); 049 forwarder = new ChangeForwarder(this, cs) { 050 protected ChangeEvent generateEvent(ChangeEvent cev) { 051 if (cev.getSource() instanceof Ontology) { 052 return new ChangeEvent( 053 getSource(), 054 Term.ONTOLOGY, 055 getOntology(), 056 null, 057 cev 058 ); 059 } else if (cev.getSource() instanceof Annotation) { 060 return new ChangeEvent( 061 getSource(), 062 Annotatable.ANNOTATION, 063 getAnnotation(), 064 null, 065 cev 066 ); 067 } else { 068 throw new BioRuntimeException("Unknown event"); 069 } 070 } 071 } ; 072 getAnnotation().addChangeListener(forwarder, ChangeType.UNKNOWN); 073 getOntology().addChangeListener(forwarder, ChangeType.UNKNOWN); 074 return cs; 075 } 076 077 public void setDescription(String description){ 078 this.description = description; 079 } 080}