001/** 002 * Copyright 2005-2017 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.ken.core; 017 018import org.apache.log4j.Logger; 019import org.springframework.beans.factory.BeanFactory; 020 021/** 022 * Class that holds a singleton reference to NotificationServiceLocator 023 * @author Kuali Rice Team (rice.collab@kuali.org) 024 */ 025public class GlobalNotificationServiceLocator { 026 private static final Logger LOG = Logger.getLogger(GlobalNotificationServiceLocator.class); 027 028 /** 029 * The NotificationServiceLocator singleton 030 */ 031 private static NotificationServiceLocator locator; 032 033 /** 034 * The global initializer that constructs the NotificationServiceLocator singleton 035 * @param beanFactory the beanFactory from which to construct the SpringNotificationServiceLocator 036 */ 037 public static synchronized void init(BeanFactory beanFactory) { 038 //LOG.debug("INITIALIZING", new Exception()); 039 if (locator != null) { 040 throw new IllegalStateException("GlobalNotificationServiceLocator already initialized"); 041 } 042 locator = new SpringNotificationServiceLocator(beanFactory); 043 } 044 045 /** 046 * Returns whether the GlobalNotificationServiceLocator has already been initialized (classloader scoped) 047 * @return whether the GlobalNotificationServiceLocator has already been initialized (classloader scoped) 048 */ 049 public static synchronized boolean isInitialized() { 050 return locator != null; 051 } 052 053 /** 054 * Un-sets the NotificationServiceLocator singleton, in order to fulfill a "lifecycle" 055 * contract (whereby init may be called again in the same class loader), specifically for 056 * unit tests. 057 */ 058 public static synchronized void destroy() { 059 //LOG.debug("DESTROYING", new Exception()); 060 locator = null; 061 } 062 063 /** 064 * Return the NotificationServiceLocator singleton 065 * @return the NotificationServiceLocator singleton 066 */ 067 public static NotificationServiceLocator getInstance() { 068 return locator; 069 } 070}