1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-12 19:02:06 +01:00

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

StateDescriptor String-based precedence API
This commit is contained in:
Florian Schmaus 2020-07-27 17:13:49 +02:00 committed by GitHub
commit d34eda61fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -22,12 +22,16 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; 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.ModularXmppClientToServerConnection;
import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal;
public abstract class StateDescriptor { public abstract class StateDescriptor {
private static final Logger LOGGER = Logger.getLogger(StateDescriptor.class.getName());
public enum Property { public enum Property {
multiVisitState, multiVisitState,
finalState, finalState,
@ -133,10 +137,35 @@ public abstract class StateDescriptor {
addAndCheckNonExistent(precedenceOver, subordinate); 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); 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) { private static <E> void addAndCheckNonExistent(Set<E> set, E e) {
boolean newElement = set.add(e); boolean newElement = set.add(e);
if (!newElement) { if (!newElement) {

View file

@ -91,7 +91,7 @@ public class StreamManagementModule extends ModularXmppClientToServerConnectionM
addPredeccessor(AuthenticatedButUnboundStateDescriptor.class); addPredeccessor(AuthenticatedButUnboundStateDescriptor.class);
addSuccessor(AuthenticatedAndResourceBoundStateDescriptor.class); addSuccessor(AuthenticatedAndResourceBoundStateDescriptor.class);
declarePrecedenceOver(ResourceBindingStateDescriptor.class); declarePrecedenceOver(ResourceBindingStateDescriptor.class);
declareInferiortyTo(CompressionStateDescriptor.class); declareInferiorityTo(CompressionStateDescriptor.class);
} }
@Override @Override