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 */
021package org.biojava.bio.search;
022
023
024/**
025 * <p>
026 * Filtering implementation of SearchContentHandler that by default passes
027 * all messages on to the next delegate in the chain.
028 * </p>
029 *
030 * <p>
031 * In this handler, all info will be passed onto a delegate handler. You can
032 * build up a chain of filters by using one filter as the delegate for
033 * another. When you over-ride a method in a filter, you can modify any
034 * state you wish. If you want that to propogate on, you should call
035 * the method on yourself via super.(), if not, just return.
036 * </p>
037 *
038 * <p>
039 * It is your responsibility to ensure that the events emitted from your filter
040 * are sensible. In particular, start/end messages must be paired even after
041 * filtering.
042 * </p>
043 *
044 * <h2>Example</h2>
045 *
046 * <pre>
047 * // we have a handler from somewhere
048 * SearchContentHandler handler = ...;
049 *
050 * // now we are going to mutate all "score" notifications to Double instances
051 * // from strings
052 * SearchContentHandler filter = new SearchContentFilter() {
053 *   public void addHitProperty(Object key, Object value) {
054 *     if("score".equals(key)) {
055 *       if(value instanceof String) {
056 *         value = new Double(value);
057 *       }
058 *     }
059 *     super(key, value);
060 *   }
061 * };
062 * </pre>
063 *
064 * @author Matthew Pocock
065 * @since 1.3
066 */
067public class SearchContentFilter
068implements SearchContentHandler {
069  private final SearchContentHandler delegate;
070
071  public SearchContentFilter(SearchContentHandler delegate) {
072    this.delegate = delegate;
073  }
074
075  public void addHitProperty(Object key, Object value) {
076    delegate.addHitProperty(key, value);
077  }
078
079  public void addSearchProperty(Object key, Object value) {
080    delegate.addSearchProperty(key, value);
081  }
082
083  public void addSubHitProperty(Object key, Object value) {
084    delegate.addSubHitProperty(key, value);
085  }
086
087  public void startHeader() {
088    delegate.startHeader();
089  }
090
091  public void endHeader() {
092    delegate.endHeader();
093  }
094
095  public void startHit() {
096    delegate.startHit();
097  }
098
099  public void endHit() {
100    delegate.endHit();
101  }
102
103  public void startSearch() {
104    delegate.startSearch();
105  }
106
107  public void endSearch() {
108    delegate.endSearch();
109  }
110
111  public void startSubHit() {
112    delegate.startSubHit();
113  }
114
115  public void endSubHit() {
116    delegate.endSubHit();
117  }
118
119  public void setQueryID(String queryID) {
120      delegate.setQueryID(queryID);
121  }
122
123  public void setDatabaseID(String databaseID) {
124      delegate.setDatabaseID(databaseID);
125  }
126
127  public boolean getMoreSearches() {
128    return delegate.getMoreSearches();
129  }
130
131  public void setMoreSearches(boolean val) {
132    delegate.setMoreSearches(val);
133  }
134}