mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 11:38:00 +01:00
[core] Add String-based StateDescriptor precedence/inferiority declaration methods
This commit is contained in:
parent
64fb47c98b
commit
ec80d5287b
1 changed files with 29 additions and 0 deletions
|
@ -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 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) {
|
||||
|
|
Loading…
Reference in a new issue