Java Code Examples for org.apache.commons.lang.reflect.MethodUtils

The following examples show how to use org.apache.commons.lang.reflect.MethodUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mycore   Source File: MCRFunctionCallJava.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object call(Context context, List args) throws FunctionCallException {
    try {
        String clazzName = (String) (args.get(0));
        String methodName = (String) (args.get(1));
        LOGGER.debug("XEditor extension function calling {} {}", clazzName, methodName);

        Class[] argTypes = new Class[args.size() - 2];
        Object[] params = new Object[args.size() - 2];
        for (int i = 0; i < argTypes.length; i++) {
            argTypes[i] = args.get(i + 2).getClass();
            params[i] = args.get(i + 2);
        }

        Class clazz = ClassUtils.getClass(clazzName);
        Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, argTypes);
        return method.invoke(null, params);
    } catch (Exception ex) {
        LOGGER.warn("Exception in call to external java method", ex);
        return ex.getMessage();
    }
}
 
Example 2
Source Project: incubator-gobblin   Source File: HiveMetaStoreUtils.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
protected static void inVokeDetermineSchemaOrThrowExceptionMethod(Properties props, Configuration conf)
    throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
  String methodName = "determineSchemaOrThrowException";
  Method method = MethodUtils.getAccessibleMethod(AvroSerdeUtils.class, methodName, Properties.class);
  boolean withConf = false;
  if (method == null) {
    method = MethodUtils
        .getAccessibleMethod(AvroSerdeUtils.class, methodName, new Class[]{Configuration.class, Properties.class});
    withConf = true;
  }
  Preconditions.checkNotNull(method, "Cannot find matching " + methodName);
  if (!withConf) {
    MethodUtils.invokeStaticMethod(AvroSerdeUtils.class, methodName, props);
  } else {
    MethodUtils.invokeStaticMethod(AvroSerdeUtils.class, methodName, new Object[]{conf, props});
  }
}
 
Example 3
public static boolean update() {
   try {
      return (Boolean)MethodUtils.invokeStaticMethod(Class.forName("be.fgov.ehealth.technicalconnector.bootstrap.bcp.EndpointUpdater"), "update", new Object[0]);
   } catch (Exception var1) {
      LOG.error("Unable to update endpoints", var1);
      return false;
   }
}
 
Example 4
public void run() {
   try {
      MethodUtils.invokeStaticMethod(Class.forName("be.fgov.ehealth.technicalconnector.bootstrap.tsl.TrustStoreUpdater"), "launch", new Object[0]);
   } catch (Exception var2) {
      LOG.error("Unable to update truststores", var2);
   }

}
 
Example 5
public void run() {
   try {
      MethodUtils.invokeStaticMethod(Class.forName("be.fgov.ehealth.technicalconnector.bootstrap.tsl.TrustStoreUpdater"), "launch", new Object[0]);
   } catch (Exception var2) {
      LOG.error("Unable to update truststores", var2);
   }

}
 
Example 6
public static boolean update() {
   try {
      return ((Boolean)MethodUtils.invokeStaticMethod(Class.forName("be.fgov.ehealth.technicalconnector.bootstrap.bcp.EndpointUpdater"), "update", new Object[0]));
   } catch (Exception var1) {
      LOG.error("Unable to update endpoints", var1);
      return false;
   }
}
 
Example 7
public void run() {
   try {
      MethodUtils.invokeStaticMethod(Class.forName("be.fgov.ehealth.technicalconnector.bootstrap.tsl.TrustStoreUpdater"), "launch", new Object[0]);
   } catch (Exception var2) {
      LOG.error("Unable to update truststores", var2);
   }

}
 
Example 8
public static boolean update() {
   try {
      return ((Boolean)MethodUtils.invokeStaticMethod(Class.forName("be.fgov.ehealth.technicalconnector.bootstrap.bcp.EndpointUpdater"), "update", new Object[0])).booleanValue();
   } catch (Exception var1) {
      LOG.error("Unable to update endpoints", var1);
      return false;
   }
}
 
Example 9
public void run() {
   try {
      MethodUtils.invokeStaticMethod(Class.forName("be.fgov.ehealth.technicalconnector.bootstrap.tsl.TrustStoreUpdater"), "launch", new Object[0]);
   } catch (Exception var2) {
      LOG.error("Unable to update truststores", var2);
   }

}
 
Example 10
public void run() {
   try {
      MethodUtils.invokeStaticMethod(Class.forName("be.fgov.ehealth.technicalconnector.bootstrap.tsl.TrustStoreUpdater"), "launch", new Object[0]);
   } catch (Exception var2) {
      LOG.error("Unable to update truststores", var2);
   }

}
 
Example 11
Source Project: mycore   Source File: MCRExternalValidator.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Method findMethod(Class<?> argType) {
    try {
        Class<?> clazz = ClassUtils.getClass(className);
        Class<?>[] argTypes = { argType };
        return MethodUtils.getMatchingAccessibleMethod(clazz, methodName, argTypes);
    } catch (ClassNotFoundException ex) {
        throw new MCRConfigurationException("class configured for external validation not found: " + className);
    }
}
 
Example 12
/**
 * Bukkit requires a static getHandlerList() method on all event classes, see {@link Event}.
 * This test checks that such a method is present, and that it is <i>absent</i> if the class
 * is not instantiable (abstract class).
 */
@Test
public void shouldHaveStaticEventHandlerMethod() {
    for (Class<?> clazz : classes) {
        Method handlerListMethod = MethodUtils.getAccessibleMethod(clazz, "getHandlerList", new Class<?>[]{});
        if (canBeInstantiated(clazz)) {
            assertThat("Class " + clazz.getSimpleName() + " has static method getHandlerList()",
                handlerListMethod != null && Modifier.isStatic(handlerListMethod.getModifiers()), equalTo(true));
        } else {
            assertThat("Non-instantiable class " + clazz.getSimpleName() + " does not have static getHandlerList()",
                handlerListMethod, nullValue());
        }
    }
}
 
Example 13
Source Project: hiped2   Source File: TaskThroughput.java    License: Apache License 2.0 4 votes vote down vote up
public static long extractLongFieldValue(TaskMetrics m,
                                         String fieldName)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
  return (Long) MethodUtils.invokeMethod(m, fieldName, null);
}
 
Example 14
Source Project: hiped2   Source File: DataSkewMetrics.java    License: Apache License 2.0 4 votes vote down vote up
public static long extractLongFieldValue(TaskMetrics m,
                                         String fieldName)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
  return (Long) MethodUtils.invokeMethod(m, fieldName, null);
}
 
Example 15
Source Project: hiped2   Source File: JobHistoryHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static long extractLongFieldValue(TaskMetrics m,
                                         String fieldName)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
  return (Long) MethodUtils.invokeMethod(m, fieldName, null);
}
 
Example 16
Source Project: hiped2   Source File: MetricSummary.java    License: Apache License 2.0 4 votes vote down vote up
public static long extractLongFieldValue(TaskMetrics m,
                                         String fieldName)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
  return (Long) MethodUtils.invokeMethod(m, fieldName, null);
}
 
Example 17
Source Project: openhab1-addons   Source File: PropertyUtils.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Returns the getter value from the object instance, nested properties are
 * possible. If the propertyName is for example temperature.current, the
 * methods getTemperature().getCurrent() are called.
 */
public static Object getPropertyValue(Object instance, String property) throws Exception {
    Object object = getNestedObject(instance, property);
    String getMethod = toGetterString(PropertyResolver.last(property));
    return MethodUtils.invokeMethod(object, getMethod, null);
}