org.jivesoftware.smackx.pubsub
Class Item<E extends org.jivesoftware.smack.packet.PacketExtension>

java.lang.Object
  extended by org.jivesoftware.smackx.pubsub.Item<E>
All Implemented Interfaces:
org.jivesoftware.smack.packet.PacketExtension

public class Item<E extends org.jivesoftware.smack.packet.PacketExtension>
extends java.lang.Object
implements org.jivesoftware.smack.packet.PacketExtension

This class represents an item that has been, or will be published to a pubsub node. An Item has several properties that are dependent on the configuration of the node to which it has been or will be published.

An Item received from a node (via Node.getItems() or Node.addItemEventListener(org.jivesoftware.smackx.pubsub.listener.ItemEventListener)
  • Will always have an id (either user or server generated) unless node configuration has both ConfigureForm.isPersistItems() and ConfigureForm.isDeliverPayloads()set to false.
  • Will have a payload if the node configuration has ConfigureForm.isDeliverPayloads() set to true, otherwise it will be null.

    An Item created to send to a node (via Node.send() or Node.publish()
  • The id is optional, since the server will generate one if necessary, but should be used if it is meaningful in the context of the node. This value must be unique within the node that it is sent to, since resending an item with the same id will overwrite the one that already exists if the items are persisted.
  • Will require payload if the node configuration has ConfigureForm.isDeliverPayloads() set to true.

    To customise the payload object being returned from the getPayload() method, you can add a custom parser as explained in ItemProvider.

    Author:
    Robin Collier

    Constructor Summary
    Item()
              Create an empty Item with no id.
    Item(java.lang.String itemId)
              Create an Item with an id but no payload.
    Item(java.lang.String itemId, E payloadExt)
              Create an Item with an id and payload.
     
    Method Summary
     java.lang.String getElementName()
               
     java.lang.String getId()
              Get the item id.
     java.lang.String getNamespace()
               
     E getPayload()
              Get the payload associated with this Item.
     java.lang.String toString()
               
     java.lang.String toXML()
               
     
    Methods inherited from class java.lang.Object
    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Constructor Detail

    Item

    public Item()
    Create an empty Item with no id. This is a valid item for nodes which are configured so that ConfigureForm.isDeliverPayloads() is false. In most cases an id will be generated by the server. For nodes configured with ConfigureForm.isDeliverPayloads() and ConfigureForm.isPersistItems() set to false, no Item is sent to the node, you have to use Node.send() or Node.publish() methods in this case.


    Item

    public Item(java.lang.String itemId)
    Create an Item with an id but no payload. This is a valid item for nodes which are configured so that ConfigureForm.isDeliverPayloads() is false.

    Parameters:
    itemId - The id if the item. It must be unique within the node unless overwriting and existing item. Passing null is the equivalent of calling Item().

    Item

    public Item(java.lang.String itemId,
                E payloadExt)
    Create an Item with an id and payload.

    Parameters:
    itemId - The id of this item. It can be null if we want the server to set the id.
    payloadExt - A PacketExtension which represents the payload data.
    Method Detail

    getPayload

    public E getPayload()
    Get the payload associated with this Item. Customising the payload parsing from the server can be accomplished as described in ItemProvider.

    Returns:
    The payload as a PacketExtension.

    getId

    public java.lang.String getId()
    Get the item id. Unique to the node it is associated with.

    Returns:
    The id

    getElementName

    public java.lang.String getElementName()
    Specified by:
    getElementName in interface org.jivesoftware.smack.packet.PacketExtension

    getNamespace

    public java.lang.String getNamespace()
    Specified by:
    getNamespace in interface org.jivesoftware.smack.packet.PacketExtension

    toXML

    public java.lang.String toXML()
    Specified by:
    toXML in interface org.jivesoftware.smack.packet.PacketExtension

    toString

    public java.lang.String toString()
    Overrides:
    toString in class java.lang.Object