Smack

org.jivesoftware.smack.packet
Class DefaultPacketExtension

java.lang.Object
  extended by org.jivesoftware.smack.packet.DefaultPacketExtension
All Implemented Interfaces:
PacketExtension

public class DefaultPacketExtension
extends Object
implements PacketExtension

Default implementation of the PacketExtension interface. Unless a PacketExtensionProvider is registered with ProviderManager, instances of this class will be returned when getting packet extensions.

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 PacketExtensionProvider should be used.

Author:
Matt Tucker

Constructor Summary
DefaultPacketExtension(String elementName, String namespace)
          Creates a new generic packet extension.
 
Method Summary
 String getElementName()
          Returns the XML element name of the extension sub-packet root element.
 Collection<String> getNames()
          Returns an unmodifiable collection of the names that can be used to get values of the packet extension.
 String getNamespace()
          Returns the XML namespace of the extension sub-packet root element.
 String getValue(String name)
          Returns a packet extension value given a name.
 void setValue(String name, String value)
          Sets a packet extension value using the given name.
 String toXML()
          Returns the XML representation of the PacketExtension.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPacketExtension

public DefaultPacketExtension(String elementName,
                              String namespace)
Creates a new generic packet extension.

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 extension sub-packet root element.

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

getNamespace

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

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

toXML

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

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

getNames

public Collection<String> getNames()
Returns an unmodifiable collection of the names that can be used to get values of the packet extension.

Returns:
the names.

getValue

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

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

setValue

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

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

Smack

Copyright © 2003-2007 Jive Software.