1 package org.andromda.andromdapp;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import org.apache.commons.lang.StringUtils;
6
7
8
9
10
11
12 public class Prompt
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 boolean required = true;
43
44
45
46
47
48
49
50 public void setRequired(final boolean required)
51 {
52 this.required = required;
53 }
54
55
56
57
58
59
60 public boolean isRequired()
61 {
62 return this.required;
63 }
64
65
66
67
68 private String text;
69
70
71
72
73
74
75 public String getText()
76 {
77 final StringBuilder text = new StringBuilder();
78 if (this.text != null)
79 {
80 text.append(this.text);
81 }
82 if (!this.responses.isEmpty())
83 {
84 text.append(' ').append(this.getResponsesAsString());
85 }
86 text.append(": ");
87 return text.toString();
88 }
89
90
91
92
93
94
95 public void setText(final String text)
96 {
97 this.text = StringUtils.trim(text);
98 }
99
100
101
102
103 private final List<String> responses = new ArrayList<String>();
104
105
106
107
108
109
110 public void addResponse(final String response)
111 {
112 if (StringUtils.isNotBlank(response))
113 {
114 this.responses.add(response.trim());
115 }
116 }
117
118
119
120
121
122
123
124
125 public boolean isValidResponse(final String response)
126 {
127 return this.responses.contains(response) ||
128 (this.responses.isEmpty() && (!this.isRequired() || (StringUtils.isNotBlank(response))));
129 }
130
131
132
133
134
135
136
137
138
139 public Object getResponse(final Object response)
140 {
141 return AndroMDAppUtils.convert(
142 response,
143 this.responseType);
144 }
145
146
147
148
149 private String responseType;
150
151
152
153
154
155
156
157 public void setResponseType(final String responseType)
158 {
159 this.responseType = responseType;
160 }
161
162
163
164
165
166
167 private String getResponsesAsString()
168 {
169 final StringBuilder responsesString = new StringBuilder("[");
170 for (String response : this.responses)
171 {
172 responsesString.append(response).append(", ");
173 }
174
175 if(!this.responses.isEmpty())
176 {
177 responsesString.delete(responsesString.length()-2, responsesString.length());
178 }
179 responsesString.append(']');
180 return responsesString.toString();
181 }
182
183
184
185
186 private final List<Condition> conditions = new ArrayList<Condition>();
187
188
189
190
191
192
193 public void addCondition(final Condition condition)
194 {
195 this.conditions.add(condition);
196 }
197
198
199
200
201
202
203 public List<Condition> getConditions()
204 {
205 return this.conditions;
206 }
207
208
209
210
211
212 private final List<Conditions> preconditions = new ArrayList<Conditions>();
213
214
215
216
217
218
219 public void addPreconditions(final Conditions preconditions)
220 {
221 this.preconditions.add(preconditions);
222 }
223
224
225
226
227
228
229 public List<Conditions> getPreconditions()
230 {
231 return this.preconditions;
232 }
233
234
235
236
237
238 private boolean setResponseAsTrue;
239
240
241
242
243
244
245 public boolean isSetResponseAsTrue()
246 {
247 return setResponseAsTrue;
248 }
249
250
251
252
253
254
255 public void setSetResponseAsTrue(final boolean setResponseAsBoolean)
256 {
257 this.setResponseAsTrue = setResponseAsBoolean;
258 }
259 }