rename fcplib to jFCPlib
[jFCPlib.git] / src / net / pterodactylus / fcp / ProtocolError.java
1 /*
2  * jSite2 - ProtocolError.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.fcp;
21
22 /**
23  * The “ProtocolError” message signals that something has gone really wrong.
24  * 
25  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
26  * @version $Id$
27  */
28 public class ProtocolError extends BaseMessage {
29
30         /**
31          * Creates a new “ProtocolError” message that wraps the received message.
32          * 
33          * @param receivedMessage
34          *            The received message
35          */
36         ProtocolError(FcpMessage receivedMessage) {
37                 super(receivedMessage);
38         }
39
40         /**
41          * Returns whether the causing message had the “Global” flag set.
42          * 
43          * @return <code>true</code> if the causing message had the “Global” flag
44          *         set
45          */
46         public boolean isGlobal() {
47                 return Boolean.valueOf(getField("Global"));
48         }
49
50         /**
51          * Returns the error code.
52          * 
53          * @return The error code, or <code>-1</code> if the error code could not
54          *         be parsed
55          */
56         public int getCode() {
57                 return FcpUtils.safeParseInt(getField("Code"));
58         }
59
60         /**
61          * Returns the description of the error.
62          * 
63          * @return The description of the error
64          */
65         public String getCodeDescription() {
66                 return getField("CodeDescription");
67         }
68
69         /**
70          * Returns some extra description of the error.
71          * 
72          * @return Extra description of the error, or <code>null</code> if there
73          *         is none
74          */
75         public String getExtraDescription() {
76                 return getField("ExtraDescription");
77         }
78
79         /**
80          * Returns whether the connection to the node can stay open.
81          * 
82          * @return <code>true</code> when the connection has to be closed,
83          *         <code>false</code> otherwise
84          */
85         public boolean isFatal() {
86                 return Boolean.valueOf(getField("Fatal"));
87         }
88
89         /**
90          * The identifier of the causing request, if any.
91          * 
92          * @return The identifier of the causing request
93          */
94         public String getIdentifier() {
95                 return getField("Identifier");
96         }
97
98 }