geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r399080 - /geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/Session.java
Date Tue, 02 May 2006 23:19:18 GMT
Author: rickmcguire
Date: Tue May  2 16:19:15 2006
New Revision: 399080

URL: http://svn.apache.org/viewcvs?rev=399080&view=rev
Log:
GERONIMO-1968 Session getProvider() resolution not properly implementing search order.



Modified:
    geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/Session.java

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/Session.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/Session.java?rev=399080&r1=399079&r2=399080&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/Session.java (original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/Session.java Tue
May  2 16:19:15 2006
@@ -209,16 +209,26 @@
      */
     public Provider getProvider(String protocol) throws NoSuchProviderException {
         ProviderInfo info = getProviderInfo();
-        Provider provider;
+        Provider provider = null;
         String providerName = properties.getProperty("mail." + protocol + ".class");
         if (providerName != null) {
             provider = (Provider) info.byClassName.get(providerName);
-        } else {
+            if (debug) {
+                writeDebug("DEBUG: new provider loaded: " + provider.toString());
+            }
+        }
+
+        // if not able to locate this by class name, just grab a registered protocol.
+        if (provider == null) {
             provider = (Provider) info.byProtocol.get(protocol);
         }
+
         if (provider == null) {
             throw new NoSuchProviderException("Unable to locate provider for protocol: "
+ protocol);
         }
+        if (debug) {
+            writeDebug("DEBUG: getProvider() returning provider " + provider.toString());
+        }
         return provider;
     }
 
@@ -446,7 +456,7 @@
         }
     }
 
-    private static ProviderInfo getProviderInfo() {
+    private ProviderInfo getProviderInfo() {
         ClassLoader cl = getClassLoader();
         ProviderInfo info = (ProviderInfo) providersByClassLoader.get(cl);
         if (info == null) {
@@ -473,7 +483,7 @@
         return cl;
     }
 
-    private static ProviderInfo loadProviders(ClassLoader cl) {
+    private ProviderInfo loadProviders(ClassLoader cl) {
         // we create a merged map from reading all of the potential address map entries.
 The locations
         // searched are:
         //   1.   java.home/lib/javamail.address.map
@@ -493,6 +503,10 @@
             Enumeration e = cl.getResources("META-INF/javamail.default.providers");
             while (e.hasMoreElements()) {
                 URL url = (URL) e.nextElement();
+                if (debug) {
+                    writeDebug("Loading javamail.default.providers from " + url.toString());
+                }
+
                 InputStream is = url.openStream();
                 try {
                     loadProviders(info, is);
@@ -512,6 +526,9 @@
             InputStream is = new FileInputStream(file);
             try {
                 loadProviders(info, is);
+                if (debug) {
+                    writeDebug("Loaded lib/javamail.providers from " + file.toString());
+                }
             } finally{
                 is.close();
             }
@@ -525,6 +542,9 @@
             Enumeration e = cl.getResources("META-INF/javamail.providers");
             while (e.hasMoreElements()) {
                 URL url = (URL) e.nextElement();
+                if (debug) {
+                    writeDebug("Loading META-INF/javamail.providers from " + url.toString());
+                }
                 InputStream is = url.openStream();
                 try {
                     loadProviders(info, is);
@@ -541,7 +561,7 @@
         return info;
     }
 
-    private static void loadProviders(ProviderInfo info, InputStream is) throws IOException
{
+    private void loadProviders(ProviderInfo info, InputStream is) throws IOException {
         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
         String line;
         while ((line = reader.readLine()) != null) {
@@ -579,6 +599,10 @@
                 //todo should we log a warning?
                 continue;
             }
+
+            if (debug) {
+                writeDebug("DEBUG: loading new provider protocol=" + protocol + ", className="
+ className + ", vendor=" + vendor + ", version=" + version);
+            }
             Provider provider = new Provider(protocol, className, type, vendor, version);
             if (!info.byClassName.containsKey(className)) {
                 info.byClassName.put(className, provider);
@@ -696,6 +720,15 @@
         }
 
         return addressMap;
+    }
+
+    /**
+     * Private convenience routine for debug output.
+     *
+     * @param msg    The message to write out to the debug stream.
+     */
+    private void writeDebug(String msg) {
+        debugOut.println(msg);
     }
 
 



Mime
View raw message