1 17 package org.alfresco.filesys.server.core; 18 19 import org.alfresco.filesys.server.auth.acl.AccessControl; 20 import org.alfresco.filesys.server.auth.acl.AccessControlList; 21 22 26 public class SharedDevice implements Comparable 27 { 28 30 public static final int Admin = 0x0001; 31 public static final int Hidden = 0x0002; 32 public static final int ReadOnly = 0x0004; 33 public static final int Temporary = 0x0008; 34 35 37 private String m_name; 38 39 41 private int m_type; 42 43 45 private String m_comment; 46 47 49 private DeviceInterface m_interface; 50 private DeviceContext m_drvCtx; 51 52 54 private int m_attrib; 55 56 58 private int m_maxUses = -1; private int m_curUses; 60 61 63 private AccessControlList m_acls; 64 65 72 protected SharedDevice(String name, int typ, DeviceContext ctx) 73 { 74 75 77 setName(name); 78 setType(typ); 79 setContext(ctx); 80 } 81 82 87 public final int getAttributes() 88 { 89 return m_attrib; 90 } 91 92 97 public final boolean hasAccessControls() 98 { 99 if (m_acls == null) 100 return false; 101 return true; 102 } 103 104 109 public final AccessControlList getAccessControls() 110 { 111 return m_acls; 112 } 113 114 119 public final boolean hasComment() 120 { 121 return m_comment != null ? true : false; 122 } 123 124 129 public final String getComment() 130 { 131 return m_comment; 132 } 133 134 139 public final DeviceContext getContext() 140 { 141 return m_drvCtx; 142 } 143 144 149 public DeviceInterface getInterface() throws InvalidDeviceInterfaceException 150 { 151 return m_interface; 152 } 153 154 159 public final String getName() 160 { 161 return m_name; 162 } 163 164 169 public int getType() 170 { 171 return m_type; 172 } 173 174 179 public final int getCurrentConnectionCount() 180 { 181 return m_curUses; 182 } 183 184 189 public final int getMaximumConnectionCount() 190 { 191 return m_maxUses; 192 } 193 194 201 public int hashCode() 202 { 203 204 206 return getName().hashCode(); 207 } 208 209 214 public final boolean isAdmin() 215 { 216 return (m_attrib & Admin) == 0 ? false : true; 217 } 218 219 224 public final boolean isHidden() 225 { 226 return (m_attrib & Hidden) == 0 ? false : true; 227 } 228 229 234 public final boolean isReadOnly() 235 { 236 return (m_attrib & ReadOnly) == 0 ? false : true; 237 } 238 239 244 public final boolean isTemporary() 245 { 246 return (m_attrib & Temporary) == 0 ? false : true; 247 } 248 249 254 public final void setComment(String comm) 255 { 256 m_comment = comm; 257 } 258 259 264 public final void setAttributes(int attr) 265 { 266 m_attrib = attr; 267 } 268 269 274 protected void setContext(DeviceContext ctx) 275 { 276 m_drvCtx = ctx; 277 } 278 279 284 protected final void setInterface(DeviceInterface iface) 285 { 286 m_interface = iface; 287 } 288 289 294 protected final void setName(String name) 295 { 296 m_name = name; 297 } 298 299 304 protected final void setType(int typ) 305 { 306 m_type = typ; 307 } 308 309 314 public final void setMaximumConnectionCount(int maxConn) 315 { 316 m_maxUses = maxConn; 317 } 318 319 324 public final void setAccessControlList(AccessControlList acls) 325 { 326 m_acls = acls; 327 } 328 329 334 public final void addAccessControl(AccessControl acl) 335 { 336 337 339 if (m_acls == null) 340 m_acls = new AccessControlList(); 341 342 344 m_acls.addControl(acl); 345 } 346 347 353 public final AccessControl removeAccessControl(int idx) 354 { 355 356 358 if (m_acls == null || idx < 0 || idx >= m_acls.numberOfControls()) 359 return null; 360 361 363 return m_acls.removeControl(idx); 364 } 365 366 369 public final void removeAllAccessControls() 370 { 371 if (m_acls != null) 372 { 373 m_acls.removeAllControls(); 374 m_acls = null; 375 } 376 } 377 378 384 public DeviceContext createContext(String [] args) 385 { 386 return new DeviceContext(args[0]); 387 } 388 389 392 public synchronized void incrementConnectionCount() 393 { 394 m_curUses++; 395 } 396 397 400 public synchronized void decrementConnectionCount() 401 { 402 m_curUses--; 403 } 404 405 410 public int compareTo(Object obj) 411 { 412 if (obj instanceof SharedDevice) 413 { 414 SharedDevice sd = (SharedDevice) obj; 415 return getName().compareTo(sd.getName()); 416 } 417 return -1; 418 } 419 420 429 public boolean equals(Object obj) 430 { 431 432 434 if (obj instanceof SharedDevice) 435 { 436 437 439 SharedDevice shr = (SharedDevice) obj; 440 if (getName().compareTo(shr.getName()) == 0) 441 return true; 442 } 443 444 446 return false; 447 } 448 449 454 public String toString() 455 { 456 457 459 StringBuffer str = new StringBuffer (); 460 str.append("["); 461 str.append(getName()); 462 str.append(","); 463 str.append(ShareType.TypeAsString(getType())); 464 str.append(","); 465 466 if (hasAccessControls()) 467 { 468 str.append("ACLs="); 469 str.append(m_acls.numberOfControls()); 470 } 471 472 if (isAdmin()) 473 str.append(",Admin"); 474 475 if (isHidden()) 476 str.append(",Hidden"); 477 478 if (isReadOnly()) 479 str.append(",ReadOnly"); 480 481 if (isTemporary()) 482 str.append(",Temp"); 483 484 if (getContext() != null && getContext().isAvailable() == false) 485 str.append(",Offline"); 486 487 if (m_drvCtx != null) 488 { 489 str.append(","); 490 str.append(m_drvCtx.toString()); 491 } 492 str.append("]"); 493 494 return str.toString(); 495 } 496 } | Popular Tags |