in geronimo-javamail_1.5_spec/src/main/java/javax/mail/Session.java [552:668]
private ProviderInfo loadProviders(final 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
//
final 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 {
final File file = new File(System.getProperty("java.home"), "lib/javamail.providers");
final InputStream is = new FileInputStream(file);
try {
loadProviders(info, is);
if (debug) {
writeDebug("Loaded lib/javamail.providers from " + file.toString());
}
} finally{
is.close();
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
try {
final Enumeration e = cl.getResources("META-INF/javamail.providers");
while (e.hasMoreElements()) {
final URL url = (URL) e.nextElement();
if (debug) {
writeDebug("Loading META-INF/javamail.providers from " + url.toString());
}
final InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
// we could be running in an OSGi environment, so there might be some globally defined
// providers
try {
final Collection<URL> l = MailProviderRegistry.getProviders();
for (final URL url : l) {
if (debug) {
writeDebug("Loading META-INF/javamail.providers from " + url.toString());
}
final InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
try {
final Enumeration e = cl.getResources("META-INF/javamail.default.providers");
while (e.hasMoreElements()) {
final URL url = (URL) e.nextElement();
if (debug) {
writeDebug("Loading javamail.default.providers from " + url.toString());
}
final InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
// we could be running in an OSGi environment, so there might be some globally defined
// providers
try {
final Collection<URL> l = MailProviderRegistry.getDefaultProviders();
for (final URL url : l) {
if (debug) {
writeDebug("Loading META-INF/javamail.providers from " + url.toString());
}
final InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
// make sure this is added to the global map.
providersByClassLoader.put(cl, info);
return info;
}