Example usage for java.lang Class getDeclaredMethod

List of usage examples for java.lang Class getDeclaredMethod

Introduction

In this page you can find the example usage for java.lang Class getDeclaredMethod.

Prototype

@CallerSensitive
public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
        throws NoSuchMethodException, SecurityException 

Source Link

Document

Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object.

Usage

From source file:net.sf.nmedit.jtheme.store.StorageContext.java

protected Method getStoreCreateMethod(String elementName) throws JTException {
    Map<String, Method> map = null;
    if (storeMethodMap != null) {
        map = storeMethodMap.get();/*from  w  w w.  j  ava2s.  c om*/
    }
    if (map == null) {
        map = new HashMap<String, Method>(160);
        storeMethodMap = new SoftReference<Map<String, Method>>(map);
    }

    Method create = map.get(elementName);
    if (create == null) {
        Class<? extends ComponentElement> storeClass = getStoreClass(elementName);
        if (storeClass == null)
            throw new JTException("No store for element: " + elementName);

        try {
            create = storeClass.getDeclaredMethod("createElement",
                    new Class<?>[] { StorageContext.class, Element.class });
        } catch (SecurityException e) {
            throw new JTException(e);
        } catch (NoSuchMethodException e) {
            throw new JTException("method createElement() not found in " + storeClass, e);
        }

        map.put(elementName, create);
    }
    return create;
}

From source file:me.st28.flexseries.flexmotd.backend.PingManager.java

@Override
protected void handleReload() {
    imageDir.mkdirs();/* w  w w .  j av  a  2s.  c o m*/

    FileConfiguration config = getConfig();

    groups.clear();
    messages.clear();
    images.clear();

    // Load groups
    ConfigurationSection groupSec = config.getConfigurationSection("groups");
    if (groupSec != null) {
        for (String name : groupSec.getKeys(false)) {
            ConfigurationSection subSec = groupSec.getConfigurationSection(name);
            Map<String, String> groupData = new HashMap<>();

            for (String subName : subSec.getKeys(false)) {
                groupData.put(subName, subSec.getString(subName));
            }

            groups.put(name.toLowerCase(), groupData);
        }
    }

    // Load messages
    ConfigurationSection messageSec = config.getConfigurationSection("message.messages");
    for (String name : messageSec.getKeys(false)) {
        messages.put(name.toLowerCase(), ChatColor.translateAlternateColorCodes('&',
                StringEscapeUtils.unescapeJava(messageSec.getString(name))));
    }

    // Load images
    ConfigurationSection imageSec = config.getConfigurationSection("image.images");

    // Begin reflection
    Server server = Bukkit.getServer();
    Class serverClass = null;
    Method methodLoadIcon = null;

    try {
        serverClass = InternalUtils.getCBClass("CraftServer");

        methodLoadIcon = serverClass.getDeclaredMethod("loadServerIcon", File.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    // End reflection

    if (serverClass != null) {
        for (String name : imageSec.getKeys(false)) {
            String fileName = imageSec.getString(name);
            File file = fileName == null ? null : new File(imageDir + File.separator + fileName);

            if (file == null || !file.exists()) {
                LogHelper.warning(this, "Image file '" + fileName + "' not found.");
            } else {
                try {
                    images.put(name.toLowerCase(), (CachedServerIcon) methodLoadIcon.invoke(server, file));
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}

From source file:fxts.stations.util.BrowserLauncher.java

/**
 * Called by a static initializer to load any classes, fields, and methods required at runtime
 * to locate the user's web browser.//from  w w w .  ja v  a2  s  . co m
 *
 * @return <code>true</code> if all intialization succeeded
 *         <code>false</code> if any portion of the initialization failed
 */
private static boolean loadClasses() {
    switch (jvm) {
    case MRJ_2_0:
        try {
            Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
            Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
            Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
            Class aeClass = Class.forName("com.apple.MacOS.ae");
            aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
            aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] { int.class });
            appleEventConstructor = appleEventClass.getDeclaredConstructor(
                    new Class[] { int.class, int.class, aeTargetClass, int.class, int.class });
            aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] { String.class });
            makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] { String.class });
            putParameter = appleEventClass.getDeclaredMethod("putParameter",
                    new Class[] { int.class, aeDescClass });
            sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {});
            Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
            keyDirectObject = (Integer) keyDirectObjectField.get(null);
            Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
            kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null);
            Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
            kAnyTransactionID = (Integer) anyTransactionIDField.get(null);
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_2_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
            Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
            kSystemFolderType = systemFolderField.get(null);
            findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] { mrjOSTypeClass });
            getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] { File.class });
            getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] { File.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchFieldException nsfe) {
            errorMessage = nsfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (SecurityException se) {
            errorMessage = se.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_3_0:
        try {
            Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
            Constructor constructor = linker.getConstructor(new Class[] { Class.class });
            linkage = constructor.newInstance(new Object[] { BrowserLauncher.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        } catch (InvocationTargetException ite) {
            errorMessage = ite.getMessage();
            return false;
        } catch (InstantiationException ie) {
            errorMessage = ie.getMessage();
            return false;
        } catch (IllegalAccessException iae) {
            errorMessage = iae.getMessage();
            return false;
        }
        break;
    case MRJ_3_1:
        try {
            mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
            openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] { String.class });
        } catch (ClassNotFoundException cnfe) {
            errorMessage = cnfe.getMessage();
            return false;
        } catch (NoSuchMethodException nsme) {
            errorMessage = nsme.getMessage();
            return false;
        }
        break;
    default:
        break;
    }
    return true;
}

From source file:com.phoenixnap.oss.ramlapisync.plugin.SpringMvcEndpointGeneratorMojo.java

private String getSchemaLocation() {

    if (StringUtils.hasText(schemaLocation)) {

        if (!schemaLocation.contains(":")) {
            String resolvedPath = project.getBasedir().getAbsolutePath();
            if (resolvedPath.endsWith(File.separator) || resolvedPath.endsWith("/")) {
                resolvedPath = resolvedPath.substring(0, resolvedPath.length() - 1);
            }//from   www .  j  a va 2 s  .co m

            if (!schemaLocation.startsWith(File.separator) && !schemaLocation.startsWith("/")) {
                resolvedPath += File.separator;
            }

            resolvedPath += schemaLocation;

            if (!schemaLocation.endsWith(File.separator) && !schemaLocation.endsWith("/")) {
                resolvedPath += File.separator;
            }
            resolvedPath = resolvedPath.replace(File.separator, "/").replace("\\", "/");
            try {
                URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
                Class<?> urlClass = URLClassLoader.class;
                Method method = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class });
                method.setAccessible(true);
                method.invoke(urlClassLoader, new Object[] { new File(resolvedPath).toURI().toURL() });
                return "classpath:/"; // since we have added this folder to the classpath this
                                      // should be used by the plugin
            } catch (Exception ex) {
                this.getLog().error("Could not add schema location to classpath", ex);
                return new File(resolvedPath).toURI().toString();
            }
        }
        return schemaLocation;
    }
    return null;
}

From source file:org.alfresco.test.PublicBeansBCKTest.java

@Test
public void testImporterBeans() {
    // ensure the required setters are still present
    Class<ImporterBootstrap> importerBootstrapClass = ImporterBootstrap.class;

    try {//from  ww  w.jav a2s  .  co  m
        Method setBootstrapViewsMethod = importerBootstrapClass.getDeclaredMethod("setBootstrapViews",
                new Class[] { List.class });
        assertNotNull("Expected to find setBootstrapViews method on ImporterBootstrap",
                setBootstrapViewsMethod);
    } catch (NoSuchMethodException error) {
        fail("Expected to find setBootstrapViews method on ImporterBootstrap");
    }

    // ensure the spacesStoreImporter abstract bean is still present
    assertTrue(beanDefinitionNames.contains("spacesStoreImporter"));
}

From source file:org.alfresco.test.PublicBeansBCKTest.java

@Test
public void testPermissionBeans() {
    // ensure the permissionModelBootstrap abstract bean is still present
    assertTrue(beanDefinitionNames.contains("permissionModelBootstrap"));

    // ensure the required setters are still present
    Class<PermissionModelBootstrap> permissionModelClass = PermissionModelBootstrap.class;

    try {/*from  w  ww  .j a v  a2s .  co m*/
        Method setModelMethod = permissionModelClass.getDeclaredMethod("setModel",
                new Class[] { String.class });
        assertNotNull("Expected to find setModel method on PermissionModelBootstrap", setModelMethod);
    } catch (NoSuchMethodException error) {
        fail("Expected to find setModel method on PermissionModelBootstrap");
    }
}

From source file:io.ionic.links.IonicDeeplink.java

private JSONObject _bundleToJson(Bundle bundle) {
    if (bundle == null) {
        return new JSONObject();
    }/* w  w w  . j  av a 2s.  co m*/

    JSONObject j = new JSONObject();
    Set<String> keys = bundle.keySet();
    for (String key : keys) {
        try {
            Class<?> jsonClass = j.getClass();
            Class[] cArg = new Class[1];
            cArg[0] = String.class;
            //Workaround for API < 19
            try {
                if (jsonClass.getDeclaredMethod("wrap", cArg) != null) {
                    j.put(key, JSONObject.wrap(bundle.get(key)));
                }
            } catch (NoSuchMethodException e) {
                j.put(key, this._wrap(bundle.get(key)));
            }
        } catch (JSONException ex) {
        }
    }

    return j;
}

From source file:org.sbml.bargraph.MainWindow.java

/**
 * Sets up menus using adapters for the Mac OS X look and feel.
 *///w  ww .j a  v a2s.  co  m
public void registerForMacOSXEvents() {
    Log.note("Setting up the Mac OS X application menu.");
    try {
        // Generate and register the OSXAdapter, passing it a hash
        // of all the methods we wish to use as delegates for
        // various com.apple.eawt.ApplicationListener methods

        Class<?> c = getClass();
        Method quit = c.getDeclaredMethod("quit", (Class[]) null);
        Method about = c.getDeclaredMethod("about", (Class[]) null);

        OSXAdapter.setQuitHandler(this, quit);
        OSXAdapter.setAboutHandler(this, about);
    } catch (Exception e) {
        Log.error("Unable to set up MacOS application menu", e);
        Main.quit(Main.STATUS_ERROR);
    }
}

From source file:de.Keyle.MyPet.util.iconmenu.IconMenuItem.java

@SuppressWarnings("unchecked")
public IconMenuItem setMeta(ItemMeta meta, boolean useTitle, boolean useLore) {
    Validate.notNull(meta, "Name cannot be null");

    if (useTitle && meta.hasDisplayName()) {
        this.title = meta.getDisplayName();
        hasChanged = true;//from w  w w.  j  a v  a 2  s . c o  m
    }
    if (useLore && meta.hasLore()) {
        this.lore.clear();
        this.lore.addAll(meta.getLore());
        hasChanged = true;
    }

    if (applyToItemMethhod == null) {
        try {
            Class craftMetaItemClass = Class.forName("org.bukkit.craftbukkit.v1_8_R2.inventory.CraftMetaItem");
            applyToItemMethhod = craftMetaItemClass.getDeclaredMethod("applyToItem", NBTTagCompound.class);
            applyToItemMethhod.setAccessible(true);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            DebugLogger.printThrowable(e);
            return this;
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            DebugLogger.printThrowable(e);
            return this;
        }
    }
    try {
        NBTTagCompound compound = new NBTTagCompound();
        applyToItemMethhod.invoke(meta, compound);

        if (compound.hasKey("display")) {
            compound = compound.getCompound("display");

            if (compound.hasKey("Name")) {
                compound.remove("Name");
            }
            if (compound.hasKey("Lore")) {
                compound.remove("Lore");
            }

            for (String key : (Set<String>) compound.c()) {
                this.displayTags.put(key, compound.get(key).clone());
            }

            hasChanged = true;
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        DebugLogger.printThrowable(e);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        DebugLogger.printThrowable(e);
    }
    return this;
}

From source file:org.alfresco.test.PublicBeansBCKTest.java

@Test
public void testDictionaryBeans() {
    // ensure the dictionaryModelBootstrap abstract bean is still present
    assertTrue(beanDefinitionNames.contains("dictionaryModelBootstrap"));

    // ensure the dictionaryBootstrap bean is still present
    Object dictionaryBootstrapBean = ctx.getBean("dictionaryBootstrap");
    assertNotNull("Expected to find the 'dictionaryBootstrap' bean", dictionaryBootstrapBean);
    assertTrue("Expected 'dictionaryBootstrap' to be an instance of DictionaryBootstrap",
            (dictionaryBootstrapBean instanceof DictionaryBootstrap));

    // ensure the required setters are still present
    Class<DictionaryBootstrap> dictionaryBootstrapClass = DictionaryBootstrap.class;

    try {/*from  w ww .  j a  va  2s.c o m*/
        Method setModelsMethod = dictionaryBootstrapClass.getDeclaredMethod("setModels",
                new Class[] { List.class });
        assertNotNull("Expected to find setModels method on DictionaryBootstrap", setModelsMethod);
    } catch (NoSuchMethodException error) {
        fail("Expected to find setModels method on DictionaryBootstrap");
    }

    try {
        Method setLabelsMethod = dictionaryBootstrapClass.getDeclaredMethod("setLabels",
                new Class[] { List.class });
        assertNotNull("Expected to find setLabels method on DictionaryBootstrap", setLabelsMethod);
    } catch (NoSuchMethodException error) {
        fail("Expected to find setLabels method on DictionaryBootstrap");
    }
}