KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > mobilitools > smi > api > BadOperation


1 /*
2 * MobiliTools: an implementation of the Object Management Group's
3 * Mobile Agent Facility specification.
4 * Copyright (C) 2003 France Telecom R&D
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * MobiliTools $Name: $
21 *
22 * Contact: mobilitools-smi@lists.debian-sf.objectweb.org
23 *
24 * Authors: Bruno Dillenseger
25 */

26
27
28 package org.objectweb.mobilitools.smi.api;
29
30
31 import java.io.*;
32
33
34 /**
35  * MobiliTools $Name: $, $Id: BadOperation.java,v 1.1.1.1 2003/03/28 14:48:05 dillense Exp $
36  * <P>
37  * Exception indicating that a request has failed.
38 */

39 public class BadOperation extends Exception JavaDoc
40 {
41     /** unspecified failure = 0 */
42     static public final int OTHER = 0;
43     /** the target agent rejected the operation = 1 */
44     static public final int REJECTED = 1;
45     /** infrastructure (network, CORBA, naming service...) problem = 2 */
46     static public final int INFRASTRUCTURE = 2;
47     /** destination agency for agent move is unknown = 3*/
48     static public final int DESTINATION = 3;
49     /** agent class fetch problem = 4 */
50     static public final int CLASSFAULT = 4;
51     /** the target agent is unknown = 5 */
52     static public final int UNKNOWNAGENT = 5;
53     /** agent or argument object de/serialization failure = 6 */
54     static public final int SERIALIZATION = 6;
55     /** agent is active after a suspend or resume request failure = 7 */
56     static public final int RUNNING = 7;
57     /** agent is suspended after a suspend or resume request failure = 8 */
58     static public final int SUSPENDED = 8;
59     /** agent class could not be instantiated (check access, security, abstract class, static constructor...) = 9 */
60     static public final int INSTANTIATION = 9;
61     /** agent type is not recognized = 10 */
62     static public final int AGENTTYPE = 10;
63     /** name is invalid (already exists? other?) = 11 */
64     static public final int INVALIDNAME = 11;
65     /** unknown agency = 13 */
66     static public final int UNKNOWNAGENCY = 13;
67     /** a (temporary/normal or permanent/abnormal?) unconsistency happened, retry later = 14 */
68     static public final int RETRY = 14;
69
70
71     /** failure identification */
72     protected int reason = OTHER;
73     /** failure explanation message */
74     protected String JavaDoc message = null;
75     /** nested exception */
76     protected Exception JavaDoc nested = null;
77
78
79     /**
80         Creates a new exception to signal any request failure.
81         @param reason failure identification - should be one of the identifiers defined in this class.
82         @param message failure explanation message.
83     */

84     public BadOperation(int reason, String JavaDoc message)
85     {
86         this(reason, message, null);
87     }
88
89
90     /**
91         Creates a new exception to signal any request failure.
92         @param reason failure identification - should be one of the identifiers defined in this class.
93         @param message failure explanation message.
94         @param nested the actual exception this BadOperation springs from.
95     */

96     public BadOperation(int reason, String JavaDoc message, Exception JavaDoc nested)
97     {
98         this.reason = reason;
99         this.message = message;
100         this.nested = nested;
101     }
102
103
104     /**
105         @return failure reason identifer.
106     */

107     public int getReason()
108     {
109         return reason;
110     }
111
112
113     /**
114         @return failure explanation message.
115     */

116     public String JavaDoc getMessage()
117     {
118         return message;
119     }
120
121
122     /**
123         @return the nested exception (if any is defined), null otherwise.
124     */

125     public Exception JavaDoc getNested()
126     {
127         return nested;
128     }
129
130
131     /**
132         @return a message describing the exception.
133     */

134     public String JavaDoc toString()
135     {
136         return "BadOperation exception: " + message + " (error code " + String.valueOf(reason) + (nested == null ? ")" : ", nested exception: " + nested + ")");
137     }
138
139
140     /**
141         Prints the execution stack trace first, and then
142         the nested exception stack trace if any.
143     */

144     public void printAllStackTrace()
145     {
146         printAllStackTrace(System.err);
147     }
148
149
150     /**
151         Prints the execution stack trace first, and then
152         the nested exception stack trace if any.
153         @param s where to print stack trace.
154     */

155     public void printAllStackTrace(PrintStream s)
156     {
157         printStackTrace(s);
158         if (nested != null)
159         {
160             s.println("NESTED EXCEPTION'S STACK TRACE BELOW:");
161             nested.printStackTrace(s);
162         }
163     }
164
165
166     /**
167         Prints the execution stack trace first, and then
168         the nested exception stack trace if any.
169         @param w where to print stack trace.
170     */

171     public void printAllStackTrace(PrintWriter w)
172     {
173         printStackTrace(w);
174         if (nested != null)
175         {
176             w.println("NESTED EXCEPTION'S STACK TRACE BELOW:");
177             nested.printStackTrace(w);
178         }
179     }
180 }
181
Popular Tags