01 package com.bea.medrec.actions;
02
03 import com.bea.medrec.controller.AdminSession;
04 import com.bea.medrec.controller.AdminSessionHome;
05 import com.bea.medrec.utils.MedRecLog4jFactory;
06 import javax.naming.InitialContext;
07 import org.apache.log4j.Logger;
08
09 /**
10 * <p>Base servlet encapsulating common servlet functionality.</p>
11 *
12 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
13 */
14 public abstract class AdminBaseAction
15 extends BaseAction implements AdminConstants {
16 private static Logger logger =
17 MedRecLog4jFactory.getLogger(AdminBaseAction.class.getName());
18
19 protected InitialContext ctx = null;
20 private AdminSession adminSession;
21
22 /**
23 * <p>Retrives AdminSession home.
24 * If instance does not exist, retrieve a new instance.<p>
25 *
26 * @return AdminSession
27 */
28 protected AdminSession getAdminSession() throws Exception {
29 if (ctx == null) ctx = new InitialContext();
30 if (adminSession == null) {
31 logger.debug("Getting new admin session.");
32 this.adminSession = getAdminSessionHome();
33 }
34 return this.adminSession;
35 }
36
37 // P R I V A T E M E T H O D S
38 /**
39 * <p>Get AdminSession</p>
40 *
41 * @return AdminSession
42 */
43 private AdminSession getAdminSessionHome() throws Exception {
44 AdminSessionHome home = (AdminSessionHome) ctx.lookup(
45 "java:/comp/env/AdminSessionEJB");
46 return (AdminSession) home.create();
47 }
48 }
|