Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.jabber.extensions
Class AbstractPacketExtension

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.jabber.extensions.AbstractPacketExtension
All Implemented Interfaces:
org.jivesoftware.smack.packet.PacketExtension
Direct Known Subclasses:
BandwidthPacketExtension, CallInfoPacketExtension, CandidatePacketExtension, CoinPacketExtension, ConferenceMediaPacketExtension, ConferenceMediumPacketExtension, ContentPacketExtension, CryptoPacketExtension, DescriptionPacketExtension, EncryptionPacketExtension, EndpointPacketExtension, ExecutionPacketExtension, HostInfoPacketExtension, IceUdpTransportPacketExtension, InputEvtPacketExtension, MediaPacketExtension, ParameterPacketExtension, PayloadTypePacketExtension, RedirectPacketExtension, RelayPacketExtension, RtpDescriptionPacketExtension, RTPHdrExtPacketExtension, ServerPacketExtension, SessionInfoPacketExtension, SidebarsByValPacketExtension, SIPDialogIDPacketExtension, SrcIdPacketExtension, StatePacketExtension, StunPacketExtension, TransferPacketExtension, TransferredPacketExtension, URIPacketExtension, URIsPacketExtension, UsagePacketExtension, UserLanguagesPacketExtension, UserPacketExtension, UserRolesPacketExtension, UsersPacketExtension, ZrtpHashPacketExtension

public abstract class AbstractPacketExtension
extends Object
implements org.jivesoftware.smack.packet.PacketExtension

A generic implementation of PacketExtension. The purpose of this class is quite similar to that of smack's DefaultPacketExtension with the main difference being that this one is meant primarily for extension rather than using as a fallback for unknown elements. We let for example our descendants handle child elements and we automate attribute handling instead.

Author:
Emil Ivov, Lyubomir Marinov

Field Summary
protected  Map<String,String> attributes
          A map of all attributes that this extension is currently using.
 
Constructor Summary
protected AbstractPacketExtension(String namespace, String elementName)
          Creates an AbstractPacketExtension instance for the specified namespace and elementName.
 
Method Summary
 void addChildExtension(org.jivesoftware.smack.packet.PacketExtension childExtension)
          Adds the specified childExtension to the list of extensions registered with this packet.
 Object getAttribute(String attribute)
          Returns the attribute with the specified name from the list of attributes registered with this packet extension.
 int getAttributeAsInt(String attribute)
          Returns the int value of the attribute with the specified name.
 int getAttributeAsInt(String attribute, int defaultValue)
          Returns the int value of the attribute with the specified name.
 String getAttributeAsString(String attribute)
          Returns the string value of the attribute with the specified name.
 URI getAttributeAsURI(String attribute)
          Tries to parse the value of the specified attribute as an URI and returns it.
 List<String> getAttributeNames()
          Gets the names of the attributes which currently have associated values in this extension.
 List<? extends org.jivesoftware.smack.packet.PacketExtension> getChildExtensions()
          Returns all sub-elements for this AbstractPacketExtension or null if there aren't any.
<T extends org.jivesoftware.smack.packet.PacketExtension>
List<T>
getChildExtensionsOfType(Class<T> type)
          Returns this packet's direct child extensions that match the specified type.
 String getElementName()
          Returns the name of the encryption element.
<T extends org.jivesoftware.smack.packet.PacketExtension>
T
getFirstChildOfType(Class<T> type)
          Returns this packet's first direct child extension that matches the specified type.
 String getNamespace()
          Returns the XML namespace for this element or null if the element does not live in a namespace of its own.
 String getText()
          Returns the text content of this extension or null if no text content has been specified so far.
 void removeAttribute(String name)
          Removes the attribute with the specified name from the list of attributes registered with this packet extension.
 void setAttribute(String name, Object value)
          Sets the value of the attribute named name to value.
 void setNamespace(String namespace)
          Set the XML namespace for this element.
 void setText(String text)
          Specifies the text content of this extension.
 String toXML()
          Returns an XML representation of this extension.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

protected final Map<String,String> attributes
A map of all attributes that this extension is currently using.

Constructor Detail

AbstractPacketExtension

protected AbstractPacketExtension(String namespace,
                                  String elementName)
Creates an AbstractPacketExtension instance for the specified namespace and elementName.

Parameters:
namespace - the XML namespace for this element.
elementName - the name of the element
Method Detail

getElementName

public String getElementName()
Returns the name of the encryption element.

Specified by:
getElementName in interface org.jivesoftware.smack.packet.PacketExtension
Returns:
the name of the encryption element.

setNamespace

public void setNamespace(String namespace)
Set the XML namespace for this element.

Parameters:
namespace - the XML namespace for this element.

getNamespace

public String getNamespace()
Returns the XML namespace for this element or null if the element does not live in a namespace of its own.

Specified by:
getNamespace in interface org.jivesoftware.smack.packet.PacketExtension
Returns:
the XML namespace for this element or null if the element does not live in a namespace of its own.

toXML

public String toXML()
Returns an XML representation of this extension.

Specified by:
toXML in interface org.jivesoftware.smack.packet.PacketExtension
Returns:
an XML representation of this extension.

getChildExtensions

public List<? extends org.jivesoftware.smack.packet.PacketExtension> getChildExtensions()
Returns all sub-elements for this AbstractPacketExtension or null if there aren't any.

Overriding extensions may need to override this method if they would like to have anything more elaborate than just a list of extensions.

Returns:
the List of elements that this packet extension contains.

addChildExtension

public void addChildExtension(org.jivesoftware.smack.packet.PacketExtension childExtension)
Adds the specified childExtension to the list of extensions registered with this packet.

Overriding extensions may need to override this method if they would like to have anything more elaborate than just a list of extensions (e.g. casting separate instances to more specific.

Parameters:
childExtension - the extension we'd like to add here.

setAttribute

public void setAttribute(String name,
                         Object value)
Sets the value of the attribute named name to value.

Parameters:
name - the name of the attribute that we are setting.
value - an Object whose toString() method returns the XML value of the attribute we are setting or null if we'd like to remove the attribute with the specified name.

removeAttribute

public void removeAttribute(String name)
Removes the attribute with the specified name from the list of attributes registered with this packet extension.

Parameters:
name - the name of the attribute that we are removing.

getAttribute

public Object getAttribute(String attribute)
Returns the attribute with the specified name from the list of attributes registered with this packet extension.

Parameters:
attribute - the name of the attribute that we'd like to retrieve.
Returns:
the value of the specified attribute or null if no such attribute is currently registered with this extension.

getAttributeAsString

public String getAttributeAsString(String attribute)
Returns the string value of the attribute with the specified name.

Parameters:
attribute - the name of the attribute that we'd like to retrieve.
Returns:
the String value of the specified attribute or null if no such attribute is currently registered with this extension.

getAttributeAsInt

public int getAttributeAsInt(String attribute)
Returns the int value of the attribute with the specified name.

Parameters:
attribute - the name of the attribute that we'd like to retrieve.
Returns:
the int value of the specified attribute or -1 if no such attribute is currently registered with this extension.

getAttributeAsInt

public int getAttributeAsInt(String attribute,
                             int defaultValue)
Returns the int value of the attribute with the specified name.

Parameters:
attribute - the name of the attribute that we'd like to retrieve
defaultValue - the int to be returned as the value of the specified attribute if no such attribute is currently registered with this extension
Returns:
the int value of the specified attribute or defaultValue if no such attribute is currently registered with this extension

getAttributeAsURI

public URI getAttributeAsURI(String attribute)
                      throws IllegalArgumentException
Tries to parse the value of the specified attribute as an URI and returns it.

Parameters:
attribute - the name of the attribute that we'd like to retrieve.
Returns:
the URI value of the specified attribute or null if no such attribute is currently registered with this extension.
Throws:
IllegalArgumentException - if attribute is not a valid URI

getAttributeNames

public List<String> getAttributeNames()
Gets the names of the attributes which currently have associated values in this extension.

Returns:
the names of the attributes which currently have associated values in this extension

setText

public void setText(String text)
Specifies the text content of this extension.

Parameters:
text - the text content of this extension.

getText

public String getText()
Returns the text content of this extension or null if no text content has been specified so far.

Returns:
the text content of this extension or null if no text content has been specified so far.

getFirstChildOfType

public <T extends org.jivesoftware.smack.packet.PacketExtension> T getFirstChildOfType(Class<T> type)
Returns this packet's first direct child extension that matches the specified type.

Type Parameters:
T - the specific type of PacketExtension to be returned
Parameters:
type - the Class of the extension we are looking for.
Returns:
this packet's first direct child extension that matches specified type or null if no such child extension was found.

getChildExtensionsOfType

public <T extends org.jivesoftware.smack.packet.PacketExtension> List<T> getChildExtensionsOfType(Class<T> type)
Returns this packet's direct child extensions that match the specified type.

Type Parameters:
T - the specific PacketExtension type of child extensions to be returned
Parameters:
type - the Class of the extension we are looking for.
Returns:
a (possibly empty) list containing all of this packet's direct child extensions that match the specified type

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.