JMMF API
pre-release v0.8

fr.umlv.jmmf.reflect
Class MultiMethod

java.lang.Object
  |
  +--fr.umlv.jmmf.reflect.MultiMethod

public final class MultiMethod
extends java.lang.Object

The multi-method object. This class support the 1.2 security model. The current implementation of the multi-method mecanism desactivate default Java language access control checks. see AccessibleObject. The method create permit to create a multi-method object.

import fr.umlv.jmmf.reflect.*;

public class Test {
  public interface A {}
  public static class B implements A {}
  public static class C implements A {
    int value;
  }

  static public String toString(B b) {
    return b.toString();
  }
  static public String toString(C c) {
    return String.valueOf(c.value);
  }

  public static void main(String[] args)
    throws Exception
  {
    MultiMethod mm=MultiMethod.create(Test.class,"toString",1);

    A a=new B();
    System.out.println(mm.invoke(null,new Object[]{a}));
    a=new C();
    System.out.println(mm.invoke(null,new Object[]{a}));
  }
}

Version:
0.8.8
Author:
Remi Forax

Method Summary
static MultiMethod create(java.lang.Class clazz, java.lang.String name, int parameterLength)
          construct a multi-method by taking all method named name with parameterLength parameter(s) in class clazz.
 java.lang.Class getDeclaringClass()
          return the class on which the multi-method is declared.
 java.lang.reflect.Method getMethod(java.lang.Class target, java.lang.Class[] types)
          return the most specific method of the multi-method according to the type of all items if args array on a specified target object.
 java.lang.String getName()
          return the name of the current multi-method.
 int getParameterLength()
          return the number of parameters of the current multi-method.
 java.lang.Object invoke(java.lang.Object target, java.lang.Object[] args)
          call the most specific method of the multi-method according to the type of all items if args array on a specified target object.
 java.lang.Object invoke(java.lang.Object target, java.lang.Object[] args, java.lang.Class[] types)
          call the most specific method of the multi-method according to the type of all items if args array on a specified target object.
 boolean isOnlyPublic()
          return true is the multi-method is constructed using the onlyPublic flag.
 java.lang.String toString()
          return a string representation of the multi-method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getMethod

public java.lang.reflect.Method getMethod(java.lang.Class target,
                                          java.lang.Class[] types)
                                   throws java.lang.NoSuchMethodException,
                                          MultipleMethodsException
return the most specific method of the multi-method according to the type of all items if args array on a specified target object.
Parameters:
target - class in which the most specific method is declared.
types - parameter types used to find the most specific method.
Returns:
the most specific method.
Throws:
NoSuchMethodException, - there is no method that match the parameter arguments.
MultipleMethodsException - there are multiple methods that match the parameter arguments.
See Also:
java.lang.Class#getMethod(Class[]), #invoke(Object, Object[], Object[])

invoke

public java.lang.Object invoke(java.lang.Object target,
                               java.lang.Object[] args)
                        throws java.lang.IllegalAccessException,
                               java.lang.reflect.InvocationTargetException,
                               java.lang.NoSuchMethodException,
                               MultipleMethodsException
call the most specific method of the multi-method according to the type of all items if args array on a specified target object.
Parameters:
target - object on which the most specific method is called.
args - arguments of the multi-method, the types on this arguments is used to called the most specific method.
Returns:
the result of the called of the most specific method.
Throws:
NoSuchMethodException, - there is no method that match the parameter arguments.
MultipleMethodsException - there are multiple methods that match the parameter arguments.
java.lang.reflect.InvocationTargetException - if the most specific method called raise an exception during its execution, this exception is wrapped into the InvocationTargetException.
java.lang.IllegalArgumentException - if the target class isn't a subtype of the declaring class.
java.lang.IllegalAccessException - if most specific method isn't accessible.
See Also:
Method.invoke(Object,Object[]), #invoke(Object, Object[], Object[])

invoke

public java.lang.Object invoke(java.lang.Object target,
                               java.lang.Object[] args,
                               java.lang.Class[] types)
                        throws java.lang.IllegalAccessException,
                               java.lang.reflect.InvocationTargetException,
                               java.lang.NoSuchMethodException,
                               MultipleMethodsException
call the most specific method of the multi-method according to the type of all items if args array on a specified target object.
Parameters:
target - object on which the most specific method is called.
args - arguments of the multi-method,
types - the most specific method of the multi-method is called according to this types.
Returns:
the result of the called of the most specific method.
Throws:
NoSuchMethodException, - there is no method that match the parameter types.
MultipleMethodsException - there are multiple methods that match the parameter arguments.
java.lang.reflect.InvocationTargetException - if the most specific method called raise an exception during its execution, this exception is wrapped into the InvocationTargetException.
java.lang.IllegalArgumentException - if the target class isn't a subtype of the declaring class.
java.lang.IllegalAccessException - if most specific method isn't accessible.
See Also:
Method.invoke(Object,Object[])

toString

public java.lang.String toString()
return a string representation of the multi-method.
Overrides:
toString in class java.lang.Object

isOnlyPublic

public boolean isOnlyPublic()
return true is the multi-method is constructed using the onlyPublic flag.
See Also:
MultiFactory.create(Class,String,int,boolean)

getParameterLength

public int getParameterLength()
return the number of parameters of the current multi-method.

getName

public java.lang.String getName()
return the name of the current multi-method.

getDeclaringClass

public java.lang.Class getDeclaringClass()
return the class on which the multi-method is declared.

create

public static MultiMethod create(java.lang.Class clazz,
                                 java.lang.String name,
                                 int parameterLength)
construct a multi-method by taking all method named name with parameterLength parameter(s) in class clazz.
Parameters:
clazz - class which owns the named methods.
name - name of the methods.
parameterLength - number of parameters.
Throws:
java.lang.IllegalArgumentException - if the class clazz contains no method named name or all methods found don't have the same number of parameters.
See Also:
MultiFactory, MultiFactory.create(Class,String,int)

JMMF API
pre-release v0.8

Rémi Forax 1999,2000 Université de Marne la Vallée