/** * Loads class by its name. If {@link #ignoreException} is set, * no exception is thrown, but <code>null</code> is returned. */ protected Class loadClass(String className) throws ClassNotFoundException { try { return ClassLoaderUtil.loadClass(className); } catch (ClassNotFoundException cnfex) { if (ignoreException) { return null; } throw cnfex; } catch (Error error) { if (ignoreException) { return null; } throw error; } }
/** * Loads class by its name. If {@link #ignoreException} is set, * no exception is thrown, but <code>null</code> is returned. */ public Class loadClass() throws ClassNotFoundException { try { return ClassLoaderUtil.loadClass(name); } catch (ClassNotFoundException | Error cnfex) { if (ignoreException) { return null; } throw cnfex; } }
public Class convert(Object value) { if (value == null) { return null; } if (value.getClass() == Class.class) { return (Class) value; } try { String className = value.toString().trim(); if (className.endsWith(".class")) { className = StringUtil.substring(className, 0, -6); } return ClassLoaderUtil.loadClass(className); } catch (ClassNotFoundException cnfex) { throw new TypeConversionException(value, cnfex); } }
@Override public Class convert(final Object value) { if (value == null) { return null; } if (value.getClass() == Class.class) { return (Class) value; } try { String className = value.toString().trim(); if (className.endsWith(".class")) { className = StringUtil.substring(className, 0, -6); } return ClassLoaderUtil.loadClass(className); } catch (ClassNotFoundException cnfex) { throw new TypeConversionException(value, cnfex); } }
/** * Loads Madvoc component that will be used for configuring the user actions. * If class name is <code>null</code>, default {@link AutomagicMadvocConfigurator} * will be used. */ protected void resolveMadvocConfigClass() { if ((madvocConfiguratorClassName == null) && (madvocConfiguratorClass == null)) { return; } try { if (madvocConfiguratorClassName != null) { madvocConfiguratorClass = ClassLoaderUtil.loadClass(madvocConfiguratorClassName); } log.info("Configuring Madvoc using: " + madvocConfiguratorClass.getName()); } catch (Exception ex) { throw new MadvocException("Unable to load Madvoc configurator class: " + madvocConfiguratorClassName, ex); } }
constraintClass = ClassLoaderUtil.loadClass(constraintClassName, this.getClass().getClassLoader());
/** * Initializes Decora filter. Loads manager and parser from init parameters. */ @Override public void init(final FilterConfig filterConfig) throws ServletException { String decoraManagerClass = filterConfig.getInitParameter(PARAM_DECORA_MANAGER); if (decoraManagerClass != null) { try { Class decoraManagerType = ClassLoaderUtil.loadClass(decoraManagerClass); decoraManager = (DecoraManager) ClassUtil.newInstance(decoraManagerType); } catch (Exception ex) { log.error("Unable to load Decora manager class: " + decoraManagerClass, ex); throw new ServletException(ex); } } else { decoraManager = createDecoraManager(); } String decoraParserClass = filterConfig.getInitParameter(PARAM_DECORA_PARSER); if (decoraParserClass != null) { try { Class decoraParserType = ClassLoaderUtil.loadClass(decoraParserClass); decoraParser = (DecoraParser) ClassUtil.newInstance(decoraParserType); } catch (Exception ex) { log.error("Unable to load Decora parser class: " + decoraParserClass, ex); throw new ServletException(ex); } } else { decoraParser = createDecoraParser(); } }
/** * Creates {@link WebApp}. */ protected WebApp createWebApplication() { if ((webAppClassName == null) && (webAppClass == null)) { return new WebApp(); } final WebApp webApp; try { if (webAppClassName != null) { webAppClass = ClassLoaderUtil.loadClass(webAppClassName); } webApp = (WebApp) ClassUtil.newInstance(webAppClass); } catch (Exception ex) { throw new MadvocException("Unable to load Madvoc web application class: " + webAppClassName, ex); } return webApp; }
protected Object[] resolveSignature(String signature) { String[] data = StringUtil.splitc(signature, '#'); try { data[0] = this.getClass().getPackage().getName() + '.' + data[0]; Class c = ClassLoaderUtil.loadClass(data[0]); Method m = ClassUtil.findMethod(c, data[1]); return new Object[]{c, m}; } catch (Exception e) { throw new RuntimeException(e); } }
void testLoadClass() throws Exception { try { ClassLoaderUtil.loadClass("not.existing.class"); } catch (ClassNotFoundException cnfex) { assertEquals("Class not found: not.existing.class", cnfex.getMessage()); Class joddClass = ClassLoaderUtil.loadClass("jodd.util.ClassLoaderUtilTest"); assertNotNull(joddClass); } catch (ClassNotFoundException ignore) { fail("error"); assertEquals(Integer.class, ClassLoaderUtil.loadClass("java.lang.Integer")); assertEquals(int.class, ClassLoaderUtil.loadClass("int")); assertEquals(boolean.class, ClassLoaderUtil.loadClass("boolean")); assertEquals(short.class, ClassLoaderUtil.loadClass("short")); assertEquals(byte.class, ClassLoaderUtil.loadClass("byte")); assertEquals(char.class, ClassLoaderUtil.loadClass("char")); assertEquals(double.class, ClassLoaderUtil.loadClass("double")); assertEquals(float.class, ClassLoaderUtil.loadClass("float")); assertEquals(long.class, ClassLoaderUtil.loadClass("long")); assertEquals(Integer[].class, ClassLoaderUtil.loadClass("java.lang.Integer[]")); assertEquals(int[].class, ClassLoaderUtil.loadClass("int[]")); assertEquals(boolean[].class, ClassLoaderUtil.loadClass("boolean[]")); assertEquals(short[].class, ClassLoaderUtil.loadClass("short[]")); assertEquals(byte[].class, ClassLoaderUtil.loadClass("byte[]")); assertEquals(char[].class, ClassLoaderUtil.loadClass("char[]")); assertEquals(double[].class, ClassLoaderUtil.loadClass("double[]")); assertEquals(float[].class, ClassLoaderUtil.loadClass("float[]"));
targetType = ClassLoaderUtil.loadClass(className); } catch (ClassNotFoundException cnfex) { throw new JsonException(cnfex);
return ClassLoaderUtil.loadClass(targetClassName); } catch (ClassNotFoundException cnfex) { throw new ProxettaException(cnfex);
/** * Loads class by its name. If {@link #ignoreException} is set, * no exception is thrown, but <code>null</code> is returned. */ public Class loadClass() throws ClassNotFoundException { try { return ClassLoaderUtil.loadClass(name); } catch (ClassNotFoundException | Error cnfex) { if (ignoreException) { return null; } throw cnfex; } }
/** * Loads class from classname using default classloader. */ protected Class loadClass(String className) throws ClassNotFoundException { return ClassLoaderUtil.loadClass(className); } }
/** * Loads class from classname using default classloader. */ protected Class loadClass(String className) throws ClassNotFoundException { return ClassLoaderUtil.loadClass(className); } }
/** * Loads madvoc result from founded {@link jodd.madvoc.result.ActionResult} instance. */ @SuppressWarnings({"unchecked"}) protected void onResultClass(String className) throws ClassNotFoundException { Class resultClass = ClassLoaderUtil.loadClass(className); if (resultClass.equals(ActionResult.class)) { return; } if (ReflectUtil.isSubclass(resultClass, ActionResult.class) == true) { resultsManager.register(resultClass); } }
@Override public Class convert(final Object value) { if (value == null) { return null; } if (value.getClass() == Class.class) { return (Class) value; } try { String className = value.toString().trim(); if (className.endsWith(".class")) { className = StringUtil.substring(className, 0, -6); } return ClassLoaderUtil.loadClass(className); } catch (ClassNotFoundException cnfex) { throw new TypeConversionException(value, cnfex); } }
/** * Registers action with provided action signature. */ public ActionConfig register(String actionSignature, String actionPath) { int ndx = actionSignature.indexOf('#'); if (ndx == -1) { throw new MadvocException("Madvoc action signature syntax error: " + actionSignature); } String actionClassName = actionSignature.substring(0, ndx); String actionMethodName = actionSignature.substring(ndx + 1); Class actionClass; try { actionClass = ClassLoaderUtil.loadClass(actionClassName); } catch (ClassNotFoundException cnfex) { throw new MadvocException("Madvoc action class not found: " + actionClassName, cnfex); } return register(actionClass, actionMethodName, actionPath); }
/** * Loads {@link jodd.madvoc.config.MadvocConfigurator}. If class name is <code>null</code>, * {@link jodd.madvoc.config.AutomagicMadvocConfigurator} will be created. */ protected MadvocConfigurator loadMadvocConfig() { if ((madvocConfiguratorClassName != null) && (madvocConfiguratorClass != null)) { throw new MadvocException("Ambiguous MadvocConfigurator setting."); } if ((madvocConfiguratorClassName == null) && (madvocConfiguratorClass == null)) { log.info("Configuring Madvoc using default automagic configurator"); return new AutomagicMadvocConfigurator(); } MadvocConfigurator configurator; try { if (madvocConfiguratorClass == null) { madvocConfiguratorClass = ClassLoaderUtil.loadClass(madvocConfiguratorClassName); } configurator = (MadvocConfigurator) madvocConfiguratorClass.newInstance(); log.info("Configuring Madvoc using configurator: " + madvocConfiguratorClass.getName()); } catch (ClassNotFoundException cnfex) { throw new MadvocException("Madvoc configurator class not found: " + madvocConfiguratorClassName, cnfex); } catch (ClassCastException ccex) { throw new MadvocException("Class '" + madvocConfiguratorClass.getName() + "' is not a Madvoc configurator.", ccex); } catch (Exception ex) { throw new MadvocException("Unable to load Madvoc configurator class: " + ex.toString(), ex); } return configurator; }