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 1, 2002
015 */
016 public class RecVal extends Atom{
017 private final Ref toolId;
018 private final Ref result;
019 private ToolInstance toolInstance;
020
021 public RecVal(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-value";
028 }
029
030 public ProcessExpression copy(){
031 Atom a = new RecVal(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.getValueFromTool(result.value, getEnv())){
052 // LoggerFactory.log(this.getProcess().getProcessName(), "RecVal " + res, IToolBusLoggerConstants.TOOLCOM);
053 // LoggerFactory.log(this.getProcess().getProcessName(), "RecVal " + res,
054 // IToolBusLoggerConstants.TOOLCOM);
055 // LoggerFactory.log(this.getProcess().getProcessName(), "RecVal " + getEnv(),
056 // IToolBusLoggerConstants.TOOLCOM);
057
058 return true;
059 }
060 return false;
061 }
062 }