001package jmri.jmrit.logixng.util.parser; 002 003import jmri.InstanceManager; 004import jmri.JmriException; 005import jmri.jmrit.logixng.SymbolTable; 006 007/** 008 * A variable that evaluates a local variable 009 */ 010public class LocalVariableExpressionVariable implements Variable { 011 012 private final String _name; 013 014 public LocalVariableExpressionVariable(String name) { 015 _name = name; 016 } 017 018 @Override 019 public String getName() { 020 return _name; 021 } 022 023 @Override 024 public Object getValue(SymbolTable symbolTable) throws JmriException { 025 try { 026 return symbolTable.getValue(_name); 027 } catch (SymbolTable.SymbolNotFound e) { 028 Constant constant = InstanceManager.getDefault(FunctionManager.class).getConstant(_name); 029 if (constant != null) return constant.getValue(); 030 throw e; 031 } 032 } 033 034 @Override 035 public void setValue(SymbolTable symbolTable, Object value) throws JmriException { 036 symbolTable.setValue(_name, value); 037 } 038 039}