01: /*
02: * Licensed under the Apache License, Version 2.0 (the "License");
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at
05: *
06: * http://www.apache.org/licenses/LICENSE-2.0
07: *
08: * Unless required by applicable law or agreed to in writing, software
09: * distributed under the License is distributed on an "AS IS" BASIS,
10: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: * See the License for the specific language governing permissions and
12: * limitations under the License.
13: */
14:
15: package org.tp23.antinstaller.runtime.logic;
16:
17: import org.tp23.antinstaller.input.ResultContainer;
18: import org.tp23.antinstaller.runtime.ConfigurationException;
19:
20: /**
21: * @author mwilson
22: * @version $Id: SimpleExpression.java,v 1.1 2006/09/08 19:16:30 anothermwilson
23: * Exp $
24: * @since 0.7.4 patch 2
25: */
26: public 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(final ResultContainer resultContainer,
35: final String value1, final ValuesTest test,
36: final String value2) throws ConfigurationException {
37:
38: this .literalValue1 = value1;
39: this .value1 = getValue(resultContainer, value1);
40: this .testCondition = test;
41: this .literalValue2 = value2;
42: this .value2 = getValue(resultContainer, value2);
43:
44: }
45:
46: public boolean evaluate() {
47: return testCondition.getTestResult(value1, value2);
48: }
49:
50: private Value getValue(ResultContainer container, String valueStr)
51: throws ConfigurationException {
52: if ((valueStr.length() > 0) && (valueStr.charAt(0) == '$')) {
53: if (valueStr.startsWith("${") && valueStr.endsWith("}")) {
54: return new VariableValue(container, valueStr);
55: } else {
56: throw new ConfigurationException(
57: "Badly formed variable: '" + valueStr + "'");
58: }
59: } else {
60: return new LiteralValue(valueStr);
61: }
62: }
63:
64: public String toString() {
65: return "[" + literalValue1 + "==" + literalValue2 + "]";
66: }
67: }
|