From e3ec422071d2503f69ab852fdd3a49944a6fc755 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 12 Jun 2019 22:30:56 +0200 Subject: [PATCH] Try to lookup QNAME first in XmppElementUtil.getQNameFor() --- .../smack/util/XmppElementUtil.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/XmppElementUtil.java b/smack-core/src/main/java/org/jivesoftware/smack/util/XmppElementUtil.java index caabf8e89..492b551c6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/XmppElementUtil.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/XmppElementUtil.java @@ -16,13 +16,30 @@ */ package org.jivesoftware.smack.util; +import java.util.logging.Logger; + import javax.xml.namespace.QName; import org.jivesoftware.smack.packet.FullyQualifiedElement; public class XmppElementUtil { + public static final Logger LOGGER = Logger.getLogger(XmppElementUtil.class.getName()); + public static QName getQNameFor(Class fullyQualifiedElement) { + try { + Object qnameObject = fullyQualifiedElement.getField("QNAME").get(null); + if (QName.class.isAssignableFrom(qnameObject.getClass())) { + return (QName) qnameObject; + } + LOGGER.warning("The QNAME field of " + fullyQualifiedElement + " is not of type QNAME."); + } catch (NoSuchFieldException e) { + LOGGER.finer("The class " + fullyQualifiedElement + " has no static QNAME field. Consider adding one."); + // Proceed to fallback strategy. + } catch (IllegalArgumentException | IllegalAccessException | SecurityException e) { + throw new IllegalArgumentException(e); + } + String element, namespace; try { element = (String) fullyQualifiedElement.getField("ELEMENT").get(null);