diff --git a/api/src/main/java/org/apache/myfaces/core/api/shared/lang/ClassUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/lang/ClassUtils.java index e99baa88a..58c45ced3 100755 --- a/api/src/main/java/org/apache/myfaces/core/api/shared/lang/ClassUtils.java +++ b/api/src/main/java/org/apache/myfaces/core/api/shared/lang/ClassUtils.java @@ -163,14 +163,15 @@ public static Class simpleClassForName(String type) /** * Same as {link {@link #simpleClassForName(String)}, but will only - * log the exception and rethrow a RunTimeException if logException is true. + * log the exception and rethrow a RunTimeException if logAndThrowException is true. * * @param type - * @param logException - true to log/throw FacesException, false to avoid logging/throwing FacesException + * @param logAndThrowException - true to log and throw FacesException, false to avoid logging and throwing + * the FacesException * @return the corresponding Class - * @throws FacesException if class not found and logException is true + * @throws FacesException if class not found and logAndThrowException is true */ - public static Class simpleClassForName(String type, boolean logException) + public static Class simpleClassForName(String type, boolean logAndThrowException) { Class returnClass = null; try @@ -179,7 +180,7 @@ public static Class simpleClassForName(String type, boolean logException) } catch (ClassNotFoundException e) { - if (logException) + if (logAndThrowException) { log.log(Level.SEVERE, "Class " + type + " not found", e); throw new FacesException(e); @@ -188,6 +189,38 @@ public static Class simpleClassForName(String type, boolean logException) return returnClass; } + /** + * Same as {link {@link #simpleClassForName(String)}, but accepts two booleans + * One to log an exception and another to rethrow a FacesExceptions + * + * @param type + * @param logException - true to log the ClassNotFoundException, false to avoid logging + * @param throwException - true to throw a FacesException, false to avoid throwing a FacesException + * @return the corresponding Class + * @throws FacesException if class not found and throwException is true + */ + public static Class simpleClassForName(String type, boolean throwException, boolean logException) + { + Class returnClass = null; + try + { + returnClass = classForName(type); + } + catch (ClassNotFoundException e) + { + if(logException) + { + log.log(Level.SEVERE, "Class " + type + " not found", e); + } + if (throwException) + { + throw new FacesException(e); + } + } + return returnClass; + } + + /** * Similar as {@link #classForName(String)}, but also supports primitive types and arrays as specified for the * JavaType element in the JavaServer Faces Config DTD. diff --git a/impl/src/main/java/org/apache/myfaces/application/FacesServletMappingUtils.java b/impl/src/main/java/org/apache/myfaces/application/FacesServletMappingUtils.java index 761c1e7e6..84498cb4c 100644 --- a/impl/src/main/java/org/apache/myfaces/application/FacesServletMappingUtils.java +++ b/impl/src/main/java/org/apache/myfaces/application/FacesServletMappingUtils.java @@ -174,7 +174,7 @@ public static boolean isFacesServlet(String servletClassName) return true; } - Class servletClass = ClassUtils.simpleClassForName(servletClassName, true); + Class servletClass = ClassUtils.simpleClassForName(servletClassName, false, true); if (servletClass != null) { return FacesServlet.class.isAssignableFrom(servletClass); diff --git a/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java b/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java index 083224a6a..737d90374 100755 --- a/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java +++ b/impl/src/main/java/org/apache/myfaces/util/lang/ClassUtils.java @@ -241,16 +241,17 @@ public static Class simpleClassForName(String type) /** * Same as {link {@link #simpleClassForName(String)}, but will only - * log the exception and rethrow a RunTimeException if logException is true. + * log the exception and rethrow a RunTimeException if logAndThrowException is true. * * @param type - * @param logException - true to log/throw FacesException, false to avoid logging/throwing FacesException + * @param logAndThrowException - true to log and throw FacesException, false to avoid logging and throwing + * the FacesException * @return the corresponding Class - * @throws FacesException if class not found and logException is true + * @throws FacesException if class not found and logAndThrowException is true */ // @Override MYFACES-4449: Methods that call ClassUtils.class.getClassLoader() need to be here // as well as in the API ClassUtils so that the correct ClassLoader is used. - public static Class simpleClassForName(String type, boolean logException) + public static Class simpleClassForName(String type, boolean logAndThrowException) { Class returnClass = null; try @@ -259,7 +260,7 @@ public static Class simpleClassForName(String type, boolean logException) } catch (ClassNotFoundException e) { - if (logException) + if (logAndThrowException) { log.log(Level.SEVERE, "Class " + type + " not found", e); throw new FacesException(e); @@ -268,6 +269,39 @@ public static Class simpleClassForName(String type, boolean logException) return returnClass; } + /** + * Same as {link {@link #simpleClassForName(String)}, but accepts two booleans + * One to log an exception and another to rethrow a FacesExceptions + * + * @param type + * @param logException - true to log the ClassNotFoundException, false to avoid logging + * @param throwException - true to throw a FacesException, false to avoid throwing a FacesException + * @return the corresponding Class + * @throws FacesException if class not found and throwException is true + */ + // @Override MYFACES-4449: Methods that call ClassUtils.class.getClassLoader() need to be here + // as well as in the API ClassUtils so that the correct ClassLoader is used. + public static Class simpleClassForName(String type, boolean throwException, boolean logException) + { + Class returnClass = null; + try + { + returnClass = classForName(type); + } + catch (ClassNotFoundException e) + { + if(logException) + { + log.log(Level.SEVERE, "Class " + type + " not found", e); + } + if (throwException) + { + throw new FacesException(e); + } + } + return returnClass; + } + // @Override MYFACES-4449: Methods that call ClassUtils.class.getClassLoader() need to be here // as well as in the API ClassUtils so that the correct ClassLoader is used. public static URL getResource(String resource)