myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From embre...@apache.org
Subject svn commit: r1805781 - /myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
Date Tue, 22 Aug 2017 15:31:12 GMT
Author: embreijo
Date: Tue Aug 22 15:31:11 2017
New Revision: 1805781

URL: http://svn.apache.org/viewvc?rev=1805781&view=rev
Log:
MYFACES-4139 Utility method in ClassUtils to not throw exception

Modified:
    myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java

Modified: myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java?rev=1805781&r1=1805780&r2=1805781&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
(original)
+++ myfaces/core/branches/2.0.x/shared-public/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
Tue Aug 22 15:31:11 2017
@@ -202,7 +202,6 @@ public final class ClassUtils
         }
     }
 
-
     /**
      * Same as {@link #classForName(String)}, but throws a RuntimeException
      * (FacesException) instead of a ClassNotFoundException.
@@ -213,15 +212,34 @@ public final class ClassUtils
      */
     public static Class simpleClassForName(String type)
     {
+        return simpleClassForName(type, true);
+    }
+
+    /**
+     * Same as {link {@link #simpleClassForName(String)}, but will only
+     * log the exception and rethrow a RunTimeException if logException is true.
+     *
+     * @param type
+     * @param logException - true to log/throw FacesException, false to avoid logging/throwing
FacesException
+     * @return the corresponding Class
+     * @throws FacesException if class not found and logException is true
+     */
+    public static Class simpleClassForName(String type, boolean logException)
+    {
+        Class returnClass = null;
         try
         {
-            return classForName(type);
+            returnClass = classForName(type);
         }
         catch (ClassNotFoundException e)
         {
-            log.log(Level.SEVERE, "Class " + type + " not found", e);
-            throw new FacesException(e);
+            if (logException)
+            {
+                log.log(Level.SEVERE, "Class " + type + " not found", e);
+                throw new FacesException(e);
+            }
         }
+        return returnClass;
     }
 
 



Mime
View raw message