Formatting fixes.
[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 David ‘Bombe’ Roden <bombe@freenetproject.org>
26  */
27 public class ProtocolError extends BaseMessage {
28
29         /**
30          * Creates a new “ProtocolError” message that wraps the received message.
31          * 
32          * @param receivedMessage
33          *            The received message
34          */
35         ProtocolError(FcpMessage receivedMessage) {
36                 super(receivedMessage);
37         }
38
39         /**
40          * Returns whether the causing message had the “Global” flag set.
41          * 
42          * @return <code>true</code> if the causing message had the “Global” flag
43          *         set
44          */
45         public boolean isGlobal() {
46                 return Boolean.valueOf(getField("Global"));
47         }
48
49         /**
50          * Returns the error code.
51          * 
52          * @return The error code, or <code>-1</code> if the error code could not be
53          *         parsed
54          */
55         public int getCode() {
56                 return FcpUtils.safeParseInt(getField("Code"));
57         }
58
59         /**
60          * Returns the description of the error.
61          * 
62          * @return The description of the error
63          */
64         public String getCodeDescription() {
65                 return getField("CodeDescription");
66         }
67
68         /**
69          * Returns some extra description of the error.
70          * 
71          * @return Extra description of the error, or <code>null</code> if there is
72          *         none
73          */
74         public String getExtraDescription() {
75                 return getField("ExtraDescription");
76         }
77
78         /**
79          * Returns whether the connection to the node can stay open.
80          * 
81          * @return <code>true</code> when the connection has to be closed,
82          *         <code>false</code> otherwise
83          */
84         public boolean isFatal() {
85                 return Boolean.valueOf(getField("Fatal"));
86         }
87
88         /**
89          * The identifier of the causing request, if any.
90          * 
91          * @return The identifier of the causing request
92          */
93         public String getIdentifier() {
94                 return getField("Identifier");
95         }
96
97 }