Commit 43518e30 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Always return a PacketExtension implementation.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5954 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1fa86029
...@@ -248,17 +248,20 @@ public abstract class Packet { ...@@ -248,17 +248,20 @@ public abstract class Packet {
List extensions = element.elements(QName.get(name, namespace)); List extensions = element.elements(QName.get(name, namespace));
if (!extensions.isEmpty()) { if (!extensions.isEmpty()) {
Class extensionClass = PacketExtension.getExtensionClass(name, namespace); Class extensionClass = PacketExtension.getExtensionClass(name, namespace);
// If a specific PacketExtension implementation has been registered, use that.
if (extensionClass != null) { if (extensionClass != null) {
try { try {
Constructor constructor = extensionClass.getDeclaredConstructor(new Class[]{ Constructor constructor = extensionClass.getDeclaredConstructor(Element.class);
Element.class}); return (PacketExtension)constructor.newInstance(extensions.get(0));
return (PacketExtension) constructor.newInstance(new Object[]{
extensions.get(0)});
} }
catch (Exception e) { catch (Exception e) {
// Ignore. // Ignore.
} }
} }
// Otherwise, use a normal PacketExtension.
else {
return new PacketExtension((Element)extensions.get(0));
}
} }
return null; return null;
} }
......
...@@ -32,15 +32,16 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -32,15 +32,16 @@ import java.util.concurrent.ConcurrentHashMap;
* PacketExtension acts as a wrapper on a child element the same way Packet does for a whole * 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.<p> * element. The wrapper provides an easy way to handle the packet extension.<p>
* *
* Subclasses of this class should be registered in the static variable * Subclasses of this class can be registered using the static variable
* <tt>registeredExtensions</tt> when loaded. The registration process associates the new subclass * <tt>registeredExtensions</tt>. The registration process associates the new subclass
* with a given qualified name (ie. element name and namespace). This information will be used by * 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 * {@link Packet#getExtension(String, String)} for locating the corresponding PacketExtension
* subclass to return for the requested qualified name. * 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 * @author Gaston Dombiak
*/ */
public abstract class PacketExtension { public class PacketExtension {
protected static DocumentFactory docFactory = DocumentFactory.getInstance(); protected static DocumentFactory docFactory = DocumentFactory.getInstance();
/** /**
...@@ -99,5 +100,9 @@ public abstract class PacketExtension { ...@@ -99,5 +100,9 @@ public abstract class PacketExtension {
* *
* @return a deep copy of this packet extension. * @return a deep copy of this packet extension.
*/ */
public abstract PacketExtension createCopy(); public PacketExtension createCopy() {
Element copy = element.createCopy();
docFactory.createDocument().add(copy);
return new PacketExtension(element);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment