KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > datashare > objects > DefaultObjectInfo


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: DefaultObjectInfo.java,v 1.2 2002/01/29 20:57:16 lizellaman Exp $
25  * $Log: DefaultObjectInfo.java,v $
26  * Revision 1.2 2002/01/29 20:57:16 lizellaman
27  * Added LoggingInterface, modified the PropertiesInterface implementation
28  *
29  * Revision 1.1.1.1 2001/10/23 13:37:20 lizellaman
30  * initial sourceforge release
31  *
32  */

33
34 package org.datashare.objects;
35
36 import java.util.Date JavaDoc;
37 import org.datashare.ChannelInfo;
38 import org.datashare.ClientInfo;
39 import org.datashare.SessionInfo;
40 import org.datashare.ConsumerInfo;
41 import org.datashare.SessionUtilities;
42
43 /**
44  * this class is used to convert the ClientInfo, ChannelInfo, SessionInfo, and ConsumerInfo
45  * classes into a class that is serializable, and common for processing on the recieving end.
46  * Note that DefaultObjectInfo instances are only created on the Server then sent to clients.
47  *
48  * @author Charles Wood
49  * @version 1.0
50  */

51 public class DefaultObjectInfo implements DSObjectInfoInterface, java.io.Serializable JavaDoc
52    {
53    /**
54     * this allows us to serialize this class without 'marshalling' errors.
55     *
56     */

57    static final long serialVersionUID = 9030593813711490593L;
58
59    /**
60     * the name used to refer to this unique instance
61     *
62     */

63    protected String JavaDoc name;
64
65    /**
66     * the Owner name string, used only for Sessions and Channels
67     *
68     */

69    protected String JavaDoc ownerName = "";
70
71    /**
72     * indicates the class of the client for this object
73     */

74    protected String JavaDoc clientClass = "";
75
76    /**
77     * this is the string that is displayed in the Jtree for this instance,
78     * this must be set for every instance.
79     *
80     */

81    protected String JavaDoc toString = "*";
82
83    /**
84     * flag to indicate if this instance is currently active in the JSDT Registry
85     *
86     */

87    protected boolean active = false;
88
89    /**
90     * when this instance was created
91     *
92     */

93    protected Date JavaDoc date;
94
95    /**
96     * the String value to use for this instance in a Hashtable. Must be unique for the
97     * context in which it is used:
98     * i.e. for ChannelInfo the keyValue must be unique in the Session,
99     * for SessionInfo the keyValue must be unique for all active Sessions,
100     * for ClientInfo the keyValue must be unique for each Client instance (Java VM) the Client is using,
101     * for ConsumerInfo the keyValue must match it's corresponding ClientInfo value and must
102     * be unique within the Channel.
103     *
104     */

105    protected String JavaDoc keyValue;
106
107    /**
108     * the String that should be displayed when the detailed information about this
109     * instance is desired
110     *
111     */

112    protected String JavaDoc infoString;
113
114    /**
115     * this is used to indicate what type this object should represent. It is especially
116     * useful when a SessionInfo has been pared-down to a DefaultObjectInfo so it can
117     * be serialized. The fact that a DefaultObjectInfo is now representing what was
118     * a SessionInfo is maintained in this attribute. In the example case, this attribute
119     * would be set to 'sessionType'
120     *
121     */

122    protected String JavaDoc originalType;
123
124    /**
125     * represents the parent instance's keyValue, used only for Channels and Consumers.
126     * For Channels, the parent is it's Session, for Consumers it is the Channel it is in.
127     *
128     */

129    protected String JavaDoc parentKeyValue;
130
131    /**
132     * represents the grandparent instance's keyValue, used only when this instance
133     * represents a Consumer. In that case, the parentKeyValue is set to its Channel
134     * and the grandparentKeyValue is set to the Session. This is because the keyValue
135     * for a Channel is not enough to find the Channel unless you also know the Session.
136     *
137     */

138    protected String JavaDoc grandparentKeyValue;
139
140    /**
141     * contains the database key String for this instance, populated only when the Server is saving
142     * data for this type. Note that this value may contain null even if data is saved (if the
143     * server has problems saving the data, or has not yet determined this key value)
144     *
145     */

146    protected String JavaDoc databaseID;
147
148    /**
149     * Used only if the server is creating/using EJBs, true indicates an EJB create was
150     * requested and we are waiting for it's key value to be returned, false otherwise.
151     *
152     */

153    protected boolean waitingForKey = true;
154
155    /**
156     * Used only if the server is creating/using EJBs, true indicates that the EJB was
157     * created and the setDatabaseID method has been called in this instance with the EJB's
158     * key value. It is set to false if EJBs are not used and also if EJBs are used,
159     * but the ADSKey String for the EJB has not yet been returned.
160     *
161     */

162    protected boolean keyHasBeenReturned = false;
163
164    /**
165     * Used to hold the URL for the image of Client/Consumers
166     */

167    protected String JavaDoc imageURL = "";
168
169    /**
170     * Used to hold the real name of a user, i.e. 'Chuck Wood', valid only for Client/Consumers
171     */

172    protected String JavaDoc clientRealName = "";
173
174    /**
175     * use depends on which object it is being applied to. Currently used only for Sessions/SessionInfo
176     */

177    protected boolean privateOnly = false;
178
179 // /**
180
// * this is the self-generated key that will be used by the server to give
181
// * Channels a unique key for use with keeping up with the Token for this Channel (if it is used).
182
// * -- really should be same as keyValue, but for channels, the keyValue is not unique among all
183
// * channels and would take too long to change at this point.
184
// */
185
// protected String tokenKey = "";
186

187    /**
188     * Empty Class constructor
189     *
190     */

191    protected DefaultObjectInfo()
192       {
193       name = "no name";
194       toString = name;
195       //originalType = DEFAULTOBJECTTYPE; // should be overwritten later
196
date = new Date JavaDoc(); //GregorianCalendar().getTime();
197
}
198
199    /**
200     * Class constructor with name of instance specified. Used for nodes that are not associated with
201     * any specific client or session
202     *
203     * @param name instance name
204     */

205    public DefaultObjectInfo(String JavaDoc name, String JavaDoc type, String JavaDoc infoString)
206       {
207       this();
208       this.name = name;
209       this.toString = name;
210       originalType = type;
211       this.infoString = infoString;
212       }
213
214    /**
215     * Class constructor with name of instance specified. Used when the node is associated with a
216     * client or session.
217     *
218     * @param name instance name
219     */

220    public DefaultObjectInfo(String JavaDoc name, String JavaDoc type, String JavaDoc clientClass, String JavaDoc infoString)
221       {
222       this(name, type, infoString);
223       this.clientClass = clientClass;
224       }
225
226    public DefaultObjectInfo(ChannelInfo infoObject)
227       {
228       this.date = infoObject.getDate();
229       this.keyValue = infoObject.getKeyValue();
230       this.name = infoObject.getConnectionDescriptor().name;
231       this.toString = infoObject.toString();
232       this.infoString = infoObject.getInfo();
233       this.originalType = infoObject.CHANNELTYPE;
234       this.parentKeyValue = infoObject.getParentKeyValue();
235       this.ownerName = infoObject.getSessionInfo().getOwnerName();
236       this.databaseID = infoObject.getDatabaseID();
237       this.active = infoObject.getActive();
238       this.clientClass = infoObject.getClientClass();
239 // this.tokenKey = infoObject.getTokenKey();
240
}
241
242    public DefaultObjectInfo(ClientInfo infoObject)
243       {
244       this.date = infoObject.getDate();
245       this.keyValue = infoObject.getKeyValue();
246       this.name = infoObject.getName();
247       this.toString = infoObject.toString(); // don't use name for display of Clients
248
this.infoString = infoObject.getInfo();
249       this.originalType = infoObject.CLIENTTYPE;
250       this.imageURL = infoObject.getImageURL();
251       this.clientRealName = infoObject.getClientRealName();
252       this.databaseID = infoObject.getDatabaseID();
253       this.active = infoObject.getActive();
254       this.clientClass = infoObject.getClientClass();
255       }
256
257    public DefaultObjectInfo(SessionInfo infoObject)
258       {
259       this.date = infoObject.getDate();
260       this.keyValue = infoObject.getKeyValue();
261       this.name = infoObject.toString();
262       this.toString = infoObject.toString();
263       this.infoString = infoObject.getInfo();
264       this.originalType = infoObject.SESSIONTYPE;
265       this.ownerName = infoObject.getOwnerName();
266       this.databaseID = infoObject.getDatabaseID();
267       this.privateOnly = infoObject.getPrivate();
268       this.active = infoObject.getActive();
269       this.clientClass = infoObject.getClientClass();
270       }
271
272    public DefaultObjectInfo(ConsumerInfo infoObject)
273       {
274       this.date = infoObject.getDate();
275       this.keyValue = infoObject.getKeyValue();
276       this.name = infoObject.getName();
277       this.toString = infoObject.toString();
278       this.infoString = infoObject.getInfo();
279       this.originalType = infoObject.CONSUMERTYPE;
280       this.parentKeyValue = infoObject.getParentKeyValue();
281       this.grandparentKeyValue = infoObject.getGrandParentKeyValue();
282       this.imageURL = infoObject.getClientInfo().getImageURL();
283       this.clientRealName = infoObject.getClientRealName();
284       this.active = infoObject.getActive();
285       this.clientClass = infoObject.getClientClass();
286 // this.databaseID = infoObject.getDatabaseID(); // who cares? and doesn't work well...times out
287
}
288
289    /**
290     * Retrieves the string to use for the JTree display of this instance
291     *
292     * @return the instance's name
293     */

294    public String JavaDoc
295    toString()
296       {
297       return toString;
298       }
299
300    /**
301     * Retrieves the unique name of this instance.
302     *
303     * @return the instance's name
304     */

305    public String JavaDoc
306    getName()
307       {
308       return name;
309       }
310
311    /**
312     * returns the client's real name, if available, empty string otherwise
313     */

314    public String JavaDoc
315    getClientRealName()
316       {
317       return clientRealName;
318       }
319
320 // /**
321
// * returns the tokenKey value, normally available only for ChannelInfo objects, empty string otherwise
322
// */
323
// public String
324
// getTokenKey()
325
// {
326
// return tokenKey;
327
// }
328

329    /**
330     * Retrieves the ADSKey string for this Instance
331     *
332     * @return the instance's databaseID
333     */

334    public String JavaDoc
335    getDatabaseID()
336       {
337       return databaseID;
338       }
339
340    /**
341     * Waits for the container to return the EJB String ID, or returns null if we have waited long enough
342     */

343    public String JavaDoc
344    retrieveEJB()
345       {
346       String JavaDoc thisKey = "";
347       int count = 0;
348       Date JavaDoc startTime = new Date JavaDoc();
349       Date JavaDoc stopTime = null;
350
351       SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
352                        SessionUtilities.getLoggingInterface().DATABASE,
353                        "Trying to retrieve a " + this.getType() + " ADSKey for " + getKeyValue());
354       // let's give the Bean a while to get created (if we have to wait)
355
while(waitingForKey && count < 35)
356          {
357          count++;
358          try
359             {
360             Thread.sleep(1000);
361             }
362          catch(InterruptedException JavaDoc ie)
363             {
364             }
365          }
366       if(keyHasBeenReturned)
367          thisKey = databaseID;
368       else
369          {
370          stopTime = new Date JavaDoc();
371          SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
372                        SessionUtilities.getLoggingInterface().DATABASE,
373                        "getDatabaseID("+this.getKeyValue()+") bad state: started EJBCreate at " +
374          SessionUtilities.getTimeString(startTime) +
375          " and gave up at " +
376          SessionUtilities.getTimeString(stopTime));
377          }
378       return thisKey;
379       }
380
381
382    /**
383     * Retrieves the Creator/Owner name for this instance, used only for Sessions and Channels
384     *
385     * @return this instance's owner/creator name
386     */

387    public String JavaDoc
388    getOwnerName()
389       {
390       return this.ownerName;
391       }
392
393    /**
394     * Retrieves a string containing 'DefaultObjectInfo'.
395     *
396     * @return fixed value of 'DefaultObjectInfo' for all instances, used when
397     * this class is referenced by it's parent class so all subclasses have a
398     * common method that can be used to test for the instance type.
399     */

400    public String JavaDoc
401    getType()
402       {
403       return DEFAULTOBJECTTYPE;
404       }
405
406    /**
407     * Retrieves a string containing the original type of object that is represented by this instance.
408     *
409     * @return value of originalType for this instance
410     */

411    public String JavaDoc
412    getOriginalType()
413       {
414       return originalType;
415       }
416
417    /**
418     * Retrieves an Object reference of this instance, used when this class
419     * is cast to the parent class for common handling of JSDTObjectInfo objects.
420     *
421     * @return the DefaultObjectInfo instance as an Object
422     */

423    public Object JavaDoc
424    getObject()
425       {
426       return this;
427       }
428
429    /**
430     * Retrieves the clientClass for this object
431     */

432    public String JavaDoc
433    getClientClass()
434       {
435       return clientClass;
436       }
437
438    /**
439     * Retrieves a description of this instance.
440     *
441     * @return the infoString for this instance which should contain detailed
442     * information about this instance; returns the name of this instance if
443     * infoString is null
444     */

445    public String JavaDoc
446    getInfo()
447       {
448       if(infoString != null && infoString.length() != 0)
449          return infoString;
450       else
451          return "<tr><td>User Name:</td><td>"+name+"</td></tr>";
452       }
453
454    /**
455     * Sets the value that is used to hold detailed information about this instance.
456     *
457     * @param infoString the detailed information about this instance.
458     */

459    public void
460    setInfo(String JavaDoc infoString)
461       {
462       this.infoString = infoString;
463       }
464
465    /**
466     * Retrieves the active flag
467     *
468     * @return true if this instance is currently active in the JSDT Registry
469     */

470    public boolean
471    getActive()
472       {
473       return active;
474       }
475
476    /**
477     * sets the active flag for this instance to the specified value
478     *
479     * @param active value to set active flag to
480     */

481    public void
482    setActive(boolean active)
483       {
484       this.active = active;
485       }
486
487    /**
488     * Retrieves when this instance was created
489     *
490     * @return the time this instance was created (first put into the JSDT
491     * Registry)
492     */

493    public Date JavaDoc
494    getDate()
495       {
496       return date;
497       }
498
499
500    /**
501     * the value to use for the key for this instance in a Hashtable of
502     * these instances (care must be taken to ensure keys are unique in the Hashtable):
503     * the String used in the constructor is used as the key here.
504     *
505     * @return the value to use as the key for this instance in a Hashtable
506     */

507    public String JavaDoc
508    getKeyValue()
509       {
510       return keyValue; // must be unique in the Hashtable
511
}
512
513    /**
514     * the value to use for the key of this instances parent's keyValue.
515     *
516     * @return the value to use as the key for this instances parent in a
517     * Hashtable
518     */

519    public String JavaDoc
520    getParentKeyValue()
521       {
522       if( parentKeyValue == null )
523          return "NULL";
524       else
525          return parentKeyValue; // must be unique in the Hashtable
526
}
527
528    /**
529     * the value to use for the key of this instances grandparent's keyValue.
530     *
531     * @return the value to use as the key for this instances grandparent in a
532     * Hashtable
533     */

534    public String JavaDoc
535    getGrandParentKeyValue()
536       {
537       if( grandparentKeyValue == null )
538          return "NULL";
539       else
540          return grandparentKeyValue; // must be unique in the Hashtable
541
}
542
543    /**
544     * Sets the value to use for the key for this instance in a Hashtable of
545     * these instances (care must be taken to ensure keys are unique in the Hashtable)
546     *
547     * @param keyValue value to use as the key in a Hashtable for this instance
548     */

549    public void
550    setKeyValue(String JavaDoc keyValue)
551       {
552       this.keyValue = keyValue; // must be unique in the Hashtable
553
}
554
555    /**
556     * Used to set the value that represents if the EJB has been created and it's
557     * corresponding ADSKey String value set into the invoking class via the setEjbId() method.
558     * This method is used only if EJBs are being used/created.
559     *
560     * @param value true if the ADSKey String has been returned, false if we
561     * are still waiting
562     */

563    public void
564    setKeyHasBeenReturned(boolean value)
565       {
566       keyHasBeenReturned = value;
567       }
568
569    /**
570     * Indicates the status of the EJB that was requested to be created: this method
571     * is called with a true value while we are waiting for the EJB to be created, and
572     * set to false after the EJB has been created and it's ADSKey String value has been
573     * returned via the setADSKey method. Note that to truly determine if the ADSKey
574     * value has been completed, this method will return a false and the method
575     * getKeyHasBeenReturned will return true. This method is used only if EJBs are
576     * being used/created.
577     *
578     * @param value true if the EJB has not been completed, false otherwise.
579     */

580    public void
581    setWaitingForKey(boolean value)
582       {
583       waitingForKey = value;
584       }
585
586    /**
587     * Sets the ADSKey String for this instance to the provided parameter value.
588     * The ADSKey String is the value provided when the EJB was created for this instance.
589     *
590     * @param ak the value to save as the ID for this instance
591     */

592    public void
593    setDatabaseID(String JavaDoc /* ADSKey */ ak)
594       {
595       SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
596                        SessionUtilities.getLoggingInterface().DATABASE,
597                        "setDatabaseID(): EJB Key for " + this.getKeyValue() + " has value of " + ak);
598       databaseID = ak;
599       waitingForKey = false;
600       keyHasBeenReturned = true;
601       }
602
603    /**
604     * returns the URL for the image of a user, probably valid only if this instance refers to a Client/Consumer
605     */

606    public String JavaDoc getImageURL()
607       {
608       return this.imageURL;
609       }
610
611    /**
612     * returns the value that was set by the original object, use is specific to the
613     * original type of object this instance was created from
614     */

615    public boolean
616    getPrivate()
617       {
618       return this.privateOnly;
619       }
620
621
622    }
623
624
Popular Tags