01: package org.obe.runtime.strategy;
02:
03: import java.security.Principal;
04: import java.security.acl.Group;
05: import java.util.Comparator;
06: import java.util.Enumeration;
07: import java.util.Set;
08: import java.util.TreeSet;
09: import org.obe.spi.runtime.AssignmentStrategy;
10:
11: /**
12: * An abstract assignment strategy that provides useful functionality to
13: * subclasses.
14: *
15: * @author Adrian Price
16: */
17: public abstract class AbstractAssignmentStrategy implements
18: AssignmentStrategy {
19: private static final Comparator _principalComparator = new Comparator() {
20: public int compare(Object o1, Object o2) {
21: return ((Principal) o1).getName().compareTo(
22: ((Principal) o2).getName());
23: }
24: };
25:
26: protected AbstractAssignmentStrategy() {
27: }
28:
29: protected static Set expandGroup(Group group, Set participantSet) {
30: if (participantSet == null)
31: participantSet = new TreeSet(_principalComparator);
32: for (Enumeration e = group.members(); e.hasMoreElements();) {
33: Object member = e.nextElement();
34: if (member instanceof Group)
35: expandGroup((Group) member, participantSet);
36: else
37: participantSet.add(member);
38: }
39: return participantSet;
40: }
41:
42: protected static Set expandGroup(Group group) {
43: return expandGroup(group, null);
44: }
45:
46: protected static Set expandGroups(Principal[] principals,
47: Set participantSet) {
48:
49: if (participantSet == null)
50: participantSet = new TreeSet(_principalComparator);
51: for (int i = 0; i < principals.length; i++) {
52: Principal principal = principals[i];
53: if (principal instanceof Group)
54: expandGroup((Group) principal, participantSet);
55: else
56: participantSet.add(principal);
57: }
58: return participantSet;
59: }
60:
61: protected static Principal[] expandGroups(Principal[] principals) {
62: Set participants = expandGroups(principals, null);
63: if (principals.length != participants.size())
64: principals = new Principal[participants.size()];
65: return (Principal[]) participants.toArray(principals);
66: }
67: }
|