001: package net.sourceforge.squirrel_sql.fw.util;
002:
003: /*
004: * Copyright (C) 2002 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.util.List;
022: import java.util.Vector;
023:
024: /**
025: * This message handler stores msgs in 2 <TT>java.util.List</TT> objects. One
026: * for exceptions and the other for strings.
027: *
028: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
029: */
030: public class ListMessageHandler implements IMessageHandler {
031: ///////////////////////////////////////////////////////////
032: // We use Vectors because a MessageHandler might be called from different threads.
033:
034: /** Stores msgs. */
035: private List<String> _msgs = new Vector<String>();
036:
037: /** Stores exceptions. */
038: private List<Throwable> _throwables = new Vector<Throwable>();
039:
040: /** Stores error msgs. */
041: private List<String> _errMsgs = new Vector<String>();
042:
043: /** Stores exceptions. */
044: private List<Throwable> _errThrowables = new Vector<Throwable>();
045:
046: private List<String> _warningMsgs = new Vector<String>();
047:
048: //
049: ///////////////////////////////////////////////////////////////////////////////////
050:
051: /**
052: * Ctor.
053: */
054: public ListMessageHandler() {
055: super ();
056: }
057:
058: /**
059: * Store this exception.
060: *
061: * @param th Exception to be stored.
062: */
063: public void showMessage(Throwable th, ExceptionFormatter formatter) {
064: _throwables.add(th);
065: }
066:
067: /**
068: * Store this msg.
069: *
070: * @param msg Message to be stored.
071: */
072: public void showMessage(String msg) {
073: _msgs.add(msg);
074: }
075:
076: /**
077: * Store this msg.
078: *
079: * @param th Exception.
080: */
081: public void showErrorMessage(Throwable th,
082: ExceptionFormatter formatter) {
083: _errThrowables.add(th);
084: }
085:
086: /**
087: * Store this exception.
088: * @param th Exception.
089: */
090: public void showErrorMessage(String msg) {
091: _errMsgs.add(msg);
092: }
093:
094: public void showWarningMessage(String msg) {
095: _warningMsgs.add(msg);
096: }
097:
098: /**
099: * Return array of stored exceptions.
100: *
101: * @return array of stored exceptions.
102: */
103: public Throwable[] getExceptions() {
104: return _throwables.toArray(new Throwable[_throwables.size()]);
105: }
106:
107: /**
108: * Return array of stored exceptionsfrom <TT>showErrorMessage(Throwable)</TT>..
109: *
110: * @return array of stored exceptions.
111: */
112: public Throwable[] getErrorExceptions() {
113: return _errThrowables.toArray(new Throwable[_errThrowables
114: .size()]);
115: }
116:
117: /**
118: * Return array of stored messages.
119: *
120: * @return array of stored messages.
121: */
122: public String[] getMessages() {
123: return _msgs.toArray(new String[_msgs.size()]);
124: }
125:
126: /**
127: * Return array of stored messages from <TT>showErrorMessage(String)</TT>.
128: *
129: * @return array of stored messages.
130: */
131: public String[] getErrorMessages() {
132: return _errMsgs.toArray(new String[_errMsgs.size()]);
133: }
134:
135: public String[] getWarningMessages() {
136: return _warningMsgs.toArray(new String[_warningMsgs.size()]);
137: }
138: }
|