1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.webdav.lock;
14
15 import org.abstracthorizon.danube.webdav.util.Timeout;
16
17
18
19
20
21
22 public class Lock {
23
24
25
26
27
28 protected int type;
29
30
31
32
33
34
35 protected int scope;
36
37
38 protected Object owner;
39
40
41 protected int depth;
42
43
44 protected Timeout timeout;
45
46
47 protected String token;
48
49
50 protected long validUntil = Long.MAX_VALUE;
51
52
53 protected static long counter = 1;
54
55
56
57
58
59
60
61
62
63 public Lock(int type, int scope, Object owner, Timeout timeout, int depth) {
64 this.type = type;
65 this.scope = scope;
66 this.owner = owner;
67 this.depth = depth;
68 this.timeout = timeout;
69 createToken();
70 }
71
72
73
74
75 protected synchronized void createToken() {
76 String t = "opaquelocktoken:" + Long.toHexString(System.currentTimeMillis()) + "-" + Long.toHexString(counter);
77 token = t;
78 counter = counter + 1;
79 }
80
81
82
83
84
85 public int getDepth() {
86 return depth;
87 }
88
89
90
91
92
93 public void setDepth(int depth) {
94 this.depth = depth;
95 }
96
97
98
99
100
101 public Object getOwner() {
102 return owner;
103 }
104
105
106
107
108
109 public void setOwner(Object owner) {
110 this.owner = owner;
111 }
112
113
114
115
116
117 public int getScope() {
118 return scope;
119 }
120
121
122
123
124
125 public void setScope(int scope) {
126 this.scope = scope;
127 }
128
129
130
131
132
133 public Timeout getTimeout() {
134 return timeout;
135 }
136
137
138
139
140
141 public void setTimeout(Timeout timeout) {
142 this.timeout = timeout;
143 validUntil = timeout.calculateValidity();
144 }
145
146
147
148
149
150 public String getToken() {
151 return token;
152 }
153
154
155
156
157
158
159 public void setToken(String token) {
160 this.token = token;
161 }
162
163
164
165
166
167 public int getType() {
168 return type;
169 }
170
171
172
173
174
175 public void setType(int type) {
176 this.type = type;
177 }
178
179
180
181
182
183 public long getValidUntil() {
184 return validUntil;
185 }
186
187
188
189
190
191
192 public boolean refreshTimeout(Timeout timeout) {
193 this.timeout = timeout;
194 validUntil = timeout.calculateValidity();
195 return true;
196 }
197
198
199
200
201
202
203 public void freeLock() {
204 }
205
206
207
208
209
210 public boolean equals(Object o) {
211 if (o instanceof Lock) {
212 Lock l = (Lock)o;
213 return token.equals(l.token);
214 }
215 return false;
216 }
217 }