/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */
package org.openmrs.api;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Holds all OpenMRS event listeners
 */
public class EventListeners {
	
	private static Log log = LogFactory.getLog(EventListeners.class);
	
	private static List<GlobalPropertyListener> globalPropertyListeners;
	
	public EventListeners() {
	}
	
	public List<GlobalPropertyListener> getGlobalPropertyListeners() {
		return globalPropertyListeners;
	}
	
	public void setGlobalPropertyListeners(List<GlobalPropertyListener> globalPropertyListeners) {
		if (log.isDebugEnabled()) {
			StringBuffer sb = new StringBuffer();
			for (GlobalPropertyListener gpl : globalPropertyListeners) {
				if (sb.length() > 0)
					sb.append(", ");
				sb.append(gpl.getClass().getName());
			}
			log.debug("GlobalPropertyListeners set to: " + sb.toString());
			
		}
		EventListeners.globalPropertyListeners = globalPropertyListeners;
	}
	
}

@@ -916,19 +916,26 @@
 isteners
+ = null
 ;%0D%0A
-
 %09%0D%0A%09publ
@@ -1067,32 +1067,259 @@
 teners;%0D%0A%09%7D%0D%0A%09%0D%0A
+%09/**%0D%0A%09 * This setter acts more like an %22appender%22.  If the list already has elements, calling this method%0D%0A%09 * will %3Cb%3Eadd to%3C/b%3E the list of listeners instead of replacing it.%0D%0A%09 * %0D%0A%09 * @param globalPropertyListeners%0D%0A%09 */%0D%0A
 %09public void set
@@ -1713,16 +1713,76 @@
 %0A%09%09%7D%0D%0A%09%09
+%0D%0A%09%09if (EventListeners.globalPropertyListeners == null)%0D%0A%09%09%09
 EventLis
@@ -1836,22 +1836,227 @@
 Listeners;%0D%0A
+%09%09else %7B%0D%0A%09%09%09for (GlobalPropertyListener gpl : globalPropertyListeners) %7B%0D%0A%09%09%09%09if (!EventListeners.globalPropertyListeners.contains(gpl))%0D%0A%09%09%09%09%09EventListeners.globalPropertyListeners.add(gpl);%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A%09%0D%0A%7D%0D%0A

Fix the logic in EventListeners.setGlobalPropertyListeners - TRUNK-2323