001    // Java tool interface class RStoreContainerTool
002    // This file is generated automatically, please do not edit!
003    // generation time: Aug 14, 2007 5:22:04 PM
004    
005    package nl.cwi.sen1.visbase.rstorecontainer;
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 RStoreContainerTool
019      extends AbstractTool
020      implements RStoreContainerTif
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 PrcUnloadRstore0;
027      private ATerm PrcGetFactData0;
028      private ATerm PrcGetRstore0;
029      private ATerm PrcGetRstoreFacts0;
030      private ATerm PrcLoadRstore0;
031      private ATerm PrcLoadRstore1;
032      private ATerm PrecAckEvent0;
033      private ATerm PrecTerminate0;
034    
035      // Mimic the constructor from the AbstractTool class
036      protected RStoreContainerTool(ATermFactory factory)
037      {
038        super(factory);
039        initSigTable();
040        initPatterns();
041      }
042    
043      // This method initializes the table with input signatures
044      private void initSigTable()
045      {
046        sigTable.add(factory.parse("rec-eval(<rStoreContainer>,rc-load-rstore(<str>))"));
047        sigTable.add(factory.parse("rec-eval(<rStoreContainer>,rc-load-rstore(<str>,<term>))"));
048        sigTable.add(factory.parse("rec-ack-event(<rStoreContainer>,<term>)"));
049        sigTable.add(factory.parse("rec-eval(<rStoreContainer>,rc-get-rstore(<int>))"));
050        sigTable.add(factory.parse("rec-eval(<rStoreContainer>,rc-get-rstore-facts(<int>))"));
051        sigTable.add(factory.parse("rec-eval(<rStoreContainer>,rc-get-fact-data(<int>,<int>))"));
052        sigTable.add(factory.parse("rec-eval(<rStoreContainer>,rc-unload-rstore(<int>))"));
053        sigTable.add(factory.parse("rec-terminate(<rStoreContainer>,<term>)"));
054      }
055    
056      // Initialize the patterns that are used to match against incoming terms
057      private void initPatterns()
058      {
059        PrcUnloadRstore0 = factory.parse("rec-eval(rc-unload-rstore(<int>))");
060        PrcGetFactData0 = factory.parse("rec-eval(rc-get-fact-data(<int>,<int>))");
061        PrcGetRstore0 = factory.parse("rec-eval(rc-get-rstore(<int>))");
062        PrcGetRstoreFacts0 = factory.parse("rec-eval(rc-get-rstore-facts(<int>))");
063        PrcLoadRstore0 = factory.parse("rec-eval(rc-load-rstore(<str>))");
064        PrcLoadRstore1 = factory.parse("rec-eval(rc-load-rstore(<str>,<term>))");
065        PrecAckEvent0 = factory.parse("rec-ack-event(<term>)");
066        PrecTerminate0 = factory.parse("rec-terminate(<term>)");
067      }
068    
069      // The generic handler calls the specific handlers
070      public ATerm handler(ATerm term)
071      {
072        List<?> result;
073    
074        result = term.match(PrcUnloadRstore0);
075        if (result != null) {
076          return rcUnloadRstore(((Integer)result.get(0)).intValue());
077        }
078        result = term.match(PrcGetFactData0);
079        if (result != null) {
080          return rcGetFactData(((Integer)result.get(0)).intValue(), ((Integer)result.get(1)).intValue());
081        }
082        result = term.match(PrcGetRstore0);
083        if (result != null) {
084          return rcGetRstore(((Integer)result.get(0)).intValue());
085        }
086        result = term.match(PrcGetRstoreFacts0);
087        if (result != null) {
088          return rcGetRstoreFacts(((Integer)result.get(0)).intValue());
089        }
090        result = term.match(PrcLoadRstore0);
091        if (result != null) {
092          return rcLoadRstore((String)result.get(0));
093        }
094        result = term.match(PrcLoadRstore1);
095        if (result != null) {
096          return rcLoadRstore((String)result.get(0), (ATerm)result.get(1));
097        }
098        result = term.match(PrecAckEvent0);
099        if (result != null) {
100          recAckEvent((ATerm)result.get(0));
101          return null;
102        }
103        result = term.match(PrecTerminate0);
104        if (result != null) {
105          recTerminate((ATerm)result.get(0));
106          return null;
107        }
108    
109        notInInputSignature(term);
110        return null;
111      }
112    
113      // Check the input signature
114      public void checkInputSignature(ATermList sigs)
115      {
116        while(!sigs.isEmpty()) {
117          ATermAppl sig = (ATermAppl)sigs.getFirst();
118          sigs = sigs.getNext();
119          if (!sigTable.contains(sig)) {
120            // Sorry, but the term is not in the input signature!
121            notInInputSignature(sig);
122          }
123        }
124      }
125    
126      // This function is called when an input term
127      // was not in the input signature.
128      void notInInputSignature(ATerm t)
129      {
130        throw new RuntimeException("term not in input signature: " + t);
131      }
132    }