001 package toolbus.atom.tool; 002 003 import toolbus.TBTermFactory; 004 import toolbus.TBTermVar; 005 import toolbus.atom.Atom; 006 import toolbus.atom.Ref; 007 import toolbus.exceptions.ToolBusException; 008 import toolbus.parsercup.PositionInformation; 009 import toolbus.process.ProcessExpression; 010 import toolbus.tool.ToolInstance; 011 import aterm.ATerm; 012 013 /** 014 * @author paulk, Aug 7, 2002 015 */ 016 public class Event extends Atom{ 017 private final Ref toolId; 018 private final Ref result; 019 private ToolInstance toolInstance; 020 021 public Event(ATerm toolId, ATerm result, TBTermFactory tbfactory, PositionInformation posInfo){ 022 super(tbfactory, posInfo); 023 024 this.toolId = new Ref(toolId); 025 this.result = new Ref(result); 026 setAtomArgs(new Ref[]{this.toolId, this.result}); 027 externalNameAsReceivedByTool = "snd-event"; 028 } 029 030 public ProcessExpression copy(){ 031 Atom a = new Event(toolId.value, result.value, tbfactory, getPosInfo()); 032 a.copyAtomAttributes(this); 033 034 return a; 035 } 036 037 public void activate(){ 038 toolInstance = null; 039 super.activate(); 040 } 041 042 public boolean execute() throws ToolBusException{ 043 if(!isEnabled()) return false; 044 045 if(toolInstance == null){ 046 ATerm tid = getEnv().getValue((TBTermVar) toolId.value); 047 toolInstance = getToolBus().getToolInstanceManager().get(tid); 048 if(toolInstance == null) return false; 049 } 050 051 if(toolInstance.getEventFromTool(result.value, getEnv())){ 052 //LoggerFactory.log(this.getProcess().getProcessName(), "Event " + result.value, IToolBusLoggerConstants.TOOLCOM); 053 return true; 054 } 055 return false; 056 } 057 }