1 /**
2 * Copyright 2005-2012 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.ken.core;
17
18 import org.apache.log4j.Logger;
19 import org.springframework.beans.factory.BeanFactory;
20
21 /**
22 * Class that holds a singleton reference to NotificationServiceLocator
23 * @author Kuali Rice Team (rice.collab@kuali.org)
24 */
25 public class GlobalNotificationServiceLocator {
26 private static final Logger LOG = Logger.getLogger(GlobalNotificationServiceLocator.class);
27
28 /**
29 * The NotificationServiceLocator singleton
30 */
31 private static NotificationServiceLocator locator;
32
33 /**
34 * The global initializer that constructs the NotificationServiceLocator singleton
35 * @param beanFactory the beanFactory from which to construct the SpringNotificationServiceLocator
36 */
37 public static synchronized void init(BeanFactory beanFactory) {
38 //LOG.debug("INITIALIZING", new Exception());
39 if (locator != null) {
40 throw new IllegalStateException("GlobalNotificationServiceLocator already initialized");
41 }
42 locator = new SpringNotificationServiceLocator(beanFactory);
43 }
44
45 /**
46 * Returns whether the GlobalNotificationServiceLocator has already been initialized (classloader scoped)
47 * @return whether the GlobalNotificationServiceLocator has already been initialized (classloader scoped)
48 */
49 public static synchronized boolean isInitialized() {
50 return locator != null;
51 }
52
53 /**
54 * Un-sets the NotificationServiceLocator singleton, in order to fulfill a "lifecycle"
55 * contract (whereby init may be called again in the same class loader), specifically for
56 * unit tests.
57 */
58 public static synchronized void destroy() {
59 //LOG.debug("DESTROYING", new Exception());
60 locator = null;
61 }
62
63 /**
64 * Return the NotificationServiceLocator singleton
65 * @return the NotificationServiceLocator singleton
66 */
67 public static NotificationServiceLocator getInstance() {
68 return locator;
69 }
70 }