|
From: <tr...@us...> - 2003-08-12 00:28:33
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core In directory sc8-pr-cvs1:/tmp/cvs-serv28668/src/com/babeldoc/core Modified Files: BabeldocCommand.java EnvironmentLoader.java Added Files: IShutdownListener.java Log Message: Added the shutdown listener framework. Classes that want to be told when babeldoc is about to be shutdown implement the IShutdownListener and call EnvironmentLoader.addShutdownListener. --- NEW FILE: IShutdownListener.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/IShutdownListener.java,v 1.1 2003/08/12 00:28:29 triphop Exp $ * $DateTime$ * $Author: triphop $ * */ package com.babeldoc.core; /** * This interface can be implemented by all classes that need to be told about * when babeldoc is about to stutdown. All services, etc that what to be called when * babeldoc is about to be shutdown, need to implement this interface and then call the * EnvironmentLoader.addShutdownListener method with 'this'. * * @author bmcdonald * @version 1.1 */ public interface IShutdownListener { /** * Callback method from the loader to signal that the babeldoc * wants to shutdown. Please finalize, etc. */ public void shutdown(); } Index: BabeldocCommand.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/BabeldocCommand.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** BabeldocCommand.java 7 Aug 2003 18:29:21 -0000 1.15 --- BabeldocCommand.java 12 Aug 2003 00:28:29 -0000 1.16 *************** *** 174,178 **** }; execute(commandLine); ! } --- 174,178 ---- }; execute(commandLine); ! EnvironmentLoader.shutdown(); } *************** *** 300,304 **** */ protected void setup() { ! com.babeldoc.core.EnvironmentLoader.loadEnvironment(); } } --- 300,304 ---- */ protected void setup() { ! EnvironmentLoader.loadEnvironment(); } } Index: EnvironmentLoader.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/EnvironmentLoader.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EnvironmentLoader.java 19 Jul 2003 15:32:27 -0000 1.9 --- EnvironmentLoader.java 12 Aug 2003 00:28:29 -0000 1.10 *************** *** 75,78 **** --- 75,79 ---- import java.util.Iterator; import java.util.StringTokenizer; + import java.util.Collection; *************** *** 100,103 **** --- 101,106 ---- private static boolean envLoaded = false; + private static Collection shutdownListeners; + /** * Get a copy of the the search paths. *************** *** 151,154 **** --- 154,182 ---- String value = config.getString(key); System.setProperty(key, value); + } + } + + /** + * Add a shutdown listener to the list of listeners that need to be told about + * babeldoc shuting down. + * + * @param listener + */ + public static synchronized void addShutdownListener(IShutdownListener listener) { + if(shutdownListeners==null) { + shutdownListeners = new ArrayList(); + } + shutdownListeners.add(listener); + } + + /** + * Shutdown babeldoc - call all of the listeners shutdown method. + */ + public static synchronized void shutdown() { + if(shutdownListeners!=null) { + for (Iterator iterator = shutdownListeners.iterator(); iterator.hasNext();) { + IShutdownListener iShutdownListener = (IShutdownListener) iterator.next(); + iShutdownListener.shutdown(); + } } } |