Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 4 package com.tc.object.config; 5 6 import org.apache.commons.lang.builder.ToStringBuilder; 7 8 public class LockDefinition { 9 10 public static final String TC_AUTOLOCK_NAME = "tc:autolock"; 11 12 private String lockName = TC_AUTOLOCK_NAME; 13 private ConfigLockLevel lockLevel; 14 15 private boolean isCommitted = false; 16 private boolean autolock; 17 18 public LockDefinition() { 19 return; 20 } 21 22 public LockDefinition(String lockName, ConfigLockLevel lockLevel) { 23 setLockName(lockName); 24 setLockLevel(lockLevel); 25 } 26 27 public String toString() { 28 return ToStringBuilder.reflectionToString(this); 29 } 30 31 public void setLockName(String lockName) { 32 commitWriteCheck(); 33 this.lockName = lockName; 34 } 35 36 public String getLockName() { 37 commitReadCheck(); 38 return this.lockName; 39 } 40 41 public void setLockLevel(ConfigLockLevel lt) { 42 commitWriteCheck(); 43 this.lockLevel = lt; 44 } 45 46 public ConfigLockLevel getLockLevel() { 47 commitReadCheck(); 48 return this.lockLevel; 49 } 50 51 public int getLockLevelAsInt() { 52 return getLockLevel().getLevel(); 53 } 54 55 public boolean isAutolock() { 56 commitReadCheck(); 57 return autolock; 58 } 59 60 63 public synchronized void commit() { 64 if (!isCommitted) { 65 normalizeLockName(); 66 this.autolock = TC_AUTOLOCK_NAME.equals(this.lockName); 67 } 68 isCommitted = true; 69 } 70 71 public boolean equals(Object o) { 72 if (o == null) return false; 73 if (!(o instanceof LockDefinition)) return false; 74 LockDefinition compare = (LockDefinition) o; 75 if (lockName == null && compare.lockName != null) return false; 76 if (lockLevel == null && compare.lockLevel != null) return false; 77 return lockName.equals(compare.lockName) && lockLevel.equals(compare.lockLevel); 78 } 79 80 public int hashCode() { 81 if (lockName == null || lockLevel == null) return 1; 82 return lockName.hashCode() | lockLevel.toString().hashCode(); 83 } 84 85 private void normalizeLockName() { 86 if (this.lockName != null) this.lockName = this.lockName.replaceAll("\\s*", ""); 88 } 89 90 private synchronized void commitWriteCheck() { 91 if (isCommitted) throw new IllegalStateException ("Attempt to alter the state of LockDefinition: " + this 92 + " after committing"); 93 } 94 95 private synchronized void commitReadCheck() { 96 if (!isCommitted) throw new IllegalStateException ("Attempt to read an uncommitted LockDefinition: " + this); 97 } 98 99 }
| Popular Tags
|