1 23 24 package org.apache.webdav.lib; 25 26 import java.util.Enumeration ; 27 import java.util.Vector ; 28 29 34 public class Ace { 35 private static final PropertyName DEFAULT_PROPERTY 36 = new PropertyName("DAV:", "owner"); 37 38 40 41 public Ace(String principal) { 42 this.principal = principal; 43 } 44 45 46 public Ace(String principal, boolean negative, boolean protectedAce, 47 boolean inherited, String inheritedFrom) { 48 this(principal); 49 this.negative = negative; 50 this.protectedAce = protectedAce; 51 this.inherited = inherited; 52 this.inheritedFrom = inheritedFrom; 53 } 54 55 56 58 59 62 protected String principal; 63 64 65 68 protected boolean negative = false; 69 70 71 74 protected Vector privileges = new Vector (); 75 76 77 80 protected boolean protectedAce = false; 81 82 83 86 protected boolean inherited = false; 87 88 89 92 protected String inheritedFrom = null; 93 94 95 98 protected PropertyName property = null; 99 100 101 103 104 107 public String getPrincipal() { 108 return principal; 109 } 110 111 112 115 public void setPrincipal(String principal) { 116 this.principal = principal; 117 } 118 119 120 123 public boolean isNegative() { 124 return (negative); 125 } 126 127 128 131 public void setNegative(boolean negative) { 132 this.negative = negative; 133 } 134 135 136 139 public boolean isProtected() { 140 return (protectedAce); 141 } 142 143 144 147 public void setProtected(boolean protectedAce) { 148 this.protectedAce = protectedAce; 149 } 150 151 152 155 public boolean isInherited() { 156 return (inherited); 157 } 158 159 160 163 public void setInherited(boolean inherited) { 164 this.inherited = inherited; 165 } 166 167 168 171 public String getInheritedFrom() { 172 return inheritedFrom; 173 } 174 175 176 179 public void setInheritedFrom(String inheritedFrom) { 180 this.inheritedFrom = inheritedFrom; 181 } 182 183 184 192 public PropertyName getProperty() { 193 return property != null ? property : DEFAULT_PROPERTY; 194 } 195 196 197 203 public void setProperty(PropertyName property) { 204 this.property = property; 205 } 206 207 208 211 public Enumeration enumeratePrivileges() { 212 return privileges.elements(); 213 } 214 215 216 219 public void addPrivilege(Privilege privilege) { 220 privileges.addElement(privilege); 221 } 222 223 224 227 public boolean removePrivilege(Privilege privilege) { 228 return privileges.removeElement(privilege); 229 } 230 231 232 235 public void clearPrivileges() { 236 privileges.clear(); 237 } 238 239 public int hashCode() { 240 return toString().hashCode() 241 + (getPrincipal().equals("property") 242 ? getProperty().hashCode() 243 : 0); 244 } 245 246 public boolean equals(Object o) { 247 if (o != null && o instanceof Ace) { 248 Ace otherAce = (Ace) o; 249 boolean equals = true; 250 equals &= isNegative() == otherAce.isNegative(); 251 equals &= isProtected() == otherAce.isProtected(); 252 equals &= isInherited() == otherAce.isInherited(); 253 if (equals && isInherited()) { 254 equals = getInheritedFrom().equals(otherAce.getInheritedFrom()); 255 } 256 equals &= getPrincipal().equals(otherAce.getPrincipal()); 257 if (equals && getPrincipal().equals("property")) { 258 equals = getProperty().equals(otherAce.getProperty()); 259 } 260 if (equals) { 261 Enumeration privileges = enumeratePrivileges(); 262 Enumeration otherPrivileges = otherAce.enumeratePrivileges(); 263 while (equals && privileges.hasMoreElements()) { 264 equals = otherPrivileges.hasMoreElements(); 265 if (equals) 267 { 268 equals = privileges.nextElement().equals(otherPrivileges.nextElement()); 269 } 270 } 271 if (equals) 272 { 273 equals = !otherPrivileges.hasMoreElements(); 276 } 277 } 278 return equals; 279 } 280 return false; 281 } 282 283 public String toString() { 284 return ((!isNegative()?"granted":"denied") + 285 " to " + getPrincipal() + 286 " (" + (isProtected()?"protected":"not protected") + ")" + 287 " (" + (isInherited()? ("inherited from '" + getInheritedFrom() + "'"): "not inherited") +")"); 288 } 289 290 } 291 | Popular Tags |