add ProtocolError message
[jSite2.git] / src / net / pterodactylus / util / fcp / ProtocolError.java
1 /**
2  * © 2008 INA Service GmbH
3  */
4 package net.pterodactylus.util.fcp;
5
6 /**
7  * The “ProtocolError” message signals that something has gone really wrong.
8  * 
9  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
10  * @version $Id$
11  */
12 public class ProtocolError extends BaseMessage {
13
14         /**
15          * Creates a new “ProtocolError” message that wraps the received message.
16          * 
17          * @param receivedMessage
18          *            The received message
19          */
20         public ProtocolError(FcpMessage receivedMessage) {
21                 super(receivedMessage);
22         }
23
24         /**
25          * Returns whether the causing message had the “Global” flag set.
26          * 
27          * @return <code>true</code> if the causing message had the “Global” flag
28          *         set
29          */
30         public boolean isGlobal() {
31                 return Boolean.valueOf(getField("Global"));
32         }
33
34         /**
35          * Returns the error code.
36          * 
37          * @return The error code, or <code>-1</code> if the error code could not
38          *         be parsed
39          */
40         public int getCode() {
41                 try {
42                         return Integer.valueOf(getField("Code"));
43                 } catch (NumberFormatException nfe1) {
44                         return -1;
45                 }
46         }
47
48         /**
49          * Returns the description of the error.
50          * 
51          * @return The description of the error
52          */
53         public String getCodeDescription() {
54                 return getField("CodeDescription");
55         }
56
57         /**
58          * Returns some extra description of the error.
59          * 
60          * @return Extra description of the error, or <code>null</code> if there
61          *         is none
62          */
63         public String getExtraDescription() {
64                 return getField("ExtraDescription");
65         }
66
67         /**
68          * Returns whether the connection to the node can stay open.
69          * 
70          * @return <code>true</code> when the connection has to be closed,
71          *         <code>false</code> otherwise
72          */
73         public boolean isFatal() {
74                 return Boolean.valueOf(getField("Fatal"));
75         }
76
77         /**
78          * The identifier of the causing request, if any.
79          * 
80          * @return The identifier of the causing request
81          */
82         public String getIdentifier() {
83                 return getField("Identifier");
84         }
85
86 }