001: /*
002: * Copyright (C) 2006 Rob Manning
003: * manningr@users.sourceforge.net
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the 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: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package net.sourceforge.squirrel_sql.fw.util;
020:
021: import net.sourceforge.squirrel_sql.client.session.ISession;
022:
023: /**
024: * An IMessageHandler implementation that can be used as a test fixture where
025: * needed.
026: *
027: * @author manningr
028: */
029: public class MockMessageHandler implements IMessageHandler {
030:
031: private boolean showMessages = false;
032:
033: private boolean showWarningMessages = false;
034:
035: private boolean showErrorMessages = false;
036:
037: public void showMessage(Throwable th, ExceptionFormatter formatter) {
038: if (showMessages) {
039: System.out
040: .println("MockMessageHandler.showMessage(Throwable): th.getMessage="
041: + th.getMessage());
042: }
043: }
044:
045: public void showMessage(String msg) {
046: if (showMessages) {
047: System.out
048: .println("MockMessageHandler.showMessage(Throwable): msg="
049: + msg);
050: }
051: }
052:
053: public void showErrorMessage(Throwable th,
054: ExceptionFormatter formatter) {
055: if (showErrorMessages) {
056: System.out
057: .println("MockMessageHandler.showErrorMessage(Throwable): th.getMessage="
058: + th.getMessage());
059: }
060: }
061:
062: public void showErrorMessage(String msg) {
063: if (showErrorMessages) {
064: System.out
065: .println("MockMessageHandler.showErrorMessage(String): msg="
066: + msg);
067: }
068: }
069:
070: /* (non-Javadoc)
071: * @see net.sourceforge.squirrel_sql.fw.util.IMessageHandler#showWarningMessage(java.lang.String)
072: */
073: public void showWarningMessage(String msg) {
074: if (showWarningMessages) {
075: System.out
076: .println("MockMessageHandler.showWarningMessage(String): msg="
077: + msg);
078: }
079: }
080:
081: /**
082: * @param showMessages the showMessages to set
083: */
084: public void setShowMessages(boolean showMessages) {
085: this .showMessages = showMessages;
086: }
087:
088: /**
089: * @return the showMessages
090: */
091: public boolean isShowMessages() {
092: return showMessages;
093: }
094:
095: /**
096: * @param showWarningMessages the showWarningMessages to set
097: */
098: public void setShowWarningMessages(boolean showWarningMessages) {
099: this .showWarningMessages = showWarningMessages;
100: }
101:
102: /**
103: * @return the showWarningMessages
104: */
105: public boolean isShowWarningMessages() {
106: return showWarningMessages;
107: }
108:
109: /**
110: * @param showErrorMessages the showErrorMessages to set
111: */
112: public void setShowErrorMessages(boolean showErrorMessages) {
113: this .showErrorMessages = showErrorMessages;
114: }
115:
116: /**
117: * @return the showErrorMessages
118: */
119: public boolean isShowErrorMessages() {
120: return showErrorMessages;
121: }
122:
123: /**
124: * @see net.sourceforge.squirrel_sql.fw.util.IMessageHandler#setExceptionFormatter(net.sourceforge.squirrel_sql.fw.util.ExceptionFormatter, ISession)
125: */
126: @SuppressWarnings("unused")
127: public void setExceptionFormatter(ExceptionFormatter formatter,
128: ISession session) {
129: // Do Nothing
130: }
131:
132: /**
133: * @see net.sourceforge.squirrel_sql.fw.util.IMessageHandler#getExceptionFormatter()
134: */
135: public ExceptionFormatter getExceptionFormatter() {
136: throw new UnsupportedOperationException();
137: }
138:
139: }
|