Package org.jivesoftware.smack.provider
Class EmbeddedExtensionProvider<PE extends ExtensionElement>
- java.lang.Object
-
- org.jivesoftware.smack.provider.AbstractProvider<E>
-
- org.jivesoftware.smack.provider.Provider<EE>
-
- org.jivesoftware.smack.provider.ExtensionElementProvider<PE>
-
- org.jivesoftware.smack.provider.EmbeddedExtensionProvider<PE>
-
- Direct Known Subclasses:
AffiliationsProvider
,ConfigEventProvider
,DeliveryReceipt.Provider
,EventProvider
,FormNodeProvider
,HeadersProvider
,ItemsProvider
,RetractEventProvider
,SimpleNodeProvider
,SubscriptionsProvider
public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE>
This class simplifies parsing of embedded elements by using the Template Method Pattern. After extracting the current element attributes and content of any child elements, the template method (createReturnExtension(String, String, Map, List)
is called. Subclasses then override this method to create the specific return type.To use this class, you simply register your subclasses as extension providers in the smack.properties file. Then they will be automatically picked up and used to parse any child elements.
For example, given the following message <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo> <event xmlns='http://jabber.org/protocol/pubsub#event> <items node='princely_musings'> <item id='asdjkwei3i34234n356'> <entry xmlns='http://www.w3.org/2005/Atom'> <title>Soliloquy</title> <link rel='alternative' type='text/html'/> <id>tag:denmark.lit,2003:entry-32397</id> </entry> </item> </items> </event> </message> I would have a classes
ItemsProvider
extendsEmbeddedExtensionProvider
ItemProvider
extendsEmbeddedExtensionProvider
and AtomProvider extendsExtensionElementProvider
These classes are then registered in the meta-inf/smack.providers file as follows. <extensionProvider> <elementName>items</elementName> <namespace>http://jabber.org/protocol/pubsub#event</namespace> <className>org.jivesoftware.smackx.provider.ItemsEventProvider</className> </extensionProvider> <extensionProvider> <elementName>item</elementName> <namespace>http://jabber.org/protocol/pubsub#event</namespace> <className>org.jivesoftware.smackx.provider.ItemProvider</className> </extensionProvider>
-
-
Constructor Summary
Constructors Constructor Description EmbeddedExtensionProvider()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract PE
createReturnExtension(java.lang.String currentElement, java.lang.String currentNamespace, java.util.Map<java.lang.String,java.lang.String> attributeMap, java.util.List<? extends ExtensionElement> content)
PE
parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
-
Methods inherited from class org.jivesoftware.smack.provider.AbstractProvider
getElementClass
-
-
-
-
Constructor Detail
-
EmbeddedExtensionProvider
public EmbeddedExtensionProvider()
-
-
Method Detail
-
parse
public final PE parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, java.io.IOException, SmackParsingException
- Specified by:
parse
in classProvider<PE extends ExtensionElement>
- Throws:
XmlPullParserException
java.io.IOException
SmackParsingException
-
createReturnExtension
protected abstract PE createReturnExtension(java.lang.String currentElement, java.lang.String currentNamespace, java.util.Map<java.lang.String,java.lang.String> attributeMap, java.util.List<? extends ExtensionElement> content)
-
-