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