1
14
15package org.tp23.antinstaller.runtime.logic;
16
17import org.tp23.antinstaller.input.ResultContainer;
18import org.tp23.antinstaller.runtime.ConfigurationException;
19
20
26public class SimpleExpression implements Expression {
27
28 private final Value value1;
29 private final ValuesTest testCondition;
30 private final Value value2;
31 private final String literalValue1;
32 private final String literalValue2;
33
34 public SimpleExpression(
35 final ResultContainer resultContainer,
36 final String value1,
37 final ValuesTest test,
38 final String value2)
39 throws ConfigurationException {
40
41 this.literalValue1 = value1;
42 this.value1 = getValue(resultContainer, value1);
43 this.testCondition = test;
44 this.literalValue2 = value2;
45 this.value2 = getValue(resultContainer, value2);
46
47 }
48
49 public boolean evaluate() {
50 return testCondition.getTestResult(value1, value2);
51 }
52
53 private Value getValue(ResultContainer container, String valueStr) throws ConfigurationException {
54 if ( (valueStr.length() > 0) && (valueStr.charAt(0) == '$') ) {
55 if ( valueStr.startsWith("${") && valueStr.endsWith("}") ) {
56 return new VariableValue(container, valueStr);
57 } else {
58 throw new ConfigurationException("Badly formed variable: '" + valueStr + "'");
59 }
60 } else {
61 return new LiteralValue(valueStr);
62 }
63 }
64
65 public String toString() {
66 return "[" + literalValue1 + "==" + literalValue2 + "]";
67 }
68}
69