01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.config.schema;
05:
06: import org.apache.commons.lang.builder.EqualsBuilder;
07: import org.apache.commons.lang.builder.HashCodeBuilder;
08:
09: import com.tc.util.Assert;
10: import com.tc.util.stringification.OurStringBuilder;
11:
12: public class AutoLock implements Lock {
13:
14: private final String methodExpression;
15: private final LockLevel lockLevel;
16:
17: public AutoLock(String methodExpression, LockLevel lockLevel) {
18: Assert.assertNotBlank(methodExpression);
19: Assert.assertNotNull(lockLevel);
20:
21: this .methodExpression = methodExpression;
22: this .lockLevel = lockLevel;
23: }
24:
25: public boolean isAutoLock() {
26: return true;
27: }
28:
29: public String lockName() {
30: throw Assert.failure("Autolocks don't have names.");
31: }
32:
33: public String methodExpression() {
34: return this .methodExpression;
35: }
36:
37: public LockLevel lockLevel() {
38: return this .lockLevel;
39: }
40:
41: public boolean equals(Object that) {
42: if (!(that instanceof AutoLock))
43: return false;
44: AutoLock thatLock = (AutoLock) that;
45: return new EqualsBuilder().append(this .methodExpression,
46: thatLock.methodExpression).append(this .lockLevel,
47: thatLock.lockLevel).isEquals();
48: }
49:
50: public int hashCode() {
51: return new HashCodeBuilder().append(this .methodExpression)
52: .append(this .lockLevel).toHashCode();
53: }
54:
55: public String toString() {
56: return new OurStringBuilder(this ,
57: OurStringBuilder.COMPACT_STYLE).append(
58: "method expression", this .methodExpression).append(
59: "lock level", this.lockLevel).toString();
60: }
61:
62: }
|