001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: LoggingMux.java,v $ 023 Revision 1.5 2004/05/05 21:22:45 markl 024 Comment header updates. 025 026 Revision 1.4 2003/01/19 09:42:39 markl 027 Javadoc & comment header updates. 028 029 Revision 1.3 2001/03/12 02:57:41 markl 030 Source code cleanup. 031 032 Revision 1.2 1999/02/09 05:07:22 markl 033 minor fixes 034 035 Revision 1.1 1999/02/02 07:35:43 markl 036 Initial revision 037 ---------------------------------------------------------------------------- 038*/ 039 040package kiwi.util; 041 042import java.util.*; 043 044/** A logging multiplexor. This class manages a set of 045 * <code>LoggingEndpoint</code>s and itself implements the 046 * <code>LoggingEndpoint</code> interface. It may be use to direct logging 047 * messages to several endpoints simultaneously. For example, an application 048 * may send messages to both a console and a file. 049 * 050 * @see kiwi.util.LoggingEndpoint 051 * 052 * @author Mark Lindner 053 */ 054 055public class LoggingMux implements LoggingEndpoint 056 { 057 private Vector v; 058 059 /** Construct a new <code>LoggingMux</code>. 060 */ 061 062 public LoggingMux() 063 { 064 v = new Vector(); 065 } 066 067 /** Log a message to all endpoints in this set. 068 */ 069 070 public void logMessage(int type, String message) 071 { 072 Enumeration e = v.elements(); 073 while(e.hasMoreElements()) 074 ((LoggingEndpoint)e.nextElement()).logMessage(type, message); 075 } 076 077 /** Close this set of endpoints. Equivalent to <code>close(false)</code>. 078 */ 079 080 public void close() 081 { 082 close(false); 083 } 084 085 /** Close this set of endpoints. 086 * 087 * @param closeEndpoints If <code>true</code>, in addition to removing every 088 * <code>LoggingEndpoint</code> from its list, the <code>LoggingMux</code> 089 * closes each <code>LoggingEndpoint</code> explicitly via a call to its 090 * <code>close()</code> method. 091 */ 092 093 public void close(boolean closeEndpoints) 094 { 095 if(closeEndpoints) 096 { 097 Enumeration e = v.elements(); 098 while(e.hasMoreElements()) 099 ((LoggingEndpoint)e.nextElement()).close(); 100 } 101 102 removeAllLoggingEndpoints(); 103 } 104 105 /** Add a <code>LoggingEndpoint</code> to the set. 106 * 107 * @param endpoint The <code>LoggingEndpoint</code> to add. 108 */ 109 110 public void addLoggingEndpoint(LoggingEndpoint endpoint) 111 { 112 v.addElement(endpoint); 113 } 114 115 /** Remove a <code>LoggingEndpoint</code> from the set. 116 * 117 * @param endpoint The <code>LoggingEndpoint</code> to remove. 118 */ 119 120 public void removeLoggingEndpoint(LoggingEndpoint endpoint) 121 { 122 v.removeElement(endpoint); 123 } 124 125 /** Remove all <code>LoggingEndpoint</code>s from the set. 126 */ 127 128 public void removeAllLoggingEndpoints() 129 { 130 v.removeAllElements(); 131 } 132 133 } 134 135/* end of source file */