001 package toolbus.tifs; 002 003 import java.util.ArrayList; 004 import java.util.Iterator; 005 import java.util.List; 006 007 import aterm.ATerm; 008 import aterm.ATermAppl; 009 import aterm.ATermInt; 010 import aterm.ATermList; 011 012 public class Tif{ 013 private final ATermAppl representation; 014 private final List<Process> processList; 015 016 public Tif(ATerm t){ 017 representation = (ATermAppl) t; 018 019 processList = new ArrayList<Process>(); 020 initProcessList(); 021 } 022 023 public int getVersion(){ 024 ATermAppl versionTerm = (ATermAppl) representation.getArgument(0); 025 return ((ATermInt) versionTerm.getArgument(0)).getInt(); 026 } 027 028 public String getPackageName(){ 029 ATermAppl pkgTerm = (ATermAppl) representation.getArgument(1); 030 return ((ATermAppl) pkgTerm.getArgument(0)).getAFun().getName(); 031 } 032 033 public String getToolName(){ 034 ATermAppl toolTerm = (ATermAppl) representation.getArgument(2); 035 return ((ATermAppl) toolTerm.getArgument(0)).getAFun().getName(); 036 } 037 038 private void initProcessList(){ 039 ATermList iter = (ATermList) representation.getArgument(3); 040 while(!iter.isEmpty()){ 041 processList.add(new Process(iter.getFirst())); 042 iter = iter.getNext(); 043 } 044 } 045 046 public Iterator<Process> fetchProcessIterator(){ 047 return processList.iterator(); 048 } 049 050 public String toString(){ 051 Iterator<Process> iter; 052 StringBuilder buf = new StringBuilder(); 053 buf.append("tifs"); 054 buf.append('('); 055 buf.append("version"); 056 buf.append('('); 057 buf.append(getVersion()); 058 buf.append(')'); 059 buf.append(','); 060 buf.append("package"); 061 buf.append('('); 062 buf.append('"'); 063 buf.append(getPackageName()); 064 buf.append('"'); 065 buf.append(')'); 066 buf.append(','); 067 buf.append("tool"); 068 buf.append('('); 069 buf.append('"'); 070 buf.append(getToolName()); 071 buf.append('"'); 072 buf.append(')'); 073 buf.append(','); 074 buf.append('['); 075 iter = fetchProcessIterator(); 076 while(iter.hasNext()){ 077 Process process = iter.next(); 078 buf.append(process); 079 if(iter.hasNext()){ 080 buf.append(','); 081 } 082 } 083 buf.append(']'); 084 buf.append(')'); 085 086 return buf.toString(); 087 } 088 089 }