1 16 17 package org.apache.axis.encoding; 18 19 import org.apache.axis.components.logger.LogFactory; 20 import org.apache.axis.utils.Messages; 21 import org.apache.commons.logging.Log; 22 import org.xml.sax.SAXException ; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 27 28 public class MethodTarget implements Target 30 { 31 protected static Log log = 32 LogFactory.getLog(MethodTarget.class.getName()); 33 34 private Object targetObject; 35 private Method targetMethod; 36 private static final Class [] objArg = new Class [] { Object .class }; 37 38 43 public MethodTarget(Object targetObject, Method targetMethod) 44 { 45 this.targetObject = targetObject; 46 this.targetMethod = targetMethod; 47 } 48 49 54 public MethodTarget(Object targetObject, String methodName) 55 throws NoSuchMethodException 56 { 57 this.targetObject = targetObject; 58 Class cls = targetObject.getClass(); 59 targetMethod = cls.getMethod(methodName, objArg); 60 } 61 62 66 public void set(Object value) throws SAXException { 67 try { 68 targetMethod.invoke(targetObject, new Object [] { value }); 69 } catch (IllegalAccessException accEx) { 70 log.error(Messages.getMessage("illegalAccessException00"), 71 accEx); 72 throw new SAXException (accEx); 73 } catch (IllegalArgumentException argEx) { 74 log.error(Messages.getMessage("illegalArgumentException00"), 75 argEx); 76 throw new SAXException (argEx); 77 } catch (InvocationTargetException targetEx) { 78 log.error(Messages.getMessage("invocationTargetException00"), 79 targetEx); 80 throw new SAXException (targetEx); 81 } 82 } 83 } 84 | Popular Tags |