001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: BaseDiscRackEventGateway.java,v 1.1 2006-09-11 12:30:36 sinisa Exp $
022: */
023:
024: package barracudaDiscRack.presentation;
025:
026: // import disc rack specifics
027: import barracudaDiscRack.presentation.personMgmt.events.*;
028: import barracudaDiscRack.business.person.*;
029:
030: // import Enhydra specifics
031: import com.lutris.appserver.server.httpPresentation.*;
032: import com.lutris.appserver.server.Enhydra;
033: import com.lutris.util.KeywordValueException;
034: import com.lutris.logging.*;
035:
036: // import barracuda specifics
037: import org.barracudamvc.core.event.*;
038:
039: public class BaseDiscRackEventGateway extends DefaultEventGateway {
040:
041: //------------------------------------------------------------
042: // BasePO functions
043: //------------------------------------------------------------
044:
045: /**
046: * Initialise the Enhydra PO session data from the event context
047: *
048: * @param EventContext
049: */
050: protected void initUsingContext(EventContext context)
051: throws EventException {
052: try {
053: this .myComms = (HttpPresentationComms) context
054: .getState(ApplicationGateway.EXTERNAL_CONTEXT_OBJ_NAME);
055: this .initSessionData(this .myComms);
056: } catch (ClassCastException ex) {
057: String errMsg = "ERROR: External Context object is NOT a HttpPresentationComms object. Cannot function";
058: throw (new EventException(errMsg, ex));
059: } catch (DiscRackPresentationException ex) {
060: String errMsg = "ERROR: Could not get session data from session:";
061: throw (new EventException(errMsg, ex));
062: }
063: }
064:
065: /**
066: * Gets HttpPresentation object
067: *
068: * @return The saved comms objects
069: * to whichever subclass needs it
070: */
071: public HttpPresentationComms getComms() {
072: return this .myComms;
073: }
074:
075: /**
076: * Gets the session data
077: *
078: * @return session data
079: */
080: public DiscRackSessionData getSessionData() {
081: return this .mySessionData;
082: }
083:
084: /**
085: * Sets the user into the session
086: *
087: * @param thePerson, the person to be set in the session
088: * @exception DiscRackPresentationException
089: */
090: public void setUser(Person thePerson)
091: throws DiscRackPresentationException {
092: this .getSessionData().setUser(thePerson);
093: }
094:
095: /**
096: * Gets the user from the session
097: *
098: * @return the person object in the session
099: */
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 obj = comms.sessionData
124: .get(DiscRackSessionData.SESSION_KEY);
125: // If we found the session data, save it in a private data member
126: if (null != obj) {
127: this .mySessionData = (DiscRackSessionData) obj;
128: } else {
129: // If no session data was found, create a new session data instance
130: this .mySessionData = new DiscRackSessionData();
131: comms.sessionData.set(DiscRackSessionData.SESSION_KEY,
132: this .mySessionData);
133: }
134: } catch (KeywordValueException ex) {
135: writeDebugMsg("Problem getting session data from session: "
136: + ex.getMessage());
137: }
138: }
139:
140: /**
141: * Method to write a debugging message to the debug log
142: * channel when the DEBUG flag is turned on
143: *
144: * @param msg The message to write to the DEBUG log channel
145: */
146: public static void writeDebugMsg(String msg) {
147: Enhydra.getLogChannel().write(Logger.DEBUG, msg);
148: }
149:
150: /**
151: * Saved input and output context, and session data
152: */
153: private HttpPresentationComms myComms = null;
154: private DiscRackSessionData mySessionData = null;
155:
156: /**
157: * Reference to the person logged in to the session
158: */
159: private Person myPerson = null;
160:
161: }
|