myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r711306 - /myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
Date Tue, 04 Nov 2008 16:49:38 GMT
Author: skitching
Date: Tue Nov  4 08:49:37 2008
New Revision: 711306

URL: http://svn.apache.org/viewvc?rev=711306&view=rev
Log:
Add some new variants of ClassUtils.newInstance.
This change is a backport of r511285 and r518534 from the shared-3.0.x branch.

Modified:
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java?rev=711306&r1=711305&r2=711306&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
(original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ClassUtils.java
Tue Nov  4 08:49:37 2008
@@ -268,6 +268,32 @@
         return newInstance(simpleClassForName(type));
     }
 
+    public static Object newInstance(String type, Class expectedType) throws FacesException
+    {
+        return newInstance(type, expectedType == null ? null : new Class[] {expectedType});
+    }
+
+    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 Object newInstance(Class clazz)
         throws FacesException



Mime
View raw message