2003-05-08 17:53:40 +02:00
|
|
|
/**
|
|
|
|
* $RCSfile$
|
|
|
|
* $Revision$
|
|
|
|
* $Date$
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2003-05-08 17:53:40 +02:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2003-05-08 17:53:40 +02:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2003-05-08 17:53:40 +02:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2003-05-08 17:53:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smack.provider;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
|
|
|
import org.jivesoftware.smack.packet.PacketExtension;
|
2005-03-23 03:36:19 +01:00
|
|
|
import org.xmlpull.mxp1.MXParser;
|
2006-07-18 07:14:33 +02:00
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
2003-05-08 17:53:40 +02:00
|
|
|
|
2006-07-18 07:14:33 +02:00
|
|
|
import java.io.InputStream;
|
2003-05-08 17:53:40 +02:00
|
|
|
import java.net.URL;
|
2006-07-18 07:14:33 +02:00
|
|
|
import java.util.*;
|
2006-07-18 08:47:38 +02:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2003-05-08 17:53:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages providers for parsing custom XML sub-documents of XMPP packets. Two types of
|
|
|
|
* providers exist:<ul>
|
|
|
|
* <li>IQProvider -- parses IQ requests into Java objects.
|
|
|
|
* <li>PacketExtension -- parses XML sub-documents attached to packets into
|
|
|
|
* PacketExtension instances.</ul>
|
|
|
|
*
|
|
|
|
* <b>IQProvider</b><p>
|
|
|
|
*
|
2003-07-31 04:28:16 +02:00
|
|
|
* By default, Smack only knows how to process IQ packets with sub-packets that
|
|
|
|
* are in a few namespaces such as:<ul>
|
2003-05-08 17:53:40 +02:00
|
|
|
* <li>jabber:iq:auth
|
|
|
|
* <li>jabber:iq:roster
|
|
|
|
* <li>jabber:iq:register</ul>
|
|
|
|
*
|
|
|
|
* Because many more IQ types are part of XMPP and its extensions, a pluggable IQ parsing
|
2003-07-31 04:28:16 +02:00
|
|
|
* mechanism is provided. IQ providers are registered programatically or by creating a
|
|
|
|
* smack.providers file in the META-INF directory of your JAR file. The file is an XML
|
|
|
|
* document that contains one or more iqProvider entries, as in the following example:
|
2003-05-08 17:53:40 +02:00
|
|
|
*
|
|
|
|
* <pre>
|
|
|
|
* <?xml version="1.0"?>
|
|
|
|
* <smackProviders>
|
|
|
|
* <iqProvider>
|
|
|
|
* <elementName>query</elementName>
|
|
|
|
* <namespace>jabber:iq:time</namespace>
|
|
|
|
* <className>org.jivesoftware.smack.packet.Time</className>
|
|
|
|
* </iqProvider>
|
|
|
|
* </smackProviders></pre>
|
|
|
|
*
|
2003-07-31 04:28:16 +02:00
|
|
|
* Each IQ provider is associated with an element name and a namespace. If multiple provider
|
|
|
|
* entries attempt to register to handle the same namespace, the first entry loaded from the
|
|
|
|
* classpath will take precedence. The IQ provider class can either implement the IQProvider
|
|
|
|
* interface, or extend the IQ class. In the former case, each IQProvider is responsible for
|
|
|
|
* parsing the raw XML stream to create an IQ instance. In the latter case, bean introspection
|
|
|
|
* is used to try to automatically set properties of the IQ instance using the values found
|
2003-05-08 17:53:40 +02:00
|
|
|
* in the IQ packet XML. For example, an XMPP time packet resembles the following:
|
|
|
|
* <pre>
|
2003-05-11 23:19:38 +02:00
|
|
|
* <iq type='result' to='joe@example.com' from='mary@example.com' id='time_1'>
|
2003-05-08 17:53:40 +02:00
|
|
|
* <query xmlns='jabber:iq:time'>
|
|
|
|
* <utc>20020910T17:58:35</utc>
|
|
|
|
* <tz>MDT</tz>
|
|
|
|
* <display>Tue Sep 10 12:58:35 2002</display>
|
|
|
|
* </query>
|
|
|
|
* </iq></pre>
|
|
|
|
*
|
|
|
|
* In order for this packet to be automatically mapped to the Time object listed in the
|
|
|
|
* providers file above, it must have the methods setUtc(String), setTz(String), and
|
2003-05-21 23:12:33 +02:00
|
|
|
* setDisplay(String). The introspection service will automatically try to convert the String
|
2003-05-08 17:53:40 +02:00
|
|
|
* value from the XML into a boolean, int, long, float, double, or Class depending on the
|
|
|
|
* type the IQ instance expects.<p>
|
|
|
|
*
|
2003-05-20 22:23:15 +02:00
|
|
|
* A pluggable system for packet extensions, child elements in a custom namespace for
|
|
|
|
* message and presence packets, also exists. Each extension provider
|
2003-05-08 17:53:40 +02:00
|
|
|
* is registered with a name space in the smack.providers file as in the following example:
|
|
|
|
*
|
|
|
|
* <pre>
|
|
|
|
* <?xml version="1.0"?>
|
|
|
|
* <smackProviders>
|
2003-05-20 22:23:15 +02:00
|
|
|
* <extensionProvider>
|
|
|
|
* <elementName>x</elementName>
|
|
|
|
* <namespace>jabber:iq:event</namespace>
|
|
|
|
* <className>org.jivesoftware.smack.packet.MessageEvent</className>
|
|
|
|
* </extensionProvider>
|
2003-05-08 17:53:40 +02:00
|
|
|
* </smackProviders></pre>
|
|
|
|
*
|
2003-05-20 22:23:15 +02:00
|
|
|
* If multiple provider entries attempt to register to handle the same element name and namespace,
|
|
|
|
* the first entry loaded from the classpath will take precedence. Whenever a packet extension
|
2003-05-08 17:53:40 +02:00
|
|
|
* is found in a packet, parsing will be passed to the correct provider. Each provider
|
2003-05-20 22:23:15 +02:00
|
|
|
* can either implement the PacketExtensionProvider interface or be a standard Java Bean. In
|
|
|
|
* the former case, each extension provider is responsible for parsing the raw XML stream to
|
|
|
|
* contruct an object. In the latter case, bean introspection is used to try to automatically
|
|
|
|
* set the properties of the class using the values in the packet extension sub-element. When an
|
|
|
|
* extension provider is not registered for an element name and namespace combination, Smack will
|
|
|
|
* store all top-level elements of the sub-packet in DefaultPacketExtension object and then
|
2006-11-16 20:31:30 +01:00
|
|
|
* attach it to the packet.<p>
|
|
|
|
*
|
|
|
|
* It is possible to provide a custom provider manager instead of the default implementation
|
|
|
|
* provided by Smack. If you want to provide your own provider manager then you need to do it
|
2010-02-09 12:55:56 +01:00
|
|
|
* before creating any {@link org.jivesoftware.smack.Connection} by sending the static
|
2006-11-16 20:31:30 +01:00
|
|
|
* {@link #setInstance(ProviderManager)} message. Trying to change the provider manager after
|
2010-02-09 12:55:56 +01:00
|
|
|
* an Connection was created will result in an {@link IllegalStateException} error.
|
2003-05-08 17:53:40 +02:00
|
|
|
*
|
|
|
|
* @author Matt Tucker
|
|
|
|
*/
|
|
|
|
public class ProviderManager {
|
|
|
|
|
2006-11-16 20:31:30 +01:00
|
|
|
private static ProviderManager instance;
|
|
|
|
|
|
|
|
private Map<String, Object> extensionProviders = new ConcurrentHashMap<String, Object>();
|
|
|
|
private Map<String, Object> iqProviders = new ConcurrentHashMap<String, Object>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the only ProviderManager valid instance. Use {@link #setInstance(ProviderManager)}
|
|
|
|
* to configure your own provider manager. If non was provided then an instance of this
|
|
|
|
* class will be used.
|
|
|
|
*
|
|
|
|
* @return the only ProviderManager valid instance.
|
|
|
|
*/
|
|
|
|
public static synchronized ProviderManager getInstance() {
|
|
|
|
if (instance == null) {
|
|
|
|
instance = new ProviderManager();
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
2003-05-08 17:53:40 +02:00
|
|
|
|
2006-11-16 20:31:30 +01:00
|
|
|
/**
|
2010-02-09 12:55:56 +01:00
|
|
|
* Sets the only ProviderManager valid instance to be used by all Connections. If you
|
2006-11-16 20:31:30 +01:00
|
|
|
* want to provide your own provider manager then you need to do it before creating
|
2010-02-09 12:55:56 +01:00
|
|
|
* any Connection. Otherwise an IllegalStateException will be thrown.
|
2006-11-16 20:31:30 +01:00
|
|
|
*
|
|
|
|
* @param providerManager the only ProviderManager valid instance to be used.
|
|
|
|
* @throws IllegalStateException if a provider manager was already configued.
|
|
|
|
*/
|
|
|
|
public static synchronized void setInstance(ProviderManager providerManager) {
|
|
|
|
if (instance != null) {
|
|
|
|
throw new IllegalStateException("ProviderManager singleton already set");
|
|
|
|
}
|
|
|
|
instance = providerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void initialize() {
|
2003-05-08 17:53:40 +02:00
|
|
|
// Load IQ processing providers.
|
|
|
|
try {
|
2003-10-23 17:38:16 +02:00
|
|
|
// Get an array of class loaders to try loading the providers files from.
|
|
|
|
ClassLoader[] classLoaders = getClassLoaders();
|
2006-07-18 07:14:33 +02:00
|
|
|
for (ClassLoader classLoader : classLoaders) {
|
|
|
|
Enumeration providerEnum = classLoader.getResources(
|
2003-10-23 17:38:16 +02:00
|
|
|
"META-INF/smack.providers");
|
2004-10-29 17:09:04 +02:00
|
|
|
while (providerEnum.hasMoreElements()) {
|
2006-07-18 07:14:33 +02:00
|
|
|
URL url = (URL) providerEnum.nextElement();
|
|
|
|
InputStream providerStream = null;
|
2003-10-23 17:38:16 +02:00
|
|
|
try {
|
|
|
|
providerStream = url.openStream();
|
2005-03-23 03:36:19 +01:00
|
|
|
XmlPullParser parser = new MXParser();
|
|
|
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
2003-10-23 17:38:16 +02:00
|
|
|
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)) {
|
2006-11-16 20:31:30 +01:00
|
|
|
iqProviders.put(key, provider.newInstance());
|
2003-10-23 17:38:16 +02:00
|
|
|
}
|
|
|
|
else if (IQ.class.isAssignableFrom(provider)) {
|
|
|
|
iqProviders.put(key, provider);
|
|
|
|
}
|
2003-05-08 17:53:40 +02:00
|
|
|
}
|
2003-10-23 17:38:16 +02:00
|
|
|
catch (ClassNotFoundException cnfe) {
|
|
|
|
cnfe.printStackTrace();
|
2003-05-08 17:53:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-23 17:38:16 +02:00
|
|
|
else if (parser.getName().equals("extensionProvider")) {
|
|
|
|
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 (!extensionProviders.containsKey(key)) {
|
|
|
|
// Attempt to load the provider class and then create
|
|
|
|
// a new instance if it's a Provider. Otherwise, if it's
|
|
|
|
// a PacketExtension, add the class object itself and
|
|
|
|
// 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 (PacketExtensionProvider.class.isAssignableFrom(
|
2006-07-18 07:14:33 +02:00
|
|
|
provider)) {
|
2003-10-23 17:38:16 +02:00
|
|
|
extensionProviders.put(key, provider.newInstance());
|
|
|
|
}
|
|
|
|
else if (PacketExtension.class.isAssignableFrom(
|
2006-07-18 07:14:33 +02:00
|
|
|
provider)) {
|
2003-10-23 17:38:16 +02:00
|
|
|
extensionProviders.put(key, provider);
|
|
|
|
}
|
2003-05-08 17:53:40 +02:00
|
|
|
}
|
2003-10-23 17:38:16 +02:00
|
|
|
catch (ClassNotFoundException cnfe) {
|
|
|
|
cnfe.printStackTrace();
|
2003-05-08 17:53:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-23 17:38:16 +02:00
|
|
|
eventType = parser.next();
|
2006-07-18 07:14:33 +02:00
|
|
|
}
|
|
|
|
while (eventType != XmlPullParser.END_DOCUMENT);
|
2003-10-23 17:38:16 +02:00
|
|
|
}
|
|
|
|
finally {
|
2006-07-18 07:14:33 +02:00
|
|
|
try {
|
|
|
|
providerStream.close();
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2006-07-18 08:47:38 +02:00
|
|
|
// Ignore.
|
2006-07-18 07:14:33 +02:00
|
|
|
}
|
2003-10-23 17:38:16 +02:00
|
|
|
}
|
2003-05-08 17:53:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-11-27 03:04:43 +01:00
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2003-05-08 17:53:40 +02:00
|
|
|
}
|
|
|
|
|
2003-05-11 23:19:38 +02:00
|
|
|
/**
|
|
|
|
* Returns the IQ provider registered to the specified XML element name and namespace.
|
|
|
|
* For example, if a provider was registered to the element name "query" and the
|
|
|
|
* namespace "jabber:iq:time", then the following packet would trigger the provider:
|
|
|
|
*
|
|
|
|
* <pre>
|
|
|
|
* <iq type='result' to='joe@example.com' from='mary@example.com' id='time_1'>
|
|
|
|
* <query xmlns='jabber:iq:time'>
|
|
|
|
* <utc>20020910T17:58:35</utc>
|
|
|
|
* <tz>MDT</tz>
|
|
|
|
* <display>Tue Sep 10 12:58:35 2002</display>
|
|
|
|
* </query>
|
|
|
|
* </iq></pre>
|
|
|
|
*
|
2003-05-15 19:36:58 +02:00
|
|
|
* <p>Note: this method is generally only called by the internal Smack classes.
|
|
|
|
*
|
2003-05-11 23:19:38 +02:00
|
|
|
* @param elementName the XML element name.
|
|
|
|
* @param namespace the XML namespace.
|
2003-06-19 20:22:25 +02:00
|
|
|
* @return the IQ provider.
|
2003-05-11 23:19:38 +02:00
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
public Object getIQProvider(String elementName, String namespace) {
|
2003-05-08 17:53:40 +02:00
|
|
|
String key = getProviderKey(elementName, namespace);
|
|
|
|
return iqProviders.get(key);
|
|
|
|
}
|
|
|
|
|
2003-10-23 18:16:53 +02:00
|
|
|
/**
|
2006-07-18 08:47:38 +02:00
|
|
|
* Returns an unmodifiable collection of all IQProvider instances. Each object
|
|
|
|
* in the collection will either be an IQProvider instance, or a Class object
|
|
|
|
* that implements the IQProvider interface.
|
2003-10-23 18:16:53 +02:00
|
|
|
*
|
2006-07-18 08:47:38 +02:00
|
|
|
* @return all IQProvider instances.
|
2003-10-23 18:16:53 +02:00
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
public Collection<Object> getIQProviders() {
|
2006-07-18 08:47:38 +02:00
|
|
|
return Collections.unmodifiableCollection(iqProviders.values());
|
2003-10-23 18:16:53 +02:00
|
|
|
}
|
|
|
|
|
2003-07-31 04:28:16 +02:00
|
|
|
/**
|
2003-08-01 23:14:51 +02:00
|
|
|
* Adds an IQ provider (must be an instance of IQProvider or Class object that is an IQ)
|
|
|
|
* with the specified element name and name space. The provider will override any providers
|
|
|
|
* loaded through the classpath.
|
2003-07-31 04:28:16 +02:00
|
|
|
*
|
|
|
|
* @param elementName the XML element name.
|
|
|
|
* @param namespace the XML namespace.
|
|
|
|
* @param provider the IQ provider.
|
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
public void addIQProvider(String elementName, String namespace,
|
2003-08-01 23:14:51 +02:00
|
|
|
Object provider)
|
2003-07-31 04:28:16 +02:00
|
|
|
{
|
2003-08-01 23:14:51 +02:00
|
|
|
if (!(provider instanceof IQProvider || (provider instanceof Class &&
|
|
|
|
IQ.class.isAssignableFrom((Class)provider))))
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("Provider must be an IQProvider " +
|
|
|
|
"or a Class instance.");
|
|
|
|
}
|
2003-07-31 04:28:16 +02:00
|
|
|
String key = getProviderKey(elementName, namespace);
|
|
|
|
iqProviders.put(key, provider);
|
|
|
|
}
|
|
|
|
|
2006-01-27 19:44:17 +01:00
|
|
|
/**
|
|
|
|
* Removes an IQ provider with the specified element name and namespace. This
|
|
|
|
* method is typically called to cleanup providers that are programatically added
|
|
|
|
* using the {@link #addIQProvider(String, String, Object) addIQProvider} method.
|
|
|
|
*
|
|
|
|
* @param elementName the XML element name.
|
|
|
|
* @param namespace the XML namespace.
|
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
public void removeIQProvider(String elementName, String namespace) {
|
2006-01-27 19:44:17 +01:00
|
|
|
String key = getProviderKey(elementName, namespace);
|
|
|
|
iqProviders.remove(key);
|
|
|
|
}
|
|
|
|
|
2003-05-11 23:19:38 +02:00
|
|
|
/**
|
|
|
|
* Returns the packet extension provider registered to the specified XML element name
|
|
|
|
* and namespace. For example, if a provider was registered to the element name "x" and the
|
|
|
|
* namespace "jabber:x:event", then the following packet would trigger the provider:
|
|
|
|
*
|
|
|
|
* <pre>
|
|
|
|
* <message to='romeo@montague.net' id='message_1'>
|
|
|
|
* <body>Art thou not Romeo, and a Montague?</body>
|
|
|
|
* <x xmlns='jabber:x:event'>
|
|
|
|
* <composing/>
|
|
|
|
* </x>
|
|
|
|
* </message></pre>
|
|
|
|
*
|
2003-05-15 19:36:58 +02:00
|
|
|
* <p>Note: this method is generally only called by the internal Smack classes.
|
|
|
|
*
|
2006-11-16 20:31:30 +01:00
|
|
|
* @param elementName element name associated with extension provider.
|
|
|
|
* @param namespace namespace associated with extension provider.
|
2003-06-19 20:22:25 +02:00
|
|
|
* @return the extenion provider.
|
2003-05-11 23:19:38 +02:00
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
public Object getExtensionProvider(String elementName, String namespace) {
|
2003-05-08 17:53:40 +02:00
|
|
|
String key = getProviderKey(elementName, namespace);
|
|
|
|
return extensionProviders.get(key);
|
|
|
|
}
|
|
|
|
|
2003-07-31 04:28:16 +02:00
|
|
|
/**
|
|
|
|
* Adds an extension provider with the specified element name and name space. The provider
|
|
|
|
* will override any providers loaded through the classpath. The provider must be either
|
|
|
|
* a PacketExtensionProvider instance, or a Class object of a Javabean.
|
|
|
|
*
|
|
|
|
* @param elementName the XML element name.
|
|
|
|
* @param namespace the XML namespace.
|
|
|
|
* @param provider the extension provider.
|
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
public void addExtensionProvider(String elementName, String namespace,
|
2003-07-31 04:28:16 +02:00
|
|
|
Object provider)
|
|
|
|
{
|
|
|
|
if (!(provider instanceof PacketExtensionProvider || provider instanceof Class)) {
|
|
|
|
throw new IllegalArgumentException("Provider must be a PacketExtensionProvider " +
|
|
|
|
"or a Class instance.");
|
|
|
|
}
|
|
|
|
String key = getProviderKey(elementName, namespace);
|
|
|
|
extensionProviders.put(key, provider);
|
|
|
|
}
|
|
|
|
|
2006-01-27 19:44:17 +01:00
|
|
|
/**
|
|
|
|
* Removes an extension provider with the specified element name and namespace. This
|
|
|
|
* method is typically called to cleanup providers that are programatically added
|
|
|
|
* using the {@link #addExtensionProvider(String, String, Object) addExtensionProvider} method.
|
|
|
|
*
|
|
|
|
* @param elementName the XML element name.
|
|
|
|
* @param namespace the XML namespace.
|
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
public void removeExtensionProvider(String elementName, String namespace) {
|
2006-01-27 19:44:17 +01:00
|
|
|
String key = getProviderKey(elementName, namespace);
|
|
|
|
extensionProviders.remove(key);
|
|
|
|
}
|
|
|
|
|
2003-10-23 18:16:53 +02:00
|
|
|
/**
|
2006-07-18 08:47:38 +02:00
|
|
|
* Returns an unmodifiable collection of all PacketExtensionProvider instances. Each object
|
|
|
|
* in the collection will either be a PacketExtensionProvider instance, or a Class object
|
|
|
|
* that implements the PacketExtensionProvider interface.
|
2003-10-23 18:16:53 +02:00
|
|
|
*
|
2006-07-18 08:47:38 +02:00
|
|
|
* @return all PacketExtensionProvider instances.
|
2003-10-23 18:16:53 +02:00
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
public Collection<Object> getExtensionProviders() {
|
2006-07-18 08:47:38 +02:00
|
|
|
return Collections.unmodifiableCollection(extensionProviders.values());
|
2003-10-23 18:16:53 +02:00
|
|
|
}
|
|
|
|
|
2003-05-11 23:19:38 +02:00
|
|
|
/**
|
|
|
|
* Returns a String key for a given element name and namespace.
|
|
|
|
*
|
|
|
|
* @param elementName the element name.
|
|
|
|
* @param namespace the namespace.
|
|
|
|
* @return a unique key for the element name and namespace pair.
|
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
private String getProviderKey(String elementName, String namespace) {
|
2006-07-18 07:14:33 +02:00
|
|
|
StringBuilder buf = new StringBuilder();
|
2003-05-11 23:19:38 +02:00
|
|
|
buf.append("<").append(elementName).append("/><").append(namespace).append("/>");
|
2003-05-08 17:53:40 +02:00
|
|
|
return buf.toString();
|
|
|
|
}
|
2003-10-23 17:38:16 +02:00
|
|
|
|
2003-10-23 18:16:53 +02:00
|
|
|
/**
|
|
|
|
* Returns an array of class loaders to load resources from.
|
|
|
|
*
|
|
|
|
* @return an array of ClassLoader instances.
|
|
|
|
*/
|
2006-11-16 20:31:30 +01:00
|
|
|
private ClassLoader[] getClassLoaders() {
|
2004-11-27 03:04:43 +01:00
|
|
|
ClassLoader[] classLoaders = new ClassLoader[2];
|
2006-07-18 08:47:38 +02:00
|
|
|
classLoaders[0] = ProviderManager.class.getClassLoader();
|
2003-10-23 17:38:16 +02:00
|
|
|
classLoaders[1] = Thread.currentThread().getContextClassLoader();
|
2006-08-03 00:31:23 +02:00
|
|
|
// Clean up possible null values. Note that #getClassLoader may return a null value.
|
|
|
|
List<ClassLoader> loaders = new ArrayList<ClassLoader>();
|
|
|
|
for (ClassLoader classLoader : classLoaders) {
|
|
|
|
if (classLoader != null) {
|
|
|
|
loaders.add(classLoader);
|
|
|
|
}
|
|
|
|
}
|
2006-08-03 19:03:19 +02:00
|
|
|
return loaders.toArray(new ClassLoader[loaders.size()]);
|
2003-10-23 17:38:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private ProviderManager() {
|
2006-11-16 20:31:30 +01:00
|
|
|
super();
|
|
|
|
initialize();
|
2003-10-23 17:38:16 +02:00
|
|
|
}
|
2003-05-11 23:19:38 +02:00
|
|
|
}
|