/** * Returns the resource specified by the <strong>absolute</strong> name. * * @param name the name of the resource * @param c the source class * @return the url of the resource or null, if not found. */ public static URL getResource(final String name, final Class c) { final ClassLoader cl = getClassLoader(c); if (cl == null) { return null; } return cl.getResource(name); }
/** * Returns the resource specified by the <strong>absolute</strong> name. * * @param name the name of the resource * @param c the source class * @return the url of the resource or null, if not found. */ public static URL getResource(final String name, final Class c) { final ClassLoader cl = getClassLoader(c); if (cl == null) { return null; } return cl.getResource(name); }
/** * Returns the resource specified by the <strong>absolute</strong> name. * * @param name the name of the resource * @param c the source class * @return the url of the resource or null, if not found. */ public static URL getResource(final String name, final Class c) { final ClassLoader cl = getClassLoader(c); if (cl == null) { return null; } return cl.getResource(name); }
/** * Tries to load a class to indirectly check for the existence * of a certain library. * * @param name the name of the library class. * @param context the context class to get a classloader from. * @return true, if the class could be loaded, false otherwise. */ protected static boolean isClassLoadable(final String name, final Class context) { try { ObjectUtilities.getClassLoader(context).loadClass(name); return true; } catch (Exception e) { return false; } }
/** * Tries to load a class to indirectly check for the existence * of a certain library. * * @param name the name of the library class. * @param context the context class to get a classloader from. * @return true, if the class could be loaded, false otherwise. */ protected static boolean isClassLoadable(final String name, final Class context) { try { ObjectUtilities.getClassLoader(context).loadClass(name); return true; } catch (Exception e) { return false; } }
/** * Tries to load a class to indirectly check for the existence * of a certain library. * * @param name the name of the library class. * @param context the context class to get a classloader from. * @return true, if the class could be loaded, false otherwise. */ protected static boolean isClassLoadable(final String name, final Class context) { try { ObjectUtilities.getClassLoader(context).loadClass(name); return true; } catch (Exception e) { return false; } }
/** * Tries to create a new instance of the given class. This is a short cut * for the common bean instantiation code. * * @param className the class name as String, never null. * @param source the source class, from where to get the classloader. * @return the instantiated object or null, if an error occured. */ public static Object loadAndInstantiate(final String className, final Class source) { try { final ClassLoader loader = getClassLoader(source); final Class c = loader.loadClass(className); return c.newInstance(); } catch (Exception e) { return null; } }
/** * Tries to create a new instance of the given class. This is a short cut * for the common bean instantiation code. * * @param className the class name as String, never null. * @param source the source class, from where to get the classloader. * @return the instantiated object or null, if an error occured. */ public static Object loadAndInstantiate(final String className, final Class source) { try { final ClassLoader loader = getClassLoader(source); final Class c = loader.loadClass(className); return c.newInstance(); } catch (Exception e) { return null; } }
/** * Tries to create a new instance of the given class. This is a short cut * for the common bean instantiation code. * * @param className the class name as String, never null. * @param source the source class, from where to get the classloader. * @return the instantiated object or null, if an error occured. */ public static Object loadAndInstantiate(final String className, final Class source) { try { final ClassLoader loader = getClassLoader(source); final Class c = loader.loadClass(className); return c.newInstance(); } catch (Exception e) { return null; } }
/** * Creates an object based on this object description. * * @return The object. */ public Object createObject() { try { final String o = (String) getParameter("class"); return ObjectUtilities.getClassLoader(getClass()).loadClass(o).newInstance(); } catch (Exception e) { return null; } }
protected Library loadLibrary(final String classname) { if (classname == null) { return null; } try { final Class c = ObjectUtilities.getClassLoader( getClass()).loadClass(classname); try { final Method m = c.getMethod("getInstance", (Class[]) null); return (Library) m.invoke(null, (Object[]) null); } catch(Exception e) { // ok, fall back ... } return (Library) c.newInstance(); } catch (Exception e) { // ok, this library has no 'getInstance()' method. Check the // default constructor ... return null; } }
/** * Returns the resource specified by the <strong>relative</strong> name. * * @param name the name of the resource relative to the given class * @param c the source class * @return the url of the resource or null, if not found. */ public static URL getResourceRelative(final String name, final Class c) { final ClassLoader cl = getClassLoader(c); final String cname = convertName(name, c); if (cl == null) { return null; } return cl.getResource(cname); }
/** * Returns the resource specified by the <strong>relative</strong> name. * * @param name the name of the resource relative to the given class * @param c the source class * @return the url of the resource or null, if not found. */ public static URL getResourceRelative(final String name, final Class c) { final ClassLoader cl = getClassLoader(c); final String cname = convertName(name, c); if (cl == null) { return null; } return cl.getResource(cname); }
/** * Returns the resource specified by the <strong>relative</strong> name. * * @param name the name of the resource relative to the given class * @param c the source class * @return the url of the resource or null, if not found. */ public static URL getResourceRelative(final String name, final Class c) { final ClassLoader cl = getClassLoader(c); final String cname = convertName(name, c); if (cl == null) { return null; } return cl.getResource(cname); }
/** * Loads the specified booter implementation. * * @param classname the class name. * * @return The boot class. */ protected AbstractBoot loadBooter(final String classname) { if (classname == null) { return null; } try { final Class c = ObjectUtilities.getClassLoader( getClass()).loadClass(classname); final Method m = c.getMethod("getInstance", (Class[]) null); return (AbstractBoot) m.invoke(null, (Object[]) null); } catch (Exception e) { Log.info ("Unable to boot dependent class: " + classname); return null; } }
/** * Loads the specified booter implementation. * * @param classname the class name. * * @return The boot class. */ protected AbstractBoot loadBooter(final String classname) { if (classname == null) { return null; } try { final Class c = ObjectUtilities.getClassLoader( getClass()).loadClass(classname); final Method m = c.getMethod("getInstance", (Class[]) null); return (AbstractBoot) m.invoke(null, (Object[]) null); } catch (Exception e) { Log.info ("Unable to boot dependent class: " + classname); return null; } }
/** * Loads the specified booter implementation. * * @param classname the class name. * * @return The boot class. */ protected AbstractBoot loadBooter(final String classname) { if (classname == null) { return null; } try { final Class c = ObjectUtilities.getClassLoader( getClass()).loadClass(classname); final Method m = c.getMethod("getInstance", (Class[]) null); return (AbstractBoot) m.invoke(null, (Object[]) null); } catch (Exception e) { Log.info ("Unable to boot dependent class: " + classname); return null; } }
/** * Loads a class by its fully qualified name. * * @param name the class name. * * @return The class (or <code>null</code> if there was a problem loading the class). */ protected Class loadClass(final String name) { try { return ObjectUtilities.getClassLoader(JavaSourceCollector.class).loadClass(name); } catch (Exception e) { Log.warn (new Log.SimpleMessage("Do not process: Failed to load class:", name)); return null; } }
/** * Loads the given class, and ignores all exceptions which may occur * during the loading. If the class was invalid, null is returned instead. * * @param className the name of the class to be loaded. * @return the class or null. * * @throws XMLWriterException if there is a writer exception. */ protected XmlWriteHandler loadHandlerClass(final String className) throws XMLWriterException { if (className == null) { throw new XMLWriterException("LoadHanderClass: Class name not defined"); } try { final Class c = ObjectUtilities.getClassLoader(getClass()).loadClass(className); return (XmlWriteHandler) c.newInstance(); } catch (Exception e) { // ignore buggy classes for now .. throw new XMLWriterException("LoadHanderClass: Unable to instantiate " + className, e); } }
/** * Loads the given class, and ignores all exceptions which may occur * during the loading. If the class was invalid, null is returned instead. * * @param className the name of the class to be loaded. * @return the class or null. * @throws XmlReaderException if there is a reader error. */ protected Class loadClass(final String className) throws XmlReaderException { if (className == null) { throw new XmlReaderException("LoadHanderClass: Class name not defined"); } try { final Class c = ObjectUtilities.getClassLoader(getClass()).loadClass(className); return c; } catch (Exception e) { // ignore buggy classes for now .. throw new XmlReaderException("LoadHanderClass: Unable to load " + className, e); } }