View Javadoc
1 /*** 2 * ShutDown.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 10.03.2003 pko creation 9 * 10 * Copyright 2003 ELCA Informatique SA 11 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 12 * www.elca.ch 13 * 14 * This library is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU Lesser General Public License 16 * as published by the Free Software Foundation; either version 2.1 of 17 * the License, or (at your option) any later version. 18 * 19 * This library is distributed in the hope that it will be useful, but 20 * WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 * Lesser General Public License for more details. 23 * 24 * You should have received a copy of the GNU Lesser General Public 25 * License along with this library; if not, write to the Free Software 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 27 * USA 28 */ 29 30 package ch.elca.dependency.util; 31 32 import java.util.ArrayList; 33 import java.util.Iterator; 34 35 /*** 36 * The class <code>Shutdown</code> is used to shut down the Dependency 37 * Tool. Because all classes which extend the class 38 * <code>NotifyOnExit</code> need to be notified that the Dependency 39 * is about to be terminated, never call System.exit() but the 40 * shutdown method of this class. 41 * 42 * @author Pawel Kowalski 43 * @version 1.0-beta 44 */ 45 public class Shutdown { 46 47 //****************************************************************************************/ 48 // instance fields 49 //****************************************************************************************/ 50 51 /*** 52 * An ArrayList of all <code>NotifyOnExit</code> instances 53 * interested in notification just before the tool terminates. 54 */ 55 private final static ArrayList m_onExitNotify = new ArrayList(); 56 57 //****************************************************************************************/ 58 // c'tor 59 //****************************************************************************************/ 60 61 /*** 62 * Creates a new <code>Shutdown</code> instance. 63 */ 64 public Shutdown() { 65 } 66 67 //****************************************************************************************/ 68 // public methods 69 //****************************************************************************************/ 70 71 /*** 72 * Shutdown the Dependency Tool. 73 */ 74 public static void shutdown() { 75 notifyOnExit(); 76 77 IOManager.deleteTempDir(); 78 System.exit(0); 79 } 80 81 /*** 82 * Register an instance of the class <code>NotifyOnExit</code> for 83 * notification just before the tool terminates. 84 * 85 * @param notifyOnExit a <code>NotifyOnExit</code> value 86 */ 87 public static void register(NotifyOnExit notifyOnExit) { 88 m_onExitNotify.add(notifyOnExit); 89 } 90 91 //****************************************************************************************/ 92 // private helpers 93 //****************************************************************************************/ 94 95 /*** 96 * Notify all <code>NotifyOnExit</code> objects that the tool is 97 * just about to terminate. 98 */ 99 private static void notifyOnExit() { 100 for (Iterator iter = m_onExitNotify.iterator(); iter.hasNext(); ) { 101 ((NotifyOnExit)iter.next()).notifyOnExit(); 102 } 103 } 104 }

This page was automatically generated by Maven