001 // Java tool interface class VisPluginTextUnparsingTool
002 // This file is generated automatically, please do not edit!
003 // generation time: Aug 22, 2007 2:40:01 PM
004
005 package nl.cwi.sen1.visplugin.text;
006
007 import java.util.HashSet;
008 import java.util.List;
009 import java.util.Set;
010
011 import toolbus.SwingTool;
012
013 import aterm.ATerm;
014 import aterm.ATermAppl;
015 import aterm.ATermFactory;
016 import aterm.ATermList;
017
018 abstract public class VisPluginTextUnparsingTool
019 extends SwingTool
020 implements VisPluginTextUnparsingTif
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 PdisplayUnparsedRtuple0;
027 private ATerm PrecAckEvent0;
028 private ATerm PrecTerminate0;
029
030 // Mimic the constructor from the AbstractTool class
031 protected VisPluginTextUnparsingTool(ATermFactory factory)
032 {
033 super(factory);
034 initSigTable();
035 initPatterns();
036 }
037
038 // This method initializes the table with input signatures
039 private void initSigTable()
040 {
041 sigTable.add(factory.parse("rec-eval(<lift-rstore>,lift-rstore(<term>))"));
042 sigTable.add(factory.parse("rec-eval(<lift-rstore>,lift-rtuple(<term>))"));
043 sigTable.add(factory.parse("rec-terminate(<lift-rstore>,<term>)"));
044 sigTable.add(factory.parse("rec-eval(<unparser>,unparse-asfix(<term>))"));
045 sigTable.add(factory.parse("rec-terminate(<unparser>,<term>)"));
046 sigTable.add(factory.parse("rec-ack-event(<vis-plugin-text-unparsing>,<term>)"));
047 sigTable.add(factory.parse("rec-do(<vis-plugin-text-unparsing>,display-unparsed-rtuple(<str>))"));
048 sigTable.add(factory.parse("rec-terminate(<vis-plugin-text-unparsing>,<term>)"));
049 }
050
051 // Initialize the patterns that are used to match against incoming terms
052 private void initPatterns()
053 {
054 PdisplayUnparsedRtuple0 = factory.parse("rec-do(display-unparsed-rtuple(<str>))");
055 PrecAckEvent0 = factory.parse("rec-ack-event(<term>)");
056 PrecTerminate0 = factory.parse("rec-terminate(<term>)");
057 }
058
059 // The generic handler calls the specific handlers
060 public ATerm handler(ATerm term)
061 {
062 List<?> result;
063
064 result = term.match(PdisplayUnparsedRtuple0);
065 if (result != null) {
066 displayUnparsedRtuple((String)result.get(0));
067 return null;
068 }
069 result = term.match(PrecAckEvent0);
070 if (result != null) {
071 recAckEvent((ATerm)result.get(0));
072 return null;
073 }
074 result = term.match(PrecTerminate0);
075 if (result != null) {
076 recTerminate((ATerm)result.get(0));
077 return null;
078 }
079
080 notInInputSignature(term);
081 return null;
082 }
083
084 // Check the input signature
085 public void checkInputSignature(ATermList sigs)
086 {
087 while(!sigs.isEmpty()) {
088 ATermAppl sig = (ATermAppl)sigs.getFirst();
089 sigs = sigs.getNext();
090 if (!sigTable.contains(sig)) {
091 // Sorry, but the term is not in the input signature!
092 notInInputSignature(sig);
093 }
094 }
095 }
096
097 // This function is called when an input term
098 // was not in the input signature.
099 void notInInputSignature(ATerm t)
100 {
101 throw new RuntimeException("term not in input signature: " + t);
102 }
103 }