1 23 24 29 30 31 package com.sun.cli.jmx.util; 32 33 import java.lang.reflect.Array ; 34 import java.lang.reflect.Method ; 35 import java.lang.reflect.InvocationTargetException ; 36 37 import com.sun.cli.util.ClassUtil; 38 39 40 41 public class InvokeHelper 42 { 43 final Object mTarget; 44 45 public 46 InvokeHelper( Object target ) 47 { 48 mTarget = target; 49 } 50 51 static public Class [] 52 StringsToClasses( String [] signature ) 53 throws ClassNotFoundException 54 { 55 final int count = Array.getLength( signature ); 56 57 Class [] classes = new Class [ count ]; 58 59 for( int i = 0; i < count; ++i ) 60 { 61 classes[ i ] = ClassUtil.getClassFromName( signature[ i ] ); 62 } 63 64 return( classes ); 65 } 66 67 public Object 68 invoke( 69 String name, 70 Object params[], 71 String signature[] ) 72 throws NoSuchMethodException , ClassNotFoundException , 73 InvocationTargetException , IllegalAccessException 74 { 75 Object result = null; 76 77 final Class [] signatureClasses = StringsToClasses( signature ); 78 79 final Method method = mTarget.getClass().getDeclaredMethod( name, signatureClasses ); 80 81 result = method.invoke( mTarget, params ); 82 83 return( result ); 84 } 85 } 86 87 88 | Popular Tags |