InvocationHandle.java :  » Aspect-oriented » dynaop » dynaop » remote » Java Open Source

Java Open Source » Aspect oriented » dynaop 
dynaop » dynaop » remote » InvocationHandle.java
package dynaop.remote;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import dynaop.util.NestedException;

/**
 * 
 * 
 * @author Bob Lee (crazybob@crazybob.org)
 */
class InvocationHandle implements Serializable {

  static final long serialVersionUID = 0;

  private Class remoteClass;
  private String methodName;
  private Class[] parameterTypes;
  private Object[] parameters;

  InvocationHandle(Method method, Object[] parameters) {
    this.remoteClass = method.getDeclaringClass();
    this.methodName = method.getName();
    this.parameterTypes = method.getParameterTypes();
    this.parameters = parameters;
  }

  Object invoke(Object ejbObject) {
    try {
      Method method =
        remoteClass.getMethod(this.methodName, this.parameterTypes);
      return method.invoke(ejbObject, this.parameters);
    }
    catch (InvocationTargetException e) {
      return new ThrowableWrapper(e.getTargetException());
    }
    catch (Exception e) {
      throw NestedException.wrap(e);
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.