public abstract class ActorHandler extends java.lang.Object implements SampXmlRpcHandler
execute
requests. This insulates the implementation object
from having to worry about any XML-RPC specifics.Modifier and Type | Class and Description |
---|---|
private static class |
ActorHandler.SampType
Enumeration of permitted types within a SAMP data structure.
|
private static class |
ActorHandler.Signature
Characterises a method signature.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
actor_ |
private java.util.logging.Logger |
logger_ |
private java.util.Map |
methodMap_ |
private java.lang.String |
prefix_ |
Constructor and Description |
---|
ActorHandler(java.lang.String prefix,
java.lang.Class actorType,
java.lang.Object actor)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canHandleCall(java.lang.String fqName)
Returns true if this handler should be able to process
given XML-RPC method.
|
java.lang.Object |
getActor()
Returns the implementation object for this handler.
|
java.lang.Object |
handleCall(java.lang.String fqName,
java.util.List params,
java.lang.Object reqInfo)
Processes an XML-RPC call.
|
protected abstract java.lang.Object |
invokeMethod(java.lang.reflect.Method method,
java.lang.Object obj,
java.lang.Object[] args)
Invokes a method reflectively on an object.
|
private final java.lang.String prefix_
private final java.lang.Object actor_
private final java.util.Map methodMap_
private final java.util.logging.Logger logger_
public ActorHandler(java.lang.String prefix, java.lang.Class actorType, java.lang.Object actor)
prefix
- string prepended to every method name in the
actorType
interface to form the XML-RPC
methodName
elementactorType
- interface defining the XML-RPC methodsactor
- object implementing actorType
public boolean canHandleCall(java.lang.String fqName)
SampXmlRpcHandler
canHandleCall
in interface SampXmlRpcHandler
fqName
- method namepublic java.lang.Object handleCall(java.lang.String fqName, java.util.List params, java.lang.Object reqInfo) throws java.lang.Exception
SampXmlRpcHandler
canHandleCall(method)
returns true.
The params
list and the return value must be
SAMP-compatible, that is only Strings, Lists and String-keyed Maps
are allowed in the data structures.
The reqInfo
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.handleCall
in interface SampXmlRpcHandler
fqName
- XML-RPC method nameparams
- XML-RPC parameter list (SAMP-compatible)reqInfo
- optional additional request information; may be nulljava.lang.Exception
public java.lang.Object getActor()
protected abstract java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object[] args) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
return 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 the actorType
class specified
in the constructor does not need to be visible from
ActorHandler
's package, only from the package where
the implementation class lives.
method
- method to invokeobj
- object to invoke the method onargs
- arguments for the method calljava.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
Method.invoke(java.lang.Object, java.lang.Object...)