1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 22:12:05 +01:00

Use multiple class loaders to try to load smack.providers file.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2154 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-10-23 15:38:16 +00:00 committed by mtucker
parent 8688966ca6
commit d4d351aae2

View file

@ -146,7 +146,10 @@ public class ProviderManager {
static {
// Load IQ processing providers.
try {
Enumeration enum = ProviderManager.class.getClassLoader().getResources(
// Get an array of class loaders to try loading the providers files from.
ClassLoader[] classLoaders = getClassLoaders();
for (int i=0; i<classLoaders.length; i++) {
Enumeration enum = classLoaders[i].getResources(
"META-INF/smack.providers");
while (enum.hasMoreElements()) {
URL url = (URL)enum.nextElement();
@ -216,10 +219,14 @@ public class ProviderManager {
try {
// Add the provider to the map.
Class provider = Class.forName(className);
if (PacketExtensionProvider.class.isAssignableFrom(provider)) {
if (PacketExtensionProvider.class.isAssignableFrom(
provider))
{
extensionProviders.put(key, provider.newInstance());
}
else if (PacketExtension.class.isAssignableFrom(provider)) {
else if (PacketExtension.class.isAssignableFrom(
provider))
{
extensionProviders.put(key, provider);
}
}
@ -238,6 +245,7 @@ public class ProviderManager {
}
}
}
}
catch (Exception e) { }
}
@ -344,4 +352,16 @@ public class ProviderManager {
buf.append("<").append(elementName).append("/><").append(namespace).append("/>");
return buf.toString();
}
private static ClassLoader[] getClassLoaders() {
ClassLoader[] classLoaders = new ClassLoader[3];
classLoaders[0] = new ProviderManager().getClass().getClassLoader();
classLoaders[1] = Thread.currentThread().getContextClassLoader();
classLoaders[2] = Object.class.getClassLoader();
return classLoaders;
}
private ProviderManager() {
}
}