All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xmpp.packet.PacketExtension Maven / Gradle / Ivy

Go to download

Tinder is a Java based XMPP library, providing an implementation for XMPP stanzas and components. Tinders origins lie in code that's shared between Jive Software's Openfire and Whack implementations. The implementation that's provided in Tinder hasn't been written again from scratch. Instead, code has been moved from the original projects into Tinder, preserving al of the existing features and functionality. Most of the code that's now in Tinder is based on the org.xmpp package implementation that previously existed in Openfire and Whack. This is the code that defines classes such as Packet, JID, IQ, Component and their extensions. Additionally, some multi-purpose code (such as the DataForm and Result Set Management implementations have been moved to Tinder as well.

There is a newer version: 1.3.0
Show newest version
/**
 * Copyright (C) 2004-2008 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
 */

package org.xmpp.packet;

import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.QName;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 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 * {@link 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 */ public class PacketExtension { protected static DocumentFactory docFactory = DocumentFactory.getInstance(); /** * Subclasses of PacketExtension should register the element name and namespace that the * subclass is using. */ protected static Map> registeredExtensions = new ConcurrentHashMap>(); protected Element element; /** * 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". * * @param name the child element name. * @param namespace the child element namespace. * @return the extension class to use for the specified element name and namespace. */ public static Class getExtensionClass(String name, String namespace) { return registeredExtensions.get(QName.get(name, namespace)); } /** * Constructs a new Packet extension using the specified name and namespace. * * @param name the child element name. * @param namespace the child element namespace. */ public PacketExtension(String name, String namespace) { this.element = docFactory.createDocument().addElement(name, namespace); } /** * Constructs a new PacketExtension. * * @param element the XML Element that contains the packet extension contents. */ public PacketExtension(Element element) { this.element = element; } /** * 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. * * @return the DOM4J Element that represents the packet. */ public Element getElement() { return element; } /** * Creates a deep copy of this packet extension. * * @return a deep copy of this packet extension. */ public PacketExtension createCopy() { Element copy = element.createCopy(); docFactory.createDocument().add(copy); return new PacketExtension(element); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy