1 package org.andromda.andromdapp;
2
3 import java.util.LinkedHashMap;
4 import java.util.Map;
5
6
7
8
9
10
11
12 public class Condition
13 {
14
15
16
17 private String id;
18
19
20
21
22
23
24 public String getId()
25 {
26 return id;
27 }
28
29
30
31
32
33
34 public void setId(final String id)
35 {
36 this.id = id;
37 }
38
39
40
41
42 private final Map<String, Object> properties = new LinkedHashMap<String, Object>();
43
44
45
46
47
48
49
50
51
52
53 public void setProperty(
54 final String id,
55 final String value,
56 final String type)
57 {
58 this.properties.put(
59 id,
60 AndroMDAppUtils.convert(
61 value,
62 type));
63 }
64
65
66
67
68
69
70 public Map<String, Object> getProperties()
71 {
72 return this.properties;
73 }
74
75
76
77
78 private String equal;
79
80
81
82
83
84
85 public String getEqual()
86 {
87 return equal;
88 }
89
90
91
92
93
94
95 public void setEqual(final String equal)
96 {
97 this.equal = equal;
98 }
99
100
101
102
103 private String notEqual;
104
105
106
107
108
109
110 public String getNotEqual()
111 {
112 return notEqual;
113 }
114
115
116
117
118
119
120 public void setNotEqual(final String notEqual)
121 {
122 this.notEqual = notEqual;
123 }
124
125
126
127
128 private Boolean present;
129
130
131
132
133
134
135 public void setPresent(final boolean present)
136 {
137 this.present = Boolean.valueOf(present);
138 }
139
140
141
142
143
144
145
146 public boolean evaluate(Object value)
147 {
148 boolean valid = true;
149 if (this.present != null)
150 {
151
152 if (this.present.booleanValue())
153 {
154 valid = value != null;
155 }
156 else if (!this.present.booleanValue())
157 {
158
159 valid = value == null;
160 }
161 }
162 if (valid)
163 {
164 final String equal = this.getEqual();
165 final String notEqual = this.getNotEqual();
166 final boolean equalConditionPresent = equal != null;
167 final boolean notEqualConditionPresent = notEqual != null;
168 value = String.valueOf(value);
169 if (equalConditionPresent && equal != null)
170 {
171 valid = equal.equals(value);
172 }
173 else if (notEqualConditionPresent && notEqual != null)
174 {
175 valid ^= notEqual.equals(value);
176 }
177 }
178 return valid;
179 }
180
181
182
183
184 public String toString()
185 {
186 return super.toString() + "[id=" + this.id + ", equal=" + this.equal + ", notEqual=" + this.notEqual + ']';
187 }
188 }