public <T> Class<T> loadClass(final String className) throws ClassNotFoundException { //noinspection unchecked return ClassLoaderUtils.loadClass(className, getClass()); } }
/** * Load a class with a given name. * <p> * It will try to load the class in the following order: * <ul> * <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()} * <li>Using the basic {@link Class#forName(java.lang.String) } * <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()} * <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() } * </ul> * * @param className The name of the class to load * @param callingClass The Class object of the calling object * @throws ClassNotFoundException If the class cannot be found anywhere. */ public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException { return loadClass(className, callingClass.getClassLoader()); }
/** * Load a class with a given name. * <p> * It will try to load the class in the following order: * <ul> * <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()} * <li>Using the basic {@link Class#forName(java.lang.String) } * <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()} * <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() } * </ul> * * @param className The name of the class to load * @param callingClass The Class object of the calling object * @throws ClassNotFoundException If the class cannot be found anywhere. */ public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException { return loadClass(className, callingClass.getClassLoader()); }
public static Object instantiateClass(String name, Object[] constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Class clazz = ClassLoaderUtils.loadClass(name, ClassHelper.class); return instantiateClass(clazz, constructorArgs); } }
public static Object instantiateClass(String name, Object[] constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Class clazz = ClassLoaderUtils.loadClass(name, ClassHelper.class); return instantiateClass(clazz, constructorArgs); } }
/** * This method will load and construct a class, but also pass it through PicoContainer, to inject any dependencies. * * @param className the name of the class to load. * @param callingClass the class requesting the class be loaded. * @throws ClassNotFoundException if the class is not found on the classpath of the classloader of the calling class. * @see ClassLoaderUtils#loadClass(java.lang.String,java.lang.Class) * @see ComponentManager * @return the instance of the requested class. */ public static <T> T loadComponent(final String className, final Class<?> callingClass) throws ClassNotFoundException { @SuppressWarnings("unchecked") final Class<T> componentClass = ClassLoaderUtils.loadClass(className, callingClass); return loadComponent(componentClass); }
public <T> Class<T> loadClass(String className) throws ClassNotFoundException { try { // First we try to load the class using the plugin framework's PluginsClassLoader // (this includes caching and is therfore the preferred method) //noinspection unchecked return ClassLoaderUtils.loadClass(className, pluginsClassLoader); } catch (ClassNotFoundException e) { // The PluginsClassLoader failed, but it may just be that the plugin is in the middle of enabling. // Try harder! return this.loadClassEvenIfNotEnabled(className); } }
/** * This method will load and construct a class, but also pass it through PicoContainer, to inject any dependencies. * * Please note that this method will only find Plugins2 classes in plugins that are enabled, and cannot inject plugins2 components. * * @param className the name of the class to load * @param classLoader the classloader to use to load the class * @return the instance of the requested class * @throws ClassNotFoundException if the given className was not able to be loaded. * * @deprecated This method does not work well with Plugins2 classes and dependency injection. Please use {@link com.atlassian.jira.plugin.ComponentClassManager}. */ public static <T> T loadComponent(final String className, final ClassLoader classLoader) throws ClassNotFoundException { @SuppressWarnings("unchecked") final Class<T> componentClass = ClassLoaderUtils.loadClass(className, classLoader); return loadComponent(componentClass); }
@Override protected Object loadObject(final String className) { try { Class objClass = ClassLoaderUtils.loadClass(className.trim(), this.getClass()); if (objClass == null) { log.error("Could not load class '" + className + "'"); return null; } return JiraUtils.loadComponent(objClass); } catch (final Exception e) { log.error("Could not load class '" + className + "'", e); return null; } } }
public JiraListener getJiraListener() throws ClassNotFoundException, IllegalAccessException, InstantiationException { return (JiraListener) ClassLoaderUtils.loadClass(getListener().getString("clazz"), pluginAccessor.getClassLoader()).newInstance(); }
private void registerExtensions() { final ApplicationProperties applicationProperties = container.getComponentContainer().getComponentInstance(ApplicationProperties.class); final String extensionClassName = applicationProperties.getDefaultBackedString(EXTENSION_PROVIDER_PROPERTY); try { if (!StringUtils.isBlank(extensionClassName)) { container.wrapWith(((ContainerProvider) ClassLoaderUtils.loadClass(extensionClassName, getClass()).newInstance())); } } catch (Exception extensionClassLoadingException) { throw new RuntimeException ( format ( "Error loading PICO extension provider container class with name '%s'", extensionClassName ), extensionClassLoadingException ); } }
/** * Attempts to instantiate the given class name as an instance of EnabledCondition and returns it. * @param enabledConditionClass the name of an implementing class with a no-arg constructor, if null will return null. * @return the constructed instance or null if the class can't be found or instantiated. */ static EnabledCondition create(String enabledConditionClass) { if (enabledConditionClass == null) { log.debug("Cannot instantiate null EnabledCondition"); return null; } try { @SuppressWarnings("unchecked") Class<EnabledCondition> conditionClass = loadClass(enabledConditionClass, EnabledConditionFactory.class); return loadComponent(conditionClass); } catch (ClassNotFoundException e) { log.warn(String.valueOf(MessageFormatter.format("Cannot find Enabled Condition: '{}'", e))); } catch (ClassCastException e) { log.warn(String.valueOf(MessageFormatter.format("Enabled Condition : '{}' must implement {}, '{}'", new String[] { enabledConditionClass, EnabledCondition.class.getName(), e.toString() }))); } return null; } }
clazz = ClassLoaderUtils.loadClass(className, this.getClass()); if (log.isDebugEnabled())