ikrs.json.rpc
Class JSONRPCHandler

java.lang.Object
  extended by ikrs.json.rpc.JSONRPCHandler

public class JSONRPCHandler
extends java.lang.Object

This is the RPC handler which translates JSONRPC requests into method calls. The handler holds a variable set of anonymous objects; each must implement the RPCInvocationTarget interface.


Constructor Summary
JSONRPCHandler()
          Create a new empty JSON-RPC handler.
 
Method Summary
 boolean addInvocationTarget(java.lang.String name, RPCInvocationTarget target, boolean useAsDefaultTarget)
          Add a new invocation target.
 JSONRPCRequest buildRPCRequest(java.io.Reader reader)
          This method builds a JSONRPCRequest from the JSON data provided by the given reader.
 JSONRPCResponse call(JSONRPCRequest request)
          Calls the method as specified in the JSON-RPC request.
 JSONRPCResponse call(java.io.Reader reader)
          Calls the method as specified in the JSON-RPC request from the reader.
 JSONRPCResponse call(java.lang.String jsonString)
          Calls the method as specified in the JSON-RPC request string.
static void main(java.lang.String[] argv)
          For testign purposes only.
 boolean removeInvocationTarget(java.lang.String name)
          Removes the invocation target with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONRPCHandler

public JSONRPCHandler()
Create a new empty JSON-RPC handler.

Method Detail

addInvocationTarget

public boolean addInvocationTarget(java.lang.String name,
                                   RPCInvocationTarget target,
                                   boolean useAsDefaultTarget)
                            throws java.lang.NullPointerException
Add a new invocation target. If the name already exists the associated target will be overriden.

Parameters:
name - The name to use.
target - The target to add.
useAsDefaultTarget - If true passed the target will be used as the default target.
Returns:
true if the target name already existed before (and was overriden), false otherwise.
Throws:
java.lang.NullPointerException - If name or target is null.

removeInvocationTarget

public boolean removeInvocationTarget(java.lang.String name)
Removes the invocation target with the given name.

Parameters:
name - The target's name.
Returns:
true if the target (name) existed and was removed, false otherwise.

call

public JSONRPCResponse call(java.lang.String jsonString)
                     throws java.lang.NullPointerException
Calls the method as specified in the JSON-RPC request string.

Parameters:
jsonString - The JSON-RPC string to execute.
Returns:
The JSON response (may be an error response).
Throws:
java.lang.NullPointerException - If the json string is null.

call

public JSONRPCResponse call(java.io.Reader reader)
                     throws java.lang.NullPointerException
Calls the method as specified in the JSON-RPC request from the reader.

Parameters:
reader - A reader to read the JSON-RPC request from.
Returns:
The JSON response (may be an error response).
Throws:
java.lang.NullPointerException - If the reader is null.

call

public JSONRPCResponse call(JSONRPCRequest request)
                     throws java.lang.NullPointerException
Calls the method as specified in the JSON-RPC request.

Parameters:
request - The request to execute.
Returns:
The JSON response (may be an error response).
Throws:
java.lang.NullPointerException - If the request is null.

buildRPCRequest

public JSONRPCRequest buildRPCRequest(java.io.Reader reader)
                               throws java.lang.NullPointerException,
                                      JSONSyntaxException,
                                      JSONRPCException,
                                      JSONException,
                                      java.io.IOException
This method builds a JSONRPCRequest from the JSON data provided by the given reader.

Parameters:
reader - The reader to read from (must not be null).
Returns:
The next JSONRPCRequest from the reader (will not read more).
Throws:
java.lang.NullPointerException - If reader is null.
JSONSyntaxException - If the provided data does not represent a valid JSON value.
JSONRPCException - If the provided JSON value does not represent a valid JSON-RPC request.
JSONException - If any type errors occur.
java.io.IOException - If any IO errors occur while reading from the reader.

main

public static void main(java.lang.String[] argv)
For testign purposes only.