%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.turbine.services.security.torque.UserPeerManager |
|
|
1 | package org.apache.turbine.services.security.torque; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2004 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
17 | */ |
|
18 | ||
19 | import java.beans.PropertyDescriptor; |
|
20 | ||
21 | import java.util.ArrayList; |
|
22 | import java.util.Iterator; |
|
23 | import java.util.List; |
|
24 | ||
25 | import org.apache.commons.configuration.Configuration; |
|
26 | ||
27 | import org.apache.commons.logging.Log; |
|
28 | import org.apache.commons.logging.LogFactory; |
|
29 | ||
30 | import org.apache.torque.TorqueException; |
|
31 | import org.apache.torque.om.Persistent; |
|
32 | import org.apache.torque.util.BasePeer; |
|
33 | import org.apache.torque.util.Criteria; |
|
34 | ||
35 | import org.apache.turbine.om.security.User; |
|
36 | import org.apache.turbine.services.InitializationException; |
|
37 | import org.apache.turbine.services.security.TurbineSecurity; |
|
38 | import org.apache.turbine.util.security.DataBackendException; |
|
39 | ||
40 | /** |
|
41 | * This class capsulates all direct Peer access for the User entities. |
|
42 | * It allows the exchange of the default Turbine supplied TurbineUserPeer |
|
43 | * class against a custom class. |
|
44 | * |
|
45 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> |
|
46 | * @version $Id: UserPeerManager.java,v 1.5.2.2 2004/05/20 03:06:50 seade Exp $ |
|
47 | */ |
|
48 | ||
49 | 0 | public class UserPeerManager |
50 | implements UserPeerManagerConstants |
|
51 | { |
|
52 | /** The class of the Peer the TorqueSecurityService uses */ |
|
53 | 8 | private static Class userPeerClass = null; |
54 | ||
55 | /** The class name of the objects returned by the configured peer. */ |
|
56 | 8 | private static Class userObject = null; |
57 | ||
58 | /** The name of the Table used for Group Object queries */ |
|
59 | 8 | private static String tableName = null; |
60 | ||
61 | /** The name of the column used as "Name" Column */ |
|
62 | 8 | private static String nameColumn = null; |
63 | ||
64 | /** The name of the column used as "Id" Column */ |
|
65 | 8 | private static String idColumn = null; |
66 | ||
67 | /** The name of the column used as "Password" Column */ |
|
68 | 8 | private static String passwordColumn = null; |
69 | ||
70 | /** The name of the column used as "First name" Column */ |
|
71 | 8 | private static String firstNameColumn = null; |
72 | ||
73 | /** The name of the column used as "Last name" Column */ |
|
74 | 8 | private static String lastNameColumn = null; |
75 | ||
76 | /** The name of the column used as "Email" Column */ |
|
77 | 8 | private static String emailColumn = null; |
78 | ||
79 | /** The name of the column used as "Confirm" Column */ |
|
80 | 8 | private static String confirmColumn = null; |
81 | ||
82 | /** The name of the column used as "create date" Column */ |
|
83 | 8 | private static String createDateColumn = null; |
84 | ||
85 | /** The name of the column used as "last login" Column */ |
|
86 | 8 | private static String lastLoginColumn = null; |
87 | ||
88 | /** The name of the column used as "objectdata" Column */ |
|
89 | 8 | private static String objectdataColumn = null; |
90 | ||
91 | /** The "Name" property descriptor */ |
|
92 | 8 | private static PropertyDescriptor namePropDesc = null; |
93 | ||
94 | /** The "Id" property descriptor */ |
|
95 | 8 | private static PropertyDescriptor idPropDesc = null; |
96 | ||
97 | /** The "Password" property descriptor */ |
|
98 | 8 | private static PropertyDescriptor passwordPropDesc = null; |
99 | ||
100 | /** The "First name" property descriptor */ |
|
101 | 8 | private static PropertyDescriptor firstNamePropDesc = null; |
102 | ||
103 | /** The "Last name" property descriptor */ |
|
104 | 8 | private static PropertyDescriptor lastNamePropDesc = null; |
105 | ||
106 | /** The "Email" property descriptor */ |
|
107 | 8 | private static PropertyDescriptor emailPropDesc = null; |
108 | ||
109 | /** The "Confirm" property descriptor */ |
|
110 | 8 | private static PropertyDescriptor confirmPropDesc = null; |
111 | ||
112 | /** The "create date" property descriptor */ |
|
113 | 8 | private static PropertyDescriptor createDatePropDesc = null; |
114 | ||
115 | /** The "last login" property descriptor */ |
|
116 | 8 | private static PropertyDescriptor lastLoginPropDesc = null; |
117 | ||
118 | /** The "objectdata" property descriptor */ |
|
119 | 8 | private static PropertyDescriptor objectdataPropDesc = null; |
120 | ||
121 | /** Logging */ |
|
122 | 26 | static Log log = LogFactory.getLog(UserPeerManager.class); |
123 | ||
124 | /** |
|
125 | * Initializes the UserPeerManager, loading the class object for the |
|
126 | * Peer used to retrieve User objects |
|
127 | * |
|
128 | * @param conf The configuration object used to configure the Manager |
|
129 | * |
|
130 | * @exception InitializationException A problem occured during |
|
131 | * initialization |
|
132 | */ |
|
133 | ||
134 | public static void init(Configuration conf) |
|
135 | throws InitializationException |
|
136 | { |
|
137 | 8 | String userPeerClassName = conf.getString(USER_PEER_CLASS_KEY, |
138 | USER_PEER_CLASS_DEFAULT); |
|
139 | 8 | String userObjectName = null; |
140 | ||
141 | try |
|
142 | { |
|
143 | 8 | userPeerClass = Class.forName(userPeerClassName); |
144 | ||
145 | 8 | tableName = |
146 | (String) userPeerClass.getField("TABLE_NAME").get(null); |
|
147 | ||
148 | // |
|
149 | // We have either an user configured Object class or we use the |
|
150 | // default as supplied by the Peer class |
|
151 | // |
|
152 | ||
153 | // Default from Peer, can be overridden |
|
154 | ||
155 | 8 | userObject = getPersistenceClass(); |
156 | ||
157 | 8 | userObjectName = conf.getString(USER_CLASS_KEY, |
158 | userObject.getName()); |
|
159 | ||
160 | // Maybe the user set a new value... |
|
161 | 8 | userObject = Class.forName(userObjectName); |
162 | ||
163 | /* If any of the following Field queries fails, the user |
|
164 | * subsystem is unusable. So check this right here at init time, |
|
165 | * which saves us much time and hassle if it fails... |
|
166 | */ |
|
167 | ||
168 | 8 | nameColumn = (String) userPeerClass.getField( |
169 | conf.getString(USER_NAME_COLUMN_KEY, |
|
170 | USER_NAME_COLUMN_DEFAULT) |
|
171 | ).get(null); |
|
172 | ||
173 | 8 | idColumn = (String) userPeerClass.getField( |
174 | conf.getString(USER_ID_COLUMN_KEY, |
|
175 | USER_ID_COLUMN_DEFAULT) |
|
176 | ).get(null); |
|
177 | ||
178 | 8 | passwordColumn = (String) userPeerClass.getField( |
179 | conf.getString(USER_PASSWORD_COLUMN_KEY, |
|
180 | USER_PASSWORD_COLUMN_DEFAULT) |
|
181 | ).get(null); |
|
182 | ||
183 | 8 | firstNameColumn = (String) userPeerClass.getField( |
184 | conf.getString(USER_FIRST_NAME_COLUMN_KEY, |
|
185 | USER_FIRST_NAME_COLUMN_DEFAULT) |
|
186 | ).get(null); |
|
187 | ||
188 | 8 | lastNameColumn = (String) userPeerClass.getField( |
189 | conf.getString(USER_LAST_NAME_COLUMN_KEY, |
|
190 | USER_LAST_NAME_COLUMN_DEFAULT) |
|
191 | ).get(null); |
|
192 | ||
193 | 8 | emailColumn = (String) userPeerClass.getField( |
194 | conf.getString(USER_EMAIL_COLUMN_KEY, |
|
195 | USER_EMAIL_COLUMN_DEFAULT) |
|
196 | ).get(null); |
|
197 | ||
198 | 8 | confirmColumn = (String) userPeerClass.getField( |
199 | conf.getString(USER_CONFIRM_COLUMN_KEY, |
|
200 | USER_CONFIRM_COLUMN_DEFAULT) |
|
201 | ).get(null); |
|
202 | ||
203 | 8 | createDateColumn = (String) userPeerClass.getField( |
204 | conf.getString(USER_CREATE_COLUMN_KEY, |
|
205 | USER_CREATE_COLUMN_DEFAULT) |
|
206 | ).get(null); |
|
207 | ||
208 | 8 | lastLoginColumn = (String) userPeerClass.getField( |
209 | conf.getString(USER_LAST_LOGIN_COLUMN_KEY, |
|
210 | USER_LAST_LOGIN_COLUMN_DEFAULT) |
|
211 | ).get(null); |
|
212 | ||
213 | 8 | objectdataColumn = (String) userPeerClass.getField( |
214 | conf.getString(USER_OBJECTDATA_COLUMN_KEY, |
|
215 | USER_OBJECTDATA_COLUMN_DEFAULT) |
|
216 | ).get(null); |
|
217 | ||
218 | 8 | namePropDesc = |
219 | new PropertyDescriptor(conf.getString( |
|
220 | USER_NAME_PROPERTY_KEY, |
|
221 | USER_NAME_PROPERTY_DEFAULT), |
|
222 | userObject); |
|
223 | ||
224 | 8 | idPropDesc = |
225 | new PropertyDescriptor(conf.getString( |
|
226 | USER_ID_PROPERTY_KEY, |
|
227 | USER_ID_PROPERTY_DEFAULT), |
|
228 | userObject); |
|
229 | ||
230 | 8 | passwordPropDesc = |
231 | new PropertyDescriptor(conf.getString( |
|
232 | USER_PASSWORD_PROPERTY_KEY, |
|
233 | USER_PASSWORD_PROPERTY_DEFAULT), |
|
234 | userObject); |
|
235 | ||
236 | 8 | firstNamePropDesc = |
237 | new PropertyDescriptor(conf.getString( |
|
238 | USER_FIRST_NAME_PROPERTY_KEY, |
|
239 | USER_FIRST_NAME_PROPERTY_DEFAULT), |
|
240 | userObject); |
|
241 | ||
242 | 8 | lastNamePropDesc = |
243 | new PropertyDescriptor(conf.getString( |
|
244 | USER_LAST_NAME_PROPERTY_KEY, |
|
245 | USER_LAST_NAME_PROPERTY_DEFAULT), |
|
246 | userObject); |
|
247 | ||
248 | 8 | emailPropDesc = |
249 | new PropertyDescriptor(conf.getString( |
|
250 | USER_EMAIL_PROPERTY_KEY, |
|
251 | USER_EMAIL_PROPERTY_DEFAULT), |
|
252 | userObject); |
|
253 | ||
254 | 8 | confirmPropDesc = |
255 | new PropertyDescriptor(conf.getString( |
|
256 | USER_CONFIRM_PROPERTY_KEY, |
|
257 | USER_CONFIRM_PROPERTY_DEFAULT), |
|
258 | userObject); |
|
259 | ||
260 | 8 | createDatePropDesc = |
261 | new PropertyDescriptor(conf.getString( |
|
262 | USER_CREATE_PROPERTY_KEY, |
|
263 | USER_CREATE_PROPERTY_DEFAULT), |
|
264 | userObject); |
|
265 | ||
266 | 8 | lastLoginPropDesc = |
267 | new PropertyDescriptor(conf.getString( |
|
268 | USER_LAST_LOGIN_PROPERTY_KEY, |
|
269 | USER_LAST_LOGIN_PROPERTY_DEFAULT), |
|
270 | userObject); |
|
271 | ||
272 | 8 | objectdataPropDesc = |
273 | new PropertyDescriptor(conf.getString( |
|
274 | USER_OBJECTDATA_PROPERTY_KEY, |
|
275 | USER_OBJECTDATA_PROPERTY_DEFAULT), |
|
276 | userObject); |
|
277 | } |
|
278 | 0 | catch (Exception e) |
279 | { |
|
280 | 0 | if (userPeerClassName == null || userPeerClass == class="keyword">null) |
281 | { |
|
282 | 0 | throw new InitializationException( |
283 | "Could not find UserPeer class (" |
|
284 | + userPeerClassName + ")", e); |
|
285 | } |
|
286 | 0 | if (tableName == null) |
287 | { |
|
288 | 0 | throw new InitializationException( |
289 | "Failed to get the table name from the Peer object", e); |
|
290 | } |
|
291 | ||
292 | 0 | if (userObject == null || userObjectName == class="keyword">null) |
293 | { |
|
294 | 0 | throw new InitializationException( |
295 | "Failed to get the object type from the Peer object", e); |
|
296 | } |
|
297 | ||
298 | ||
299 | 0 | if (nameColumn == null || namePropDesc == class="keyword">null) |
300 | { |
|
301 | 0 | throw new InitializationException( |
302 | "UserPeer " + userPeerClassName |
|
303 | + " has no name column information!", e); |
|
304 | } |
|
305 | 0 | if (idColumn == null || idPropDesc == class="keyword">null) |
306 | { |
|
307 | 0 | throw new InitializationException( |
308 | "UserPeer " + userPeerClassName |
|
309 | + " has no id column information!", e); |
|
310 | } |
|
311 | 0 | if (passwordColumn == null || passwordPropDesc == class="keyword">null) |
312 | { |
|
313 | 0 | throw new InitializationException( |
314 | "UserPeer " + userPeerClassName |
|
315 | + " has no password column information!", e); |
|
316 | } |
|
317 | 0 | if (firstNameColumn == null || firstNamePropDesc == class="keyword">null) |
318 | { |
|
319 | 0 | throw new InitializationException( |
320 | "UserPeer " + userPeerClassName |
|
321 | + " has no firstName column information!", e); |
|
322 | } |
|
323 | 0 | if (lastNameColumn == null || lastNamePropDesc == class="keyword">null) |
324 | { |
|
325 | 0 | throw new InitializationException( |
326 | "UserPeer " + userPeerClassName |
|
327 | + " has no lastName column information!", e); |
|
328 | } |
|
329 | 0 | if (emailColumn == null || emailPropDesc == class="keyword">null) |
330 | { |
|
331 | 0 | throw new InitializationException( |
332 | "UserPeer " + userPeerClassName |
|
333 | + " has no email column information!", e); |
|
334 | } |
|
335 | 0 | if (confirmColumn == null || confirmPropDesc == class="keyword">null) |
336 | { |
|
337 | 0 | throw new InitializationException( |
338 | "UserPeer " + userPeerClassName |
|
339 | + " has no confirm column information!", e); |
|
340 | } |
|
341 | 0 | if (createDateColumn == null || createDatePropDesc == class="keyword">null) |
342 | { |
|
343 | 0 | throw new InitializationException( |
344 | "UserPeer " + userPeerClassName |
|
345 | + " has no createDate column information!", e); |
|
346 | } |
|
347 | 0 | if (lastLoginColumn == null || lastLoginPropDesc == class="keyword">null) |
348 | { |
|
349 | 0 | throw new InitializationException( |
350 | "UserPeer " + userPeerClassName |
|
351 | + " has no lastLogin column information!", e); |
|
352 | } |
|
353 | 0 | if (objectdataColumn == null || objectdataPropDesc == class="keyword">null) |
354 | { |
|
355 | 0 | throw new InitializationException( |
356 | "UserPeer " + userPeerClassName |
|
357 | + " has no objectdata column information!", e); |
|
358 | } |
|
359 | 8 | } |
360 | 8 | } |
361 | ||
362 | /** |
|
363 | * Get the name of this table. |
|
364 | * |
|
365 | * @return A String with the name of the table. |
|
366 | */ |
|
367 | public static String getTableName() |
|
368 | { |
|
369 | 0 | return tableName; |
370 | } |
|
371 | ||
372 | /** |
|
373 | * Returns the fully qualified name of the Column to |
|
374 | * use as the Name Column for a group |
|
375 | * |
|
376 | * @return A String containing the column name |
|
377 | */ |
|
378 | public static String getNameColumn() |
|
379 | { |
|
380 | 117 | return nameColumn; |
381 | } |
|
382 | ||
383 | /** |
|
384 | * Returns the fully qualified name of the Column to |
|
385 | * use as the Id Column for a group |
|
386 | * |
|
387 | * @return A String containing the column id |
|
388 | */ |
|
389 | public static String getIdColumn() |
|
390 | { |
|
391 | 21 | return idColumn; |
392 | } |
|
393 | ||
394 | /** |
|
395 | * Returns the fully qualified name of the Column to |
|
396 | * use as the Password Column for a role |
|
397 | * |
|
398 | * @return A String containing the column name |
|
399 | */ |
|
400 | public static String getPasswordColumn() |
|
401 | { |
|
402 | 0 | return passwordColumn; |
403 | } |
|
404 | ||
405 | /** |
|
406 | * Returns the fully qualified name of the Column to |
|
407 | * use as the FirstName Column for a role |
|
408 | * |
|
409 | * @return A String containing the column name |
|
410 | */ |
|
411 | public static String getFirstNameColumn() |
|
412 | { |
|
413 | 0 | return firstNameColumn; |
414 | } |
|
415 | ||
416 | /** |
|
417 | * Returns the fully qualified name of the Column to |
|
418 | * use as the LastName Column for a role |
|
419 | * |
|
420 | * @return A String containing the column name |
|
421 | */ |
|
422 | public static String getLastNameColumn() |
|
423 | { |
|
424 | 0 | return lastNameColumn; |
425 | } |
|
426 | ||
427 | /** |
|
428 | * Returns the fully qualified name of the Column to |
|
429 | * use as the Email Column for a role |
|
430 | * |
|
431 | * @return A String containing the column name |
|
432 | */ |
|
433 | public static String getEmailColumn() |
|
434 | { |
|
435 | 0 | return emailColumn; |
436 | } |
|
437 | ||
438 | /** |
|
439 | * Returns the fully qualified name of the Column to |
|
440 | * use as the Confirm Column for a role |
|
441 | * |
|
442 | * @return A String containing the column name |
|
443 | */ |
|
444 | public static String getConfirmColumn() |
|
445 | { |
|
446 | 0 | return confirmColumn; |
447 | } |
|
448 | ||
449 | /** |
|
450 | * Returns the fully qualified name of the Column to |
|
451 | * use as the CreateDate Column for a role |
|
452 | * |
|
453 | * @return A String containing the column name |
|
454 | */ |
|
455 | public static String getCreateDateColumn() |
|
456 | { |
|
457 | 0 | return createDateColumn; |
458 | } |
|
459 | ||
460 | /** |
|
461 | * Returns the fully qualified name of the Column to |
|
462 | * use as the LastLogin Column for a role |
|
463 | * |
|
464 | * @return A String containing the column name |
|
465 | */ |
|
466 | public static String getLastLoginColumn() |
|
467 | { |
|
468 | 0 | return lastLoginColumn; |
469 | } |
|
470 | ||
471 | /** |
|
472 | * Returns the fully qualified name of the Column to |
|
473 | * use as the objectdata Column for a role |
|
474 | * |
|
475 | * @return A String containing the column name |
|
476 | */ |
|
477 | public static String getObjectdataColumn() |
|
478 | { |
|
479 | 0 | return objectdataColumn; |
480 | } |
|
481 | ||
482 | /** |
|
483 | * Returns the full name of a column. |
|
484 | * |
|
485 | * @param name The column to fully qualify |
|
486 | * |
|
487 | * @return A String with the full name of the column. |
|
488 | */ |
|
489 | public static String getColumnName(String name) |
|
490 | { |
|
491 | 0 | StringBuffer sb = new StringBuffer(); |
492 | 0 | sb.append(getTableName()); |
493 | 0 | sb.append("."); |
494 | 0 | sb.append(name); |
495 | 0 | return sb.toString(); |
496 | } |
|
497 | ||
498 | /** |
|
499 | * Returns the full name of a column. |
|
500 | * |
|
501 | * @param name The column to fully qualify |
|
502 | * |
|
503 | * @return A String with the full name of the column. |
|
504 | * @deprecated use getColumnName(String name) |
|
505 | */ |
|
506 | public String getFullColumnName(String name) |
|
507 | { |
|
508 | 0 | return getColumnName(name); |
509 | } |
|
510 | ||
511 | ||
512 | /** |
|
513 | * Returns a new, empty object for the underlying peer. |
|
514 | * Used to create a new underlying object |
|
515 | * |
|
516 | * @return A new object which is compatible to the Peer |
|
517 | * and can be used as a User object |
|
518 | * |
|
519 | */ |
|
520 | ||
521 | public static Persistent newPersistentInstance() |
|
522 | { |
|
523 | 12 | Persistent obj = null; |
524 | ||
525 | 12 | if(userObject == null) |
526 | { |
|
527 | // This can happen if the Turbine wants to determine the |
|
528 | // name of the anonymous user before the security service |
|
529 | // has been initialized. In this case, the Peer Manager |
|
530 | // has not yet been inited and the userObject is still |
|
531 | // null. Return null in this case. |
|
532 | // |
|
533 | 0 | return obj; |
534 | } |
|
535 | ||
536 | try |
|
537 | { |
|
538 | 12 | obj = (Persistent) userObject.newInstance(); |
539 | } |
|
540 | 0 | catch (Exception e) |
541 | { |
|
542 | 0 | log.error("Could not instantiate a user object", e); |
543 | 0 | obj = null; |
544 | 12 | } |
545 | 12 | return obj; |
546 | } |
|
547 | ||
548 | /** |
|
549 | * Checks if a User is defined in the system. The name |
|
550 | * is used as query criteria. |
|
551 | * |
|
552 | * @param user The User to be checked. |
|
553 | * @return <code>true</code> if given User exists in the system. |
|
554 | * @throws DataBackendException when more than one User with |
|
555 | * the same name exists. |
|
556 | * @throws Exception A generic exception. |
|
557 | */ |
|
558 | public static boolean checkExists(User user) |
|
559 | throws DataBackendException, Exception |
|
560 | { |
|
561 | 0 | Criteria criteria = new Criteria(); |
562 | ||
563 | 0 | criteria.addSelectColumn(getIdColumn()); |
564 | ||
565 | 0 | criteria.add(getNameColumn(), user.getName()); |
566 | ||
567 | 0 | List results = BasePeer.doSelect(criteria); |
568 | ||
569 | 0 | if (results.size() > 1) |
570 | { |
|
571 | 0 | throw new DataBackendException("Multiple users named '" + |
572 | user.getName() + "' exist!"); |
|
573 | } |
|
574 | 0 | return (results.size() == 1); |
575 | } |
|
576 | ||
577 | /** |
|
578 | * Returns a List of all User objects. |
|
579 | * |
|
580 | * @return A List with all users in the system. |
|
581 | * @exception Exception A generic exception. |
|
582 | */ |
|
583 | public static List selectAllUsers() |
|
584 | throws Exception |
|
585 | { |
|
586 | 0 | Criteria criteria = new Criteria(); |
587 | 0 | criteria.addAscendingOrderByColumn(getLastNameColumn()); |
588 | 0 | criteria.addAscendingOrderByColumn(getFirstNameColumn()); |
589 | 0 | criteria.setIgnoreCase(true); |
590 | 0 | return doSelect(criteria); |
591 | } |
|
592 | ||
593 | /** |
|
594 | * Returns a List of all confirmed User objects. |
|
595 | * |
|
596 | * @return A List with all confirmed users in the system. |
|
597 | * @exception Exception A generic exception. |
|
598 | */ |
|
599 | public static List selectAllConfirmedUsers() |
|
600 | throws Exception |
|
601 | { |
|
602 | 0 | Criteria criteria = new Criteria(); |
603 | ||
604 | 0 | criteria.add (getConfirmColumn(), User.CONFIRM_DATA); |
605 | 0 | criteria.addAscendingOrderByColumn(getLastNameColumn()); |
606 | 0 | criteria.addAscendingOrderByColumn(getFirstNameColumn()); |
607 | 0 | criteria.setIgnoreCase(true); |
608 | 0 | return doSelect(criteria); |
609 | } |
|
610 | ||
611 | /* |
|
612 | * ======================================================================== |
|
613 | * |
|
614 | * WARNING! Do not read on if you have a weak stomach. What follows here |
|
615 | * are some abominations thanks to the braindead static peers of Torque |
|
616 | * and the rigidity of Java.... |
|
617 | * |
|
618 | * ======================================================================== |
|
619 | * |
|
620 | */ |
|
621 | ||
622 | /** |
|
623 | * Calls buildCriteria(User user) in the configured UserPeer. If you get |
|
624 | * a ClassCastException in this routine, you put a User object into this |
|
625 | * method which can't be cast into an object for the TorqueSecurityService. This is a |
|
626 | * configuration error most of the time. |
|
627 | * |
|
628 | * @param user An object which implements the User interface |
|
629 | * |
|
630 | * @return A criteria for the supplied user object |
|
631 | */ |
|
632 | ||
633 | public static Criteria buildCriteria(User user) |
|
634 | { |
|
635 | Criteria crit; |
|
636 | ||
637 | try |
|
638 | { |
|
639 | 0 | Class[] clazz = new Class[] { userObject }; |
640 | 0 | Object[] params = |
641 | new Object[] { ((TorqueUser) user).getPersistentObj() }; |
|
642 | ||
643 | 0 | crit = (Criteria) userPeerClass |
644 | .getMethod("buildCriteria", clazz) |
|
645 | .invoke(null, params); |
|
646 | } |
|
647 | 0 | catch (Exception e) |
648 | { |
|
649 | 0 | crit = null; |
650 | 0 | } |
651 | ||
652 | 0 | return crit; |
653 | } |
|
654 | ||
655 | /** |
|
656 | * Invokes doUpdate(Criteria c) on the configured Peer Object |
|
657 | * |
|
658 | * @param criteria A Criteria Object |
|
659 | * |
|
660 | * @exception TorqueException A problem occured. |
|
661 | */ |
|
662 | ||
663 | public static void doUpdate(Criteria criteria) |
|
664 | throws TorqueException |
|
665 | { |
|
666 | try |
|
667 | { |
|
668 | 0 | Class[] clazz = new Class[] { Criteria.class }; |
669 | 0 | Object[] params = new Object[] { criteria }; |
670 | ||
671 | 0 | userPeerClass |
672 | .getMethod("doUpdate", clazz) |
|
673 | .invoke(null, params); |
|
674 | } |
|
675 | 0 | catch (Exception e) |
676 | { |
|
677 | 0 | throw new TorqueException("doUpdate failed", e); |
678 | 0 | } |
679 | 0 | } |
680 | ||
681 | /** |
|
682 | * Invokes doInsert(Criteria c) on the configured Peer Object |
|
683 | * |
|
684 | * @param criteria A Criteria Object |
|
685 | * |
|
686 | * @exception TorqueException A problem occured. |
|
687 | */ |
|
688 | ||
689 | public static void doInsert(Criteria criteria) |
|
690 | throws TorqueException |
|
691 | { |
|
692 | try |
|
693 | { |
|
694 | 0 | Class[] clazz = new Class[] { Criteria.class }; |
695 | 0 | Object[] params = new Object[] { criteria }; |
696 | ||
697 | 0 | userPeerClass |
698 | .getMethod("doInsert", clazz) |
|
699 | .invoke(null, params); |
|
700 | } |
|
701 | 0 | catch (Exception e) |
702 | { |
|
703 | 0 | throw new TorqueException("doInsert failed", e); |
704 | 0 | } |
705 | 0 | } |
706 | ||
707 | /** |
|
708 | * Invokes doSelect(Criteria c) on the configured Peer Object |
|
709 | * |
|
710 | * @param criteria A Criteria Object |
|
711 | * |
|
712 | * @return A List of User Objects selected by the Criteria |
|
713 | * |
|
714 | * @exception TorqueException A problem occured. |
|
715 | */ |
|
716 | public static List doSelect(Criteria criteria) |
|
717 | throws TorqueException |
|
718 | { |
|
719 | List list; |
|
720 | ||
721 | try |
|
722 | { |
|
723 | 127 | Class[] clazz = |
724 | new Class[] { Criteria.class }; |
|
725 | 127 | Object[] params = new Object[] { criteria }; |
726 | ||
727 | 127 | list = (List) userPeerClass |
728 | .getMethod("doSelect", clazz) |
|
729 | .invoke(null, params); |
|
730 | } |
|
731 | 0 | catch (Exception e) |
732 | { |
|
733 | 0 | throw new TorqueException("doSelect failed", e); |
734 | 127 | } |
735 | 127 | List newList = new ArrayList(list.size()); |
736 | ||
737 | // |
|
738 | // Wrap the returned Objects into TorqueUsers. |
|
739 | // |
|
740 | 127 | for (Iterator it = list.iterator(); it.hasNext(); ) |
741 | { |
|
742 | 143 | User u = getNewUser((Persistent) it.next()); |
743 | 143 | newList.add(u); |
744 | } |
|
745 | ||
746 | 127 | return newList; |
747 | } |
|
748 | ||
749 | /** |
|
750 | * Invokes doDelete(Criteria c) on the configured Peer Object |
|
751 | * |
|
752 | * @param criteria A Criteria Object |
|
753 | * |
|
754 | * @exception TorqueException A problem occured. |
|
755 | */ |
|
756 | public static void doDelete(Criteria criteria) |
|
757 | throws TorqueException |
|
758 | { |
|
759 | try |
|
760 | { |
|
761 | 2 | Class[] clazz = new Class[] { Criteria.class }; |
762 | 2 | Object[] params = new Object[] { criteria }; |
763 | ||
764 | 2 | userPeerClass |
765 | .getMethod("doDelete", clazz) |
|
766 | .invoke(null, params); |
|
767 | } |
|
768 | 0 | catch (Exception e) |
769 | { |
|
770 | 0 | throw new TorqueException("doDelete failed", e); |
771 | 2 | } |
772 | 2 | } |
773 | ||
774 | /** |
|
775 | * Invokes setName(String s) on the supplied base object |
|
776 | * |
|
777 | * @param obj The object to use for setting the name |
|
778 | * @param name The Name to set |
|
779 | */ |
|
780 | public static void setUserName(Persistent obj, String name) |
|
781 | { |
|
782 | 8 | if(obj == null) |
783 | { |
|
784 | 0 | return; |
785 | } |
|
786 | ||
787 | try |
|
788 | { |
|
789 | 8 | Object[] params = new Object[] { name }; |
790 | 8 | namePropDesc.getWriteMethod().invoke(obj, params); |
791 | } |
|
792 | 0 | catch (ClassCastException cce) |
793 | { |
|
794 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
795 | 0 | log.error(msg); |
796 | 0 | throw new RuntimeException(msg); |
797 | } |
|
798 | 0 | catch (Exception e) |
799 | { |
|
800 | 0 | log.error(e, e); |
801 | 8 | } |
802 | 8 | } |
803 | ||
804 | /** |
|
805 | * Invokes getName() on the supplied base object |
|
806 | * |
|
807 | * @param obj The object to use for getting the name |
|
808 | * |
|
809 | * @return A string containing the name |
|
810 | * |
|
811 | * @deprecated use getName(obj) |
|
812 | */ |
|
813 | public static String getUserName(Persistent obj) |
|
814 | { |
|
815 | 0 | return getName(obj); |
816 | } |
|
817 | ||
818 | /** |
|
819 | * Invokes getName() on the supplied base object |
|
820 | * |
|
821 | * @param obj The object to use for getting the name |
|
822 | * |
|
823 | * @return A string containing the name |
|
824 | */ |
|
825 | public static String getName(Persistent obj) |
|
826 | { |
|
827 | 91 | String name = null; |
828 | ||
829 | 91 | if(obj == null) |
830 | { |
|
831 | 0 | return null; |
832 | } |
|
833 | ||
834 | try |
|
835 | { |
|
836 | 91 | name = (String) namePropDesc |
837 | .getReadMethod() |
|
838 | .invoke(obj, new Object[] {}); |
|
839 | } |
|
840 | 0 | catch (ClassCastException cce) |
841 | { |
|
842 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
843 | 0 | log.error(msg); |
844 | 0 | throw new RuntimeException(msg); |
845 | } |
|
846 | 0 | catch (Exception e) |
847 | { |
|
848 | 0 | log.error(e, e); |
849 | 91 | } |
850 | 91 | return name; |
851 | } |
|
852 | ||
853 | /** |
|
854 | * Invokes setPassword(String s) on the supplied base object |
|
855 | * |
|
856 | * @param obj The object to use for setting the password |
|
857 | * @param password The Password to set |
|
858 | */ |
|
859 | public static void setUserPassword(Persistent obj, String password) |
|
860 | { |
|
861 | 8 | if(obj == null) |
862 | { |
|
863 | 0 | return; |
864 | } |
|
865 | ||
866 | try |
|
867 | { |
|
868 | 8 | Object[] params = new Object[] { password }; |
869 | 8 | passwordPropDesc.getWriteMethod().invoke(obj, params); |
870 | } |
|
871 | 0 | catch (ClassCastException cce) |
872 | { |
|
873 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
874 | 0 | log.error(msg); |
875 | 0 | throw new RuntimeException(msg); |
876 | } |
|
877 | 0 | catch (Exception e) |
878 | { |
|
879 | 0 | log.error(e, e); |
880 | 8 | } |
881 | 8 | } |
882 | ||
883 | /** |
|
884 | * Invokes getPassword() on the supplied base object |
|
885 | * |
|
886 | * @param obj The object to use for getting the password |
|
887 | * |
|
888 | * @return A string containing the password |
|
889 | */ |
|
890 | public static String getUserPassword(Persistent obj) |
|
891 | { |
|
892 | 19 | String password = null; |
893 | ||
894 | 19 | if(obj == null) |
895 | { |
|
896 | 0 | return null; |
897 | } |
|
898 | ||
899 | try |
|
900 | { |
|
901 | 19 | password = (String) passwordPropDesc |
902 | .getReadMethod() |
|
903 | .invoke(obj, new Object[] {}); |
|
904 | } |
|
905 | 0 | catch (ClassCastException cce) |
906 | { |
|
907 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
908 | 0 | log.error(msg); |
909 | 0 | throw new RuntimeException(msg); |
910 | } |
|
911 | 0 | catch (Exception e) |
912 | { |
|
913 | 0 | log.error(e, e); |
914 | 19 | } |
915 | 19 | return password; |
916 | } |
|
917 | ||
918 | /** |
|
919 | * Invokes setFirstName(String s) on the supplied base object |
|
920 | * |
|
921 | * @param obj The object to use for setting the first name |
|
922 | * @param firstName The first name to set |
|
923 | */ |
|
924 | public static void setUserFirstName(Persistent obj, String firstName) |
|
925 | { |
|
926 | 2 | if(obj == null) |
927 | { |
|
928 | 0 | return; |
929 | } |
|
930 | ||
931 | try |
|
932 | { |
|
933 | 2 | Object[] params = new Object[] { firstName }; |
934 | 2 | firstNamePropDesc.getWriteMethod().invoke(obj, params); |
935 | } |
|
936 | 0 | catch (ClassCastException cce) |
937 | { |
|
938 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
939 | 0 | log.error(msg); |
940 | 0 | throw new RuntimeException(msg); |
941 | } |
|
942 | 0 | catch (Exception e) |
943 | { |
|
944 | 0 | log.error(e, e); |
945 | 2 | } |
946 | 2 | } |
947 | ||
948 | /** |
|
949 | * Invokes getFirstName() on the supplied base object |
|
950 | * |
|
951 | * @param obj The object to use for getting the first name |
|
952 | * |
|
953 | * @return A string containing the first name |
|
954 | */ |
|
955 | public static String getUserFirstName(Persistent obj) |
|
956 | { |
|
957 | 0 | String firstName = null; |
958 | ||
959 | 0 | if(obj == null) |
960 | { |
|
961 | 0 | return null; |
962 | } |
|
963 | ||
964 | try |
|
965 | { |
|
966 | 0 | firstName = (String) firstNamePropDesc |
967 | .getReadMethod() |
|
968 | .invoke(obj, new Object[] {}); |
|
969 | } |
|
970 | 0 | catch (ClassCastException cce) |
971 | { |
|
972 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
973 | 0 | log.error(msg); |
974 | 0 | throw new RuntimeException(msg); |
975 | } |
|
976 | 0 | catch (Exception e) |
977 | { |
|
978 | 0 | log.error(e, e); |
979 | 0 | } |
980 | 0 | return firstName; |
981 | } |
|
982 | ||
983 | /** |
|
984 | * Invokes setLastName(String s) on the supplied base object |
|
985 | * |
|
986 | * @param obj The object to use for setting the last name |
|
987 | * @param lastName The Last Name to set |
|
988 | */ |
|
989 | public static void setUserLastName(Persistent obj, String lastName) |
|
990 | { |
|
991 | 2 | if(obj == null) |
992 | { |
|
993 | 0 | return; |
994 | } |
|
995 | ||
996 | try |
|
997 | { |
|
998 | 2 | Object[] params = new Object[] { lastName }; |
999 | 2 | lastNamePropDesc.getWriteMethod().invoke(obj, params); |
1000 | } |
|
1001 | 0 | catch (ClassCastException cce) |
1002 | { |
|
1003 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1004 | 0 | log.error(msg); |
1005 | 0 | throw new RuntimeException(msg); |
1006 | } |
|
1007 | 0 | catch (Exception e) |
1008 | { |
|
1009 | 0 | log.error(e, e); |
1010 | 2 | } |
1011 | 2 | } |
1012 | ||
1013 | /** |
|
1014 | * Invokes getLastName() on the supplied base object |
|
1015 | * |
|
1016 | * @param obj The object to use for getting the last name |
|
1017 | * |
|
1018 | * @return A string containing the last name |
|
1019 | */ |
|
1020 | public static String getUserLastName(Persistent obj) |
|
1021 | { |
|
1022 | 0 | String lastName = null; |
1023 | ||
1024 | 0 | if(obj == null) |
1025 | { |
|
1026 | 0 | return null; |
1027 | } |
|
1028 | ||
1029 | try |
|
1030 | { |
|
1031 | 0 | lastName = (String) lastNamePropDesc |
1032 | .getReadMethod() |
|
1033 | .invoke(obj, new Object[] {}); |
|
1034 | } |
|
1035 | 0 | catch (ClassCastException cce) |
1036 | { |
|
1037 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1038 | 0 | log.error(msg); |
1039 | 0 | throw new RuntimeException(msg); |
1040 | } |
|
1041 | 0 | catch (Exception e) |
1042 | { |
|
1043 | 0 | log.error(e, e); |
1044 | 0 | } |
1045 | 0 | return lastName; |
1046 | } |
|
1047 | ||
1048 | /** |
|
1049 | * Invokes setEmail(String s) on the supplied base object |
|
1050 | * |
|
1051 | * @param obj The object to use for setting the email |
|
1052 | * @param email The Email to set |
|
1053 | */ |
|
1054 | public static void setUserEmail(Persistent obj, String email) |
|
1055 | { |
|
1056 | 0 | if(obj == null) |
1057 | { |
|
1058 | 0 | return; |
1059 | } |
|
1060 | ||
1061 | try |
|
1062 | { |
|
1063 | 0 | Object[] params = new Object[] { email }; |
1064 | 0 | emailPropDesc.getWriteMethod().invoke(obj, params); |
1065 | } |
|
1066 | 0 | catch (ClassCastException cce) |
1067 | { |
|
1068 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1069 | 0 | log.error(msg); |
1070 | 0 | throw new RuntimeException(msg); |
1071 | } |
|
1072 | 0 | catch (Exception e) |
1073 | { |
|
1074 | 0 | log.error(e, e); |
1075 | 0 | } |
1076 | 0 | } |
1077 | ||
1078 | /** |
|
1079 | * Invokes getEmail() on the supplied base object |
|
1080 | * |
|
1081 | * @param obj The object to use for getting the email |
|
1082 | * |
|
1083 | * @return A string containing the email |
|
1084 | */ |
|
1085 | public static String getUserEmail(Persistent obj) |
|
1086 | { |
|
1087 | 0 | String email = null; |
1088 | ||
1089 | 0 | if(obj == null) |
1090 | { |
|
1091 | 0 | return null; |
1092 | } |
|
1093 | ||
1094 | try |
|
1095 | { |
|
1096 | 0 | email = (String) emailPropDesc |
1097 | .getReadMethod() |
|
1098 | .invoke(obj, new Object[] {}); |
|
1099 | } |
|
1100 | 0 | catch (ClassCastException cce) |
1101 | { |
|
1102 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1103 | 0 | log.error(msg); |
1104 | 0 | throw new RuntimeException(msg); |
1105 | } |
|
1106 | 0 | catch (Exception e) |
1107 | { |
|
1108 | 0 | log.error(e, e); |
1109 | 0 | } |
1110 | 0 | return email; |
1111 | } |
|
1112 | ||
1113 | /** |
|
1114 | * Invokes setConfirmed(String s) on the supplied base object |
|
1115 | * |
|
1116 | * @param obj The object to use for setting the confirm value |
|
1117 | * @param confirm The confirm value to set |
|
1118 | */ |
|
1119 | public static void setUserConfirmed(Persistent obj, String confirm) |
|
1120 | { |
|
1121 | 0 | if(obj == null) |
1122 | { |
|
1123 | 0 | return; |
1124 | } |
|
1125 | ||
1126 | try |
|
1127 | { |
|
1128 | 0 | Object[] params = new Object[] { confirm }; |
1129 | 0 | confirmPropDesc.getWriteMethod().invoke(obj, params); |
1130 | } |
|
1131 | 0 | catch (ClassCastException cce) |
1132 | { |
|
1133 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1134 | 0 | log.error(msg); |
1135 | 0 | throw new RuntimeException(msg); |
1136 | } |
|
1137 | 0 | catch (Exception e) |
1138 | { |
|
1139 | 0 | log.error(e, e); |
1140 | 0 | } |
1141 | 0 | } |
1142 | ||
1143 | /** |
|
1144 | * Invokes getConfirmed() on the supplied base object |
|
1145 | * |
|
1146 | * @param obj The object to use for getting the confirm value |
|
1147 | * |
|
1148 | * @return A string containing the confirm value |
|
1149 | */ |
|
1150 | public static String getUserConfirmed(Persistent obj) |
|
1151 | { |
|
1152 | 0 | String confirm = null; |
1153 | ||
1154 | 0 | if(obj == null) |
1155 | { |
|
1156 | 0 | return null; |
1157 | } |
|
1158 | ||
1159 | try |
|
1160 | { |
|
1161 | 0 | confirm = (String) confirmPropDesc |
1162 | .getReadMethod() |
|
1163 | .invoke(obj, new Object[] {}); |
|
1164 | } |
|
1165 | 0 | catch (ClassCastException cce) |
1166 | { |
|
1167 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1168 | 0 | log.error(msg); |
1169 | 0 | throw new RuntimeException(msg); |
1170 | } |
|
1171 | 0 | catch (Exception e) |
1172 | { |
|
1173 | 0 | log.error(e, e); |
1174 | 0 | } |
1175 | 0 | return confirm; |
1176 | } |
|
1177 | ||
1178 | /** |
|
1179 | * Invokes setCreateDate(java.util.Date date) on the supplied base object |
|
1180 | * |
|
1181 | * @param obj The object to use for setting the create date |
|
1182 | * @param createDate The create date to set |
|
1183 | */ |
|
1184 | public static void setUserCreateDate(Persistent obj, java.util.Date createDate) |
|
1185 | { |
|
1186 | 12 | if(obj == null) |
1187 | { |
|
1188 | 0 | return; |
1189 | } |
|
1190 | ||
1191 | try |
|
1192 | { |
|
1193 | 12 | Object[] params = new Object[] { createDate }; |
1194 | 12 | createDatePropDesc.getWriteMethod().invoke(obj, params); |
1195 | } |
|
1196 | 0 | catch (ClassCastException cce) |
1197 | { |
|
1198 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1199 | 0 | log.error(msg); |
1200 | 0 | throw new RuntimeException(msg); |
1201 | } |
|
1202 | 0 | catch (Exception e) |
1203 | { |
|
1204 | 0 | log.error(e, e); |
1205 | 12 | } |
1206 | 12 | } |
1207 | ||
1208 | /** |
|
1209 | * Invokes getCreateDate() on the supplied base object |
|
1210 | * |
|
1211 | * @param obj The object to use for getting the create date |
|
1212 | * |
|
1213 | * @return A string containing the create date |
|
1214 | */ |
|
1215 | public static java.util.Date getUserCreateDate(Persistent obj) |
|
1216 | { |
|
1217 | 0 | java.util.Date createDate = null; |
1218 | ||
1219 | 0 | if(obj == null) |
1220 | { |
|
1221 | 0 | return null; |
1222 | } |
|
1223 | ||
1224 | try |
|
1225 | { |
|
1226 | 0 | createDate = (java.util.Date) createDatePropDesc |
1227 | .getReadMethod() |
|
1228 | .invoke(obj, new Object[] {}); |
|
1229 | } |
|
1230 | 0 | catch (ClassCastException cce) |
1231 | { |
|
1232 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1233 | 0 | log.error(msg); |
1234 | 0 | throw new RuntimeException(msg); |
1235 | } |
|
1236 | 0 | catch (Exception e) |
1237 | { |
|
1238 | 0 | log.error(e, e); |
1239 | 0 | } |
1240 | 0 | return createDate; |
1241 | } |
|
1242 | ||
1243 | /** |
|
1244 | * Invokes setLastLogin(java.util.Date date) on the supplied base object |
|
1245 | * |
|
1246 | * @param obj The object to use for setting the last login daet |
|
1247 | * @param lastLogin The last login date to set |
|
1248 | */ |
|
1249 | public static void setUserLastLogin(Persistent obj, java.util.Date lastLogin) |
|
1250 | { |
|
1251 | 0 | if(obj == null) |
1252 | { |
|
1253 | 0 | return; |
1254 | } |
|
1255 | ||
1256 | try |
|
1257 | { |
|
1258 | 0 | Object[] params = new Object[] { lastLogin }; |
1259 | 0 | lastLoginPropDesc.getWriteMethod().invoke(obj, params); |
1260 | } |
|
1261 | 0 | catch (ClassCastException cce) |
1262 | { |
|
1263 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1264 | 0 | log.error(msg); |
1265 | 0 | throw new RuntimeException(msg); |
1266 | } |
|
1267 | 0 | catch (Exception e) |
1268 | { |
|
1269 | 0 | log.error(e, e); |
1270 | 0 | } |
1271 | 0 | } |
1272 | ||
1273 | /** |
|
1274 | * Invokes getLastLogin() on the supplied base object |
|
1275 | * |
|
1276 | * @param obj The object to use for getting the last login date |
|
1277 | * |
|
1278 | * @return A string containing the last login date |
|
1279 | */ |
|
1280 | public static java.util.Date getUserLastLogin(Persistent obj) |
|
1281 | { |
|
1282 | 0 | java.util.Date lastLogin = null; |
1283 | ||
1284 | 0 | if(obj == null) |
1285 | { |
|
1286 | 0 | return null; |
1287 | } |
|
1288 | ||
1289 | try |
|
1290 | { |
|
1291 | 0 | lastLogin = (java.util.Date) lastLoginPropDesc |
1292 | .getReadMethod() |
|
1293 | .invoke(obj, new Object[] {}); |
|
1294 | } |
|
1295 | 0 | catch (ClassCastException cce) |
1296 | { |
|
1297 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1298 | 0 | log.error(msg); |
1299 | 0 | throw new RuntimeException(msg); |
1300 | } |
|
1301 | 0 | catch (Exception e) |
1302 | { |
|
1303 | 0 | log.error(e, e); |
1304 | 0 | } |
1305 | 0 | return lastLogin; |
1306 | } |
|
1307 | ||
1308 | /** |
|
1309 | * Invokes setObjectdata(byte [] date) on the supplied base object |
|
1310 | * |
|
1311 | * @param obj The object to use for setting the last login daet |
|
1312 | * @param objectdata The objectdata to use |
|
1313 | */ |
|
1314 | public static void setUserObjectdata(Persistent obj, byte [] objectdata) |
|
1315 | { |
|
1316 | 11 | if(obj == null) |
1317 | { |
|
1318 | 0 | return; |
1319 | } |
|
1320 | ||
1321 | try |
|
1322 | { |
|
1323 | 11 | Object[] params = new Object[] { objectdata }; |
1324 | 11 | objectdataPropDesc.getWriteMethod().invoke(obj, params); |
1325 | } |
|
1326 | 0 | catch (ClassCastException cce) |
1327 | { |
|
1328 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1329 | 0 | log.error(msg); |
1330 | 0 | throw new RuntimeException(msg); |
1331 | } |
|
1332 | 0 | catch (Exception e) |
1333 | { |
|
1334 | 0 | log.error(e, e); |
1335 | 11 | } |
1336 | 11 | } |
1337 | ||
1338 | /** |
|
1339 | * Invokes getObjectdata() on the supplied base object |
|
1340 | * |
|
1341 | * @param obj The object to use for getting the last login date |
|
1342 | * |
|
1343 | * @return A string containing the last login date |
|
1344 | */ |
|
1345 | public static byte [] getUserObjectdata(Persistent obj) |
|
1346 | { |
|
1347 | 10 | byte [] objectdata = null; |
1348 | ||
1349 | 10 | if(obj == null) |
1350 | { |
|
1351 | 0 | return null; |
1352 | } |
|
1353 | ||
1354 | try |
|
1355 | { |
|
1356 | 10 | objectdata = (byte []) objectdataPropDesc |
1357 | .getReadMethod() |
|
1358 | .invoke(obj, new Object[] {}); |
|
1359 | } |
|
1360 | 0 | catch (ClassCastException cce) |
1361 | { |
|
1362 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1363 | 0 | log.error(msg); |
1364 | 0 | throw new RuntimeException(msg); |
1365 | } |
|
1366 | 0 | catch (Exception e) |
1367 | { |
|
1368 | 0 | log.error(e, e); |
1369 | 10 | } |
1370 | 10 | return objectdata; |
1371 | } |
|
1372 | ||
1373 | /** |
|
1374 | * Invokes setId(int n) on the supplied base object |
|
1375 | * |
|
1376 | * @param obj The object to use for setting the name |
|
1377 | * @param id The new Id |
|
1378 | */ |
|
1379 | public static void setId(Persistent obj, int id) |
|
1380 | { |
|
1381 | 0 | if(obj == null) |
1382 | { |
|
1383 | 0 | return; |
1384 | } |
|
1385 | ||
1386 | try |
|
1387 | { |
|
1388 | 0 | Object[] params = new Object[] { Integer.TYPE }; |
1389 | 0 | idPropDesc.getWriteMethod().invoke(obj, params); |
1390 | } |
|
1391 | 0 | catch (ClassCastException cce) |
1392 | { |
|
1393 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1394 | 0 | log.error(msg); |
1395 | 0 | throw new RuntimeException(msg); |
1396 | } |
|
1397 | 0 | catch (Exception e) |
1398 | { |
|
1399 | 0 | log.error(e, e); |
1400 | 0 | } |
1401 | 0 | } |
1402 | ||
1403 | /** |
|
1404 | * Invokes getId() on the supplied base object |
|
1405 | * |
|
1406 | * @param obj The object to use for getting the id |
|
1407 | * |
|
1408 | * @return The Id of this object |
|
1409 | */ |
|
1410 | public static Integer getIdAsObj(Persistent obj) |
|
1411 | { |
|
1412 | 2 | Integer id = null; |
1413 | ||
1414 | 2 | if(obj == null) |
1415 | { |
|
1416 | 0 | return new Integer(0); |
1417 | } |
|
1418 | ||
1419 | try |
|
1420 | { |
|
1421 | 2 | id = (Integer) idPropDesc |
1422 | .getReadMethod() |
|
1423 | .invoke(obj, new Object[] {}); |
|
1424 | } |
|
1425 | 0 | catch (ClassCastException cce) |
1426 | { |
|
1427 | 0 | String msg = obj.getClass().getName() + " does not seem to be an User Object!"; |
1428 | 0 | log.error(msg); |
1429 | 0 | throw new RuntimeException(msg); |
1430 | } |
|
1431 | 0 | catch (Exception e) |
1432 | { |
|
1433 | 0 | log.error(e, e); |
1434 | 2 | } |
1435 | 2 | return id; |
1436 | } |
|
1437 | ||
1438 | /** |
|
1439 | * Returns the Class of the configured Object class |
|
1440 | * from the peer |
|
1441 | * |
|
1442 | * @return The class of the objects returned by the configured peer |
|
1443 | * |
|
1444 | */ |
|
1445 | ||
1446 | private static Class getPersistenceClass() |
|
1447 | { |
|
1448 | 8 | Class persistenceClass = null; |
1449 | ||
1450 | try |
|
1451 | { |
|
1452 | 8 | Object[] params = new Object[0]; |
1453 | ||
1454 | 8 | persistenceClass = (Class) userPeerClass |
1455 | .getMethod("getOMClass", null) |
|
1456 | .invoke(null, params); |
|
1457 | } |
|
1458 | 0 | catch (Exception e) |
1459 | { |
|
1460 | 0 | persistenceClass = null; |
1461 | 8 | } |
1462 | ||
1463 | 8 | return persistenceClass; |
1464 | } |
|
1465 | ||
1466 | /** |
|
1467 | * Returns a new, configured User Object with |
|
1468 | * a supplied Persistent object at its core |
|
1469 | * |
|
1470 | * @param p The persistent object |
|
1471 | * |
|
1472 | * @return a new, configured User Object |
|
1473 | * |
|
1474 | * @exception Exception Could not create a new Object |
|
1475 | * |
|
1476 | */ |
|
1477 | ||
1478 | public static User getNewUser(Persistent p) |
|
1479 | { |
|
1480 | 143 | User u = null; |
1481 | try |
|
1482 | { |
|
1483 | 143 | Class userWrapperClass = TurbineSecurity.getUserClass(); |
1484 | ||
1485 | 143 | Class [] clazz = new Class [] { Persistent.class }; |
1486 | 143 | Object [] params = new Object [] { p }; |
1487 | ||
1488 | 143 | u = (User) userWrapperClass |
1489 | .getConstructor(clazz) |
|
1490 | .newInstance(params); |
|
1491 | } |
|
1492 | 0 | catch (Exception e) |
1493 | { |
|
1494 | 0 | log.error("Could not instantiate a new user from supplied persistent: ", e); |
1495 | 143 | } |
1496 | ||
1497 | 143 | return u; |
1498 | } |
|
1499 | } |
|
1500 | ||
1501 |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |