KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > server > error > ServerException


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.framework.server.error;
20
21 import sync4j.framework.core.StatusCode;
22 import sync4j.framework.core.Sync4jException;
23
24 /**
25  * @version $Id: ServerException.java,v 1.3 2005/07/19 12:23:29 nichele Exp $
26  * @author Stefano Fornari @ Funambol
27  */

28 public class ServerException extends Sync4jException {
29
30     // --------------------------------------------------------------- Constants
31

32     public static int UNKNOWN = -1;
33
34     // ------------------------------------------------------------ Private data
35

36     private int statusCode = UNKNOWN;
37
38     // ------------------------------------------------------------ Constructors
39

40     /**
41      * @param strMsg human readable String that describes the cause of the
42      * exception
43      */

44     public ServerException(final String JavaDoc strMsg) {
45         super(strMsg);
46     }
47
48     /**
49      * Constructor for the ServerException object
50      *
51      * @param statusCode Description of the Parameter
52      * @param strMsg Description of the Parameter
53      */

54     public ServerException(final int statusCode, final String JavaDoc strMsg) {
55         this(statusCode, strMsg, null);
56     }
57
58     public ServerException(final String JavaDoc strMsg, final Throwable JavaDoc cause) {
59         this(UNKNOWN, strMsg, cause);
60     }
61
62     public ServerException(final int statusCode, final String JavaDoc strMsg, final Throwable JavaDoc cause) {
63         super(strMsg, cause);
64
65         this.statusCode = statusCode;
66     }
67
68     public ServerException(final Throwable JavaDoc cause) {
69         this(UNKNOWN, "", cause);
70     }
71
72     // ---------------------------------------------------------- Public methods
73

74     /**
75      * Gets the statusCode attribute of the ServerException object
76      *
77      * @return The statusCode value
78      */

79     public int getStatusCode() {
80         return statusCode;
81     }
82
83
84     /**
85      * Returns the SyncML message associated to the status code of this exception
86      *
87      * @return the SyncML message associated to the status code of this exception
88      */

89     public String JavaDoc getSyncMLMessage() {
90         int code = getStatusCode();
91
92         String JavaDoc msg = StatusCode.getStatusDescription(code);
93
94         return (msg == null) ? "" : msg;
95     }
96
97     /**
98      * Redefines the standard <i>getMessage()</i> method.
99      *
100      * @return <status code> <status description> - <message description>
101      */

102     public String JavaDoc getMessage() {
103         String JavaDoc message;
104         if (statusCode != UNKNOWN) {
105             message = statusCode
106                        + " "
107                        + getSyncMLMessage()
108                        + " - "
109                        + super.getMessage()
110                        ;
111         } else {
112             message = super.getMessage();
113         }
114         return message;
115     }
116
117 }
118
Popular Tags