001 // Java tool interface class ConsoleGrabberTool 002 // This file is generated automatically, please do not edit! 003 // generation time: Feb 23, 2007 1:41:31 PM 004 005 package nl.cwi.sen1.consolegrabber; 006 007 import java.util.HashSet; 008 import java.util.List; 009 import java.util.Set; 010 011 import toolbus.AbstractTool; 012 013 import aterm.ATerm; 014 import aterm.ATermAppl; 015 import aterm.ATermFactory; 016 import aterm.ATermList; 017 018 abstract public class ConsoleGrabberTool 019 extends AbstractTool 020 implements ConsoleGrabberTif 021 { 022 // This table will hold the complete input signature 023 private Set<ATerm> sigTable = new HashSet<ATerm>(); 024 025 // Patterns that are used to match against incoming terms 026 private ATerm PrecAckEvent0; 027 private ATerm PrecTerminate0; 028 029 // Mimic the constructor from the AbstractTool class 030 protected ConsoleGrabberTool(ATermFactory factory) 031 { 032 super(factory); 033 initSigTable(); 034 initPatterns(); 035 } 036 037 // This method initializes the table with input signatures 038 private void initSigTable() 039 { 040 sigTable.add(factory.parse("rec-ack-event(<console-grabber>,<term>)")); 041 sigTable.add(factory.parse("rec-terminate(<console-grabber>,<term>)")); 042 } 043 044 // Initialize the patterns that are used to match against incoming terms 045 private void initPatterns() 046 { 047 PrecAckEvent0 = factory.parse("rec-ack-event(<term>)"); 048 PrecTerminate0 = factory.parse("rec-terminate(<term>)"); 049 } 050 051 // The generic handler calls the specific handlers 052 public ATerm handler(ATerm term) 053 { 054 List<?> result; 055 056 result = term.match(PrecAckEvent0); 057 if (result != null) { 058 recAckEvent((ATerm)result.get(0)); 059 return null; 060 } 061 result = term.match(PrecTerminate0); 062 if (result != null) { 063 recTerminate((ATerm)result.get(0)); 064 return null; 065 } 066 067 notInInputSignature(term); 068 return null; 069 } 070 071 // Check the input signature 072 public void checkInputSignature(ATermList sigs) 073 { 074 while(!sigs.isEmpty()) { 075 ATermAppl sig = (ATermAppl)sigs.getFirst(); 076 sigs = sigs.getNext(); 077 if (!sigTable.contains(sig)) { 078 // Sorry, but the term is not in the input signature! 079 notInInputSignature(sig); 080 } 081 } 082 } 083 084 // This function is called when an input term 085 // was not in the input signature. 086 void notInInputSignature(ATerm t) 087 { 088 throw new RuntimeException("term not in input signature: " + t); 089 } 090 }