1 package de.webman.acl; 2 3 import com.teamkonzept.lib.ErrorCodes; 4 import com.teamkonzept.lib.TKException; 5 import com.teamkonzept.lib.TKVector; 6 import de.webman.acl.db.LoginDBData; 7 import com.teamkonzept.webman.mainint.events.TKUserException; 8 import com.teamkonzept.webman.mainint.events.UserCodes; 9 10 17 public class Profile 18 extends Login 19 { 20 21 23 25 30 protected Profile (LoginDBData data) 31 { 32 super(data); 33 } 34 35 36 38 44 public final ObjectFactory getFactory () 45 throws TKException 46 { 47 return ProfileFactory.getInstance(); 48 } 49 50 55 public final boolean isUser () 56 { 57 return false; 58 } 59 60 65 public final boolean isProfile () 66 { 67 return true; 68 } 69 70 78 public final boolean isParent (Login login) 79 throws TKException 80 { 81 if (hasChild(login)) 83 { 84 return true; 85 } 86 87 TKVector children = getChildren(); 89 90 if (children != null) 91 { 92 int index = 0; 93 int size = children.size(); 94 95 while (index < size) 96 { 97 if (((Login) children.elementAt(index)).isParent(login)) 98 { 99 return true; 100 } 101 102 index++; 103 } 104 } 105 106 return false; 108 } 109 110 120 public final boolean isMember (Login login) 121 throws TKException 122 { 123 return hasChild(login); 124 } 125 126 132 public final TKVector getChildren () 133 throws TKException 134 { 135 return LoginFactory.getInstance().getObjects(super.getAssociations()); 136 } 137 138 145 public final void addChild (Login child) 146 throws TKException 147 { 148 if (child.equals(this)) 150 { 151 throw new TKUserException("A group cannot contain itself.", 152 UserCodes.SELF_RELATION, 153 ErrorCodes.USER_SEVERITY, 154 true, 155 null); 156 } 157 158 if (child.isParent(this)) 160 { 161 throw new TKUserException("The group '" + 162 child.getName() + 163 "' is already contains this group.", 164 UserCodes.CYCLIC_RELATION, 165 ErrorCodes.USER_SEVERITY, 166 true, 167 new Object []{child.getName()}, 168 null); 169 } 170 171 super.addAssociation(child); 173 174 child.updatedParents(); 176 } 177 178 184 public final void removeChild (Login child) 185 throws TKException 186 { 187 super.removeAssociation(child); 189 190 child.updatedParents(); 192 } 193 194 199 public final void removeChildren () 200 throws TKException 201 { 202 TKVector children = LoginFactory.getInstance().getObjects(super.getAssociations()); 204 205 super.removeAssociations(); 207 208 if (children != null) 210 { 211 int index = 0; 212 int size = children.size(); 213 214 while (index < size) 215 { 216 ((Login) children.elementAt(index++)).updatedParents(); 217 } 218 } 219 } 220 221 229 public final boolean hasChild (Login login) 230 throws TKException 231 { 232 return super.containsAssociation(login); 233 } 234 235 } 236 | Popular Tags |