1
14
15package org.tp23.antinstaller.input;
16
17import org.tp23.antinstaller.InstallerContext;
18import org.tp23.antinstaller.ValidationException;
19import org.tp23.antinstaller.runtime.ConfigurationException;
20import org.tp23.antinstaller.runtime.logic.Expression;
21import org.tp23.antinstaller.runtime.logic.ExpressionBuilder;
22
23
32public class ConditionalField extends InputField {
33
34 private String ifProperty;
35 private Expression expression;
36 private InputField[] fields;
37
38 public void setIfProperty(final String expressionStr) {
39 this.ifProperty = expressionStr;
40 }
41
42 public String getIfProperty() {
43 return ifProperty;
44 }
45
46 public InputField[] getFields() {
47 return fields;
48 }
49
50 public void setFields(InputField[] fields) {
51 this.fields = fields;
52 }
53
54
61 public boolean validate(InstallerContext context)
62 throws ValidationException {
63 try {
64 getExpression();
65 if ((fields != null) && (fields.length > 0)) {
66 int i = 0;
67 for (; (i < fields.length) && (fields[i].validate(context)); i++) {
68 }
69
70 if (i == fields.length) {
71 return true;
72 }
73 }
74 } catch (ConfigurationException configExc) {
75 if(context.getInstaller().isVerbose()) {
76 context.log(configExc);
77 }
78 }
79 return false;
80 }
81
82
87 public boolean validateObject() {
88 try {
89 getExpression();
90 if ((fields != null) && (fields.length > 0)) {
91 int i = 0;
92 for (; (i < fields.length) && (fields[i].validateObject()); i++) {
93 }
94
95 if (i == fields.length) {
96 return true;
97 }
98
99 System.out.println("Invalid field:" + fields[i]);
00 }
01 } catch (ConfigurationException configExc) {
02 System.out.println("Invalid conditional expression: " + configExc);
03 }
04 return false;
05 }
06
07
12 public Expression getExpression() throws ConfigurationException {
13 if (expression == null) {
14 expression = ExpressionBuilder.parseLogicalExpressions(resultContainer, ifProperty);
15 }
16
17 return expression;
18 }
19}
20