mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-23 13:07:59 +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:
parent
8688966ca6
commit
d4d351aae2
1 changed files with 103 additions and 83 deletions
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue