Class componentTypeClass = classForName(componentType); return Array.newInstance(componentTypeClass, 0).getClass(); return classForName(type);
/** * Returns the ClassLoader to use when looking up resources under the top level package. By default, this is the * context class loader. * * @return the ClassLoader used to lookup resources */ protected ClassLoader getClassLoader() { return ClassUtils.getContextClassLoader(); }
public static Object newInstance(String type) throws FacesException { if (type == null) { return null; } return newInstance(simpleClassForName(type)); }
public static Object newInstance(String type, Class expectedType) throws FacesException { return newInstance(type, expectedType == null ? null : new Class[] {expectedType}); }
/** * Creates ApplicationObjects like NavigationHandler or StateManager and creates * the right wrapping chain of the ApplicationObjects known as the decorator pattern. * @param <T> * @param interfaceClass The class from which the implementation has to inherit from. * @param classNamesIterator All the class names of the actual ApplicationObject implementations * from the faces-config.xml. * @param defaultObject The default implementation for the given ApplicationObject. * @return * @since 1.0.1 */ public static <T> T buildApplicationObject(Class<T> interfaceClass, Collection<String> classNamesIterator, T defaultObject) { return buildApplicationObject(interfaceClass, null, null, classNamesIterator, defaultObject); }
/** * @param resource Name of resource(s) to find in classpath * @param defaultObject The default object to use to determine the class loader * (if none associated with current thread.) * @return Iterator over URL Objects */ public static Iterator getResources(String resource, Object defaultObject) { try { Enumeration resources = getCurrentLoader(defaultObject).getResources(resource); List lst = new ArrayList(); while (resources.hasMoreElements()) { lst.add(resources.nextElement()); } return lst.iterator(); } catch (IOException e) { log.error(e.getMessage(), e); throw new FacesException(e); } }
/** * Same as {@link #javaTypeToClass(String)}, but throws a RuntimeException * (FacesException) instead of a ClassNotFoundException. * * @return the corresponding Class * @throws NullPointerException if type is null * @throws FacesException if class not found */ public static Class simpleJavaTypeToClass(String type) { try { return javaTypeToClass(type); } catch (ClassNotFoundException e) { log.error("Class " + type + " not found", e); throw new FacesException(e); } }
= (MyFacesResourceHandlerUrlProvider) ClassUtils.newInstance(resourceHandlerUrlProviderClassName);
/** * Same as {@link #classForName(String)}, but throws a RuntimeException * (FacesException) instead of a ClassNotFoundException. * * @return the corresponding Class * @throws NullPointerException if type is null * @throws FacesException if class not found */ public static Class simpleClassForName(String type) { try { return classForName(type); } catch (ClassNotFoundException e) { log.error("Class " + type + " not found", e); throw new FacesException(e); } }
public static Object newInstance(String type, Class[] expectedTypes) { if (type == null) { return null; } Class clazzForName = simpleClassForName(type); if(expectedTypes != null) { for (int i = 0, size = expectedTypes.length; i < size; i++) { if (!expectedTypes[i].isAssignableFrom(clazzForName)) { throw new FacesException("'" + type + "' does not implement expected type '" + expectedTypes[i] + "'"); } } } return newInstance(clazzForName); }
public static InputStream getResourceAsStream(String resource) { InputStream stream = getContextClassLoader() .getResourceAsStream(resource); if (stream == null) { // fallback stream = ClassUtils.class.getClassLoader().getResourceAsStream(resource); } return stream; }
return (T) ClassUtils.classForName(param).newInstance();
Class<? extends T> implClass = ClassUtils.simpleClassForName(implClassName); current = (T) ClassUtils.newInstance(implClass); newCurrent = (T) ClassUtils.newInstance(implClass);
/** * Gets the ClassLoader associated with the current thread. Returns the class loader associated with * the specified default object if no context loader is associated with the current thread. * * @param defaultObject The default object to use to determine the class loader * (if none associated with current thread.) * @return ClassLoader */ protected static ClassLoader getCurrentLoader(Object defaultObject) { ClassLoader loader = getContextClassLoader(); if(loader == null) { loader = defaultObject.getClass().getClassLoader(); } return loader; }
Class servletClass = ClassUtils.classForName(registration.getClassName()); if (DELEGATE_FACES_SERVLET_INTERFACE_CLASS.isAssignableFrom(servletClass))
protected Converter createConverter() throws JspException { ELContext elContext = FacesContext.getCurrentInstance().getELContext(); org.apache.myfaces.commons.converter.EnumConverter converter = (org.apache.myfaces.commons.converter.EnumConverter)super.createConverter(); if (_targetClass != null) { if (_targetClass.isLiteralText()) { try { converter.setTargetClass( org.apache.myfaces.commons.util.ClassUtils.classForName(_targetClass.getExpressionString())); } catch (ClassNotFoundException e) { throw new JspException(e); } } else { converter.setTargetClass((java.lang.Class) _targetClass.getValue(elContext)); } } return converter; }
public Collection<URL> getMetaInfConfigurationResources(ExternalContext context) throws IOException { ClassLoader contextClassLoader = ClassUtils.getContextClassLoader(); Enumeration<URL> metaInfConfigUrls = null; List<URL> configUrls = new ArrayList<URL>(); try { // NOTE that there could be multiple config files (in different jar files) metaInfConfigUrls = contextClassLoader.getResources(META_INF_CONFIG_FILE); } catch (IOException e) { throw new FacesException("Could not open " + MyFacesResourceHandlerUrlProvider.META_INF_CONFIG_FILE, e); } if (metaInfConfigUrls != null && metaInfConfigUrls.hasMoreElements()) { while (metaInfConfigUrls.hasMoreElements()) { URL url = metaInfConfigUrls.nextElement(); if (url != null) { configUrls.add(url); } } } return configUrls; }
protected Converter createConverter() throws JspException { FacesContext facesContext = FacesContext.getCurrentInstance(); org.apache.myfaces.commons.converter.EnumConverter converter = (org.apache.myfaces.commons.converter.EnumConverter)super.createConverter(); if (_targetClass != null) { if (UIComponentTag.isValueReference(_targetClass)) { ValueBinding vb = facesContext.getApplication().createValueBinding(_targetClass); converter.setTargetClass((java.lang.Class) vb.getValue(facesContext)); } else { try { converter.setTargetClass( org.apache.myfaces.commons.util.ClassUtils.classForName(_targetClass)); } catch (ClassNotFoundException e) { throw new JspException(e); } } } return converter; }
.getBundle(bundleName, locale, ClassUtils.getContextClassLoader());