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 NamedLock implements Lock {
13:
14: private final String lockName;
15: private final String methodExpression;
16: private final LockLevel lockLevel;
17:
18: public NamedLock(String lockName, String methodExpression,
19: LockLevel lockLevel) {
20: Assert.assertNotBlank(lockName);
21: Assert.assertNotBlank(methodExpression);
22:
23: this .lockName = lockName;
24: this .methodExpression = methodExpression;
25: this .lockLevel = lockLevel;
26: }
27:
28: public boolean isAutoLock() {
29: return false;
30: }
31:
32: public String lockName() {
33: return this .lockName;
34: }
35:
36: public String methodExpression() {
37: return this .methodExpression;
38: }
39:
40: public LockLevel lockLevel() {
41: return this .lockLevel;
42: }
43:
44: public boolean equals(Object that) {
45: if (!(that instanceof NamedLock))
46: return false;
47: NamedLock thatLock = (NamedLock) that;
48: return new EqualsBuilder().append(this .methodExpression,
49: thatLock.methodExpression).append(this .lockLevel,
50: thatLock.lockLevel).append(this .lockName,
51: thatLock.lockName).isEquals();
52: }
53:
54: public int hashCode() {
55: return new HashCodeBuilder().append(this .methodExpression)
56: .append(this .lockLevel).append(this .lockName)
57: .toHashCode();
58: }
59:
60: public String toString() {
61: return new OurStringBuilder(this ,
62: OurStringBuilder.COMPACT_STYLE).append(
63: "method expression", this .methodExpression).append(
64: "lock level", this .lockLevel).append("lock name",
65: this.lockName).toString();
66: }
67:
68: }
|