KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > dcerpc > info > ConnectionInfo


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.dcerpc.info;
18
19 import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
20 import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
21 import org.alfresco.filesys.smb.dcerpc.DCEReadable;
22
23 /**
24  * Connection Information Class
25  * <p>
26  * Contains the details of a connection on a remote server.
27  */

28 public class ConnectionInfo implements DCEReadable
29 {
30
31     // Information level
32

33     private int m_infoLevel;
34
35     // Connection id and type
36

37     private int m_connId;
38     private int m_connType;
39
40     // Count of open files
41

42     private int m_openFiles;
43
44     // Number of users
45

46     private int m_numUsers;
47
48     // Time connected, in minutes
49

50     private int m_connTime;
51
52     // User name
53

54     private String JavaDoc m_userName;
55
56     // Client name
57

58     private String JavaDoc m_clientName;
59
60     /**
61      * Default constructor
62      */

63     public ConnectionInfo()
64     {
65     }
66
67     /**
68      * Class constructor
69      *
70      * @param infoLevel int
71      */

72     public ConnectionInfo(int infoLevel)
73     {
74         m_infoLevel = infoLevel;
75     }
76
77     /**
78      * Get the information level
79      *
80      * @return int
81      */

82     public final int getInformationLevel()
83     {
84         return m_infoLevel;
85     }
86
87     /**
88      * Get the connection id
89      *
90      * @return int
91      */

92     public final int getConnectionId()
93     {
94         return m_connId;
95     }
96
97     /**
98      * Get the connection type
99      *
100      * @return int
101      */

102     public final int getConnectionType()
103     {
104         return m_connType;
105     }
106
107     /**
108      * Get the number of open files on the connection
109      *
110      * @return int
111      */

112     public final int getOpenFileCount()
113     {
114         return m_openFiles;
115     }
116
117     /**
118      * Return the number of users on the connection
119      *
120      * @return int
121      */

122     public final int getNumberOfUsers()
123     {
124         return m_numUsers;
125     }
126
127     /**
128      * Return the connection time in seconds
129      *
130      * @return int
131      */

132     public final int getConnectionTime()
133     {
134         return m_connTime;
135     }
136
137     /**
138      * Return the user name
139      *
140      * @return String
141      */

142     public final String JavaDoc getUserName()
143     {
144         return m_userName;
145     }
146
147     /**
148      * Return the client name
149      *
150      * @return String
151      */

152     public final String JavaDoc getClientName()
153     {
154         return m_clientName;
155     }
156
157     /**
158      * Read a connection information object from a DCE buffer
159      *
160      * @param buf DCEBuffer
161      * @throws DCEBufferException
162      */

163     public void readObject(DCEBuffer buf) throws DCEBufferException
164     {
165
166         // Unpack the connection information
167

168         switch (getInformationLevel())
169         {
170
171         // Information level 0
172

173         case 0:
174             m_connId = buf.getInt();
175             m_userName = null;
176             m_clientName = null;
177             break;
178
179         // Information level 1
180

181         case 1:
182             m_connId = buf.getInt();
183             m_connType = buf.getInt();
184             m_openFiles = buf.getInt();
185             m_numUsers = buf.getInt();
186             m_connTime = buf.getInt();
187
188             m_userName = buf.getPointer() != 0 ? "" : null;
189             m_clientName = buf.getPointer() != 0 ? "" : null;
190             break;
191         }
192     }
193
194     /**
195      * Read the strings for this connection information from the DCE/RPC buffer
196      *
197      * @param buf DCEBuffer
198      * @exception DCEBufferException
199      */

200     public void readStrings(DCEBuffer buf) throws DCEBufferException
201     {
202
203         // Read the strings for this connection information
204

205         switch (getInformationLevel())
206         {
207
208         // Information level 1
209

210         case 1:
211             if (getUserName() != null)
212                 m_userName = buf.getString(DCEBuffer.ALIGN_INT);
213             if (getClientName() != null)
214                 m_clientName = buf.getString(DCEBuffer.ALIGN_INT);
215             break;
216         }
217     }
218
219     /**
220      * Return the connection information as a string
221      *
222      * @return String
223      */

224     public String JavaDoc toString()
225     {
226         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
227
228         str.append("[ID=");
229         str.append(getConnectionId());
230         str.append(":Level=");
231         str.append(getInformationLevel());
232         str.append(":");
233
234         if (getInformationLevel() == 1)
235         {
236             str.append("Type=");
237             str.append(getConnectionType());
238             str.append(",OpenFiles=");
239             str.append(getOpenFileCount());
240             str.append(",NumUsers=");
241             str.append(getNumberOfUsers());
242             str.append(",Connected=");
243             str.append(getConnectionTime());
244             str.append(",User=");
245             str.append(getUserName());
246             str.append(",Client=");
247             str.append(getClientName());
248         }
249
250         str.append("]");
251         return str.toString();
252     }
253 }
254
Popular Tags