KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > filesys > TreeConnectionHash


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server.filesys;
18
19 import java.util.Enumeration JavaDoc;
20 import java.util.Hashtable JavaDoc;
21
22 /**
23  * Tree Connection Hash Class
24  * <p>
25  * Hashtable of TreeConnections for the available disk shared devices. TreeConnections are indexed
26  * using the hash of the share name to allow mounts to be persistent across server restarts.
27  */

28 public class TreeConnectionHash
29 {
30
31     // Share name hash to tree connection
32

33     private Hashtable JavaDoc<Integer JavaDoc, TreeConnection> m_connections;
34
35     /**
36      * Class constructor
37      */

38     public TreeConnectionHash()
39     {
40         m_connections = new Hashtable JavaDoc<Integer JavaDoc, TreeConnection>();
41     }
42
43     /**
44      * Return the number of tree connections in the hash table
45      *
46      * @return int
47      */

48     public final int numberOfEntries()
49     {
50         return m_connections.size();
51     }
52
53     /**
54      * Add a connection to the list of available connections
55      *
56      * @param tree TreeConnection
57      */

58     public final void addConnection(TreeConnection tree)
59     {
60         m_connections.put(tree.getSharedDevice().getName().hashCode(), tree);
61     }
62
63     /**
64      * Delete a connection from the list
65      *
66      * @param shareName String
67      * @return TreeConnection
68      */

69     public final TreeConnection deleteConnection(String JavaDoc shareName)
70     {
71         return (TreeConnection) m_connections.get(shareName.hashCode());
72     }
73
74     /**
75      * Find a connection for the specified share name
76      *
77      * @param shareName String
78      * @return TreeConnection
79      */

80     public final TreeConnection findConnection(String JavaDoc shareName)
81     {
82
83         // Get the tree connection for the associated share name
84

85         TreeConnection tree = m_connections.get(shareName.hashCode());
86
87         // Return the tree connection
88

89         return tree;
90     }
91
92     /**
93      * Find a connection for the specified share name hash code
94      *
95      * @param hashCode int
96      * @return TreeConnection
97      */

98     public final TreeConnection findConnection(int hashCode)
99     {
100
101         // Get the tree connection for the associated share name
102

103         TreeConnection tree = m_connections.get(hashCode);
104
105         // Return the tree connection
106

107         return tree;
108     }
109
110     /**
111      * Enumerate the connections
112      *
113      * @return Enumeration<TreeConnection>
114      */

115     public final Enumeration JavaDoc<TreeConnection> enumerateConnections()
116     {
117         return m_connections.elements();
118     }
119 }
120
Popular Tags