Class PacketExtension

  • Direct Known Subclasses:
    DataForm

    @NotThreadSafe
    public class PacketExtension
    extends Object
    A packet extension represents a child element of a Packet for a given qualified name. The PacketExtension acts as a wrapper on a child element the same way Packet does for a whole element. The wrapper provides an easy way to handle the packet extension.

    Subclasses of this class can be registered using the static variable registeredExtensions. The registration process associates the new subclass with a given qualified name (ie. element name and namespace). This information will be used by Packet.getExtension(String, String) for locating the corresponding PacketExtension subclass to return for the requested qualified name. Each PacketExtension must have a public constructor that takes an Element instance as an argument.

    Author:
    Gaston Dombiak
    • Field Detail

      • docFactory

        protected static final org.dom4j.DocumentFactory docFactory
      • registeredExtensions

        protected static final Map<org.dom4j.QName,​Class<? extends PacketExtension>> registeredExtensions
        Subclasses of PacketExtension should register the element name and namespace that the subclass is using.
      • element

        protected org.dom4j.Element element
    • Constructor Detail

      • PacketExtension

        public PacketExtension​(String name,
                               String namespace)
        Constructs a new Packet extension using the specified name and namespace.
        Parameters:
        name - the child element name.
        namespace - the child element namespace.
      • PacketExtension

        public PacketExtension​(org.dom4j.Element element)
        Constructs a new PacketExtension.
        Parameters:
        element - the XML Element that contains the packet extension contents.
    • Method Detail

      • getExtensionClass

        public static Class<? extends PacketExtension> getExtensionClass​(String name,
                                                                         String namespace)
        Returns the extension class to use for the specified element name and namespace. For instance, the DataForm class should be used for the element "x" and namespace "jabber:x:data".
        Parameters:
        name - the child element name.
        namespace - the child element namespace.
        Returns:
        the extension class to use for the specified element name and namespace.
      • getElement

        public org.dom4j.Element getElement()
        Returns the DOM4J Element that backs the packet. The element is the definitive representation of the packet and can be manipulated directly to change packet contents.
        Returns:
        the DOM4J Element that represents the packet.
      • createCopy

        public PacketExtension createCopy()
        Creates a deep copy of this packet extension.
        Returns:
        a deep copy of this packet extension.