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 * Rename tags using a TagMapper.
029 * </p>
030 *
031 * <p> 
032 * This will rename tags as they stream into this listener using a TagMapper.
033 * Once renamed, the events will be forwarded onto a delegate TagValueListener
034 * for further processing.
035 * </p>
036 *
037 * @author Matthew Pocock
038 * @since 1.2
039 */
040public class TagRenamer extends SimpleTagValueWrapper {
041  private PropertyChanger mapper;
042  
043  /**
044   * Build a new TagRenamer with a delegate and mapper.
045   *
046   * @param delegate TagValueListener to pass mapped events onto
047   * @param mapper TagMapper used to rename tags
048   */
049  public TagRenamer(TagValueListener delegate, PropertyChanger mapper) {
050    super(delegate);
051    this.mapper = mapper;
052  }
053  
054  /**
055   * Retrieve the mapper used to rename tags
056   *
057   * @return the current mapper
058   */
059  public PropertyChanger getMapper() {
060    return mapper;
061  }
062  
063  public void startTag(Object tag)
064  throws ParserException {
065    Object newTag = mapper.getNewTag(tag);
066    if(newTag != null) {
067      tag = newTag;
068    }
069    
070    super.startTag(tag);
071  }
072}
073