Class ActorHandler

  • All Implemented Interfaces:
    SampXmlRpcHandler
    Direct Known Subclasses:
    WebHubXmlRpcHandler

    public abstract class ActorHandler
    extends java.lang.Object
    implements SampXmlRpcHandler
    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 
      Constructor Description
      ActorHandler​(java.lang.String prefix, java.lang.Class actorType, java.lang.Object actor)
      Constructor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ActorHandler

        public ActorHandler​(java.lang.String prefix,
                            java.lang.Class actorType,
                            java.lang.Object actor)
        Constructor.
        Parameters:
        prefix - string prepended to every method name in the actorType interface to form the XML-RPC methodName element
        actorType - interface defining the XML-RPC methods
        actor - object implementing actorType
    • Method Detail

      • canHandleCall

        public boolean canHandleCall​(java.lang.String fqName)
        Description copied from interface: SampXmlRpcHandler
        Returns true if this handler should be able to process given XML-RPC method.
        Specified by:
        canHandleCall in interface SampXmlRpcHandler
        Parameters:
        fqName - method name
      • handleCall

        public java.lang.Object handleCall​(java.lang.String fqName,
                                           java.util.List params,
                                           java.lang.Object reqInfo)
                                    throws java.lang.Exception
        Description copied from interface: SampXmlRpcHandler
        Processes an XML-RPC call. This method should only be called if 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.
        Specified by:
        handleCall in interface SampXmlRpcHandler
        Parameters:
        fqName - XML-RPC method name
        params - XML-RPC parameter list (SAMP-compatible)
        reqInfo - optional additional request information; may be null
        Returns:
        return value (SAMP-compatible)
        Throws:
        java.lang.Exception
      • getActor

        public java.lang.Object getActor()
        Returns the implementation object for this handler.
        Returns:
        implementation object
      • invokeMethod

        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
        Invokes a method reflectively on an object. This method should be implemented in the obvious way, that is 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.

        Parameters:
        method - method to invoke
        obj - object to invoke the method on
        args - arguments for the method call
        Throws:
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
        See Also:
        Method.invoke(java.lang.Object, java.lang.Object...)