Add a mandatory response message name to Command.Response.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 11 Apr 2011 07:29:54 +0000 (09:29 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 11 Apr 2011 07:29:54 +0000 (09:29 +0200)
src/main/java/net/pterodactylus/sone/fcp/GetLocalSonesCommand.java
src/main/java/net/pterodactylus/sone/fcp/GetPostCommand.java
src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
src/main/java/net/pterodactylus/sone/fcp/GetPostsCommand.java
src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
src/main/java/net/pterodactylus/sone/fcp/VersionCommand.java
src/main/java/net/pterodactylus/sone/freenet/fcp/Command.java

index 718dd89..c4206d5 100644 (file)
@@ -45,7 +45,7 @@ public class GetLocalSonesCommand extends AbstractSoneCommand {
         */
        @Override
        public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
-               return new Response(encodeSones(getCore().getLocalSones(), "LocalSones."));
+               return new Response("ListLocalSones", encodeSones(getCore().getLocalSones(), "LocalSones."));
        }
 
 }
index 391694f..b01b8f2 100644 (file)
@@ -48,7 +48,7 @@ public class GetPostCommand extends AbstractSoneCommand {
                Post post = getPost(parameters, "Post");
                boolean includeReplies = getBoolean(parameters, "IncludeReplies", true);
 
-               return new Response(encodePost(post, "Post.", includeReplies));
+               return new Response("Post", encodePost(post, "Post.", includeReplies));
        }
 
 }
index 895c1c6..3331c4f 100644 (file)
@@ -73,10 +73,10 @@ public class GetPostFeedCommand extends AbstractSoneCommand {
                Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
 
                if (sortedPosts.size() < startPost) {
-                       return new Response(encodePosts(Collections.<Post> emptyList(), "Posts.", false));
+                       return new Response("PostFeed", encodePosts(Collections.<Post> emptyList(), "Posts.", false));
                }
 
-               return new Response(encodePosts(sortedPosts.subList(startPost, (maxPosts == -1) ? sortedPosts.size() : Math.min(startPost + maxPosts, sortedPosts.size())), "Posts.", true));
+               return new Response("PostFeed", encodePosts(sortedPosts.subList(startPost, (maxPosts == -1) ? sortedPosts.size() : Math.min(startPost + maxPosts, sortedPosts.size())), "Posts.", true));
        }
 
 }
index 0a02a89..24362d9 100644 (file)
@@ -55,9 +55,9 @@ public class GetPostsCommand extends AbstractSoneCommand {
                int maxPosts = getInt(parameters, "MaxPosts", -1);
                List<Post> posts = sone.getPosts();
                if (posts.size() < startPost) {
-                       return new Response(encodePosts(Collections.<Post> emptyList(), "Posts.", false));
+                       return new Response("Posts", encodePosts(Collections.<Post> emptyList(), "Posts.", false));
                }
-               return new Response(encodePosts(sone.getPosts().subList(startPost, (maxPosts == -1) ? posts.size() : Math.min(startPost + maxPosts, posts.size())), "Posts.", true));
+               return new Response("Posts", encodePosts(sone.getPosts().subList(startPost, (maxPosts == -1) ? posts.size() : Math.min(startPost + maxPosts, posts.size())), "Posts.", true));
        }
 
 }
index 42ca409..2147682 100644 (file)
@@ -50,7 +50,7 @@ public class LikePostCommand extends AbstractSoneCommand {
                Post post = getPost(parameters, "Post");
                Sone sone = getSone(parameters, "Sone");
                sone.addLikedPostId(post.getId());
-               return new Response(new SimpleFieldSetBuilder().put("Message", "PostLiked").put("LikeCount", getCore().getLikes(post).size()).get());
+               return new Response("PostLiked", new SimpleFieldSetBuilder().put("LikeCount", getCore().getLikes(post).size()).get());
        }
 
 }
index ff57c40..6817476 100644 (file)
@@ -35,7 +35,7 @@ public class VersionCommand implements Command {
         */
        @Override
        public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) {
-               return new Response(new SimpleFieldSetBuilder().put("Version", SonePlugin.VERSION.toString()).put("ProtocolVersion", 1).get());
+               return new Response("Version", new SimpleFieldSetBuilder().put("Version", SonePlugin.VERSION.toString()).put("ProtocolVersion", 1).get());
        }
 
 }
index 2a083ee..46032dd 100644 (file)
@@ -70,6 +70,9 @@ public interface Command {
         */
        public static class Response {
 
+               /** The message name of the reponse. */
+               private final String messageName;
+
                /** The reply parameters. */
                private final SimpleFieldSet replyParameters;
 
@@ -82,40 +85,48 @@ public interface Command {
                /**
                 * Creates a new reply with the given parameters.
                 *
+                * @param messageName
+                *            The message name
                 * @param replyParameters
                 *            The reply parameters
                 */
-               public Response(SimpleFieldSet replyParameters) {
-                       this(replyParameters, null, null);
+               public Response(String messageName, SimpleFieldSet replyParameters) {
+                       this(messageName, replyParameters, null, null);
                }
 
                /**
                 * Creates a new reply with the given parameters.
                 *
+                * @param messageName
+                *            The message name
                 * @param replyParameters
                 *            The reply parameters
                 * @param data
                 *            The data of the reply (may be {@code null})
                 */
-               public Response(SimpleFieldSet replyParameters, byte[] data) {
-                       this(replyParameters, data, null);
+               public Response(String messageName, SimpleFieldSet replyParameters, byte[] data) {
+                       this(messageName, replyParameters, data, null);
                }
 
                /**
                 * Creates a new reply with the given parameters.
                 *
+                * @param messageName
+                *            The message name
                 * @param replyParameters
                 *            The reply parameters
                 * @param bucket
                 *            The bucket of the reply (may be {@code null})
                 */
-               public Response(SimpleFieldSet replyParameters, Bucket bucket) {
-                       this(replyParameters, null, bucket);
+               public Response(String messageName, SimpleFieldSet replyParameters, Bucket bucket) {
+                       this(messageName, replyParameters, null, bucket);
                }
 
                /**
                 * Creates a new reply with the given parameters.
                 *
+                * @param messageName
+                *            The message name
                 * @param replyParameters
                 *            The reply parameters
                 * @param data
@@ -123,7 +134,8 @@ public interface Command {
                 * @param bucket
                 *            The bucket of the reply (may be {@code null})
                 */
-               private Response(SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
+               private Response(String messageName, SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
+                       this.messageName = messageName;
                        this.replyParameters = replyParameters;
                        this.data = data;
                        this.bucket = bucket;
@@ -135,7 +147,7 @@ public interface Command {
                 * @return The reply parameters
                 */
                public SimpleFieldSet getReplyParameters() {
-                       return replyParameters;
+                       return new SimpleFieldSetBuilder(replyParameters).put("Message", messageName).get();
                }
 
                /**
@@ -194,7 +206,7 @@ public interface Command {
                 *            The error message
                 */
                public ErrorResponse(String message) {
-                       super(new SimpleFieldSetBuilder().put("ErrorMessage", message).get());
+                       super("Error", new SimpleFieldSetBuilder().put("ErrorMessage", message).get());
                }
 
                /**
@@ -206,7 +218,7 @@ public interface Command {
                 *            The error message
                 */
                public ErrorResponse(int code, String message) {
-                       super(new SimpleFieldSetBuilder().put("ErrorMessage", message).put("ErrorCode", code).get());
+                       super("Error", new SimpleFieldSetBuilder().put("ErrorMessage", message).put("ErrorCode", code).get());
                }
 
        }