@SuppressWarnings("unchecked") public static void addLoader(ProviderLoader loader) { if (loader.getIQProviderInfo() != null) { for (IQProviderInfo info : loader.getIQProviderInfo()) { addIQProvider(info.getElementName(), info.getNamespace(), info.getProvider()); } } if (loader.getExtensionProviderInfo() != null) { for (ExtensionProviderInfo info : loader.getExtensionProviderInfo()) { addExtensionProvider(info.getElementName(), info.getNamespace(), info.getProvider()); } } if (loader.getStreamFeatureProviderInfo() != null) { for (StreamFeatureProviderInfo info : loader.getStreamFeatureProviderInfo()) { addStreamFeatureProvider(info.getElementName(), info.getNamespace(), (ExtensionElementProvider<ExtensionElement>) info.getProvider()); } } }
public static void removeStreamFeatureProvider(String elementName, String namespace) { String key = getKey(elementName, namespace); streamFeatureProviders.remove(key); }
/** * Parses an extension element. * * @param elementName the XML element name of the extension element. * @param namespace the XML namespace of the stanza extension. * @param parser the XML parser, positioned at the starting element of the extension. * * @return an extension element. * @throws Exception when an error occurs during parsing. */ public static ExtensionElement parseExtensionElement(String elementName, String namespace, XmlPullParser parser) throws Exception { ParserUtils.assertAtStartTag(parser); // See if a provider is registered to handle the extension. ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getExtensionProvider(elementName, namespace); if (provider != null) { return provider.parse(parser); } // No providers registered, so use a default extension. return StandardExtensionElementProvider.INSTANCE.parse(parser); }
@Test public void addClasspathFileLoaderProvider() throws Exception { ProviderManager.addLoader(new ProviderFileLoader(FileUtils.getStreamForClasspathFile("test.providers", null))); Assert.assertNotNull(ProviderManager.getIQProvider("provider", "test:file_provider")); }
@Before public void init() { ProviderManager.addExtensionProvider(ThrowException.ELEMENT, ThrowException.NAMESPACE, new ThrowException()); }
/** * This test should be run in a clean (e.g. forked) VM */ @Test public void shouldInitializeSmackTest() throws Exception { ProviderManager.addIQProvider("foo", "bar", new TestIQProvider()); assertTrue(SmackConfiguration.isSmackInitialized()); }
/** * Setup the jingle system to let the remote clients know we support Jingle. * (This used to be a static part of construction. The problem is a remote client might * attempt a Jingle connection to us after we've created an XMPPConnection, but before we've * setup an instance of a JingleManager. We will appear to not support Jingle. With the new * method you just call it once and all new connections will report Jingle support.) */ public static void setJingleServiceEnabled() { ProviderManager.addIQProvider("jingle", "urn:xmpp:tmp:jingle", new JingleProvider()); // Enable the Jingle support on every established connection // The ServiceDiscoveryManager class should have been already // initialized XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { @Override public void connectionCreated(XMPPConnection connection) { JingleManager.setServiceEnabled(connection, true); } }); }
@Test public void addGenericLoaderProvider() { ProviderManager.addLoader(new ProviderLoader() { @Override public Collection<IQProviderInfo> getIQProviderInfo() { ArrayList<IQProviderInfo> l = new ArrayList<IQProviderInfo>(1); l.add(new IQProviderInfo("provider", "test:provider", new TestIQProvider())); return l; } @Override public Collection<ExtensionProviderInfo> getExtensionProviderInfo() { return null; } @Override public Collection<StreamFeatureProviderInfo> getStreamFeatureProviderInfo() { return null; } }); Assert.assertNotNull(ProviderManager.getIQProvider("provider", "test:provider")); }
/** * 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. */ @SuppressWarnings("unchecked") public static void addExtensionProvider(String elementName, String namespace, Object provider) { validate(elementName, namespace); // First remove existing providers String key = removeExtensionProvider(elementName, namespace); if (provider instanceof ExtensionElementProvider) { extensionProviders.put(key, (ExtensionElementProvider<ExtensionElement>) provider); } else { throw new IllegalArgumentException("Provider must be a PacketExtensionProvider"); } }
@Override public Collection<IQProviderInfo> getIQProviderInfo() { ArrayList<IQProviderInfo> l = new ArrayList<IQProviderInfo>(1); l.add(new IQProviderInfo("provider", "test:provider", new TestIQProvider())); return l; }
@After public void tini() { ProviderManager.removeExtensionProvider(ThrowException.ELEMENT, ThrowException.NAMESPACE); }
@SuppressWarnings("unchecked") @Override public I parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { try { return (I) parseWithIntrospection(elementClass, parser, initialDepth); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassNotFoundException e) { throw new SmackException(e); } } }
public final E parse(XmlPullParser parser) throws Exception { // XPP3 calling convention assert: Parser should be at start tag ParserUtils.assertAtStartTag(parser); final int initialDepth = parser.getDepth(); E e = parse(parser, initialDepth); // XPP3 calling convention assert: Parser should be at end tag of the consumed/parsed element ParserUtils.forwardToEndTagOfDepth(parser, initialDepth); return e; }
public static ExtensionElementProvider<ExtensionElement> getStreamFeatureProvider(String elementName, String namespace) { String key = getKey(elementName, namespace); return streamFeatureProviders.get(key); }
@SuppressWarnings("unchecked") @Override public PE parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { try { return (PE) parseWithIntrospection(elementClass, parser, initialDepth); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassNotFoundException e) { throw new SmackException(e); } } }
/** * Removes an extension provider with the specified element name and namespace. This * method is typically called to cleanup providers that are programmatically added * using the {@link #addExtensionProvider(String, String, Object) addExtensionProvider} method. * * @param elementName the XML element name. * @param namespace the XML namespace. * @return the key of the removed stanza extension provider */ public static String removeExtensionProvider(String elementName, String namespace) { String key = getKey(elementName, namespace); extensionProviders.remove(key); return key; }
/** * Removes an IQ provider with the specified element name and namespace. This * method is typically called to cleanup providers that are programmatically added * using the {@link #addIQProvider(String, String, Object) addIQProvider} method. * * @param elementName the XML element name. * @param namespace the XML namespace. * @return the key of the removed IQ Provider */ public static String removeIQProvider(String elementName, String namespace) { String key = getKey(elementName, namespace); iqProviders.remove(key); return key; }
/** * 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 stanza 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> * * <p>Note: this method is generally only called by the internal Smack classes. * * @param elementName the XML element name. * @param namespace the XML namespace. * @return the IQ provider. */ public static IQProvider<IQ> getIQProvider(String elementName, String namespace) { String key = getKey(elementName, namespace); return iqProviders.get(key); }
/** * Returns the stanza 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 stanza 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> * * <p>Note: this method is generally only called by the internal Smack classes. * * @param elementName element name associated with extension provider. * @param namespace namespace associated with extension provider. * @return the extension provider. */ public static ExtensionElementProvider<ExtensionElement> getExtensionProvider(String elementName, String namespace) { String key = getKey(elementName, namespace); return extensionProviders.get(key); }