com.googlecode.android_scripting.rpc
Class MethodDescriptor

java.lang.Object
  extended by com.googlecode.android_scripting.rpc.MethodDescriptor

public final class MethodDescriptor
extends java.lang.Object

An adapter that wraps Method.

Author:
igor.v.karp@gmail.com (Igor Karp)

Constructor Summary
MethodDescriptor(java.lang.Class<? extends RpcReceiver> clazz, java.lang.reflect.Method method)
           
 
Method Summary
static java.lang.Object buildIntent(JSONObject jsonObject)
           
static java.util.Collection<MethodDescriptor> collectFrom(java.lang.Class<? extends RpcReceiver> clazz)
          Collects all methods with RPC annotation from given class.
 java.lang.Class<? extends RpcReceiver> getDeclaringClass()
           
static java.lang.Object getDefaultValue(java.lang.reflect.Type parameterType, java.lang.annotation.Annotation[] annotations)
          Returns the default value for a specific parameter.
 java.lang.reflect.Type[] getGenericParameterTypes()
           
 java.lang.String getHelp()
          Returns a human-readable help text for this RPC, based on annotations in the source code.
 java.lang.reflect.Method getMethod()
           
 java.lang.String getName()
           
 java.lang.annotation.Annotation[][] getParameterAnnotations()
           
 java.lang.String[] getParameterHints()
          Returns parameter hints.
 ParameterDescriptor[] getParameterValues(java.lang.String[] values)
          Returns parameter descriptors suitable for the RPC call text representation.
static boolean hasDefaultValue(java.lang.annotation.Annotation[] annotations)
          Determines whether or not this parameter has default value.
 java.lang.Object invoke(RpcReceiverManager manager, JSONArray parameters)
          Invokes the call that belongs to this object with the given parameters.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodDescriptor

public MethodDescriptor(java.lang.Class<? extends RpcReceiver> clazz,
                        java.lang.reflect.Method method)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

collectFrom

public static java.util.Collection<MethodDescriptor> collectFrom(java.lang.Class<? extends RpcReceiver> clazz)
Collects all methods with RPC annotation from given class.


invoke

public java.lang.Object invoke(RpcReceiverManager manager,
                               JSONArray parameters)
                        throws java.lang.Throwable
Invokes the call that belongs to this object with the given parameters. Wraps the response (possibly an exception) in a JSONObject.

Parameters:
parameters - JSONArray containing the parameters
Returns:
result
Throws:
java.lang.Throwable

buildIntent

public static java.lang.Object buildIntent(JSONObject jsonObject)
                                    throws JSONException
Throws:
JSONException

getMethod

public java.lang.reflect.Method getMethod()

getDeclaringClass

public java.lang.Class<? extends RpcReceiver> getDeclaringClass()

getName

public java.lang.String getName()

getGenericParameterTypes

public java.lang.reflect.Type[] getGenericParameterTypes()

getParameterAnnotations

public java.lang.annotation.Annotation[][] getParameterAnnotations()

getHelp

public java.lang.String getHelp()
Returns a human-readable help text for this RPC, based on annotations in the source code.

Returns:
derived help string

getParameterValues

public ParameterDescriptor[] getParameterValues(java.lang.String[] values)
Returns parameter descriptors suitable for the RPC call text representation.

Uses parameter value, default value or name, whatever is available first.

Returns:
an array of parameter descriptors

getParameterHints

public java.lang.String[] getParameterHints()
Returns parameter hints.

Returns:
an array of parameter hints

getDefaultValue

public static java.lang.Object getDefaultValue(java.lang.reflect.Type parameterType,
                                               java.lang.annotation.Annotation[] annotations)
Returns the default value for a specific parameter.

Parameters:
parameterType - parameterType
annotations - annotations of the parameter

hasDefaultValue

public static boolean hasDefaultValue(java.lang.annotation.Annotation[] annotations)
Determines whether or not this parameter has default value.

Parameters:
annotations - annotations of the parameter