| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.util; |
| 16 | |
| 17 | import org.apache.commons.logging.Log; |
| 18 | import org.apache.commons.logging.LogFactory; |
| 19 | |
| 20 | import net.sourceforge.hiveboard.ServerErrorException; |
| 21 | import net.sourceforge.hivegui.application.HiveGuiApplicationMain; |
| 22 | import net.sourceforge.hivelock.SecurityException; |
| 23 | |
| 24 | import com.caucho.hessian.client.HessianRuntimeException; |
| 25 | |
| 26 | final public class ErrorHelper |
| 27 | { |
| 28 | static private final Log _logger = LogFactory.getLog(ErrorHelper.class); |
| 29 | |
| 30 | private ErrorHelper() |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | static public void handle(HiveGuiApplicationMain app, Throwable e) |
| 35 | { |
| 36 | _logger.error("handle()", e); |
| 37 | if (app != null && !(e instanceof ExitException)) |
| 38 | { |
| 39 | if (e instanceof SecurityException) |
| 40 | { |
| 41 | app.showMessage("security-error", e.getMessage()); |
| 42 | } |
| 43 | else if (e instanceof OutOfMemoryError) |
| 44 | { |
| 45 | app.showMessage("memory-error"); |
| 46 | } |
| 47 | else if (e instanceof VersionMismatchException) |
| 48 | { |
| 49 | VersionMismatchException ex = (VersionMismatchException) e; |
| 50 | app.showMessage("version-problem", |
| 51 | ex.getMessage(), |
| 52 | ex.getClientVersion(), |
| 53 | ex.getServerVersion(), |
| 54 | ex.getSupportedClientVersions()); |
| 55 | } |
| 56 | else if (e instanceof HessianRuntimeException) |
| 57 | { |
| 58 | app.showMessage("connection-problem", e.getMessage()); |
| 59 | } |
| 60 | else if (e instanceof ServerErrorException) |
| 61 | { |
| 62 | if (e.getCause() instanceof OutOfMemoryError) |
| 63 | { |
| 64 | app.showMessage("server-memory-error"); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | app.showMessage("server-unexpected-error"); |
| 69 | } |
| 70 | } |
| 71 | else if (e instanceof Error && e.getCause() != null) |
| 72 | { |
| 73 | // Workaround Swing AppFW JIRA-42 |
| 74 | handle(app, e.getCause()); |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | app.showMessage("unexpected-error"); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |