Merge pull request #414 from Flowdalic/state-string-precedence

StateDescriptor String-based precedence API
listEqualsHashcode
Florian Schmaus 2 years ago committed by GitHub
commit d34eda61fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      smack-core/src/main/java/org/jivesoftware/smack/fsm/StateDescriptor.java
  2. 2
      smack-tcp/src/main/java/org/jivesoftware/smack/sm/StreamManagementModule.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<? extends StateDescriptor> superior) {
protected void declarePrecedenceOver(String subordinate) {
addAndCheckNonExistent(precedenceOver, subordinate);
}
protected void declareInferiorityTo(Class<? extends StateDescriptor> superior) {
addAndCheckNonExistent(inferiorTo, superior);
}
protected void declareInferiorityTo(String superior) {
addAndCheckNonExistent(inferiorTo, superior);
}
private static void addAndCheckNonExistent(Set<Class<? extends StateDescriptor>> 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<? extends StateDescriptor> stateDescriptorClass = clazz.asSubclass(StateDescriptor.class);
addAndCheckNonExistent(set, stateDescriptorClass);
}
private static <E> void addAndCheckNonExistent(Set<E> set, E e) {
boolean newElement = set.add(e);
if (!newElement) {

@ -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

Loading…
Cancel
Save