1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-09 10:19:41 +02:00

Add (IQ|PacketExtension)IntrospectionProvider

This simplifies code as there is no longer a distinction between
"normal" providers and introspection providers in ProviderManager
necessary.

It's also easier to get an idea where introspection is used for parsing.
This commit is contained in:
Florian Schmaus 2014-12-10 11:06:04 +01:00
parent 00f5008794
commit 77f0fdc156
11 changed files with 284 additions and 212 deletions

View file

@ -17,13 +17,16 @@ There are two types of providers:
* jabber:iq:roster
* jabber:iq:register There are many more IQ types and extensions that are part of XMPP standards, and of course an endless number that can be added as custom extensions. To support this, an extensible parsing mechanism is provided via Smack and user build providers.
Whenever a packet extension is found in a packet, parsing will be passed to
the correct provider. Each provider 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,
via the [XML Pull Parser](http://www.xmlpull.org/), 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.
Whenever a packet extension is found in a packet, parsing will be
passed to the correct provider. Each provider must implement the
PacketExtensionProvider interface. Each extension provider is
responsible for parsing the raw XML stream, via the
[XML Pull Parser](http://www.xmlpull.org/), to contruct an object.
You can also create an introspection provider
(`provider.IntrospectionProvider.PacketExtensionIntrospectionProvider`). Here,
bean introspection is used to try to automatically set the properties
of the class using the values in the packet extension sub-element.
When no extension provider is registered for an element name and namespace
combination, Smack will store all top-level elements of the sub-packet in the
@ -58,17 +61,17 @@ or
IQ Providers
------------
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 in the IQ packet XML. For example, an XMPP
time packet resembles the following:
The IQ provider class must implement the IQProvider interface. Each
IQProvider is responsible for parsing the raw XML stream to create an
IQ instance.
### Introspection (DEPRECATED)
You can also create an introspection provider
(`provider.IntrospectionProvider.IQIntrospectionProvider`). Which
uses, bean introspection to try to automatically set properties of the
IQ instance using the values found in the IQ packet XML. For example,
an XMPP time packet resembles the following:
*Note*: This feature is deprecated, using introspection for parsing is not recommended.
Instead implement your own provider like shown in the next section.
### Introspection
_Time Packet_
@ -111,6 +114,18 @@ _Time IQ Class_
}
}
_Time Provider_
```java
public class TimeProvider extends IQIntrospectionProvider<Time> {
public TimeProvider() {
super(Time.class);
}
}
```
The introspection service will automatically try to convert the String value
from the XML into a boolean, int, long, float, double, or Class depending on
the type the IQ instance expects.