1 55 56 package org.apache.bsf.engines.javaclass; 57 58 import java.util.*; 59 import java.io.*; 60 import java.lang.reflect.*; 61 62 import org.apache.bsf.util.MethodUtils; 63 import org.apache.bsf.*; 64 import org.apache.bsf.util.BSFEngineImpl; 65 66 72 public class JavaClassEngine extends BSFEngineImpl { 73 79 public Object call (Object object, String method, Object [] args) 80 throws BSFException { 81 Class [] argTypes = null; 83 if (args != null) { 84 argTypes = new Class [args.length]; 85 for (int i = 0; i < args.length; i++) { 86 argTypes[i] = (args[i] != null) ? args[i].getClass () : null; 87 } 88 } 89 90 try { 92 Method m = MethodUtils.getMethod (object, method, argTypes); 93 return m.invoke (object, args); 94 } catch (Exception e) { 95 Throwable t = (e instanceof InvocationTargetException) ? 97 ((InvocationTargetException)e).getTargetException () : 98 null; 99 throw new BSFException (BSFException.REASON_OTHER_ERROR, 100 "method invocation failed: " + e + 101 ((t==null)?"":(" target exception: "+t)), t); 102 } 103 } 104 108 public Object eval (String source, int lineNo, int columnNo, 109 Object oscript) throws BSFException { 110 throw new BSFException (BSFException.REASON_UNSUPPORTED_FEATURE, 111 "Java bytecode engine can't evaluate expressions"); 112 } 113 } 114 | Popular Tags |