类org.apache.commons.lang.reflect.MethodUtils源码实例Demo

下面列出了怎么用org.apache.commons.lang.reflect.MethodUtils的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: mycore   文件: MCRFunctionCallJava.java

@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();
    }
}
 

@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});
  }
}
 

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;
   }
}
 

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);
   }

}
 

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);
   }

}
 

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;
   }
}
 

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);
   }

}
 

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;
   }
}
 

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);
   }

}
 

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);
   }

}
 
源代码11 项目: mycore   文件: MCRExternalValidator.java

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);
    }
}
 

/**
 * 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());
        }
    }
}
 
源代码13 项目: hiped2   文件: TaskThroughput.java

public static long extractLongFieldValue(TaskMetrics m,
                                         String fieldName)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
  return (Long) MethodUtils.invokeMethod(m, fieldName, null);
}
 
源代码14 项目: hiped2   文件: DataSkewMetrics.java

public static long extractLongFieldValue(TaskMetrics m,
                                         String fieldName)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
  return (Long) MethodUtils.invokeMethod(m, fieldName, null);
}
 
源代码15 项目: hiped2   文件: JobHistoryHelper.java

public static long extractLongFieldValue(TaskMetrics m,
                                         String fieldName)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
  return (Long) MethodUtils.invokeMethod(m, fieldName, null);
}
 
源代码16 项目: hiped2   文件: MetricSummary.java

public static long extractLongFieldValue(TaskMetrics m,
                                         String fieldName)
    throws IllegalAccessException, InvocationTargetException,
    NoSuchMethodException {
  return (Long) MethodUtils.invokeMethod(m, fieldName, null);
}
 
源代码17 项目: openhab1-addons   文件: PropertyUtils.java

/**
 * 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);
}
 
 类所在包
 同包方法