openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r603666 - /openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java
Date Wed, 12 Dec 2007 16:32:29 GMT
Author: pcl
Date: Wed Dec 12 08:32:28 2007
New Revision: 603666

URL: http://svn.apache.org/viewvc?rev=603666&view=rev
Log:
Change Services.getImplementorClasses(Class) and Services.getImplementorClasses(Class,ClassLoader)
to filter out implementations that are not assignable to the Class argument. This allows the
Services call to be more fault-tolerant in environments with odd classloader configurations.

Modified:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java?rev=603666&r1=603665&r2=603666&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java Wed
Dec 12 08:32:28 2007
@@ -25,7 +25,9 @@
 import java.net.URL;
 import java.security.AccessController;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.StringTokenizer;
@@ -145,7 +147,21 @@
 
     public static Class[] getImplementorClasses(Class serviceClass,
         ClassLoader loader) {
-        return getImplementorClasses(serviceClass.getName(), loader);
+        Set invalid = new HashSet();
+        Class[] classes = getImplementorClasses(serviceClass.getName(), loader);
+
+        // filter out any classes that have any classloader issues wrt.
+        // the specified service class.
+        for (int i = 0; i < classes.length; i++)
+            if (!serviceClass.isAssignableFrom(classes[i]))
+                invalid.add(classes[i]);
+        if (invalid.size() != 0) {
+            List list = new ArrayList(Arrays.asList(classes));
+            list.removeAll(invalid);
+            return (Class[]) list.toArray(new Class[list.size()]);
+        } else {
+            return classes;
+        }
     }
 
     /**



Mime
View raw message