PhysBaseLookupDispatchAction.java
01 package com.bea.medrec.actions;
02 
03 import com.bea.medrec.controller.PhysicianSession;
04 import com.bea.medrec.controller.PhysicianSessionHome;
05 import com.bea.medrec.utils.ClientException;
06 import com.bea.medrec.utils.MedRecLog4jFactory;
07 import javax.naming.InitialContext;
08 import javax.servlet.http.HttpServletRequest;
09 import javax.servlet.http.HttpServletResponse;
10 import org.apache.log4j.Logger;
11 import org.apache.struts.action.ActionForm;
12 import org.apache.struts.action.ActionForward;
13 import org.apache.struts.action.ActionMapping;
14 
15 /**
16  <p>Base lookup dispatch action encapsulating
17  * common physician webapp functionality.</p>
18  *
19  @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
20  */
21 public abstract class PhysBaseLookupDispatchAction
22     extends BaseLookupDispatchAction implements PhysicianConstants {
23 
24   private static Logger logger =
25       MedRecLog4jFactory.getLogger(PhysBaseLookupDispatchAction.class.getName());
26 
27   protected InitialContext ctx = null;
28   private PhysicianSession physicianSession;
29 
30   /**
31    <p>Calls base lookup dispatch action.
32    * First checks for valid session</p>
33    *
34    @param mapping  The ActionMapping used to select this instance
35    @param form  The optional ActionForm bean for this request (if any)
36    @param request  The HTTP request we are processing
37    @param response  The HTTP response we are creating
38    */
39   public ActionForward execute(ActionMapping mapping,
40                                ActionForm form,
41                                HttpServletRequest request,
42                                HttpServletResponse response)
43       throws Exception, ClientException {
44     logger.debug("PhysBaseLookupDispatchAction execute.");
45     ActionForward forward;
46     try {
47       // Minimal check for valid session.
48       //checkSession(request, mapping);
49       forward = super.execute(mapping, form, request, response);
50     catch (Exception e) {
51       return handleException(e, request, mapping);
52     }
53     return forward;
54   }
55 
56   /**
57    <p>Get physician session.</p>
58    */
59   protected PhysicianSession getPhysicianSession() throws Exception {
60     if (ctx == nullctx = new InitialContext();
61     if (physicianSession == null) {
62       logger.debug("Getting new physician session.");
63       this.physicianSession = getPhysicianSessionHome();
64     }
65     return this.physicianSession;
66   }
67 
68   //   P R I V A T E   M E T H O D S
69   /**
70    * Get PhysicianSession EJB
71    */
72   private PhysicianSession getPhysicianSessionHome() throws Exception {
73     PhysicianSessionHome home = (PhysicianSessionHomectx.lookup(
74         "java:/comp/env/PhysicianSessionEJB");
75     return (PhysicianSessionhome.create();
76   }
77 }