Example usage for org.apache.commons.lang.reflect MethodUtils invokeStaticMethod

List of usage examples for org.apache.commons.lang.reflect MethodUtils invokeStaticMethod

Introduction

In this page you can find the example usage for org.apache.commons.lang.reflect MethodUtils invokeStaticMethod.

Prototype

public static Object invokeStaticMethod(Class cls, String methodName, Object[] args)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException 

Source Link

Document

Invoke a named static method whose parameter type matches the object type.

This method delegates the method search to #getMatchingAccessibleMethod(Class,String,Class[]) .

This method supports calls to methods taking primitive parameters via passing in wrapping classes.

Usage

From source file:deck36.yaml.YamlLoader.java

public static Map updateMap(Map resultYamlMap, Map<String, Object> localYamlMap) {

    for (Map.Entry<String, Object> entry : localYamlMap.entrySet()) {

        if (resultYamlMap.containsKey(entry.getKey())) {
            System.out.println(entry.getKey());

            try {

                Object startValue = resultYamlMap.get(entry.getKey());
                Object updateValue = entry.getValue();

                if (startValue == null) {
                    resultYamlMap.put(entry.getKey(), updateValue);
                } else {
                    resultYamlMap.put(entry.getKey(), MethodUtils.invokeStaticMethod(YamlLoader.class,
                            "updateMap", new Object[] { startValue, updateValue }));
                }//w  ww. j  a  v  a2s  .  c  om

            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }

        } else {
            resultYamlMap.put(entry.getKey(), entry.getValue());
        }

    }

    return resultYamlMap;
}

From source file:gobblin.hive.metastore.HiveMetaStoreUtils.java

@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;//from   w w  w .  j av a2s  .c  o  m
    }
    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 });
    }
}

From source file:org.usergrid.benchmark.boostrap.Command.java

/**
 * @param args/*from   w  ww.j a  v  a  2  s .c  o  m*/
 */
public static void main(String[] args) {

    if ((args == null) || (args.length < 1)) {
        System.out.println("No command specified");
        return;
    }

    String command = args[0];

    Class<?> clazz = null;

    try {
        clazz = Class.forName(command);
    } catch (ClassNotFoundException e) {
    }

    if (clazz == null) {
        try {
            clazz = Class.forName("org.usergrid.benchmark.commands." + command);
        } catch (ClassNotFoundException e) {
        }
    }

    if (clazz == null) {
        try {
            clazz = Class.forName("org.usergrid.benchmark.commands." + StringUtils.capitalize(command));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (clazz == null) {
        System.out.println("Unable to find command");
        return;
    }

    args = Arrays.copyOfRange(args, 1, args.length);

    try {
        if (ToolBase.class.isAssignableFrom(clazz)) {
            ToolBase tool = (ToolBase) clazz.newInstance();
            tool.startTool(args);
        } else {
            MethodUtils.invokeStaticMethod(clazz, "main", (Object) args);
        }
    } catch (NoSuchMethodException e) {
        System.out.println("Unable to invoke command");
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        System.out.println("Unable to invoke command");
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        System.out.println("Error while invoking command");
        e.printStackTrace();
    } catch (InstantiationException e) {
        System.out.println("Error while instantiating tool object");
        e.printStackTrace();
    }
}