Update license to GPLv3, fix header comments
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / ProtocolError.java
1 /*
2  * jFCPlib - ProtocolError.java - Copyright © 2008–2016 David Roden
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 3 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, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.fcp;
19
20 /**
21  * The “ProtocolError” message signals that something has gone really wrong.
22  *
23  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
24  */
25 public class ProtocolError extends BaseMessage {
26
27         /**
28          * Creates a new “ProtocolError” message that wraps the received message.
29          *
30          * @param receivedMessage
31          *            The received message
32          */
33         public ProtocolError(FcpMessage receivedMessage) {
34                 super(receivedMessage);
35         }
36
37         /**
38          * Returns whether the causing message had the “Global” flag set.
39          *
40          * @return <code>true</code> if the causing message had the “Global” flag
41          *         set
42          */
43         public boolean isGlobal() {
44                 return Boolean.valueOf(getField("Global"));
45         }
46
47         /**
48          * Returns the error code.
49          *
50          * @return The error code, or <code>-1</code> if the error code could not
51          *         be parsed
52          */
53         public int getCode() {
54                 return FcpUtils.safeParseInt(getField("Code"));
55         }
56
57         /**
58          * Returns the description of the error.
59          *
60          * @return The description of the error
61          */
62         public String getCodeDescription() {
63                 return getField("CodeDescription");
64         }
65
66         /**
67          * Returns some extra description of the error.
68          *
69          * @return Extra description of the error, or <code>null</code> if there is
70          *         none
71          */
72         public String getExtraDescription() {
73                 return getField("ExtraDescription");
74         }
75
76         /**
77          * Returns whether the connection to the node can stay open.
78          *
79          * @return <code>true</code> when the connection has to be closed,
80          *         <code>false</code> otherwise
81          */
82         public boolean isFatal() {
83                 return Boolean.valueOf(getField("Fatal"));
84         }
85
86         /**
87          * The identifier of the causing request, if any.
88          *
89          * @return The identifier of the causing request
90          */
91         public String getIdentifier() {
92                 return getField("Identifier");
93         }
94
95 }