KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smack > packet > XMPPError


1 /**
2  * $RCSfile$
3  * $Revision: 2408 $
4  * $Date: 2004-11-02 20:53:30 -0300 (Tue, 02 Nov 2004) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

20
21 package org.jivesoftware.smack.packet;
22
23 /**
24  * Represents a XMPP error sub-packet. Typically, a server responds to a request that has
25  * problems by sending the packet back and including an error packet. Each error has a code
26  * as well as as an optional text explanation. Typical error codes are as follows:<p>
27  *
28  * <table border=1>
29  * <tr><td><b>Code</b></td><td><b>Description</b></td></tr>
30  * <tr><td> 302 </td><td> Redirect </td></tr>
31  * <tr><td> 400 </td><td> Bad Request </td></tr>
32  * <tr><td> 401 </td><td> Unauthorized </td></tr>
33  * <tr><td> 402 </td><td> Payment Required </td></tr>
34  * <tr><td> 403 </td><td> Forbidden </td></tr>
35  * <tr><td> 404 </td><td> Not Found </td></tr>
36  * <tr><td> 405 </td><td> Not Allowed </td></tr>
37  * <tr><td> 406 </td><td> Not Acceptable </td></tr>
38  * <tr><td> 407 </td><td> Registration Required </td></tr>
39  * <tr><td> 408 </td><td> Request Timeout </td></tr>
40  * <tr><td> 409 </td><td> Conflict </td></tr>
41  * <tr><td> 500 </td><td> Internal Server XMPPError </td></tr>
42  * <tr><td> 501 </td><td> Not Implemented </td></tr>
43  * <tr><td> 502 </td><td> Remote Server Error </td></tr>
44  * <tr><td> 503 </td><td> Service Unavailable </td></tr>
45  * <tr><td> 504 </td><td> Remote Server Timeout </td></tr>
46  * </table>
47  *
48  * @author Matt Tucker
49  */

50 public class XMPPError {
51
52     private int code;
53     private String JavaDoc message;
54
55     /**
56      * Creates a new error with the specified code and no message..
57      *
58      * @param code the error code.
59      */

60     public XMPPError(int code) {
61         this.code = code;
62         this.message = null;
63     }
64
65     /**
66      * Creates a new error with the specified code and message.
67      *
68      * @param code the error code.
69      * @param message a message describing the error.
70      */

71     public XMPPError(int code, String JavaDoc message) {
72         this.code = code;
73         this.message = message;
74     }
75
76     /**
77      * Returns the error code.
78      *
79      * @return the error code.
80      */

81     public int getCode() {
82         return code;
83     }
84
85     /**
86      * Returns the message describing the error, or null if there is no message.
87      *
88      * @return the message describing the error, or null if there is no message.
89      */

90     public String JavaDoc getMessage() {
91         return message;
92     }
93
94     /**
95      * Returns the error as XML.
96      *
97      * @return the error as XML.
98      */

99     public String JavaDoc toXML() {
100         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
101         buf.append("<error code=\"").append(code).append("\">");
102         if (message != null) {
103             buf.append(message);
104         }
105         buf.append("</error>");
106         return buf.toString();
107     }
108
109     public String JavaDoc toString() {
110         StringBuffer JavaDoc txt = new StringBuffer JavaDoc();
111         txt.append("(").append(code).append(")");
112         if (message != null) {
113             txt.append(" ").append(message);
114         }
115         return txt.toString();
116     }
117 }
118
Popular Tags