geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r921027 - in /geronimo/specs/trunk: geronimo-activation_1.1_spec/src/main/java/javax/activation/ geronimo-el_2.2_spec/src/main/java/javax/el/ geronimo-javamail_1.4_spec/src/main/java/javax/mail/ geronimo-jaxb_2.2_spec/src/main/java/javax/xm...
Date Tue, 09 Mar 2010 18:12:51 GMT
Author: rickmcguire
Date: Tue Mar  9 18:12:51 2010
New Revision: 921027

URL: http://svn.apache.org/viewvc?rev=921027&view=rev
Log:
Clean up specs classloading to use a common utility method

Modified:
    geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/javax/activation/MailcapCommandMap.java
    geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java
    geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/Session.java
    geronimo/specs/trunk/geronimo-jaxb_2.2_spec/src/main/java/javax/xml/bind/ContextFinder.java
    geronimo/specs/trunk/geronimo-jaxr_1.0_spec/src/main/java/javax/xml/registry/ConnectionFactory.java
    geronimo/specs/trunk/geronimo-jaxrpc_1.1_spec/src/main/java/javax/xml/rpc/FactoryFinder.java
    geronimo/specs/trunk/geronimo-jaxws_2.1.1_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java
    geronimo/specs/trunk/geronimo-jaxws_2.2_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java
    geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
    geronimo/specs/trunk/geronimo-saaj_1.3_spec/src/main/java/javax/xml/soap/FactoryFinder.java
    geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java
    geronimo/specs/trunk/geronimo-validation_1.0_spec/src/main/java/javax/validation/Validation.java

Modified: geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/javax/activation/MailcapCommandMap.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/javax/activation/MailcapCommandMap.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/javax/activation/MailcapCommandMap.java
(original)
+++ geronimo/specs/trunk/geronimo-activation_1.1_spec/src/main/java/javax/activation/MailcapCommandMap.java
Tue Mar  9 18:12:51 2010
@@ -469,20 +469,9 @@ public class MailcapCommandMap extends C
             cl = getClass().getClassLoader();
         }
         try {
-            return (DataContentHandler) cl.loadClass(info.getCommandClass()).newInstance();
+            return (DataContentHandler) ProviderLocator.loadClass(info.getCommandClass(),
cl).newInstance();
         } catch (ClassNotFoundException e) {
-            // last gasp, use the OSGi locator to try to find this
-            Class cls = ProviderLocator.locate(info.getCommandClass());
-            if (cls == null) {
-                return null;
-            }
-            try {
-                return (DataContentHandler)cls.newInstance();
-            } catch (IllegalAccessException ex) {
-                return null;
-            } catch (InstantiationException ex) {
-                return null;
-            }
+            return null;
         } catch (IllegalAccessException e) {
             return null;
         } catch (InstantiationException e) {

Modified: geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java
(original)
+++ geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java
Tue Mar  9 18:12:51 2010
@@ -170,19 +170,9 @@ public abstract class ExpressionFactory 
         String implClassName = null;
         try {
             implClassName = lookupExpressionFactoryImplClass();
-            ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-            if (contextClassLoader != null) {
-                return contextClassLoader.loadClass(implClassName);
-            } else {
-                return Class.forName(implClassName);
-            }
+            return ProviderLocator.loadClass(implClassName);
         } catch (ClassNotFoundException e) {
-            // last gasp, use the OSGi locator to try to find this
-            Class cls = ProviderLocator.locate(implClassName);
-            if (cls == null) {
-                throw new ELException("Fail to load implementation class " + implClassName,
e);
-            }
-            return cls;
+            throw new ELException("Fail to load implementation class " + implClassName, e);
         }
     }
 }

Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/Session.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/Session.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/Session.java
(original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/Session.java
Tue Mar  9 18:12:51 2010
@@ -489,13 +489,9 @@ public final class Session {
             ClassLoader cl = getClassLoader();
             Class clazz = null;
             try {
-                clazz = cl.loadClass(provider.getClassName());
+                clazz = ProviderLocator.loadClass(provider.getClassName(), cl);
             } catch (ClassNotFoundException e) {
-                // last gasp, use the OSGi locator to try to find this
-                clazz  = ProviderLocator.locate(provider.getClassName());
-                if (clazz == null) {
-                    throw (NoSuchProviderException) new NoSuchProviderException("Unable to
load class for provider: " + provider).initCause(e);
-                }
+                throw (NoSuchProviderException) new NoSuchProviderException("Unable to load
class for provider: " + provider).initCause(e);
             }
             Constructor ctr = clazz.getConstructor(PARAM_TYPES);
             return(Service) ctr.newInstance(new Object[]{this, name});

Modified: geronimo/specs/trunk/geronimo-jaxb_2.2_spec/src/main/java/javax/xml/bind/ContextFinder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jaxb_2.2_spec/src/main/java/javax/xml/bind/ContextFinder.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jaxb_2.2_spec/src/main/java/javax/xml/bind/ContextFinder.java
(original)
+++ geronimo/specs/trunk/geronimo-jaxb_2.2_spec/src/main/java/javax/xml/bind/ContextFinder.java
Tue Mar  9 18:12:51 2010
@@ -158,21 +158,11 @@ class ContextFinder {
     }
 
     private static Class loadSpi(String className, ClassLoader classLoader) throws JAXBException
{
-        Class spiClass;
         try {
-            if (classLoader != null) {
-                spiClass = classLoader.loadClass(className);
-            } else {
-                spiClass = Class.forName(className);
-            }
+            return ProviderLocator.loadClass(className, classLoader);
         } catch (ClassNotFoundException e) {
-            // last gasp, use the OSGi locator to try to find this
-            spiClass = ProviderLocator.locate(className);
-            if (spiClass == null) {
-                throw new JAXBException("Provider " + className + " not found", e);
-            }
+            throw new JAXBException("Provider " + className + " not found", e);
         }
-        return spiClass;
     }
 
 

Modified: geronimo/specs/trunk/geronimo-jaxr_1.0_spec/src/main/java/javax/xml/registry/ConnectionFactory.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jaxr_1.0_spec/src/main/java/javax/xml/registry/ConnectionFactory.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jaxr_1.0_spec/src/main/java/javax/xml/registry/ConnectionFactory.java
(original)
+++ geronimo/specs/trunk/geronimo-jaxr_1.0_spec/src/main/java/javax/xml/registry/ConnectionFactory.java
Tue Mar  9 18:12:51 2010
@@ -51,17 +51,10 @@ public abstract class ConnectionFactory 
             cl = ConnectionFactory.class.getClassLoader();
         }
         try {
-            Class factoryClass = null;
-            try {
-                factoryClass = cl.loadClass(className);
-            } catch (ClassNotFoundException e) {
-                // last gasp, use the OSGi locator to try to find this
-                factoryClass = ProviderLocator.locate(className);
-                if (factoryClass == null) {
-                    throw new JAXRException("Unable to load JAXR ConnectionFactoryClass:
" + className, e);
-                }
-            }
+            Class factoryClass = ProviderLocator.loadClass(className, cl);
             return (ConnectionFactory) factoryClass.newInstance();
+        } catch (ClassNotFoundException e) {
+            throw new JAXRException("Unable to load JAXR ConnectionFactoryClass: " + className,
e);
         } catch (InstantiationException e) {
             throw new JAXRException("Unable to instantiate JAXR ConnectionFactoryClass: "
+ className, e);
         } catch (IllegalAccessException e) {

Modified: geronimo/specs/trunk/geronimo-jaxrpc_1.1_spec/src/main/java/javax/xml/rpc/FactoryFinder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jaxrpc_1.1_spec/src/main/java/javax/xml/rpc/FactoryFinder.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jaxrpc_1.1_spec/src/main/java/javax/xml/rpc/FactoryFinder.java
(original)
+++ geronimo/specs/trunk/geronimo-jaxrpc_1.1_spec/src/main/java/javax/xml/rpc/FactoryFinder.java
Tue Mar  9 18:12:51 2010
@@ -104,25 +104,10 @@ class FactoryFinder {
         throws ConfigurationError
     {
         try {
-            if (classLoader != null) {
-                try {
-                    return classLoader.loadClass(className).newInstance ();
-                } catch (ClassNotFoundException x) {
-                      // try again
-                }
-            }
-            try {
-                // try again with just Class.forName()
-                return Class.forName(className).newInstance();
-            } catch (ClassNotFoundException x) {
-                // last gasp, use the OSGi locator to try to find this
-                Class<?> cls = ProviderLocator.locate(className);
-                if (cls == null) {
-                    throw new ConfigurationError(
-                        "Provider " + className + " not found", x);
-                }
-                return cls.newInstance();
-            }
+            return ProviderLocator.loadClass(className, classLoader).newInstance();
+        } catch (ClassNotFoundException x) {
+            throw new ConfigurationError(
+                "Provider " + className + " not found", x);
         } catch (Exception x) {
             throw new ConfigurationError(
                 "Provider " + className + " could not be instantiated: " + x,

Modified: geronimo/specs/trunk/geronimo-jaxws_2.1.1_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jaxws_2.1.1_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jaxws_2.1.1_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java
(original)
+++ geronimo/specs/trunk/geronimo-jaxws_2.1.1_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java
Tue Mar  9 18:12:51 2010
@@ -125,23 +125,7 @@ class FactoryFinder {
             doPrivileged( new PrivilegedAction() {
                 public Object run() {
                     try {
-                        if (iClassLoader != null) {
-                            try {
-                                return iClassLoader.loadClass(iClassName).newInstance();
-                            } catch (ClassNotFoundException x) {
-                                // try again
-                            }
-                        }
-                        try {
-                            return Class.forName(iClassName).newInstance();
-                        } catch (ClassNotFoundException x) {
-                            // last gasp, use the OSGi locator to try to find this
-                            Class cls = ProviderLocator.locate(iClassName);
-                            if (cls == null) {
-                                throw x;
-                            }
-                            return cls.newInstance();
-                        }
+                        return ProviderLocator.loadClass(iClassName, iClassLoader).newInstance();
                     } catch (ClassNotFoundException x) {
                         throw new ConfigurationError(
                                 "Provider " + iClassName + " not found", x);

Modified: geronimo/specs/trunk/geronimo-jaxws_2.2_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jaxws_2.2_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jaxws_2.2_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java
(original)
+++ geronimo/specs/trunk/geronimo-jaxws_2.2_spec/src/main/java/javax/xml/ws/spi/FactoryFinder.java
Tue Mar  9 18:12:51 2010
@@ -125,23 +125,7 @@ class FactoryFinder {
             doPrivileged( new PrivilegedAction<Object>() {
                 public Object run() {
                     try {
-                        if (iClassLoader != null) {
-                            try {
-                                return iClassLoader.loadClass(iClassName).newInstance();
-                            } catch (ClassNotFoundException x) {
-                                // try again
-                            }
-                        }
-                        try {
-                            return Class.forName(iClassName).newInstance();
-                        } catch (ClassNotFoundException x) {
-                            // last gasp, use the OSGi locator to try to find this
-                            Class cls = ProviderLocator.locate(iClassName);
-                            if (cls == null) {
-                                throw x;
-                            }
-                            return cls.newInstance();
-                        }
+                        return ProviderLocator.loadClass(iClassName, iClassLoader).newInstance();
                     } catch (ClassNotFoundException x) {
                         throw new ConfigurationError(
                                 "Provider " + iClassName + " not found", x);

Modified: geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
(original)
+++ geronimo/specs/trunk/geronimo-osgi-support/geronimo-osgi-locator/src/main/java/org/apache/geronimo/osgi/locator/ProviderLocator.java
Tue Mar  9 18:12:51 2010
@@ -112,4 +112,50 @@ public class ProviderLocator {
         // the rest of the work is done by the registry
         return registry.locateAll(providerId);
     }
+
+    /**
+     * Utility class for locating a class with OSGi registry
+     * support.  Uses the thread context classloader as part of
+     * the search order.
+     *
+     * @param className The name of the target class.
+     *
+     * @return The loaded class.
+     * @exception ClassNotFoundException
+     *                   Thrown if the class cannot be located.
+     */
+    static public Class<?> loadClass(String className) throws ClassNotFoundException
{
+        return loadClass(className, Thread.currentThread().getContextClassLoader());
+    }
+
+    /**
+     * Standardized utility method for performing class lookups
+     * with support for OSGi registry lookups.
+     *
+     * @param className The name of the target class.
+     * @param loader    An optional class loader.
+     *
+     * @return The loaded class
+     * @exception ClassNotFoundException
+     *                   Thrown if the class cannot be loaded.
+     */
+    static public Class<?> loadClass(String className, ClassLoader loader) throws ClassNotFoundException
{
+        if (loader != null) {
+            try {
+                return loader.loadClass(className);
+            } catch (ClassNotFoundException x) {
+                // try again
+            }
+        }
+        try {
+            return Class.forName(className);
+        } catch (ClassNotFoundException x) {
+            // last gasp, use the OSGi locator to try to find this
+            Class cls = locate(className);
+            if (cls == null) {
+                throw x;
+            }
+            return cls;
+        }
+    }
 }

Modified: geronimo/specs/trunk/geronimo-saaj_1.3_spec/src/main/java/javax/xml/soap/FactoryFinder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-saaj_1.3_spec/src/main/java/javax/xml/soap/FactoryFinder.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-saaj_1.3_spec/src/main/java/javax/xml/soap/FactoryFinder.java
(original)
+++ geronimo/specs/trunk/geronimo-saaj_1.3_spec/src/main/java/javax/xml/soap/FactoryFinder.java
Tue Mar  9 18:12:51 2010
@@ -48,31 +48,7 @@ class FactoryFinder {
         }
 
         try {
-            Class factory = null;
-            if (classloader == null) {
-                factory = Class.forName(factoryClassName);
-            } else {
-                try {
-                    factory = classloader.loadClass(factoryClassName);
-                } catch (ClassNotFoundException cnfe) {
-                }
-            }
-            if (factory == null) {
-                classloader = FactoryFinder.class.getClassLoader();
-                try {
-                    factory = classloader.loadClass(factoryClassName);
-                } catch (ClassNotFoundException e) {
-                    // if the got a ClassNotFoundException using the provided class loader,
-                    // we might be running in an OSGi environment.  In that case, there's
-                    // an additional registry we can check to locate the provider.
-                    factory = ProviderLocator.locate(factoryClassName);
-                    // if not found here, then go ahead and throw the exception
-                    if (factory == null) {
-                        throw e;
-                    }
-                }
-            }
-            return factory.newInstance();
+            return ProviderLocator.loadClass(factoryClassName, classloader).newInstance();
         } catch (ClassNotFoundException classnotfoundexception) {
             throw new SOAPException(
                     "Provider " + factoryClassName + " not found",

Modified: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java
(original)
+++ geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java
Tue Mar  9 18:12:51 2010
@@ -114,28 +114,11 @@ class FactoryLocator {
 	private static Object loadFactory(String className, ClassLoader classLoader)
 			throws FactoryConfigurationError {
 		try {
-			Class factoryClass = classLoader == null ? Class.forName(className)
-					: classLoader.loadClass(className);
-
-			return factoryClass.newInstance();
+			return ProviderLocator.loadClass(className, classLoader).newInstance();
 		} catch (ClassNotFoundException x) {
-			// if the got a ClassNotFoundException using the provided class loader,
-			// we might be running in an OSGi environment.  In that case, there's
-			// an additional registry we can check to locate the provider.
-			Class factoryClass = ProviderLocator.locate(className);
-			// if not found here, then go ahead and throw the exception
-			if (factoryClass == null) {
-				throw new FactoryConfigurationError("Requested factory "
-						+ className + " cannot be located.  Classloader ="
-						+ classLoader.toString(), x);
-			}
-			// another attempt at instantiating this
-			try {
-				return factoryClass.newInstance();
-			} catch (Exception ex) {
-				throw new FactoryConfigurationError("Requested factory "
-						+ className + " could not be instantiated: " + ex, ex);
-			}
+  			throw new FactoryConfigurationError("Requested factory "
+  					+ className + " cannot be located.  Classloader ="
+  					+ classLoader.toString(), x);
 		} catch (Exception x) {
 			throw new FactoryConfigurationError("Requested factory "
 					+ className + " could not be instantiated: " + x, x);

Modified: geronimo/specs/trunk/geronimo-validation_1.0_spec/src/main/java/javax/validation/Validation.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-validation_1.0_spec/src/main/java/javax/validation/Validation.java?rev=921027&r1=921026&r2=921027&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-validation_1.0_spec/src/main/java/javax/validation/Validation.java
(original)
+++ geronimo/specs/trunk/geronimo-validation_1.0_spec/src/main/java/javax/validation/Validation.java
Tue Mar  9 18:12:51 2010
@@ -227,14 +227,10 @@ public class Validation {
                                         Class<?> provider = null;
                                         try {
                                             // try loading the specified class
-                                            provider = cl.loadClass(line);
+                                            provider = ProviderLocator.loadClass(line, cl);
                                         } catch (ClassNotFoundException e) {
-                                            // last gasp, use the OSGi locator to try to
find this
-                                            provider = ProviderLocator.locate(line);
-                                            if (provider == null) {
-                                                throw new ValidationException("Failed to
load provider " +
-                                                    line + " configured in file " + url,
e);
-                                            }
+                                            throw new ValidationException("Failed to load
provider " +
+                                                line + " configured in file " + url, e);
                                         }
                                         // create an instance to return
                                         providers.add((ValidationProvider<?>) provider.newInstance());



Mime
View raw message