From 77f0fdc15610aa824271c3317a3966a9170726f5 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 10 Dec 2014 11:06:04 +0100 Subject: [PATCH] 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. --- documentation/providers.md | 47 ++++-- .../smack/provider/ExtensionProviderInfo.java | 10 -- .../smack/provider/IQProviderInfo.java | 11 -- .../smack/provider/IntrospectionProvider.java | 143 ++++++++++++++++++ .../smack/provider/ProviderFileLoader.java | 15 +- .../smack/provider/ProviderManager.java | 39 +---- .../smack/util/PacketParserUtils.java | 104 ++----------- .../smackx/time/provider/TimeProvider.java | 28 ++++ .../extensions.providers | 2 +- .../smackx/time/packet/TimeTest.java | 36 ----- .../time/provider/TimeProviderTest.java | 61 ++++++++ 11 files changed, 284 insertions(+), 212 deletions(-) create mode 100644 smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/time/provider/TimeProvider.java create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/time/provider/TimeProviderTest.java diff --git a/documentation/providers.md b/documentation/providers.md index 492a9d26e..a37c7be0c 100644 --- a/documentation/providers.md +++ b/documentation/providers.md @@ -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