Smack

org.jivesoftware.smackx.pubsub
Class Item

java.lang.Object
  extended by org.jivesoftware.smackx.pubsub.NodeExtension
      extended by org.jivesoftware.smackx.pubsub.Item
All Implemented Interfaces:
PacketExtension
Direct Known Subclasses:
PayloadItem

public class Item
extends NodeExtension

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 LeafNode.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 LeafNode.send() or LeafNode.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(String itemId)
              Create an Item with an id but no payload.
    Item(String itemId, String nodeId)
              Create an Item with an id and a node id.
     
    Method Summary
     String getId()
              Get the item id.
     String getNamespace()
              Returns the root element XML namespace.
     String toString()
               
     String toXML()
              Returns the XML representation of the PacketExtension.
     
    Methods inherited from class org.jivesoftware.smackx.pubsub.NodeExtension
    getElementName, getNode
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, 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 LeafNode.send() or LeafNode.publish() methods in this case.


    Item

    public Item(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(String itemId,
                String nodeId)
    Create an Item with an id and a node id.

    Note: This is not valid for publishing an item to a node, only receiving from one as part of Message. If used to create an Item to publish (via LeafNode.publish(Item), the server may return an error for an invalid packet.

    Parameters:
    itemId - The id of the item.
    nodeId - The id of the node which the item was published to.
    Method Detail

    getId

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

    Returns:
    The id

    getNamespace

    public String getNamespace()
    Description copied from interface: PacketExtension
    Returns the root element XML namespace.

    Specified by:
    getNamespace in interface PacketExtension
    Overrides:
    getNamespace in class NodeExtension
    Returns:
    the namespace.

    toXML

    public String toXML()
    Description copied from interface: PacketExtension
    Returns the XML representation of the PacketExtension.

    Specified by:
    toXML in interface PacketExtension
    Overrides:
    toXML in class NodeExtension
    Returns:
    the packet extension as XML.

    toString

    public String toString()
    Overrides:
    toString in class NodeExtension

    Smack

    Copyright © 2003-2007 Jive Software.