congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
MethodInvoker
Code IndexAdd Tabnine to your IDE (free)

How to use
MethodInvoker
in
org.springframework.util

Best Java code snippets using org.springframework.util.MethodInvoker (Showing top 20 results out of 324)

origin: spring-projects/spring-batch

  /**
   * 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 | NoSuchMethodException | IllegalAccessException | InvocationTargetException nsme) {
      throw new SQLFeatureNotSupportedException(nsme);
    }
  }
}
origin: spring-projects/spring-batch

/**
 * Performs the actual write to the repository.  This can be overridden by
 * a subclass if necessary.
 *
 * @param items the list of items to be persisted.
 *
 * @throws Exception thrown if error occurs during writing.
 */
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);
  }
}
origin: spring-projects/spring-framework

  this.targetClass = resolveClassName(className);
  this.targetMethod = methodName;
Class<?> targetClass = getTargetClass();
String targetMethod = getTargetMethod();
Assert.notNull(targetClass, "Either 'targetClass' or 'targetObject' is required");
Assert.notNull(targetMethod, "Property 'targetMethod' is required");
Object[] arguments = getArguments();
Class<?>[] argTypes = new Class<?>[arguments.length];
for (int i = 0; i < arguments.length; ++i) {
  this.methodObject = findMatchingMethod();
  if (this.methodObject == null) {
    throw ex;
origin: spring-projects/spring-framework

/**
 * Constructor for JobMethodInvocationFailedException.
 * @param methodInvoker the MethodInvoker used for reflective invocation
 * @param cause the root cause (as thrown from the target method)
 */
public JobMethodInvocationFailedException(MethodInvoker methodInvoker, Throwable cause) {
  super("Invocation of method '" + methodInvoker.getTargetMethod() +
      "' on target class [" + methodInvoker.getTargetClass() + "] failed", cause);
}
origin: spring-projects/spring-batch

  private MethodInvoker createMethodInvoker(Object targetObject, String targetMethod) {
    MethodInvoker invoker = new MethodInvoker();
    invoker.setTargetObject(targetObject);
    invoker.setTargetMethod(targetMethod);
    return invoker;
  }
}
origin: spring-projects/spring-batch

private Object doInvoke(MethodInvoker invoker) throws Exception{
  try {
    invoker.prepare();
  }
  catch (ClassNotFoundException | NoSuchMethodException e) {
    throw new DynamicMethodInvocationException(e);
  }
  try {
    return invoker.invoke();
  }
  catch (InvocationTargetException e) {
    if (e.getCause() instanceof Exception) {
      throw (Exception) e.getCause();
    }
    else {
      throw new InvocationTargetThrowableWrapper(e.getCause());
    }
  }
  catch (IllegalAccessException e) {
    throw new DynamicMethodInvocationException(e);
  }
}
origin: de.tudarmstadt.ukp.dkpro.lab/dkpro-lab-core

Object toPath = MethodUtils.invokeExactMethod(aTarget, "toPath", new Object[0]);
Object options = Array.newInstance(Class.forName("java.nio.file.attribute.FileAttribute"), 0);
MethodInvoker inv = new MethodInvoker();
inv.setStaticMethod("java.nio.file.Files.createSymbolicLink");
inv.setArguments(new Object[] { toPath, fromPath, options });
inv.prepare();
inv.invoke();
return;
origin: org.kuali.common/kuali-util

public static Object invokeMethod(Class<?> targetClass, String targetMethod, Object... arguments) {
  MethodInvoker invoker = new MethodInvoker();
  invoker.setTargetClass(targetClass);
  invoker.setTargetMethod(targetMethod);
  invoker.setArguments(arguments);
  return invoke(invoker);
}
origin: ltsopensource/light-task-scheduler

  @Override
  public void execute(QuartzJobContext quartzJobContext, Job job) throws Throwable {
    methodInvoker.invoke();
  }
}
origin: org.onehippo.cms7.hst.components/hst-core

/** {@inheritDoc} */
public void onApplicationEvent(ApplicationEvent event) {
  boolean doIt = false;
  ApplicationContext ac = ctx;
  while (ac != null && !doIt) {
    if (event.getSource() == ac) {
      doIt = true;
    }
    ac = ac.getParent();
  }
  if (!doIt) {
    return;
  }
  List<MethodInvoker> invokers = findMethodInvokersByEvent(event);
  if (invokers != null && !invokers.isEmpty()) {
    for (MethodInvoker invoker : invokers) {
      try {
        if (autoPrepareInvoker && !invoker.isPrepared()) {
          invoker.prepare();
        }
        invoker.invoke();
      } catch (Exception e) {
        log.error("Failed to invoke application event callback invoker. " + e, e);
      }
    }
  }
}
origin: spring-projects/spring-framework

String targetMethod = getTargetMethod();
Object[] arguments = getArguments();
int argCount = arguments.length;
Class<?> targetClass = getTargetClass();
Assert.state(targetClass != null, "No target class set");
Method[] candidates = ReflectionUtils.getAllDeclaredMethods(targetClass);
    Class<?>[] paramTypes = candidate.getParameterTypes();
    if (paramTypes.length == argCount) {
      int typeDiffWeight = getTypeDifferenceWeight(paramTypes, arguments);
      if (typeDiffWeight < minTypeDiffWeight) {
        minTypeDiffWeight = typeDiffWeight;
origin: uncodecn/uncode-schedule

protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
  try {
    String name = ScheduleUtil.getTaskNameFormBean(context.getJobDetail().getKey().getName(), this.methodInvoker.getTargetMethod());
    boolean isOwner = false;
    try {
      ReflectionUtils.invokeMethod(setResultMethod, context, this.methodInvoker.invoke());
      LOGGER.info("Cron job has been executed.");
origin: springframework/spring-core

/**
 * Find a matching method with the specified name for the specified arguments.
 * @return a matching method, or <code>null</code> if none
 * @see #getTargetClass()
 * @see #getTargetMethod()
 * @see #getArguments()
 */
protected Method findMatchingMethod() {
  Method[] candidates = getTargetClass().getMethods();
  int argCount = getArguments().length;
  Method matchingMethod = null;
  int numberOfMatchingMethods = 0;
  for (int i = 0; i < candidates.length; i++) {
    // Check if the inspected method has the correct name and number of parameters.
    if (candidates[i].getName().equals(getTargetMethod()) &&
        candidates[i].getParameterTypes().length == argCount) {
      matchingMethod = candidates[i];
      numberOfMatchingMethods++;
    }
  }
  // Only return matching method if exactly one found.
  if (numberOfMatchingMethods == 1) {
    return matchingMethod;
  }
  else {
    return null;
  }
}
origin: springframework/spring-core

/**
 * Set a fully qualified static method name to invoke,
 * e.g. "example.MyExampleClass.myExampleMethod".
 * Convenient alternative to specifying targetClass and targetMethod.
 * @see #setTargetClass
 * @see #setTargetMethod
 */
public void setStaticMethod(String staticMethod) throws ClassNotFoundException {
  int lastDotIndex = staticMethod.lastIndexOf('.');
  if (lastDotIndex == -1 || lastDotIndex == staticMethod.length()) {
    throw new IllegalArgumentException("staticMethod must be a fully qualified class plus method name: " +
        "e.g. 'example.MyExampleClass.myExampleMethod'");
  }
  String className = staticMethod.substring(0, lastDotIndex);
  String methodName = staticMethod.substring(lastDotIndex + 1);
  setTargetClass(ClassUtils.forName(className));
  setTargetMethod(methodName);
}
origin: stackoverflow.com

return new MethodInvoker(obj, methodName);
return new MethodInvoker(clazz, methodName);
origin: spring-projects/spring-framework

/**
 * This implementation looks for a method with matching parameter types.
 * @see #doFindMatchingMethod
 */
@Override
protected Method findMatchingMethod() {
  Method matchingMethod = super.findMatchingMethod();
  // Second pass: look for method where arguments can be converted to parameter types.
  if (matchingMethod == null) {
    // Interpret argument array as individual method arguments.
    matchingMethod = doFindMatchingMethod(getArguments());
  }
  if (matchingMethod == null) {
    // Interpret argument array as single method argument of array type.
    matchingMethod = doFindMatchingMethod(new Object[] {getArguments()});
  }
  return matchingMethod;
}
origin: apache/servicemix-bundles

this.targetClass = resolveClassName(className);
this.targetMethod = methodName;
this.methodObject = findMatchingMethod();
if (this.methodObject == null) {
  throw ex;
origin: spring-projects/spring-batch

/**
 * Prepare and invoke the invoker, rethrow checked exceptions as unchecked.
 * @param invoker configured invoker
 * @return return value of the invoked method
 */
@SuppressWarnings("unchecked")
private T doInvoke(MethodInvoker invoker) throws Exception {
  try {
    invoker.prepare();
  }
  catch (ClassNotFoundException | NoSuchMethodException e) {
    throw new DynamicMethodInvocationException(e);
  }
  try {
    return (T) invoker.invoke();
  }
  catch (InvocationTargetException e) {
    if (e.getCause() instanceof Exception) {
      throw (Exception) e.getCause();
    }
    else {
      throw new InvocationTargetThrowableWrapper(e.getCause());
    }
  }
  catch (IllegalAccessException e) {
    throw new DynamicMethodInvocationException(e);
  }
}
origin: de.tudarmstadt.ukp.dkpro.lab/de.tudarmstadt.ukp.dkpro.lab.core

Object toPath = MethodUtils.invokeExactMethod(aTarget, "toPath", new Object[0]);
Object options = Array.newInstance(Class.forName("java.nio.file.attribute.FileAttribute"), 0);
MethodInvoker inv = new MethodInvoker();
inv.setStaticMethod("java.nio.file.Files.createSymbolicLink");
inv.setArguments(new Object[] { toPath, fromPath, options });
inv.prepare();
inv.invoke();
return;
origin: spring-projects/spring-batch

  private MethodInvoker createMethodInvoker(Object targetObject, String targetMethod) {
    MethodInvoker invoker = new MethodInvoker();
    invoker.setTargetObject(targetObject);
    invoker.setTargetMethod(targetMethod);
    return invoker;
  }
}
org.springframework.utilMethodInvoker

Javadoc

Helper class that allows for specifying a method to invoke in a declarative fashion, be it static or non-static.

Usage: Specify "targetClass"/"targetMethod" or "targetObject"/"targetMethod", optionally specify arguments, prepare the invoker. Afterwards, you may invoke the method any number of times, obtaining the invocation result.

Typically not used directly but via its subclasses org.springframework.beans.factory.config.MethodInvokingFactoryBean and org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.

Most used methods

  • invoke
    Invoke the specified method. The invoker needs to have been prepared before.
  • prepare
    Prepare the specified method. The method can be invoked any number of times afterwards.
  • <init>
  • setTargetMethod
    Set the name of the method to be invoked. Refers to either a static method or a non-static method, d
  • setArguments
    Set arguments for the method invocation. If this property is not set, or the Object array is of leng
  • setTargetObject
    Set the target object on which to call the target method. Only necessary when the target method is n
  • getTargetMethod
    Return the name of the method to be invoked.
  • getTargetClass
    Return the target class on which to call the target method.
  • findMatchingMethod
    Find a matching method with the specified name for the specified arguments.
  • getPreparedMethod
    Return the prepared Method object that will be invoker. Can for example be used to determine the ret
  • getTypeDifferenceWeight
    Algorithm that judges the match between the declared parameter types of a candidate method and a spe
  • getArguments
    Retrun the arguments for the method invocation.
  • getTypeDifferenceWeight,
  • getArguments,
  • setTargetClass,
  • getTargetObject,
  • resolveClassName,
  • isPrepared,
  • setStaticMethod

Popular in Java

  • Making http requests using okhttp
  • compareTo (BigDecimal)
  • findViewById (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Top 15 Vim Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now