KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > ProtocolHandler


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.smb.server;
18
19 import java.io.IOException JavaDoc;
20
21 import org.alfresco.filesys.server.filesys.DiskDeviceContext;
22 import org.alfresco.filesys.server.filesys.DiskInterface;
23 import org.alfresco.filesys.server.filesys.DiskSizeInterface;
24 import org.alfresco.filesys.server.filesys.DiskVolumeInterface;
25 import org.alfresco.filesys.server.filesys.SrvDiskInfo;
26 import org.alfresco.filesys.server.filesys.TooManyConnectionsException;
27 import org.alfresco.filesys.server.filesys.VolumeInfo;
28 import org.alfresco.filesys.smb.PacketType;
29
30 /**
31  * Protocol handler abstract base class.
32  * <p>
33  * The protocol handler class is the base of all SMB protocol/dialect handler classes.
34  */

35 abstract class ProtocolHandler
36 {
37
38     // Server session that this protocol handler is associated with.
39

40     protected SMBSrvSession m_sess;
41
42     /**
43      * Create a protocol handler for the specified session.
44      */

45     protected ProtocolHandler()
46     {
47     }
48
49     /**
50      * Create a protocol handler for the specified session.
51      *
52      * @param sess SMBSrvSession
53      */

54     protected ProtocolHandler(SMBSrvSession sess)
55     {
56         m_sess = sess;
57     }
58
59     /**
60      * Return the protocol handler name.
61      *
62      * @return java.lang.String
63      */

64     public abstract String JavaDoc getName();
65
66     /**
67      * Run the SMB protocol handler for this server session.
68      *
69      * @exception java.io.IOException
70      * @exception SMBSrvException
71      */

72     public abstract boolean runProtocol() throws IOException JavaDoc, SMBSrvException, TooManyConnectionsException;
73
74     /**
75      * Get the server session that this protocol handler is associated with.
76      *
77      * @param sess SMBSrvSession
78      */

79     protected final SMBSrvSession getSession()
80     {
81         return m_sess;
82     }
83
84     /**
85      * Set the server session that this protocol handler is associated with.
86      *
87      * @param sess SMBSrvSession
88      */

89     protected final void setSession(SMBSrvSession sess)
90     {
91         m_sess = sess;
92     }
93
94     /**
95      * Determine if the request is a chained (AndX) type command and there is a chained command in
96      * this request.
97      *
98      * @param pkt SMBSrvPacket
99      * @return true if there is a chained request to be handled, else false.
100      */

101     protected final boolean hasChainedCommand(SMBSrvPacket pkt)
102     {
103
104         // Determine if the command code is an AndX command
105

106         int cmd = pkt.getCommand();
107
108         if (cmd == PacketType.SessionSetupAndX || cmd == PacketType.TreeConnectAndX || cmd == PacketType.OpenAndX
109                 || cmd == PacketType.WriteAndX || cmd == PacketType.ReadAndX || cmd == PacketType.LogoffAndX
110                 || cmd == PacketType.LockingAndX || cmd == PacketType.NTCreateAndX)
111         {
112
113             // Check if there is a chained command
114

115             return pkt.hasAndXCommand();
116         }
117
118         // Not a chained type command
119

120         return false;
121     }
122
123     /**
124      * Get disk sizing information from the specified driver and context.
125      *
126      * @param disk DiskInterface
127      * @param ctx DiskDeviceContext
128      * @return SrvDiskInfo
129      * @exception IOException
130      */

131     protected final SrvDiskInfo getDiskInformation(DiskInterface disk, DiskDeviceContext ctx) throws IOException JavaDoc
132     {
133
134         // Get the static disk information from the context, if available
135

136         SrvDiskInfo diskInfo = ctx.getDiskInformation();
137
138         // If we did not get valid disk information from the device context check if the driver
139
// implements the
140
// disk sizing interface
141

142         if (diskInfo == null)
143             diskInfo = new SrvDiskInfo();
144
145         // Check if the driver implements the dynamic sizing interface to get realtime disk size
146
// information
147

148         if (disk instanceof DiskSizeInterface)
149         {
150
151             // Get the dynamic disk sizing information
152

153             DiskSizeInterface sizeInterface = (DiskSizeInterface) disk;
154             sizeInterface.getDiskInformation(ctx, diskInfo);
155         }
156
157         // Return the disk information
158

159         return diskInfo;
160     }
161
162     /**
163      * Get disk volume information from the specified driver and context
164      *
165      * @param disk DiskInterface
166      * @param ctx DiskDeviceContext
167      * @return VolumeInfo
168      */

169     protected final VolumeInfo getVolumeInformation(DiskInterface disk, DiskDeviceContext ctx)
170     {
171
172         // Get the static volume information from the context, if available
173

174         VolumeInfo volInfo = ctx.getVolumeInformation();
175
176         // If we did not get valid volume information from the device context check if the driver
177
// implements the
178
// disk volume interface
179

180         if (disk instanceof DiskVolumeInterface)
181         {
182
183             // Get the dynamic disk volume information
184

185             DiskVolumeInterface volInterface = (DiskVolumeInterface) disk;
186             volInfo = volInterface.getVolumeInformation(ctx);
187         }
188
189         // If we still have not got valid volume information then create empty volume information
190

191         if (volInfo == null)
192             volInfo = new VolumeInfo("");
193
194         // Return the volume information
195

196         return volInfo;
197     }
198 }
Popular Tags