001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: Console.java 11017 2007-12-17 23:04:39Z elu $
023: */
024: package com.bostechcorp.cbesb.console.client;
025:
026: import com.bostechcorp.cbesb.console.client.dialogs.MessageViewDialog;
027: import com.bostechcorp.cbesb.console.common.ExceptionUtil;
028: import com.bostechcorp.cbesb.console.common.IRPCResultInfo;
029: import com.bostechcorp.cbesb.console.common.ServerSideException;
030: import com.google.gwt.user.client.rpc.AsyncCallback;
031:
032: /**
033: * It is the base class for AsncCallback class in Admon console and Alert monitor
034: * @author Lpp.Zheng
035: *
036: */
037: abstract public class ConsoleCallback implements AsyncCallback {
038:
039: protected ICallbackHandler handler;
040:
041: public ConsoleCallback(ICallbackHandler handler) {
042: super ();
043: this .handler = handler;
044: }
045:
046: public void onFailure(Throwable caught) {
047: closeWaitingDialog();
048: // handler.handleFailure(caught);
049: handleFailure(caught);
050: handleExtFailure(caught);
051: }
052:
053: public void onSuccess(Object result) {
054: if (result instanceof IRPCResultInfo) {
055: IRPCResultInfo info = (IRPCResultInfo) result;
056: if (info.isError()) {
057: // handler.handleFailure(info.getExceptionText(),info.getExceptionTrace());
058: handleFailure(info.getExceptionText(), info
059: .getExceptionTrace());
060: handleExtFailure(result);
061: } else {
062: handleSuccess(result);
063: }
064: } else {
065: handleSuccess(result);
066: }
067: closeWaitingDialog();
068:
069: }
070:
071: abstract public void handleSuccess(Object result);
072:
073: public void handleExtFailure(Object result) {
074: }
075:
076: public void handleFailure(Throwable caught) {
077: if (!ClientUtils.checkTimeOut(caught)) {
078: if (caught instanceof ServerSideException) {
079:
080: handleFailure(ExceptionUtil.stackTextString(caught),
081: ((ServerSideException) caught)
082: .getServerStackTrace());
083: } else
084: handleFailure(ExceptionUtil.stackTextString(caught),
085: ExceptionUtil.stackTraceString(caught));
086: }
087:
088: }
089:
090: public void handleFailure(String exceptionText,
091: String exceptionTrace) {
092:
093: MessageViewDialog.showError(exceptionText, exceptionTrace);
094:
095: }
096:
097: public void closeWaitingDialog() {
098:
099: Console.instance.waiting.close();
100: }
101:
102: }
|