Package org.astrogrid.samp.xmlrpc
Class ActorHandler
java.lang.Object
org.astrogrid.samp.xmlrpc.ActorHandler
- All Implemented Interfaces:
SampXmlRpcHandler
- Direct Known Subclasses:
WebHubXmlRpcHandler
Utility class to facilitate constructing a SampXmlRpcHandler which handles
particular named methods.
You supply at construction time an interface which defines the methods
to be handled and an object which implements that interface.
This object then uses reflection to invoke the correct methods on the
implementation object as they are required from incoming XML-RPC
execute
requests. This insulates the implementation object
from having to worry about any XML-RPC specifics.- Since:
- 15 Jul 2008
- Author:
- Mark Taylor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canHandleCall
(String fqName) Returns true if this handler should be able to process given XML-RPC method.getActor()
Returns the implementation object for this handler.handleCall
(String fqName, List params, Object reqInfo) Processes an XML-RPC call.protected abstract Object
invokeMethod
(Method method, Object obj, Object[] args) Invokes a method reflectively on an object.
-
Constructor Details
-
ActorHandler
Constructor.- Parameters:
prefix
- string prepended to every method name in theactorType
interface to form the XML-RPCmethodName
elementactorType
- interface defining the XML-RPC methodsactor
- object implementingactorType
-
-
Method Details
-
canHandleCall
Description copied from interface:SampXmlRpcHandler
Returns true if this handler should be able to process given XML-RPC method.- Specified by:
canHandleCall
in interfaceSampXmlRpcHandler
- Parameters:
fqName
- method name
-
handleCall
Description copied from interface:SampXmlRpcHandler
Processes an XML-RPC call. This method should only be called ifcanHandleCall(method)
returns true. Theparams
list and the return value must be SAMP-compatible, that is only Strings, Lists and String-keyed Maps are allowed in the data structures. ThereqInfo
parameter may be used to provide additional information about the XML-RPC request, for instance the originating host; this is implementation specific, and may be null.- Specified by:
handleCall
in interfaceSampXmlRpcHandler
- Parameters:
fqName
- XML-RPC method nameparams
- XML-RPC parameter list (SAMP-compatible)reqInfo
- optional additional request information; may be null- Returns:
- return value (SAMP-compatible)
- Throws:
Exception
-
getActor
Returns the implementation object for this handler.- Returns:
- implementation object
-
invokeMethod
protected abstract Object invokeMethod(Method method, Object obj, Object[] args) throws IllegalAccessException, InvocationTargetException Invokes a method reflectively on an object. This method should be implemented in the obvious way, that isreturn method.invoke(obj,params)
.If the implementation is effectively prescribed, why is this abstract method here? It's tricky. The reason is so that reflective method invocation from this class is done by code within the actor implementation class itself rather than by code in the superclass,
ActorHandler
. That in turn means that theactorType
class specified in the constructor does not need to be visible fromActorHandler
's package, only from the package where the implementation class lives.- Parameters:
method
- method to invokeobj
- object to invoke the method onargs
- arguments for the method call- Throws:
IllegalAccessException
InvocationTargetException
- See Also:
-