public abstract class AbstractPacketExtension
extends java.lang.Object
implements org.jivesoftware.smack.packet.PacketExtension
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.Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.Object> |
attributes
A map of all attributes that this extension is currently using.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractPacketExtension(java.lang.String namespace,
java.lang.String elementName)
Creates an
AbstractPacketExtension instance for the specified
namespace and elementName. |
Modifier and Type | Method and Description |
---|---|
void |
addChildExtension(org.jivesoftware.smack.packet.PacketExtension childExtension)
Adds the specified childExtension to the list of extensions
registered with this packet.
|
void |
addPacket(org.jivesoftware.smack.packet.Packet packet)
Adds packet to the list of packets.
|
static <T extends AbstractPacketExtension> |
clone(T src)
Clones the attributes, namespace and text of a specific
AbstractPacketExtension into a new
AbstractPacketExtension instance of the same run-time type.
|
java.lang.Object |
getAttribute(java.lang.String attribute)
Returns the attribute with the specified name from the list of
attributes registered with this packet extension.
|
int |
getAttributeAsInt(java.lang.String attribute)
Returns the int value of the attribute with the specified
name.
|
int |
getAttributeAsInt(java.lang.String attribute,
int defaultValue)
Returns the int value of the attribute with the specified
name.
|
java.lang.String |
getAttributeAsString(java.lang.String attribute)
Returns the string value of the attribute with the specified
name.
|
java.net.URI |
getAttributeAsURI(java.lang.String attribute)
Tries to parse the value of the specified attribute as an
URI and returns it.
|
java.util.List<java.lang.String> |
getAttributeNames()
Gets the names of the attributes which currently have associated values
in this extension.
|
java.util.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> |
getChildExtensionsOfType(java.lang.Class<T> type)
Returns this packet's direct child extensions that match the
specified type.
|
java.lang.String |
getElementName()
Returns the name of the encryption element.
|
<T extends org.jivesoftware.smack.packet.PacketExtension> |
getFirstChildOfType(java.lang.Class<T> type)
Returns this packet's first direct child extension that matches the
specified type.
|
java.lang.String |
getNamespace()
Returns the XML namespace for this element or null if the
element does not live in a namespace of its own.
|
java.util.List<org.jivesoftware.smack.packet.Packet> |
getPackets()
Returns the list of packets.
|
java.lang.String |
getText()
Returns the text content of this extension or null if no text
content has been specified so far.
|
void |
removeAttribute(java.lang.String name)
Removes the attribute with the specified name from the list of
attributes registered with this packet extension.
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets the value of the attribute named name to value.
|
void |
setNamespace(java.lang.String namespace)
Set the XML namespace for this element.
|
void |
setText(java.lang.String text)
Specifies the text content of this extension.
|
java.lang.String |
toXML()
Returns an XML representation of this extension.
|
protected final java.util.Map<java.lang.String,java.lang.Object> attributes
protected AbstractPacketExtension(java.lang.String namespace, java.lang.String elementName)
AbstractPacketExtension
instance for the specified
namespace and elementName.namespace
- the XML namespace for this element.elementName
- the name of the elementpublic java.lang.String getElementName()
getElementName
in interface org.jivesoftware.smack.packet.PacketExtension
public void setNamespace(java.lang.String namespace)
namespace
- the XML namespace for this element.public java.lang.String getNamespace()
getNamespace
in interface org.jivesoftware.smack.packet.PacketExtension
public java.lang.String toXML()
toXML
in interface org.jivesoftware.smack.packet.PacketExtension
public java.util.List<? extends org.jivesoftware.smack.packet.PacketExtension> getChildExtensions()
Overriding extensions may need to override this method if they would like to have anything more elaborate than just a list of extensions.
List
of elements that this packet extension contains.public void addChildExtension(org.jivesoftware.smack.packet.PacketExtension childExtension)
childExtension
- the extension we'd like to add here.public java.util.List<org.jivesoftware.smack.packet.Packet> getPackets()
public void addPacket(org.jivesoftware.smack.packet.Packet packet)
packet
- the packet to add.public void setAttribute(java.lang.String name, java.lang.Object value)
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.public void removeAttribute(java.lang.String name)
name
- the name of the attribute that we are removing.public java.lang.Object getAttribute(java.lang.String attribute)
attribute
- the name of the attribute that we'd like to retrieve.public java.lang.String getAttributeAsString(java.lang.String attribute)
attribute
- the name of the attribute that we'd like to retrieve.public int getAttributeAsInt(java.lang.String attribute)
attribute
- the name of the attribute that we'd like to retrieve.public int getAttributeAsInt(java.lang.String attribute, int defaultValue)
attribute
- the name of the attribute that we'd like to retrievedefaultValue
- the int to be returned as the value of the
specified attribute if no such attribute is currently registered with
this extensionpublic java.net.URI getAttributeAsURI(java.lang.String attribute) throws java.lang.IllegalArgumentException
attribute
- the name of the attribute that we'd like to retrieve.java.lang.IllegalArgumentException
- if attribute is not a valid URI
public java.util.List<java.lang.String> getAttributeNames()
public void setText(java.lang.String text)
text
- the text content of this extension.public java.lang.String getText()
public <T extends org.jivesoftware.smack.packet.PacketExtension> T getFirstChildOfType(java.lang.Class<T> type)
T
- the specific type of PacketExtension to be returnedtype
- the Class of the extension we are looking for.public <T extends org.jivesoftware.smack.packet.PacketExtension> java.util.List<T> getChildExtensionsOfType(java.lang.Class<T> type)
T
- the specific PacketExtension type of child extensions
to be returnedtype
- the Class of the extension we are looking for.public static <T extends AbstractPacketExtension> T clone(T src)
src
- the AbstractPacketExtension to be clonedjava.lang.Exception
- if an error occurs during the cloning of the specified
src
Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under Apache license.