Package org.springframework.util

Examples of org.springframework.util.MethodInvoker


  public static <T> T invokeMethod(Object target, String name, Object... args) {
    Assert.notNull(target, "Target object must not be null");
    Assert.hasText(name, "Method name must not be empty");

    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(target);
      methodInvoker.setTargetMethod(name);
      methodInvoker.setArguments(args);
      methodInvoker.prepare();

      if (logger.isDebugEnabled()) {
        logger.debug("Invoking method [" + name + "] on target [" + target + "] with arguments ["
            + ObjectUtils.nullSafeToString(args) + "]");
      }

      return (T) methodInvoker.invoke();
    }
    catch (Exception e) {
      ReflectionUtils.handleReflectionException(e);
    }
View Full Code Here


   * @see #getListenerMethodName
   * @see #buildListenerArguments
   */
  protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException {
    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(getDelegate());
      methodInvoker.setTargetMethod(methodName);
      methodInvoker.setArguments(arguments);
      methodInvoker.prepare();
      return methodInvoker.invoke();
    }
    catch (InvocationTargetException ex) {
      Throwable targetEx = ex.getTargetException();
      if (targetEx instanceof JMSException) {
        throw (JMSException) targetEx;
View Full Code Here

   * @see #getListenerMethodName
   * @see #buildListenerArguments
   */
  protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException {
    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(getDelegate());
      methodInvoker.setTargetMethod(methodName);
      methodInvoker.setArguments(arguments);
      methodInvoker.prepare();
      return methodInvoker.invoke();
    }
    catch (InvocationTargetException ex) {
      Throwable targetEx = ex.getTargetException();
      if (targetEx instanceof JMSException) {
        throw (JMSException) targetEx;
View Full Code Here

  protected void doWrite(List<? extends T> items) throws Exception {
    if (logger.isDebugEnabled()) {
      logger.debug("Writing to the repository with " + items.size() + " items.");
    }

    MethodInvoker invoker = createMethodInvoker(repository, methodName);

    for (T object : items) {
      invoker.setArguments(new Object [] {object});
      doInvoke(invoker);
    }
  }
View Full Code Here

      throw new DynamicMethodInvocationException(e);
    }
  }

  private MethodInvoker createMethodInvoker(Object targetObject, String targetMethod) {
    MethodInvoker invoker = new MethodInvoker();
    invoker.setTargetObject(targetObject);
    invoker.setTargetMethod(targetMethod);
    return invoker;
  }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  protected List<T> doPageRead() throws Exception {
    Pageable pageRequest = new PageRequest(page, pageSize, sort);

    MethodInvoker invoker = createMethodInvoker(repository, methodName);

    List<Object> parameters = new ArrayList<Object>();

    if(arguments != null && arguments.size() > 0) {
      parameters.addAll(arguments);
    }

    parameters.add(pageRequest);

    invoker.setArguments(parameters.toArray());

    Page<T> curPage = (Page<T>) doInvoke(invoker);

    return curPage.getContent();
  }
View Full Code Here

      throw new DynamicMethodInvocationException(e);
    }
  }

  private MethodInvoker createMethodInvoker(Object targetObject, String targetMethod) {
    MethodInvoker invoker = new MethodInvoker();
    invoker.setTargetObject(targetObject);
    invoker.setTargetMethod(targetMethod);
    return invoker;
  }
View Full Code Here

  /**
   * Added due to JDK 7 compatibility.
   */
  public Logger getParentLogger() throws SQLFeatureNotSupportedException{
    MethodInvoker invoker = new MethodInvoker();
    invoker.setTargetObject(dataSource);
    invoker.setTargetMethod("getParentLogger");

    try {
      invoker.prepare();
      return (Logger) invoker.invoke();
    } catch (ClassNotFoundException cnfe) {
      throw new SQLFeatureNotSupportedException(cnfe);
    } catch (NoSuchMethodException nsme) {
      throw new SQLFeatureNotSupportedException(nsme);
    } catch (IllegalAccessException iae) {
View Full Code Here

   * @return object returned by invoked method
   * @throws DynamicMethodInvocationException if the {@link MethodInvoker}
   * used throws exception
   */
  protected T invokeDelegateMethod() throws Exception {
    MethodInvoker invoker = createMethodInvoker(targetObject, targetMethod);
    invoker.setArguments(arguments);
    return doInvoke(invoker);
  }
View Full Code Here

   * @return object returned by target method
   * @throws DynamicMethodInvocationException if the {@link MethodInvoker}
   * used throws exception
   */
  protected T invokeDelegateMethodWithArgument(Object object) throws Exception {
    MethodInvoker invoker = createMethodInvoker(targetObject, targetMethod);
    invoker.setArguments(new Object[] { object });
    return doInvoke(invoker);
  }
View Full Code Here

TOP

Related Classes of org.springframework.util.MethodInvoker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.