com.flat502.rox.server
Class RpcMethodProxy

java.lang.Object
  extended by com.flat502.rox.marshal.UnmarshallerAid
      extended by com.flat502.rox.marshal.MethodCallUnmarshallerAid
          extended by com.flat502.rox.server.RpcMethodProxy
Direct Known Subclasses:
XmlRpcMethodProxy

public abstract class RpcMethodProxy
extends MethodCallUnmarshallerAid

This class dynamically proxies a plain old Java object (POJO) by mapping RPC method calls onto methods onto a target object using reflection.

The ProxyingRequestHandler class makes use of this to provide a proxying synchronous request handler.

The mapping is relatively unsophisticated and is based entirely on the method name. As a result, method overloading is not supported. Overloading methods results in undefined behaviour, as Class.getMethods() makes no guarantees regarding the order in which methods are returned. You're free to overload methods (i.e. this implementation will not prevent it) but you do so at your own risk.

This class also extends MethodCallUnmarshallerAid and uses the Method.getParameterTypes() to determine type mappings dynamically when RPC structs are involved.

Methods that accept RPC arrays must be defined to accept List instances for those parameters. Type coercion is as per Method.invoke(java.lang.Object, java.lang.Object[]).


Constructor Summary
RpcMethodProxy(java.lang.String namePattern, java.lang.Object target)
           
 
Method Summary
protected  java.lang.String decodeRpcMethodName(java.lang.String name)
           
protected  java.lang.String encodeJavaMethodName(java.lang.String name)
           
 FieldNameCodec getFieldNameCodec(java.lang.String methodName)
          Invoked when a method call unmarshaller is required.
 java.lang.Class getType(java.lang.String methodName, int index)
          An implementation should return a Class instance representing the type a complex parameter value (a struct or an array) at the given index should be unmarshalled as.
 RpcResponse invoke(RpcCall call)
          Deprecated. Override invoke(RpcCall, RpcCallContext) instead.
 RpcResponse invoke(RpcCall call, RpcCallContext context)
           
abstract  RpcFault newRpcFault(java.lang.Throwable e)
           
protected abstract  RpcResponse newRpcResponse(java.lang.Object returnValue)
           
 
Methods inherited from class com.flat502.rox.marshal.UnmarshallerAid
ignoreMissingFields
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RpcMethodProxy

public RpcMethodProxy(java.lang.String namePattern,
                      java.lang.Object target)
Method Detail

invoke

public RpcResponse invoke(RpcCall call)
                   throws java.lang.Exception
Deprecated. Override invoke(RpcCall, RpcCallContext) instead.

Retired method.

This method has been retired and has an empty method body. Overriding implementations will still be delegated to but direct calls to this method will simply return null (unless it is overridden).

Parameters:
call -
Returns:
null
Throws:
java.lang.Exception

invoke

public RpcResponse invoke(RpcCall call,
                          RpcCallContext context)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getType

public java.lang.Class getType(java.lang.String methodName,
                               int index)
Description copied from class: MethodCallUnmarshallerAid
An implementation should return a Class instance representing the type a complex parameter value (a struct or an array) at the given index should be unmarshalled as.

A null return value will result in the parameter value being unmarshalled into a Map instance if, and only if, the parameter value is an XML-RPC struct and a List instance if, and only if, the value is an XML-RPC array.

The returned Class must be accessible, instantiable, and have an accessible default constructor.

Specified by:
getType in class MethodCallUnmarshallerAid
Parameters:
methodName - The name of the XML-RPC method call being unmarshalled.
index - The index of the parameter value being unmarshalled.
Returns:
The Class for the type the parameter value should be unmarshalled as, assuming it is a struct or an array.

decodeRpcMethodName

protected java.lang.String decodeRpcMethodName(java.lang.String name)

encodeJavaMethodName

protected java.lang.String encodeJavaMethodName(java.lang.String name)

getFieldNameCodec

public FieldNameCodec getFieldNameCodec(java.lang.String methodName)
Description copied from class: UnmarshallerAid
Invoked when a method call unmarshaller is required.

This method allows request handlers to override the default unmarshaller implementation for a given method (or class of methods) without imposing that unmarshaller on all request handlers.

Implementations may return the same instance for multiple calls to this method as long as the unmarshaller is thread-safe.

Implementations may return null in which case a default unmarshalling implementation will be used.

Overrides:
getFieldNameCodec in class UnmarshallerAid
Parameters:
methodName - The name of the XML-RPC method call being unmarshalled.
Returns:
this implementation always returns null.

newRpcFault

public abstract RpcFault newRpcFault(java.lang.Throwable e)

newRpcResponse

protected abstract RpcResponse newRpcResponse(java.lang.Object returnValue)