1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.domain.dao;
17
18 import org.springframework.util.Assert;
19
20
21
22 /***
23 * Convenience methods that support initialization of lazily loaded collections
24 * and associations using DAOs and other objects that implement
25 * {@link org.acegisecurity.domain.dao.InitializationCapable}.
26 *
27 * @author Ben Alex
28 * @version $Id: InitializationUtils.java,v 1.3 2005/11/17 00:55:47 benalex Exp $
29 */
30 public class InitializationUtils {
31
32
33 /***
34 * Initializes the passed entity using the passed
35 * DAO or services layer <code>Object</code> (provided that the passed
36 * <code>Object</code> implements <code>InitializationCapable</code>).
37 *
38 * @param daoOrServices the potential source for
39 * <code>InitializationCapable</code> services (never <code>null</code>)
40 * @param entity to evict (can be <code>null</code>)
41 */
42 public static void initializeIfRequired(Object daoOrServices,
43 Object entity) {
44 Assert.notNull(daoOrServices);
45 if (daoOrServices instanceof InitializationCapable) {
46 ((InitializationCapable) daoOrServices).initialize(entity);
47 }
48 }
49
50 /***
51 * Indicates whether the passed entity has been initialized, by delegating
52 * to the passed daoOrServices (provided that the passed daoOrServices
53 * implements <code>InitializationCapable</code>.
54 *
55 * @param entity to determine whether initialized or not
56 * @return <code>true</code> if initialized, <code>false</code> if it is
57 * uninitialized or the passed daoOrServices does not provide
58 * initialization querying support
59 */
60 public static boolean isInitialized(Object daoOrServices, Object entity) {
61 Assert.notNull(daoOrServices);
62 if (daoOrServices instanceof InitializationCapable) {
63 return ((InitializationCapable) daoOrServices).isInitialized(entity);
64 }
65 return false;
66 }
67 }