KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > lib > Lock


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/Lock.java,v 1.3.2.1 2004/10/11 08:17:19 luetzkendorf Exp $
3  * $Revision: 1.3.2.1 $
4  * $Date: 2004/10/11 08:17:19 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.webdav.lib;
25
26 import org.apache.webdav.lib.methods.DepthSupport;
27
28 /**
29  * This class represents a lock on a resource.
30  *
31  * @version $Revision: 1.3.2.1 $
32  */

33 public class Lock {
34
35
36     // -------------------------------------------------------------- Constants
37

38
39     /**
40      * The property name.
41      */

42     public static final String JavaDoc TAG_NAME = "activelock";
43
44
45     /**
46      * The write constant in the locktype.
47      */

48     public static final int TYPE_WRITE = 0;
49     
50     /**
51      * Type indicating lock is a transaction lock.
52      */

53     public static final int TYPE_TRANSACTION = 1;
54
55
56     /**
57      * The exclusive constant in the lockscope.
58      */

59     public static final int SCOPE_EXCLUSIVE = 0;
60
61
62     /**
63      * The shared constant in the lockscope.
64      */

65     public static final int SCOPE_SHARED = 1;
66
67
68     // ----------------------------------------------------------- Constructors
69

70
71     /**
72      * Default constructor for the lockentry.
73      */

74     public Lock(int lockScope, int lockType) {
75         this.lockScope = lockScope;
76         this.lockType = lockType;
77     }
78
79
80     /**
81      * Default constructor for the activelock.
82      */

83     public Lock(int lockScope, int lockType, int depth, String JavaDoc owner,
84                 int timeout, String JavaDoc lockToken) {
85         this.lockScope = lockScope;
86         this.lockType = lockType;
87         this.depth = depth;
88         this.owner = owner;
89         this.timeout = timeout;
90         this.lockToken = lockToken;
91     }
92
93     public Lock(int lockScope, int lockType, int depth, String JavaDoc owner,
94             int timeout, String JavaDoc lockToken, String JavaDoc principalUrl) {
95         this.lockScope = lockScope;
96         this.lockType = lockType;
97         this.depth = depth;
98         this.owner = owner;
99         this.timeout = timeout;
100         this.lockToken = lockToken;
101         this.principalUrl = principalUrl;
102     }
103
104     /**
105      * Default constructor for the activelock.
106      * @deprecated The timeout value MUST NOT be greater than 2^32-1.
107      */

108     public Lock(int lockScope, int lockType, int depth, String JavaDoc owner,
109                 long timeout, String JavaDoc lockToken) {
110         this(lockScope, lockType, depth, owner, (int) timeout, lockToken);
111     }
112
113
114     // ------------------------------------------------------ Instance Variable
115

116
117     protected int lockScope = -1;
118
119
120     protected int lockType = -1;
121
122
123     protected int depth = -1;
124
125
126     protected String JavaDoc owner = null;
127
128
129     protected int timeout = -1;
130
131
132     protected String JavaDoc lockToken = null;
133     
134     protected String JavaDoc principalUrl = null;
135
136
137     // --------------------------------------------------------- Public Methods
138

139
140     /**
141      * Get whether a lock is an exclusive lock, or a shared lock.
142      *
143      * @return The lock scope. If it's not set, it could be -1.
144      */

145     public int getLockScope() {
146         return lockScope;
147     }
148
149
150     /**
151      * Get the access type of a lock.
152      *
153      * @return The lock type. If it's not set, it could be -1.
154      */

155     public int getLockType() {
156         return lockType;
157     }
158
159
160     /**
161      * Get the value of the depth.
162      *
163      * @return The depth vlaue. If it's not set, it could be -1.
164      */

165     public int getDepth() {
166         return depth;
167     }
168
169
170     /**
171      * Get information about the principal taking out a lock.
172      *
173      * @return The owner.
174      */

175     public String JavaDoc getOwner() {
176         return owner;
177     }
178     
179     /**
180      * Get the <code>principal-URL</code> property of the lock, if one.
181      * @return an URL as String
182      */

183     public String JavaDoc getPrincipalUrl() {
184         return principalUrl;
185     }
186
187
188     /**
189      * Get the timeout associated with a lock.
190      *
191      * @return The timeout vlaue. If it's not set, it could be -1.
192      */

193     public int getTimeout() {
194         return timeout;
195     }
196
197
198     /**
199      * Get the access type of a lock.
200      *
201      * @return The lock token.
202      */

203     public String JavaDoc getLockToken() {
204         return lockToken;
205     }
206
207     public String JavaDoc toString() {
208         StringBuffer JavaDoc tmp=new StringBuffer JavaDoc();
209
210         if (lockScope==Lock.SCOPE_EXCLUSIVE) {
211             tmp.append("Exclusive");
212         }
213         else if (lockScope==Lock.SCOPE_SHARED) {
214             tmp.append("Shared");
215         }
216
217         if (lockType==Lock.TYPE_WRITE) {
218             tmp.append(" write lock");
219         }
220
221         if (depth==DepthSupport.DEPTH_INFINITY) {
222             tmp.append(" depth:infinity");
223         }
224         else if (depth==-1) {
225             // unknown
226
}
227         else {
228             tmp.append(" depth:" + depth);
229         }
230
231         if (owner!=null)
232             tmp.append(" owner:" + owner);
233
234         if (timeout!=-1)
235             tmp.append(" timeout:" + timeout);
236
237         if (lockToken!=null)
238             tmp.append(" token:" + lockToken);
239
240         return tmp.toString();
241     }
242
243 }
244
Popular Tags