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 023import java.io.PrintStream; 024 025/** 026 * This class prints to a PrintStream 027 * calls to the SearchContentHandler interface 028 * in human readable form. Use to debug parser/adaptor 029 * classes that output to the SearchContentHandler interface. 030 * @author David Huen 031 */ 032public class SearchContentHandlerDebugger 033 implements SearchContentHandler 034{ 035 private String [] margin = {"", "\t", "\t\t", "\t\t\t"}; 036 private int nesting = 0; 037 private boolean moreSearches = false; 038 039 /** 040 * Create an instance that dumps to System.out. 041 */ 042 public SearchContentHandlerDebugger() 043 { 044 } 045 046 /** 047 * @param pStream Stream to dump output to. 048 */ 049 public SearchContentHandlerDebugger(PrintStream pStream) 050 { 051 } 052 053 public void addHitProperty(Object key, Object value) 054 { 055 System.out.println(margin[nesting] + key.toString() + "->" + value.toString()); 056 } 057 058 public void addSubHitProperty(Object key, Object value) 059 { 060 System.out.println(margin[nesting] + key.toString() + "->" + value.toString()); 061 } 062 063 public void addSearchProperty(Object key, Object value) 064 { 065 System.out.println(margin[nesting] + key.toString() + "->" + value.toString()); 066 } 067 068 public void setMoreSearches(boolean value) { moreSearches = value; } 069 public boolean getMoreSearches() { return moreSearches; } 070 071 public void endHeader() { nesting--; } 072 public void endHit() { nesting--; } 073 public void endSearch() { nesting--; } 074 public void endSubHit() { nesting--; } 075 076 public void setDatabaseID(String databaseID) 077 { 078 System.out.println(margin[nesting] + "setDatabaseID: " + databaseID); 079 } 080 081 public void setQueryID(String queryID) 082 { 083 System.out.println(margin[nesting] + "setQueryID: " + queryID); 084 } 085 086 public void startHeader() 087 { 088 System.out.println(margin[nesting] + "Start header"); 089 nesting++; 090 } 091 092 public void startHit() 093 { 094 System.out.println(margin[nesting] + "Start hit"); 095 nesting++; 096 } 097 098 public void startSearch() 099 { 100 System.out.println(margin[nesting] + "Start search"); 101 nesting++; 102 } 103 104 public void startSubHit() 105 { 106 System.out.println(margin[nesting] + "Start subhit"); 107 nesting++; 108 } 109} 110