KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavState.java,v 1.4 2004/07/28 09:31:38 ib Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/07/28 09:31:38 $
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 java.util.ArrayList JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Vector JavaDoc;
30 import org.apache.commons.httpclient.HttpState;
31
32 /**
33  * Session state.
34  *
35  */

36 public class WebdavState extends HttpState {
37
38
39     // -------------------------------------------------------------- Constants
40

41
42     private static final String JavaDoc[] EMPTY_ARRAY = new String JavaDoc[0];
43
44
45     // ----------------------------------------------------- Instance Variables
46

47
48     /**
49      * Lock tokens.
50      */

51     protected HashMap JavaDoc locks = new HashMap JavaDoc();
52
53
54     /**
55      * Lock list.
56      */

57     protected ArrayList JavaDoc lockTokens = new ArrayList JavaDoc();
58
59     /**
60      * Transaction handle of current session of <code>null</code> if not inside of transaction.
61      */

62     protected String JavaDoc transactionHandle = null;
63
64     // ------------------------------------------------------------- Properties
65

66
67     /**
68      * Add a lock token.
69      *
70      * @param uri Uri
71      * @param value Lock token value
72      */

73     public void addLock(String JavaDoc uri, String JavaDoc value) {
74
75         if (value == null)
76             return;
77
78         if (lockTokens.contains(value))
79             return;
80
81         locks.put(uri, value);
82         lockTokens.add(value);
83
84     }
85
86
87     /**
88      * Remove a lock.
89      *
90      * @param uri Uri
91      * @param value LockToken value
92      */

93     public void removeLock(String JavaDoc uri, String JavaDoc value) {
94
95         locks.remove(uri);
96         int i = lockTokens.indexOf(value);
97         if (i != -1)
98             lockTokens.remove(i);
99
100     }
101
102
103     /**
104      * Remove locks.
105      *
106      * @param uri Uri
107      */

108     public void removeLocks(String JavaDoc uri) {
109
110         String JavaDoc result = (String JavaDoc) locks.remove(uri);
111         if (result != null) {
112             int i = lockTokens.indexOf(result);
113             if (i != -1)
114                 lockTokens.remove(i);
115         }
116
117     }
118
119
120     /**
121      * Get lock
122      *
123      * @param uri Uri
124      */

125     public String JavaDoc getLock(String JavaDoc uri) {
126
127         return (String JavaDoc) locks.get(uri);
128
129     }
130
131
132     /**
133      * Get locks
134      *
135      * @param uri Uri
136      * @return Enumeration of lock tokens
137      * @deprecated
138      */

139     public Enumeration JavaDoc getLocks(String JavaDoc uri) {
140
141         Vector JavaDoc result = new Vector JavaDoc();
142         String JavaDoc lockToken = getLock(uri);
143         if (lockToken != null)
144             result.addElement(lockToken);
145         return result.elements();
146
147     }
148
149
150     /**
151      * Get all locks scoped to that uri.
152      *
153      * @param uri Uri
154      * @return Iterator of lock tokens
155      */

156     public String JavaDoc[] getAllLocks(String JavaDoc uri) {
157
158         return (String JavaDoc[]) lockTokens.toArray(EMPTY_ARRAY);
159
160     }
161
162     public String JavaDoc getTransactionHandle() {
163         return transactionHandle;
164     }
165
166     public void setTransactionHandle(String JavaDoc transactionHandle) {
167         this.transactionHandle = transactionHandle;
168     }
169 }
170
Popular Tags