1 17 18 19 20 package org.apache.lenya.ac.impl; 21 22 import java.util.HashSet ; 23 import java.util.Set ; 24 25 import org.apache.lenya.ac.AccessControlException; 26 import org.apache.lenya.ac.Accreditable; 27 import org.apache.lenya.ac.Group; 28 import org.apache.lenya.ac.Groupable; 29 30 31 34 public abstract class AbstractGroup extends AbstractItem implements Accreditable, Group { 35 38 public AbstractGroup() { 39 } 40 41 45 public AbstractGroup(String id) { 46 setId(id); 47 } 48 49 private Set members = new HashSet (); 50 51 55 public Groupable[] getMembers() { 56 return (Groupable[]) members.toArray(new Groupable[members.size()]); 57 } 58 59 63 public void add(Groupable member) { 64 assert (member != null) && !members.contains(member); 65 members.add(member); 66 member.addedToGroup(this); 67 } 68 69 73 public void remove(Groupable member) { 74 assert (member != null) && members.contains(member); 75 members.remove(member); 76 member.removedFromGroup(this); 77 } 78 79 82 public void removeAllMembers() { 83 Groupable[] members = getMembers(); 84 for (int i = 0; i < members.length; i++) { 85 remove(members[i]); 86 } 87 } 88 89 94 public boolean contains(Groupable member) { 95 return members.contains(member); 96 } 97 98 101 public Accreditable[] getAccreditables() { 102 Accreditable[] accreditables = { this }; 103 return accreditables; 104 } 105 106 111 public void delete() throws AccessControlException { 112 Groupable[] members = getMembers(); 113 for (int i = 0; i < members.length; i++) { 114 remove(members[i]); 115 } 116 } 117 118 } 119 | Popular Tags |