1 16 17 package org.apache.taglibs.xtags.xpath; 18 19 20 21 import java.lang.reflect.Method ; 22 23 import org.dom4j.Node; 24 import org.dom4j.rule.Action; 25 26 30 public class ReflectionAction implements Action { 31 32 protected static final Object [] NULL_ARGS = {}; 33 34 protected static final Class [] NULL_PARAMS = {}; 35 36 37 private Object object; 38 39 40 private Method method; 41 42 43 44 public ReflectionAction( Object object, String methodName ) { 45 this.object = object; 46 Class theClass = object.getClass(); 47 try { 48 this.method = theClass.getMethod( methodName, NULL_PARAMS ); 49 } 50 catch (NoSuchMethodException e) { 51 System.out.println( "WARNING: " + getClass().getName() + 52 ": Could not find method: " + methodName 53 + " in class: " + theClass.getName() 54 ); 55 } 56 } 57 58 public ReflectionAction( Object object, Method method ) { 59 this.object = object; 60 this.method = method; 61 } 62 63 64 public void run( Node node ) throws Exception { 67 if ( method != null ) { 69 method.invoke( object, NULL_ARGS ); 70 } 71 } 72 } 73 | Popular Tags |