in geronimo-javamail_1.4_spec/src/main/java/javax/mail/Session.java [552:668]
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
// 2. META-INF/javamail.address.map
// 3. META-INF/javamail.default.address.map
//
ProviderInfo info = new ProviderInfo();
// NOTE: Unlike the addressMap, we process these in the defined order. The loading routine
// will not overwrite entries if they already exist in the map.
try {
File file = new File(System.getProperty("java.home"), "lib/javamail.providers");
InputStream is = new FileInputStream(file);
try {
loadProviders(info, is);
if (debug) {
writeDebug("Loaded lib/javamail.providers from " + file.toString());
}
} finally{
is.close();
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
try {
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);
} finally{
is.close();
}
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
// we could be running in an OSGi environment, so there might be some globally defined
// providers
try {
Collection<URL> l = MailProviderRegistry.getProviders();
for (URL url : l) {
if (debug) {
writeDebug("Loading META-INF/javamail.providers from " + url.toString());
}
InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
try {
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);
} finally{
is.close();
}
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
// we could be running in an OSGi environment, so there might be some globally defined
// providers
try {
Collection<URL> l = MailProviderRegistry.getDefaultProviders();
for (URL url : l) {
if (debug) {
writeDebug("Loading META-INF/javamail.providers from " + url.toString());
}
InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
// make sure this is added to the global map.
providersByClassLoader.put(cl, info);
return info;
}