KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > datashare > ClientInfo


1 /* ----- BEGIN LICENSE BLOCK -----
2  * Version: MPL 1.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is the DataShare server.
15  *
16  * The Initial Developer of the Original Code is
17  * Ball Aerospace & Technologies Corp, Fairborn, Ohio
18  * Portions created by the Initial Developer are Copyright (C) 2001
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s): Charles Wood <cwood@ball.com>
22  *
23  * ----- END LICENSE BLOCK ----- */

24 /* RCS $Id: ClientInfo.java,v 1.4 2002/02/04 19:34:57 lizellaman Exp $
25  * $Log: ClientInfo.java,v $
26  * Revision 1.4 2002/02/04 19:34:57 lizellaman
27  * correct spelling of privilege
28  *
29  * Revision 1.3 2002/01/29 20:50:17 lizellaman
30  * Added LoggingInterface, modified the PropertiesInterface implementation
31  *
32  * Revision 1.2 2002/01/03 03:37:36 lizellaman
33  * periodic update of changes I have made
34  *
35  * Revision 1.1.1.1 2001/10/23 13:37:19 lizellaman
36  * initial sourceforge release
37  *
38  */

39
40 package org.datashare;
41
42 import org.datashare.objects.DataShareConnectionDescriptor;
43 import org.datashare.objects.DefaultObjectInfo;
44 import org.datashare.objects.RegistrationInfo;
45 import java.util.Date JavaDoc;
46 import java.net.InetAddress JavaDoc;
47
48
49 /**
50  * Holds information about a Client.
51  *
52  * @date March 01, 2000
53  * @author Charles Wood
54  * @version 1.0
55  */

56 public class ClientInfo extends DefaultObjectInfo implements PersistDataCallbackInterface
57    {
58    /**
59     * Client's unique name, used as a key for the client
60     */

61    protected String JavaDoc clientKey = null;
62
63    /**
64     * machine Client is located on
65     */

66    protected InetAddress JavaDoc hostMachine;
67
68    /**
69     * this client's commandStatus connection
70     */

71    protected DataShareConnectionDescriptor clientCommandStatusConnectionDescriptor = null;
72
73    /**
74     * UserInfo for this client
75     */

76    protected UserInfo userInfo = null;
77
78    /**
79     * true if this client has admin privileges
80     */

81    protected boolean admin = false;
82
83    /**
84     * indicates if user wants to see all sessions/clients in their tree objects
85     */

86    protected boolean seeAllTreeObjects = false;
87
88    /**
89     * indicates how the client code was launched (applet/application/desktop)
90     */

91    protected int clientMode;
92
93    /**
94     * indicates if this instance can expect to access beans
95     */

96    boolean saveData = false;
97
98    /**
99     * info from the client's RegistrationInfo
100     */

101    String JavaDoc userSuppliedInfo = "";
102
103    /**
104     * Class constructor, should not be used because it leaves attributes with null values
105     * and there are no methods to populate them.
106     */

107    private ClientInfo()
108      {
109      originalType = CLIENTTYPE;
110      }
111
112    /**
113     * Class constructor
114     *
115     */

116    public ClientInfo(DataShareConnectionDescriptor commandStatusConnectionDescriptor,
117                      UserInfo userInfo,
118                      boolean saveData)
119      {
120      this(); // set create time, set originalType
121
name = userInfo.getUserName();
122      clientKey = userInfo.uniqueName;
123      clientCommandStatusConnectionDescriptor = commandStatusConnectionDescriptor;
124      this.userInfo = userInfo;
125      this.admin = userInfo.admin;
126      this.saveData = saveData;
127      this.clientMode = userInfo.getClientMode();
128      this.userSuppliedInfo = userInfo.getOtherInfo();
129      hostMachine = commandStatusConnectionDescriptor.clientIP;
130      this.clientClass = userInfo.getClientClass();
131      toString = clientKey;
132      if(userInfo != null)
133          {
134          try{
135             clientRealName = userInfo.firstName + " " + userInfo.lastName;
136             imageURL = userInfo.imageURL;
137             }
138          catch(Exception JavaDoc e)
139             {
140             e.printStackTrace();
141             }
142          }
143      }
144
145    /**
146     *
147     */

148    public void
149    updateCommandStatusConnectionDescriptor(DataShareConnectionDescriptor newDescriptor)
150       {
151       clientCommandStatusConnectionDescriptor = newDescriptor;
152       hostMachine = clientCommandStatusConnectionDescriptor.clientIP;
153       }
154
155    /**
156     * allows the host machine to be retreived
157     *
158     * @return returns information about host machine
159     */

160    public InetAddress JavaDoc
161    getHostMachine()
162       {
163       return hostMachine;
164       }
165
166    /**
167     * Retrieves a string containing 'Client'.
168     *
169     * @return fixed value of 'Client' for all instances
170     */

171    public String JavaDoc
172    getType()
173       {
174       return CLIENTTYPE;
175       }
176
177    /**
178     * Retrieves a description of this instance.
179     *
180     * @return the name of the Client for this instance
181     */

182    public String JavaDoc
183    getInfo()
184       {
185       if(this.infoString == null)
186          {
187          // should get in here the first call to getInfo() for each user
188
String JavaDoc adminString = "";
189          String JavaDoc userInfoString = "";
190          String JavaDoc realName = "";
191          if(!clientRealName.equals(" ")) // the space between the first and last names
192
realName = clientRealName;
193
194          if(admin)
195             adminString = "<tr><td>Privileges</td><td>This client has admin privileges</td></tr>";
196          if(userInfo != null)
197             {
198             try{
199                userInfoString =
200                    ((!userInfo.primaryEmail.equals("")) ? "<tr><td>Email address</td><td>" + userInfo.primaryEmail + "</td></tr>" : "" ) +
201                    ((!userInfo.primaryPhone.equals("")) ? "<tr><td>Phone</td><td>" + userInfo.primaryPhone + "</td></tr>" : "");
202                }
203             catch(Exception JavaDoc e)
204                {
205                e.printStackTrace();
206                }
207             }
208          else
209             {
210             if(this.saveData) // if not using beans, don't know about accounts
211
userInfoString = "<tr><td colspan=2>This client has no account on this server</td></tr>";
212             }
213
214          
215          infoString = "";
216          if (realName.trim().length() >0 )infoString = "<tr><td>Real name</td><td>"+realName +"</td></tr>";
217
218          infoString += userInfoString +
219                 "<tr><td>User's Name</td><td>" + this.name + "</td></tr>" +
220                 "<tr><td>Unique Name</td><td>" + this.clientKey + "</td></tr>" +
221                 "<tr><td>Client's IP address</td><td>" + hostMachine.getHostAddress() + " (server perspective)</td></tr>" +
222                 "<tr><td>Client's Machine</td><td>" + hostMachine.getHostName() + " (server perspective)</td></tr>" +
223 // "<tr><td>Client class</td><td>" + this.getClientClass() + "</td></tr>" +
224
"<tr><td>Connected</td><td>" + this.getDate().toString() + "</td></tr>" +
225                 "<tr><td>Running mode</td><td>" + RegistrationInfo.clientModes[clientMode] + "</td></tr>" +
226                 adminString + userSuppliedInfo;
227          }
228       return infoString;
229       }
230
231    /**
232     * the value to use for the key for this instance in the Hashtable of
233     * the Server's ClientInfo instances
234     *
235     * @return returns the key to use for this instance, String version of URL
236     * for ClientInfo
237     */

238    public String JavaDoc
239    getKeyValue()
240       {
241       return clientKey; // this will be unique for the client+VM+server
242
}
243
244    public boolean
245    getSeeAllTreeObjects()
246       {
247       return this.seeAllTreeObjects;
248       }
249
250    public void
251    setSeeAllTreeObjects(boolean seeAllTreeObjects)
252       {
253       this.seeAllTreeObjects = seeAllTreeObjects;
254       }
255
256    /**
257     * Sets the ADSKey String for this instance to the provided parameter value.
258     * The ADSKey String is the value provided when the EJB was created for this instance.
259     *
260     * @param ak the value to save as the ID for this instance
261     */

262    public void
263    setDatabaseID(String JavaDoc /* ADSKey */ ak)
264       {
265       SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
266          SessionUtilities.getLoggingInterface().DATABASE,
267          "setDatabaseID(): Table Key for " + this.getKeyValue() + " has value of " + ak);
268       databaseID = ak;
269       waitingForKey = false;
270       keyHasBeenReturned = true;
271       }
272
273    /**
274     * Retrieves the ADSKey String for this instance. Should always be checked for null.
275     * Also realize that this method may block until the ADSKey value is available.
276     *
277     * @return the ADSKey String that was previously set for this instance.
278     */

279    public String JavaDoc /* ADSKey */
280    getDatabaseID()
281       {
282       String JavaDoc thisKey = null;
283       if(saveData)
284          {
285          if(databaseID != null)
286             thisKey = databaseID;
287          else
288             thisKey = retrieveEJB();
289          }
290       return thisKey;
291       }
292
293    /**
294     * returns true if this client has admin privileges, false otherwise
295     */

296    public boolean
297    getAdmin()
298       {
299       return this.admin;
300       }
301
302
303    }
304
Popular Tags