/** * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jivesoftware.smackx.pubsub; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smackx.pubsub.provider.ItemProvider; import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; /** * 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. * *
To customise the payload object being returned from the {@link #getPayload()} method, you can
* add a custom parser as explained in {@link ItemProvider}.
*
* @author Robin Collier
*/
public class PayloadItem
* Note: This is not valid for publishing an item to a node, only receiving from
* one as part of {@link Message}. If used to create an Item to publish
* (via {@link LeafNode#publish(Item)}, the server may return an
* error for an invalid packet.
*
* @param itemId The id of this item.
* @param nodeId The id of the node the item was published to.
* @param payloadExt A {@link PacketExtension} which represents the payload data.
*/
public PayloadItem(String itemId, String nodeId, E payloadExt)
{
super(itemId, nodeId);
if (payloadExt == null)
throw new IllegalArgumentException("payload cannot be 'null'");
payload = payloadExt;
}
/**
* Get the payload associated with this Item. Customising the payload
* parsing from the server can be accomplished as described in {@link ItemProvider}.
*
* @return The payload as a {@link PacketExtension}.
*/
public E getPayload()
{
return payload;
}
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("