Java Code Examples for org.apache.commons.lang3.reflect.MethodUtils#invokeExactMethod()

The following examples show how to use org.apache.commons.lang3.reflect.MethodUtils#invokeExactMethod() . 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 File: JQueryExtractor.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Main method.
 * @param args program arguments
 * @throws Exception s
 */
public static void main(final String[] args) throws Exception {
    // final Class<? extends WebDriverTestCase> testClass = JQuery1x8x2Test.class;
    // final Class<? extends WebDriverTestCase> testClass = JQuery1x11x3Test.class;
    final Class<? extends WebDriverTestCase> testClass = JQuery3x3x1Test.class;

    final String version = (String) MethodUtils.invokeExactMethod(testClass.newInstance(), "getVersion");
    final File baseDir = new File("src/test/resources/libraries/jQuery/" + version + "/expectations");

    for (String browser : new String[] {"CHROME", "FF", "FF68", "FF60", "IE"}) {
        final File out = new File(baseDir, browser + ".out");
        final File results = new File(baseDir, "results." + browser + ".txt");
        extractExpectations(out, results);
    }

    generateTestCases(testClass, baseDir);
}
 
Example 2
Source File: EnumUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
/** Calls the value() method of the given enum. */
public static <E extends Enum<E>> String value(E type) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ {
	try {
		return (String) MethodUtils.invokeExactMethod(type, "value", 
			new Object[]{});
	} catch (Exception e) {
		return null;
	}
}
 
Example 3
Source File: EnumUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
public static <E extends Enum<E>> String getStr(E type) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ {
	try {
		return (String) MethodUtils.invokeExactMethod(type, "getStr", 
			new Object[]{});
	} catch (Exception e) {
		return null;
	}
}
 
Example 4
Source File: Gui.java    From IF with The Unlicense 4 votes vote down vote up
/**
 * Loads a Gui from a given input stream.
 * Throws a {@link RuntimeException} instead of returning null in case of a failure.
 *
 * @param instance the class instance for all reflection lookups
 * @param inputStream the file
 * @return the gui
 * @see #load(Object, InputStream)
 */
@NotNull
public static Gui loadOrThrow(@NotNull Object instance, @NotNull InputStream inputStream) {
    Plugin plugin = JavaPlugin.getProvidingPlugin(Gui.class);
    try {
        Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
        Element documentElement = document.getDocumentElement();

        documentElement.normalize();

        Gui gui = new Gui(plugin, Integer.parseInt(documentElement.getAttribute("rows")), ChatColor
                .translateAlternateColorCodes('&', documentElement.getAttribute("title")));

        if (documentElement.hasAttribute("field"))
            XMLUtil.loadFieldAttribute(instance, documentElement, gui);

        if (documentElement.hasAttribute("onTopClick")) {
            gui.setOnTopClick(XMLUtil.loadOnEventAttribute(instance,
                    documentElement, InventoryClickEvent.class, "onTopClick"));
        }

        if (documentElement.hasAttribute("onBottomClick")) {
            gui.setOnBottomClick(XMLUtil.loadOnEventAttribute(instance,
                    documentElement, InventoryClickEvent.class, "onBottomClick"));
        }

        if (documentElement.hasAttribute("onGlobalClick")) {
            gui.setOnGlobalClick(XMLUtil.loadOnEventAttribute(instance,
                    documentElement, InventoryClickEvent.class, "onGlobalClick"));
        }

        if (documentElement.hasAttribute("onOutsideClick")) {
            gui.setOnOutsideClick(XMLUtil.loadOnEventAttribute(instance,
                    documentElement, InventoryClickEvent.class, "onOutsideClick"));
        }

        if (documentElement.hasAttribute("onClose")) {
            gui.setOnClose(XMLUtil.loadOnEventAttribute(instance,
                    documentElement, InventoryCloseEvent.class, "onClose"));
        }

        if (documentElement.hasAttribute("populate")) {
            MethodUtils.invokeExactMethod(instance, "populate", gui, Gui.class);
        } else {
            NodeList childNodes = documentElement.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node item = childNodes.item(i);

                if (item.getNodeType() == Node.ELEMENT_NODE)
                    gui.addPane(loadPane(instance, item));
            }
        }

        return gui;
    } catch (Exception e) {
        throw new XMLLoadException("Error loading " + plugin.getName() + "'s gui with associated class: "
                + instance.getClass().getSimpleName(), e);
    }
}