diff --git a/smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptor.java b/smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptor.java index aec14b18e..8f399480e 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptor.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptor.java @@ -22,12 +22,16 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection; import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; public abstract class StateDescriptor { + private static final Logger LOGGER = Logger.getLogger(StateDescriptor.class.getName()); + public enum Property { multiVisitState, finalState, @@ -133,10 +137,35 @@ public abstract class StateDescriptor { addAndCheckNonExistent(precedenceOver, subordinate); } - protected void declareInferiortyTo(Class superior) { + protected void declarePrecedenceOver(String subordinate) { + addAndCheckNonExistent(precedenceOver, subordinate); + } + + protected void declareInferiorityTo(Class superior) { addAndCheckNonExistent(inferiorTo, superior); } + protected void declareInferiorityTo(String superior) { + addAndCheckNonExistent(inferiorTo, superior); + } + + private static void addAndCheckNonExistent(Set> set, String clazzName) { + Class clazz; + try { + clazz = Class.forName(clazzName); + } catch (ClassNotFoundException e) { + // The state descriptor class is not in classpath, which probably means that the smack module is not loaded + // into the classpath. Hence we can silently ignore that. + LOGGER.log(Level.FINEST, "Ignoring unknown state descriptor '" + clazzName + "'", e); + return; + } + if (!StateDescriptor.class.isAssignableFrom(clazz)) { + throw new IllegalArgumentException(clazz + " is no state descriptor class"); + } + Class stateDescriptorClass = clazz.asSubclass(StateDescriptor.class); + addAndCheckNonExistent(set, stateDescriptorClass); + } + private static void addAndCheckNonExistent(Set set, E e) { boolean newElement = set.add(e); if (!newElement) { diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/sm/StreamManagementModule.java b/smack-tcp/src/main/java/org/jivesoftware/smack/sm/StreamManagementModule.java index 58be31a34..1a6c78a93 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/sm/StreamManagementModule.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/sm/StreamManagementModule.java @@ -91,7 +91,7 @@ public class StreamManagementModule extends ModularXmppClientToServerConnectionM addPredeccessor(AuthenticatedButUnboundStateDescriptor.class); addSuccessor(AuthenticatedAndResourceBoundStateDescriptor.class); declarePrecedenceOver(ResourceBindingStateDescriptor.class); - declareInferiortyTo(CompressionStateDescriptor.class); + declareInferiorityTo(CompressionStateDescriptor.class); } @Override