From d4d351aae27f66df1d7347820ff3903a4f9017aa Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Thu, 23 Oct 2003 15:38:16 +0000 Subject: [PATCH] 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 --- .../smack/provider/ProviderManager.java | 186 ++++++++++-------- 1 file changed, 103 insertions(+), 83 deletions(-) diff --git a/source/org/jivesoftware/smack/provider/ProviderManager.java b/source/org/jivesoftware/smack/provider/ProviderManager.java index 43594ac4d..63e8d4463 100644 --- a/source/org/jivesoftware/smack/provider/ProviderManager.java +++ b/source/org/jivesoftware/smack/provider/ProviderManager.java @@ -146,95 +146,103 @@ public class ProviderManager { static { // Load IQ processing providers. try { - Enumeration enum = ProviderManager.class.getClassLoader().getResources( - "META-INF/smack.providers"); - while (enum.hasMoreElements()) { - URL url = (URL)enum.nextElement(); - java.io.InputStream providerStream = null; - try { - providerStream = url.openStream(); - XmlPullParserFactory factory = XmlPullParserFactory.newInstance( - "org.xmlpull.mxp1.MXParserFactory", null); - factory.setNamespaceAware(true); - XmlPullParser parser = factory.newPullParser(); - parser.setInput(providerStream, "UTF-8"); - int eventType = parser.getEventType(); - do { - if (eventType == XmlPullParser.START_TAG) { - if (parser.getName().equals("iqProvider")) { - parser.next(); - parser.next(); - String elementName = parser.nextText(); - parser.next(); - parser.next(); - String namespace = parser.nextText(); - parser.next(); - parser.next(); - String className = parser.nextText(); - // Only add the provider for the namespace if one isn't - // already registered. - String key = getProviderKey(elementName, namespace); - if (!iqProviders.containsKey(key)) { - // Attempt to load the provider class and then create - // a new instance if it's an IQProvider. Otherwise, if it's - // an IQ class, add the class object itself, then we'll use - // reflection later to create instances of the class. - try { - // Add the provider to the map. - Class provider = Class.forName(className); - if (IQProvider.class.isAssignableFrom(provider)) { - iqProviders.put(key, provider.newInstance()); + // Get an array of class loaders to try loading the providers files from. + ClassLoader[] classLoaders = getClassLoaders(); + for (int i=0; i<").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() { + + } } \ No newline at end of file