OpenMISException.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  * 
00027  */
00028 
00029 
00030 package org.openmobileis.common.util.exception;
00031 
00032 import java.io.*;
00033 
00034 import org.openmobileis.common.util.OpenMISSerializable;
00035 import org.openmobileis.common.util.log.*;
00036 
00055 //The class is abstract so you must specialize it to use it for your own purpose
00056 public abstract class OpenMISException extends Exception implements     OpenMISSerializable {
00057   static final long serialVersionUID = 5521257935120563452L;
00058 
00059         //can be null
00060         private Throwable associatedException = null;
00061 
00062         private int priority;
00063 
00064         public OpenMISException(String msg) {
00065                 super(msg);
00066                 priority = LogPriorities.ERROR;
00067         }
00068 
00069         public OpenMISException(String msg, int logPriority) {
00070                 super(msg);
00071                 priority = logPriority;
00072         }
00073 
00074         public OpenMISException(String msg, Throwable t) {
00075                 super(msg);
00076                 priority = LogPriorities.ERROR;
00077                 associatedException = t;
00078         }
00079 
00080         public OpenMISException(String msg, Throwable t, int logPriority) {
00081                 super(msg);
00082                 priority = logPriority;
00083                 associatedException = t;
00084         }
00085 
00086         public OpenMISException() {
00087                 super();
00088                 priority = LogPriorities.ERROR;
00089         }
00090 
00091         public OpenMISException(int logPriority) {
00092                 super();
00093                 priority = logPriority;
00094         }
00095 
00096         public OpenMISException(Throwable t) {
00097                 this(t.getMessage());
00098                 associatedException = t;
00099         }
00100 
00101         public OpenMISException(Throwable t, int logPriority) {
00102                 this(t.getMessage());
00103                 associatedException = t;
00104                 priority = logPriority;
00105         }
00106 
00107         public Throwable getNestedError() {
00108                 return associatedException;
00109         }
00110 
00111         public final int getPriority() {
00112                 return priority;
00113         }
00114 
00115         public void printStackTrace() {
00116                 printStackTrace(System.err);
00117         }
00118 
00119         public void printStackTrace(PrintStream ps) {
00120                 printStackTrace(new PrintWriter(new OutputStreamWriter(ps)));
00121         }
00122 
00123         public void printStackTrace(PrintWriter writer) {
00124                 if (null != getNestedError()) {
00125                         getNestedError().printStackTrace(writer);
00126                 }
00127                 //append the original message as well as the localized one (when relevant)
00128                 //    String message = getMessage();
00129                 writer.println(this.getClass().getName() + "; service="
00130                                 + LogServices.toString(getService()) + "; priority="
00131                                 + LogPriorities.toString(getPriority()) + " : " + getMessage());
00132                 //the localized one is output-ed by the default stack trace...
00133                 super.printStackTrace(writer);
00134                 writer.flush();
00135         }
00136 
00143         public abstract int getService();
00144 }

Generated on Mon Dec 4 11:03:28 2006 for OpenMobileIS by  doxygen 1.5.1-p1