1 package org.andromda.cartridges.spring.metafacades;
2
3 import org.andromda.cartridges.spring.SpringProfile;
4 import org.apache.commons.lang.BooleanUtils;
5 import org.apache.commons.lang.ObjectUtils;
6 import org.apache.commons.lang.StringUtils;
7
8
9
10
11
12
13 public class SpringCriteriaAttributeLogicImpl
14 extends SpringCriteriaAttributeLogic
15 {
16 private static final long serialVersionUID = 34L;
17
18
19
20
21
22
23 public SpringCriteriaAttributeLogicImpl(
24 Object metaObject,
25 String context)
26 {
27 super(metaObject, context);
28 }
29
30
31
32
33
34 protected String handleGetAttributeName()
35 {
36
37 String attributeName = getName();
38
39
40 Object value = findTaggedValue(SpringProfile.TAGGEDVALUE_HIBERNATE_CRITERIA_ATTRIBUTE);
41 if (value != null)
42 {
43 attributeName = String.valueOf(value);
44 }
45
46 return StringUtils.trimToEmpty(attributeName);
47 }
48
49
50
51
52
53 protected String handleGetComparator()
54 {
55 String comparator = null;
56 Object value = findTaggedValue(SpringProfile.TAGGEDVALUE_HIBERNATE_CRITERIA_COMPARATOR);
57 if (value != null)
58 {
59 comparator = String.valueOf(value);
60 }
61 return StringUtils.trimToEmpty(comparator);
62 }
63
64
65
66
67
68 protected boolean handleIsComparatorPresent()
69 {
70 return !StringUtils.isBlank(getComparator());
71 }
72
73
74
75
76
77 protected String handleGetComparatorConstant()
78 {
79 String comparator = getComparator();
80 String comparatorConstant = null;
81
82 if (comparator != null)
83 {
84 if (SpringProfile.TAGGEDVALUEVALUE_COMPARATOR_LIKE.equalsIgnoreCase(comparator))
85 {
86 comparatorConstant = "LIKE_COMPARATOR";
87 }
88 else if (SpringProfile.TAGGEDVALUEVALUE_INSENSITIVE_LIKE_COMPARATOR.equalsIgnoreCase(comparator))
89 {
90 comparatorConstant = "INSENSITIVE_LIKE_COMPARATOR";
91 }
92 else if (SpringProfile.TAGGEDVALUEVALUE_COMPARATOR_EQUAL.equalsIgnoreCase(comparator))
93 {
94 comparatorConstant = "EQUAL_COMPARATOR";
95 }
96 else if (SpringProfile.TAGGEDVALUEVALUE_COMPARATOR_GREATER_OR_EQUAL.equalsIgnoreCase(comparator))
97 {
98 comparatorConstant = "GREATER_THAN_OR_EQUAL_COMPARATOR";
99 }
100 else if (SpringProfile.TAGGEDVALUEVALUE_COMPARATOR_GREATER.equalsIgnoreCase(comparator))
101 {
102 comparatorConstant = "GREATER_THAN_COMPARATOR";
103 }
104 else if (SpringProfile.TAGGEDVALUEVALUE_COMPARATOR_LESS_OR_EQUAL.equalsIgnoreCase(comparator))
105 {
106 comparatorConstant = "LESS_THAN_OR_EQUAL_COMPARATOR";
107 }
108 else if (SpringProfile.TAGGEDVALUEVALUE_COMPARATOR_LESS.equalsIgnoreCase(comparator))
109 {
110 comparatorConstant = "LESS_THAN_COMPARATOR";
111 }
112 else if (SpringProfile.TAGGEDVALUEVALUE_COMPARATOR_IN.equalsIgnoreCase(comparator))
113 {
114 comparatorConstant = "IN_COMPARATOR";
115 }
116 else if (SpringProfile.TAGGEDVALUEVALUE_COMPARATOR_NOT_EQUAL.equalsIgnoreCase(comparator))
117 {
118 comparatorConstant = "NOT_EQUAL_COMPARATOR";
119 }
120 }
121 return comparatorConstant;
122 }
123
124
125
126
127 protected boolean handleIsNullable()
128 {
129 boolean result = false;
130 String value =
131 StringUtils.trimToEmpty((String)findTaggedValue(SpringProfile.TAGGEDVALUE_HIBERNATE_CRITERIA_NULLABLE));
132 if (!StringUtils.isBlank(value))
133 {
134 result = BooleanUtils.toBoolean(value);
135 }
136 return result;
137 }
138
139
140
141
142 protected String handleGetMatchMode()
143 {
144 String matchMode = null;
145 Object value = findTaggedValue(SpringProfile.TAGGEDVALUE_HIBERNATE_CRITERIA_MATCHMODE);
146 if (value != null)
147 {
148 matchMode = String.valueOf(value);
149 }
150 return StringUtils.trimToEmpty(matchMode);
151 }
152
153
154
155
156 protected String handleGetMatchModeConstant()
157 {
158 String matchMode = getMatchMode();
159 String matchModeConstant = null;
160
161 if (matchMode != null)
162 {
163 if (matchMode.equalsIgnoreCase(SpringProfile.TAGGEDVALUEVALUE_MATCHMODE_ANYWHERE))
164 {
165 matchModeConstant = "ANYWHERE";
166 }
167 else if (matchMode.equalsIgnoreCase(SpringProfile.TAGGEDVALUEVALUE_MATCHMODE_END))
168 {
169 matchModeConstant = "END";
170 }
171 else if (matchMode.equalsIgnoreCase(SpringProfile.TAGGEDVALUEVALUE_MATCHMODE_EXACT))
172 {
173 matchModeConstant = "EXACT";
174 }
175 else if (matchMode.equalsIgnoreCase(SpringProfile.TAGGEDVALUEVALUE_MATCHMODE_START))
176 {
177 matchModeConstant = "START";
178 }
179 }
180 return matchModeConstant;
181 }
182
183
184
185
186 protected boolean handleIsMatchModePresent()
187 {
188 return !StringUtils.isBlank(getMatchMode());
189 }
190
191 private static final String ORDER_UNSET = "ORDER_UNSET";
192
193
194
195
196 protected boolean handleIsOrderable()
197 {
198 return !ORDER_UNSET.equals(getOrderDirection());
199 }
200
201
202
203
204 protected String handleGetOrderDirection()
205 {
206 String result = ORDER_UNSET;
207 String value =
208 StringUtils.trimToEmpty(
209 (String)findTaggedValue(SpringProfile.TAGGEDVALUE_HIBERNATE_CRITERIA_ORDER_DIRECTION));
210 if (!StringUtils.isBlank(value))
211 {
212 if (value.equals(SpringProfile.TAGGEDVALUEVALUE_ORDER_ASCENDING))
213 {
214 result = "ORDER_ASC";
215 }
216 else if (value.equals(SpringProfile.TAGGEDVALUEVALUE_ORDER_DESCENDING))
217 {
218 result = "ORDER_DESC";
219 }
220 }
221 return result;
222 }
223
224
225
226
227 private static final int UNSET = -1;
228
229
230
231
232 protected int handleGetOrderRelevance()
233 {
234 int result = UNSET;
235 String value =
236 StringUtils.trimToEmpty(
237 (String)findTaggedValue(SpringProfile.TAGGEDVALUE_HIBERNATE_CRITERIA_ORDER_RELEVANCE));
238 if (!StringUtils.isBlank(value))
239 {
240 try
241 {
242 result = Integer.parseInt(value);
243 }
244 catch (NumberFormatException ignore)
245 {
246 }
247 }
248 return result;
249 }
250
251
252
253
254 private static final String HIBERNATE_CRITERIA_QUERY_IGNORE_CASE = "hibernateCriteriaQueryIgnoreCase";
255
256
257
258
259
260 protected boolean handleIsIgnoreCase()
261 {
262 Object value = this.findTaggedValue(SpringProfile.TAGGEDVALUE_HIBERNATE_CRITERIA_COMPARATOR_IGNORE_CASE);
263 if (value == null)
264 {
265 value = this.getConfiguredProperty(HIBERNATE_CRITERIA_QUERY_IGNORE_CASE);
266 }
267 return Boolean.valueOf(ObjectUtils.toString(value)).booleanValue();
268 }
269 }