2 * jSite2 - GetFailed.java -
3 * Copyright © 2008 David Roden
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.
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.
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.
20 package net.pterodactylus.fcp;
22 import java.util.ArrayList;
23 import java.util.List;
25 import java.util.Map.Entry;
28 * The “PutFailed” message signals the client that a {@link ClientPut} request
29 * has failed. This also means that no further progress messages for that
30 * request will be sent.
32 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
35 public class PutFailed extends BaseMessage {
38 * Creates a new “PutFailed” message that wraps the received message.
40 * @param receivedMessage
41 * The received message
43 PutFailed(FcpMessage receivedMessage) {
44 super(receivedMessage);
48 * Returns the code of the error.
50 * @return The code of the error, or <code>-1</code> if the error code
53 public int getCode() {
54 return FcpUtils.safeParseInt(getField("Code"));
58 * Returns the identifier of the request.
60 * @return The identifier of the request
62 public String getIdentifier() {
63 return getField("Identifier");
67 * Returns whether the request is on the global queue.
69 * @return <code>true</code> if the request is on the global queue,
70 * <code>false</code> if it is on the client-local queue
72 public boolean isGlobal() {
73 return Boolean.valueOf(getField("Global"));
77 * Returns the description of the error code.
79 * @return The description of the error code
81 public String getCodeDescription() {
82 return getField("CodeDescription");
86 * Returns the extra description of the error.
88 * @return The extra description of the error
90 public String getExtraDescription() {
91 return getField("ExtraDescription");
95 * Returns the short description of the error.
97 * @return The short description of the error
99 public String getShortCodeDescription() {
100 return getField("ShortCodeDescription");
104 * Returns the expected URI of the request.
106 * @return The expected URI
108 public String getExpectedURI() {
109 return getField("ExpectedURI");
113 * Returns whether the request failed fatally. If a request fails fatally it
114 * can never complete, even with inifinite retries.
116 * @return <code>true</code> if the request failed fatally,
117 * <code>false</code> otherwise
119 public boolean isFatal() {
120 return Boolean.valueOf(getField("Fatal"));
124 * Returns a list of complex error codes with the message. Use
125 * {@link #getComplexErrorDescription(int)} and
126 * {@link #getComplexErrorCount(int)} to get details.
128 * @return A list of complex error codes
130 public int[] getComplexErrorCodes() {
131 Map<String, String> allFields = getFields();
132 List<Integer> errorCodeList = new ArrayList<Integer>();
133 for (Entry<String, String> field: allFields.entrySet()) {
134 String fieldKey = field.getKey();
135 if (fieldKey.startsWith("Errors.")) {
136 int nextDot = fieldKey.indexOf('.', 7);
138 int errorCode = FcpUtils.safeParseInt(fieldKey.substring(7, nextDot));
139 if (errorCode != -1) {
140 errorCodeList.add(errorCode);
145 int[] errorCodes = new int[errorCodeList.size()];
147 for (int errorCode: errorCodeList) {
148 errorCodes[errorIndex++] = errorCode;
154 * Returns the description of the complex error. You should only hand it
155 * error codes you got from {@link #getComplexErrorCodes()}!
159 * @return The description of the complex error
161 public String getComplexErrorDescription(int errorCode) {
162 return getField("Errors." + errorCode + ".Description");
166 * Returns the count of the complex error. You should only hand it error
167 * codes you got from {@link #getComplexErrorCodes()}!
171 * @return The count of the complex error, or <code>-1</code> if the count
172 * could not be parsed
174 public int getComplexErrorCount(int errorCode) {
175 return FcpUtils.safeParseInt(getField("Errors." + errorCode + ".Count"));