Source Code Cross Referenced for SessionInfo.java in  » Groupware » Data-share » org » datashare » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Groupware » Data share » org.datashare 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ----- BEGIN LICENSE BLOCK -----
002:         * Version: MPL 1.1
003:         *
004:         * The contents of this file are subject to the Mozilla Public License Version
005:         * 1.1 (the "License"); you may not use this file except in compliance with
006:         * the License. You may obtain a copy of the License at
007:         * http://www.mozilla.org/MPL/
008:         *
009:         * Software distributed under the License is distributed on an "AS IS" basis,
010:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011:         * for the specific language governing rights and limitations under the
012:         * License.
013:         *
014:         * The Original Code is the DataShare server.
015:         *
016:         * The Initial Developer of the Original Code is
017:         * Ball Aerospace & Technologies Corp, Fairborn, Ohio
018:         * Portions created by the Initial Developer are Copyright (C) 2001
019:         * the Initial Developer. All Rights Reserved.
020:         *
021:         * Contributor(s): Charles Wood <cwood@ball.com>
022:         *
023:         * ----- END LICENSE BLOCK ----- */
024:        /* RCS $Id: SessionInfo.java,v 1.2 2002/01/29 20:50:17 lizellaman Exp $
025:         * $Log: SessionInfo.java,v $
026:         * Revision 1.2  2002/01/29 20:50:17  lizellaman
027:         * Added LoggingInterface, modified the PropertiesInterface implementation
028:         *
029:         * Revision 1.1.1.1  2001/10/23 13:37:18  lizellaman
030:         * initial sourceforge release
031:         *
032:         */
033:
034:        package org.datashare;
035:
036:        import java.util.Date;
037:        import java.util.Hashtable;
038:        import java.util.Enumeration;
039:        import org.datashare.objects.DefaultObjectInfo;
040:        import org.datashare.objects.DataShareConnectionDescriptor;
041:
042:        /**
043:         * Holds information about a Session.  The keyValue for a SessionInfo is derived
044:         * from it's name and an integer
045:         *
046:         * @author Charles Wood
047:         * @date March 01, 2001
048:         * @version 1.0
049:         */
050:        public class SessionInfo extends DefaultObjectInfo implements 
051:                PersistDataCallbackInterface, java.io.Serializable {
052:            /**
053:             * this allows us to serialize this class without 'marshalling' errors, and to
054:             * invalidate instances that are 'different' (too old or new).
055:             */
056:            static final long serialVersionUID = 9030593815464356544L;
057:
058:            /**
059:             * the Client that requested this session be created
060:             *
061:             */
062:            private String owningClientName; // use name instead of clientKey
063:
064:            /**
065:             * set to contain all Channels in this Session, values are ChannelInfo instances,
066:             * keys are ChannelInfo getKeyValue() Strings.  We will not persist this attribute
067:             * because we will re-create the contents if we need to pull this instance back out
068:             * of however we persisted it.  We should be able to find all the appropriate ChannelInfo
069:             * instances that were in this table just by looking at all the ChannelInfo instances to
070:             * see if they have their session ID matching this one.
071:             *
072:             */
073:            private transient Hashtable channelInfoTable = new Hashtable();
074:
075:            /**
076:             * a short description of the purpose of this Session, used for display only
077:             *
078:             */
079:            private String sessionDescription;
080:
081:            /**
082:             * true indicates that only the owner and those in the Session can see it,
083:             * false is the default and means that all clients/users can see the Session.
084:             * Note that this must be set after the instance is created because it is not
085:             * a parameter of the constructor.
086:             */
087:            boolean privateSession = false;
088:
089:            /**
090:             * set to the server's value of saveData, saves data about the Session, not the data in it's channel(s)
091:             */
092:            boolean saveData = false;
093:
094:            /**
095:             * if true, the Session and all it's Channels will be deleted after at least one Consumer joins the
096:             * a Channel, then all Consumer's leave all Channels.
097:             */
098:            private boolean autoDelete = false;
099:
100:            /**
101:             * class constructor (empty), use should be avoided
102:             *
103:             */
104:            private SessionInfo() {
105:                // date is set by automatic super() call
106:                originalType = SESSIONTYPE;
107:            }
108:
109:            /**
110:             * class constructor, assigns a keyValue automatically
111:             *
112:             * @param sessionName the Session name for this instance, must be unique on Server
113:             * @param sessionDescription a description for this session
114:             * @param owningClientKey the client userName that created this Session
115:             * @param saveData used to determine if the server is creating/saving data
116:             */
117:            public SessionInfo(String sessionName, String sessionDescription,
118:                    String owningClientName, String clientClass,
119:                    boolean saveData) {
120:                this ();
121:                name = sessionName;
122:                toString = sessionName;
123:                keyValue = name; // name was made unique (no other active session has same name)
124:                this .sessionDescription = sessionDescription;
125:                this .owningClientName = owningClientName;
126:                this .clientClass = clientClass;
127:                this .saveData = saveData;
128:            }
129:
130:            /**
131:             * returns the DataShareConnectionDescriptors for all channels in this Session
132:             */
133:            public DataShareConnectionDescriptor[] getChannelConnectionDescriptors() {
134:                synchronized (channelInfoTable) {
135:                    DataShareConnectionDescriptor dscd[] = new DataShareConnectionDescriptor[channelInfoTable
136:                            .size()];
137:                    int x = 0;
138:
139:                    for (Enumeration channelEnum = channelInfoTable.elements(); channelEnum
140:                            .hasMoreElements(); x++) {
141:                        ChannelInfo channelInfo = (ChannelInfo) channelEnum
142:                                .nextElement();
143:                        dscd[x] = channelInfo.getConnectionDescriptor();
144:                    }
145:                    return dscd;
146:                }
147:            }
148:
149:            /**
150:             * allows the owner of this Session to be retreived
151:             *
152:             * @return the Client that requested the creation of this Session
153:             */
154:            public String getOwnerName() {
155:                return owningClientName;
156:            }
157:
158:            /**
159:             * allows the description for this Session to be saved
160:             *
161:             * @param sessionDescription the purpose for the creation of this Session
162:             */
163:            public void setSessionDescription(String sessionDescription) {
164:                this .sessionDescription = sessionDescription;
165:            }
166:
167:            /**
168:             * allows the description for this Session to be retreived
169:             *
170:             * @return the description of the purpose for the creation of this Session
171:             */
172:            public String getSessionDescription() {
173:                return sessionDescription;
174:            }
175:
176:            /**
177:             * returns 'Session' string, used when this class is accessed as its superclass
178:             * to determine which subclass this class is
179:             *
180:             * @return sessionType attribute (final static)
181:             */
182:            public String getType() {
183:                return SESSIONTYPE;
184:            }
185:
186:            /**
187:             * Should return as much info about this Session as possible
188:             *
189:             * @return a String with this Session name and other relevant comments
190:             */
191:            public String getInfo() {
192:                String info = "<tr><td>Session type</td><td>"
193:                        + (this .privateSession ? "private" : "public")
194:                        + "</td></tr>" + "<tr><td>Session name</td><td>"
195:                        + this .getName() + "</td></tr>"
196:                        + "<tr><td>Description</td><td>" + sessionDescription
197:                        + "</td></tr>" + "<tr><td>Created on</td><td>"
198:                        + this .getDate() + "</td></tr>"
199:                        + "<tr><td>Owner</td><td>" + this .getOwnerName()
200:                        + "</td></tr>" + "<tr><td>Database ID</td><td>"
201:                        + this .databaseID + "</td></tr>";
202:                return info;
203:            }
204:
205:            /**
206:             * adds a Channel to this Session
207:             *
208:             * @param channel the channel to be added to this session
209:             */
210:            public void addChannel(ChannelInfo channel) {
211:                SessionUtilities.getLoggingInterface().debugMsg(
212:                        SessionUtilities.getLoggingInterface().DEBUG,
213:                        SessionUtilities.getLoggingInterface().SESSION,
214:                        "Adding a ChannelInfo (" + channel.toString()
215:                                + ") to SessionInfo " + this .toString());
216:
217:                // if this object was retrieved from persistenceInterface, the table is null to start with...
218:                if (channelInfoTable == null)
219:                    channelInfoTable = new Hashtable();
220:
221:                channelInfoTable.put(channel.getKeyValue(), channel);
222:            }
223:
224:            /**
225:             * removes a Channel from this Session
226:             *
227:             * @param channel the channel to be removed from this session
228:             */
229:            public void removeChannel(ChannelInfo channel) {
230:                SessionUtilities.getLoggingInterface().debugMsg(
231:                        SessionUtilities.getLoggingInterface().DEBUG,
232:                        SessionUtilities.getLoggingInterface().SESSION,
233:                        "Removing a ChannelInfo (" + channel.toString()
234:                                + ") from SessionInfo " + this .toString());
235:                channelInfoTable.remove(channel.getKeyValue());
236:            }
237:
238:            /**
239:             * returns the Hashtable of Channels for this Session
240:             *
241:             * @return all Channels in this Session
242:             */
243:            public Hashtable getChannelTable() {
244:                return channelInfoTable;
245:            }
246:
247:            /**
248:             * Sets the ADSKey String for this instance to the provided parameter value.
249:             * The ADSKey String is the value provided when the EJB was created for this instance.
250:             *
251:             * @param ak the value to save as the ID for this instance
252:             */
253:            public void setDatabaseID(String /* ADSKey */ak) {
254:                SessionUtilities.getLoggingInterface().debugMsg(
255:                        SessionUtilities.getLoggingInterface().DEBUG,
256:                        SessionUtilities.getLoggingInterface().DATABASE,
257:                        "setDatabaseID(): Key for " + this .getKeyValue()
258:                                + " has value of " + ak);
259:                databaseID = ak;
260:                waitingForKey = false;
261:                keyHasBeenReturned = true;
262:            }
263:
264:            /**
265:             * Retrieves the ADSKey String for this instance.  Should always be checked for null.
266:             * Also realize that this method may block until the ADSKey value is available.
267:             *
268:             * @return the ADSKey String that was previously set for this instance.
269:             */
270:            public String /* ADSKey */
271:            getDatabaseID() {
272:                String this Key = null;
273:                if (this .saveData) {
274:                    if (this .databaseID != null)
275:                        this Key = databaseID;
276:                    else
277:                        this Key = retrieveEJB();
278:                }
279:                return this Key;
280:            }
281:
282:            /**
283:             * if return value is true, this is a private Session
284:             */
285:            public boolean getPrivate() {
286:                return this .privateSession;
287:            }
288:
289:            /**
290:             * allows us to set a creation date, used only when an instance is created to replicate
291:             * the original SessionInfo, as in the case of retrieving the Session information from
292:             * history to make a new SessionInfo look like the original one.
293:             */
294:            public void setCreationDate(Date date) {
295:                this .date = date;
296:            }
297:
298:            /**
299:             * used to determine if a session already exists, compares session name,
300:             * session description, clientClass, and any channels in the object (sessionInfo) must also exist in
301:             * this instance as determined by having the same name.  This instance may contain additional channels
302:             * and still be considered equal to the object (sessionInfo).
303:             */
304:            public boolean
305:   isSubSet(SessionInfo sessionInfo)
306:      {
307:      boolean retValue = true;
308:      if(!getName().equals(sessionInfo.getName()))
309:         retValue = false;
310:      else if(!getSessionDescription().equals(sessionInfo.getSessionDescription()))
311:         retValue = false;
312:      else if(!getClientClass().equals(sessionInfo.getClientClass()))
313:         retValue = false;
314:      else
315:         {
316:         // now check to see if all supplied channels are in this instance...
317:         for(Enumeration enum = sessionInfo.getChannelTable().elements(); enum.hasMoreElements(); )
318:            {
319:            ChannelInfo channelInfo = (ChannelInfo)enum.nextElement();
320:            if(!this .channelInfoTable.containsKey(channelInfo.getKeyValue()))
321:               {
322:               retValue = false;  // all it takes is one channel name not present to fail
323:               break;
324:               }
325:            }
326:         }
327:
328:      return retValue;
329:      }
330:
331:            /**
332:             * when called, causes any Channels in this Session to be deleted once the last Consumer leaves, note
333:             * that at least one consumer must leave first (implying that at least one Consumer must have joined).
334:             */
335:            public void setAutoDelete() {
336:                autoDelete = true;
337:            }
338:
339:            /**
340:             * if true, indicates that any Channels in this Session will be deleted once the last Consumer leaves, note
341:             * that at least one consumer must leave first (implying that at least one Consumer must have joined).
342:             */
343:            public boolean getAutoDelete() {
344:                return autoDelete;
345:            }
346:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.