KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > barracudaDiscRack > presentation > BaseDiscRackEventGateway


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: BaseDiscRackEventGateway.java,v 1.4 2004/12/03 14:12:34 slobodan Exp $
23  */

24
25 package barracudaDiscRack.presentation;
26
27 // import disc rack specifics
28
import barracudaDiscRack.presentation.personMgmt.events.*;
29 import barracudaDiscRack.business.person.*;
30
31 // import Enhydra specifics
32
import com.lutris.appserver.server.httpPresentation.*;
33 import com.lutris.appserver.server.Enhydra;
34 import com.lutris.util.KeywordValueException;
35 import com.lutris.logging.*;
36
37 // import barracuda specifics
38
import org.enhydra.barracuda.core.event.*;
39
40 public class BaseDiscRackEventGateway extends DefaultEventGateway {
41
42     //------------------------------------------------------------
43
// BasePO functions
44
//------------------------------------------------------------
45

46     /**
47      * Initialise the Enhydra PO session data from the event context
48      *
49    * @param EventContext
50      */

51     protected void initUsingContext( EventContext context ) throws EventException {
52         try {
53             this.myComms =
54             (HttpPresentationComms)context.getState( ApplicationGateway.EXTERNAL_CONTEXT_OBJ_NAME );
55             this.initSessionData(this.myComms);
56         } catch ( ClassCastException JavaDoc ex ) {
57             String JavaDoc errMsg = "ERROR: External Context object is NOT a HttpPresentationComms object. Cannot function";
58             throw ( new EventException( errMsg, ex ) );
59         } catch ( DiscRackPresentationException ex ) {
60             String JavaDoc errMsg = "ERROR: Could not get session data from session:";
61             throw ( new EventException( errMsg, ex ) );
62         }
63     }
64
65     /**
66      * Gets HttpPresentation object
67      *
68      * @return The saved comms objects
69      * to whichever subclass needs it
70      */

71     public HttpPresentationComms getComms() {
72         return this.myComms;
73     }
74
75     /**
76      * Gets the session data
77      *
78      * @return session data
79      */

80     public DiscRackSessionData getSessionData() {
81         return this.mySessionData;
82     }
83
84     /**
85      * Sets the user into the session
86      *
87      * @param thePerson, the person to be set in the session
88      * @exception DiscRackPresentationException
89      */

90     public void setUser(Person thePerson)
91     throws DiscRackPresentationException {
92         this.getSessionData().setUser(thePerson);
93     }
94
95     /**
96      * Gets the user from the session
97      *
98      * @return the person object in the session
99      */

100     public Person getUser() {
101         return this.getSessionData().getUser();
102     }
103
104     /**
105      * Method to remove the current user from the session
106      */

107     public void removeUserFromSession() {
108         this.getSessionData().removeUser();
109     }
110
111     /**
112      * Method to get or create the AgSessionData object from the user session
113      * This object is saved in the EbrokerPresentation object
114      *
115      * @param HttpPresentationComms
116      * @exception Exception
117      */

118     protected void initSessionData(HttpPresentationComms comms)
119     throws DiscRackPresentationException {
120         this.myComms = comms;
121
122         try {
123             Object JavaDoc obj = comms.sessionData.get(DiscRackSessionData.SESSION_KEY);
124             // If we found the session data, save it in a private data member
125
if ( null != obj ) {
126                 this.mySessionData = (DiscRackSessionData)obj;
127             } else {
128                 // If no session data was found, create a new session data instance
129
this.mySessionData = new DiscRackSessionData();
130                 comms.sessionData.set(DiscRackSessionData.SESSION_KEY, this.mySessionData);
131             }
132         } catch ( KeywordValueException ex ) {
133             writeDebugMsg("Problem getting session data from session: " +
134                                         ex.getMessage());
135         }
136     }
137
138     /**
139      * Method to write a debugging message to the debug log
140      * channel when the DEBUG flag is turned on
141      *
142      * @param msg The message to write to the DEBUG log channel
143      */

144     public static void writeDebugMsg(String JavaDoc msg) {
145         Enhydra.getLogChannel().write(Logger.DEBUG,msg);
146     }
147
148     /**
149      * Saved input and output context, and session data
150      */

151     private HttpPresentationComms myComms = null;
152     private DiscRackSessionData mySessionData = null;
153
154     /**
155      * Reference to the person logged in to the session
156      */

157     private Person myPerson = null;
158
159 }
160
Popular Tags