KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 import org.alfresco.config.ConfigElement;
22 import org.alfresco.filesys.server.SrvSession;
23 import org.alfresco.filesys.server.auth.InvalidUserException;
24 import org.alfresco.filesys.server.config.InvalidConfigurationException;
25 import org.alfresco.filesys.server.config.ServerConfiguration;
26 import org.alfresco.filesys.server.core.ShareMapper;
27 import org.alfresco.filesys.server.core.SharedDevice;
28 import org.alfresco.filesys.server.core.SharedDeviceList;
29
30 /**
31  * Default Share Mapper Class
32  *
33  * <p>Maps disk and print share lookup requests to the list of shares defined in the server
34  * configuration.
35  *
36  * @author GKSpencer
37  */

38 public class DefaultShareMapper implements ShareMapper
39 {
40     // Server configuration
41

42     private ServerConfiguration m_config;
43
44     // Debug enable flag
45

46     private boolean m_debug;
47
48     /**
49      * Default constructor
50      */

51     public DefaultShareMapper()
52     {
53     }
54
55     /**
56      * Initialize the share mapper
57      *
58      * @param config ServerConfiguration
59      * @param params ConfigElement
60      * @exception InvalidConfigurationException
61      */

62     public void initializeMapper(ServerConfiguration config, ConfigElement params) throws InvalidConfigurationException
63     {
64
65         // Save the server configuration
66

67         m_config = config;
68
69         // Check if debug is enabled
70

71         if (params != null && params.getChild("debug") != null)
72             m_debug = true;
73     }
74
75     /**
76      * Check if debug output is enabled
77      *
78      * @return boolean
79      */

80     public final boolean hasDebug()
81     {
82         return m_debug;
83     }
84
85     /**
86      * Find a share using the name and type for the specified client.
87      *
88      * @param host String
89      * @param name String
90      * @param typ int
91      * @param sess SrvSession
92      * @param create boolean
93      * @return SharedDevice
94      * @exception InvalidUserException
95      */

96     public SharedDevice findShare(String JavaDoc host, String JavaDoc name, int typ, SrvSession sess, boolean create)
97             throws InvalidUserException
98     {
99
100         // Check for the special HOME disk share
101

102         SharedDevice share = null;
103
104         // Search the sessions dynamic share list first
105

106         if ( sess.hasDynamicShares()) {
107             
108             // Check if the required share exists in the sessions dynamic share list
109

110             share = sess.getDynamicShareList().findShare(name, typ, true);
111         }
112
113         // If we did not find a share then search the global share list
114

115         if ( share == null)
116         {
117             // Find the required share by name/type. Use a case sensitive search first, if that fails
118
// use a case insensitive search.
119

120             share = m_config.getShares().findShare(name, typ, false);
121     
122             if (share == null)
123             {
124     
125                 // Try a case insensitive search for the required share
126

127                 share = m_config.getShares().findShare(name, typ, true);
128             }
129         }
130         
131         // Check if the share is available
132

133         if (share != null && share.getContext() != null && share.getContext().isAvailable() == false)
134             share = null;
135
136         // Return the shared device, or null if no matching device was found
137

138         return share;
139     }
140
141     /**
142      * Delete temporary shares for the specified session
143      *
144      * @param sess SrvSession
145      */

146     public void deleteShares(SrvSession sess)
147     {
148         // Check if the session has any dynamic shares
149

150         if ( sess.hasDynamicShares() == false)
151             return;
152             
153         // Delete the dynamic shares
154

155         SharedDeviceList shares = sess.getDynamicShareList();
156         Enumeration JavaDoc<SharedDevice> enm = shares.enumerateShares();
157         
158         while ( enm.hasMoreElements()) {
159
160             // Get the current share from the list
161

162             SharedDevice shr = (SharedDevice) enm.nextElement();
163             
164             // Close the shared device
165

166             shr.getContext().CloseContext();
167         }
168         
169         // Clear the dynamic share list
170

171         shares.removeAllShares();
172     }
173
174     /**
175      * Return the list of available shares.
176      *
177      * @param host String
178      * @param sess SrvSession
179      * @param allShares boolean
180      * @return SharedDeviceList
181      */

182     public SharedDeviceList getShareList(String JavaDoc host, SrvSession sess, boolean allShares)
183     {
184
185         // Check if the session is valid, if so then check if the session has any dynamic shares
186

187         // Make a copy of the global share list and add the per session dynamic shares
188

189         SharedDeviceList shrList = new SharedDeviceList(m_config.getShares());
190
191         if ( sess != null && sess.hasDynamicShares()) {
192             
193             // Add the per session dynamic shares
194

195             shrList.addShares(sess.getDynamicShareList());
196         }
197
198         // Remove unavailable shares from the list and return the list
199

200         if (allShares == false)
201             shrList.removeUnavailableShares();
202         return shrList;
203     }
204
205     /**
206      * Close the share mapper, release any resources.
207      */

208     public void closeMapper()
209     {
210     }
211 }
212
Popular Tags