1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-15 20:12:04 +01:00

Add AndroidDebugger as possible debugger

Create AbstractXMPPConnection.DEBUGGERS with possible debugger classes.
This commit is contained in:
Florian Schmaus 2014-06-01 12:24:50 +02:00
parent f67d655fe7
commit 12b9e9d507

View file

@ -53,6 +53,15 @@ import org.jivesoftware.smack.packet.Session;
public abstract class AbstractXMPPConnection implements XMPPConnection { public abstract class AbstractXMPPConnection implements XMPPConnection {
private static final Logger LOGGER = Logger.getLogger(AbstractXMPPConnection.class.getName()); private static final Logger LOGGER = Logger.getLogger(AbstractXMPPConnection.class.getName());
/**
* Possible default debugger implementations. The order of enumeration is the one in which we try
* to instantiate these.
*/
private static final String[] DEBUGGERS = new String[] {
"org.jivesoftware.smackx.debugger.EnhancedDebugger",
"org.jivesoftware.smackx.debugger.android.AndroidDebugger",
"org.jivesoftware.smack.debugger.LiteDebugger" };
/** /**
* Counter to uniquely identify connections that are created. * Counter to uniquely identify connections that are created.
*/ */
@ -794,31 +803,39 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
if (debuggerClass == null) { if (debuggerClass == null) {
try { for (String debugger : DEBUGGERS) {
debuggerClass =
Class.forName("org.jivesoftware.smackx.debugger.EnhancedDebugger");
}
catch (Exception ex) {
try { try {
debuggerClass = debuggerClass = Class.forName(debugger);
Class.forName("org.jivesoftware.smack.debugger.LiteDebugger");
} }
catch (Exception ex2) { catch (ClassNotFoundException cnfe) {
LOGGER.fine("Did not find debugger class '" + debugger + "'");
}
catch (Exception ex) {
LOGGER.warning("Unabled to instantiate either Smack debugger class"); LOGGER.warning("Unabled to instantiate either Smack debugger class");
} }
if (debuggerClass != null) {
// We found a debugger, let's use it
break;
}
} }
} }
// Create a new debugger instance. If an exception occurs then disable the debugging if (debuggerClass != null) {
// option // Create a new debugger instance. If an exception occurs then disable the
try { // debugging
Constructor<?> constructor = debuggerClass // option
.getConstructor(XMPPConnection.class, Writer.class, Reader.class); try {
debugger = (SmackDebugger) constructor.newInstance(this, writer, reader); Constructor<?> constructor = debuggerClass.getConstructor(
reader = debugger.getReader(); XMPPConnection.class, Writer.class, Reader.class);
writer = debugger.getWriter(); debugger = (SmackDebugger) constructor.newInstance(this, writer, reader);
} reader = debugger.getReader();
catch (Exception e) { writer = debugger.getWriter();
throw new IllegalArgumentException("Can't initialize the configured debugger!", e); }
catch (Exception e) {
throw new IllegalArgumentException(
"Can't initialize the configured debugger!", e);
}
} else {
LOGGER.severe("Debugging enabled but could not find debugger class");
} }
} }
else { else {