001 package toolbus.tifs; 002 003 import java.util.ArrayList; 004 import java.util.Iterator; 005 import java.util.List; 006 007 import aterm.AFun; 008 import aterm.ATerm; 009 import aterm.ATermAppl; 010 011 abstract public class Communication{ 012 private final ATermAppl representation; 013 private final List<String> argumentList; 014 015 public Communication(ATerm t){ 016 representation = (ATermAppl) t; 017 018 argumentList = new ArrayList<String>(); 019 initArgumentList(); 020 } 021 022 protected ATermAppl getRepresentation(){ 023 return representation; 024 } 025 026 public String getName(){ 027 ATermAppl resultTerm = (ATermAppl) representation.getArgument(0); 028 return resultTerm.getAFun().getName(); 029 } 030 031 public String getResultType(){ 032 return "void"; 033 } 034 035 public Iterator<String> fetchArgumentIterator(){ 036 return argumentList.iterator(); 037 } 038 039 private void initArgumentList(){ 040 ATermAppl args = (ATermAppl) representation.getArgument(0); 041 int arity = args.getArity(); 042 for(int i = 0; i < arity; i++){ 043 ATermAppl arg = (ATermAppl) args.getArgument(i); 044 String typeName = arg.getAFun().getName(); 045 argumentList.add(typeName); 046 } 047 } 048 049 public static Communication create(ATermAppl appl){ 050 AFun fun = appl.getAFun(); 051 String name = fun.getName(); 052 053 // <yuck> 054 if(name.equals("eval")){ 055 return new Eval(appl); 056 }else if(name.equals("do")){ 057 return new Do(appl); 058 }else if(name.equals("event")){ 059 return new Event(appl); 060 } 061 // </yuck> 062 063 throw new RuntimeException("illegal communication construct: " + name); 064 } 065 066 }