001 package com.bea.medrec.actions;
002
003 import com.bea.medrec.utils.MedRecLog4jFactory;
004 import com.bea.medrec.controller.*;
005 import javax.naming.InitialContext;
006 import org.apache.log4j.Logger;
007
008 /**
009 * <p>Base servlet encapsulating common servlet functionality.</p>
010 *
011 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
012 */
013 public abstract class PatientBaseAction
014 extends BaseAction implements PatientConstants
015 {
016 private static Logger logger =
017 MedRecLog4jFactory.getLogger(PatientBaseAction.class.getName());
018
019 protected InitialContext ctx = null;
020 private AdminSession adminSession;
021 private PatientSession patientSession;
022 private RecordSession recordSession;
023
024 /**
025 * <p>Retrives AdminSession home.
026 * If instance does not exist, retrieve a new instance.<p>
027 *
028 * @return AdminSession
029 */
030 protected AdminSession getAdminSession() throws Exception {
031 if (ctx == null) ctx = new InitialContext();
032 if (adminSession == null) {
033 logger.debug("Getting new admin session.");
034 this.adminSession = getAdminSessionHome();
035 }
036 return this.adminSession;
037 }
038
039 /**
040 * <p>Retrives PatientSession home.
041 * If instance does not exist, retrieve a new instance.<p>
042 *
043 * @return PatientSession
044 */
045 protected PatientSession getPatientSession() throws Exception {
046 if (ctx == null) ctx = new InitialContext();
047 if (patientSession == null) {
048 logger.debug("Getting new patient session.");
049 this.patientSession = getPatientSessionHome();
050 }
051 return this.patientSession;
052 }
053
054 /**
055 * <p>Retrives RecordSession home.
056 * If instance does not exist, retrieve a new instance.<p>
057 *
058 * @return RecordSession
059 */
060 protected RecordSession getRecordSession() throws Exception {
061 if (ctx == null) ctx = new InitialContext();
062 if (recordSession == null) {
063 logger.debug("Getting new record session.");
064 this.recordSession = getRecordSessionHome();
065 }
066 return this.recordSession;
067 }
068
069 // P R I V A T E M E T H O D S
070 /**
071 * <p>Get AdminSession</p>
072 *
073 * @return AdminSession
074 */
075 private AdminSession getAdminSessionHome() throws Exception {
076 AdminSessionHome home = (AdminSessionHome)ctx.lookup(
077 "java:/comp/env/AdminSessionEJB");
078 return (AdminSession)home.create();
079 }
080
081 /**
082 * <p>Get PatientSession EJB</p>
083 *
084 * @return PatientSession
085 */
086 private PatientSession getPatientSessionHome() throws Exception {
087 PatientSessionHome home = (PatientSessionHome)ctx.lookup(
088 "java:/comp/env/PatientSessionEJB");
089 return (PatientSession)home.create();
090 }
091
092 /**
093 * <p>Get RecordSession EJB</p>
094 *
095 * @return RecordSession
096 */
097 private RecordSession getRecordSessionHome() throws Exception {
098 RecordSessionHome home = (RecordSessionHome)ctx.lookup(
099 "java:/comp/env/RecordSessionEJB");
100 return (RecordSession)home.create();
101 }
102 }
|