Smack

org.jivesoftware.smackx.packet
Class DefaultPrivateData

java.lang.Object
  extended by org.jivesoftware.smackx.packet.DefaultPrivateData
All Implemented Interfaces:
PrivateData

public class DefaultPrivateData
extends Object
implements PrivateData

Default implementation of the PrivateData interface. Unless a PrivateDataProvider is registered with the PrivateDataManager class, instances of this class will be returned when getting private data.

This class provides a very simple representation of an XML sub-document. Each element is a key in a Map with its CDATA being the value. For example, given the following XML sub-document:

 <foo xmlns="http://bar.com">
     <color>blue</color>
     <food>pizza</food>
 </foo>
In this case, getValue("color") would return "blue", and getValue("food") would return "pizza". This parsing mechanism mechanism is very simplistic and will not work as desired in all cases (for example, if some of the elements have attributes. In those cases, a custom PrivateDataProvider should be used.

Author:
Matt Tucker

Constructor Summary
DefaultPrivateData(String elementName, String namespace)
          Creates a new generic private data object.
 
Method Summary
 String getElementName()
          Returns the XML element name of the private data sub-packet root element.
 Iterator<String> getNames()
          Returns an Iterator for the names that can be used to get values of the private data.
 String getNamespace()
          Returns the XML namespace of the private data sub-packet root element.
 String getValue(String name)
          Returns a value given a name.
 void setValue(String name, String value)
          Sets a value given the name.
 String toXML()
          Returns the XML reppresentation of the PrivateData.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPrivateData

public DefaultPrivateData(String elementName,
                          String namespace)
Creates a new generic private data object.

Parameters:
elementName - the name of the element of the XML sub-document.
namespace - the namespace of the element.
Method Detail

getElementName

public String getElementName()
Returns the XML element name of the private data sub-packet root element.

Specified by:
getElementName in interface PrivateData
Returns:
the XML element name of the packet extension.

getNamespace

public String getNamespace()
Returns the XML namespace of the private data sub-packet root element.

Specified by:
getNamespace in interface PrivateData
Returns:
the XML namespace of the packet extension.

toXML

public String toXML()
Description copied from interface: PrivateData
Returns the XML reppresentation of the PrivateData.

Specified by:
toXML in interface PrivateData
Returns:
the private data as XML.

getNames

public Iterator<String> getNames()
Returns an Iterator for the names that can be used to get values of the private data.

Returns:
an Iterator for the names.

getValue

public String getValue(String name)
Returns a value given a name.

Parameters:
name - the name.
Returns:
the value.

setValue

public void setValue(String name,
                     String value)
Sets a value given the name.

Parameters:
name - the name.
value - the value.

Smack

Copyright © 2003-2007 Jive Software.