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.bio.program.tagvalue;
023
024import org.biojava.utils.ParserException;
025
026/**
027 * <p>
028 * Helper class to wrap one TagValueListener inside another one.
029 * </p>
030 *
031 * <p>
032 * Implementations will tend to intercept the tags or values as they stream
033 * through and modify them in some manner before forwarding them to the delegate
034 * listener. Using classes derived from SimpleTagValueWrapper, it is possible to build
035 * up complex chains of handlers that process and collate information as it
036 * streams through.
037 * </p>
038 *
039 * @author Matthew Pocock
040 * @author David Huen (change of TagValueWrapper to interface)
041 * @since 1.2
042 */
043public abstract class SimpleTagValueWrapper
044  implements
045    TagValueWrapper
046{
047  private TagValueListener delegate;
048  
049  /**
050   * Build a SimpleTagValueWrapper that will forward everything to a delegate.
051   *
052   * @param delegate the SimpleTagValueWrapper to forward events to
053   */
054  public SimpleTagValueWrapper(TagValueListener delegate) {
055    this.delegate = delegate;
056  }
057
058  public SimpleTagValueWrapper() {
059    delegate = null;
060  }
061  
062  public TagValueListener getDelegate() {
063    return delegate;
064  }
065
066  public void setDelegate(TagValueListener delegate) {
067    this.delegate = delegate;
068  }
069  
070  public void startRecord()
071  throws ParserException {
072    delegate.startRecord();
073  }
074  
075  public void endRecord()
076  throws ParserException {
077    delegate.endRecord();
078  }
079  
080  public void startTag(Object tag)
081  throws ParserException {
082    delegate.startTag(tag);
083  }
084  
085  public void endTag()
086  throws ParserException {
087    delegate.endTag();
088  }
089  
090  public void value(TagValueContext ctxt, Object value)
091  throws ParserException {
092    delegate.value(ctxt, value);
093  }
094}
095