KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > ejb > BaseSessionBean


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.core.ejb;
15
16 import javax.ejb.SessionBean JavaDoc;
17 import javax.ejb.SessionContext JavaDoc;
18 import javax.naming.InitialContext JavaDoc;
19
20 import org.apache.log4j.Logger;
21
22
23
24 /**
25  * Base for Session Beans providing common features, new Session Beans should extend this.
26  *
27  * @version $Id: BaseSessionBean.java,v 1.1 2006/01/17 20:30:04 anatom Exp $
28  */

29 public class BaseSessionBean implements SessionBean JavaDoc {
30
31     /** Log4j instance for actual implementation class */
32     public transient Logger log;
33     private SessionContext JavaDoc ctx;
34
35     /** Cached initial context to save JNDI lookups */
36     transient InitialContext JavaDoc cacheCtx = null;
37
38     /**
39      * Initializes logging mechanism per instance
40      */

41     public BaseSessionBean() {
42         log = Logger.getLogger(this.getClass());
43     }
44
45     /**
46      * Logs a message with priority DEBUG
47      *
48      * @param msg Message
49      */

50     public void debug(String JavaDoc msg) {
51         log.debug(msg);
52     }
53
54     /**
55      * Logs a message and an exception with priority DEBUG
56      *
57      * @param msg Message
58      * @param t Exception
59      */

60     public void debug(String JavaDoc msg, Throwable JavaDoc t) {
61         log.debug(msg, t);
62     }
63
64     /**
65      * Logs a message with priority INFO
66      *
67      * @param msg Message
68      */

69     public void info(String JavaDoc msg) {
70         log.info(msg);
71     }
72
73     /**
74      * Logs a message and an exception with priority INFO
75      *
76      * @param msg Message
77      * @param t Exception
78      */

79     public void info(String JavaDoc msg, Throwable JavaDoc t) {
80         log.info(msg, t);
81     }
82
83     /**
84      * Logs a message with priority WARN
85      *
86      * @param msg Message
87      */

88     public void warn(String JavaDoc msg) {
89         log.warn(msg);
90     }
91
92     /**
93      * Logs a message and an exception with priority WARN
94      *
95      * @param msg Message
96      * @param t Exception
97      */

98     public void warn(String JavaDoc msg, Throwable JavaDoc t) {
99         log.warn(msg, t);
100     }
101
102     /**
103      * Logs a message with priority ERROR
104      *
105      * @param msg Message
106      */

107     public void error(String JavaDoc msg) {
108         log.error(msg);
109     }
110
111     /**
112      * Logs a message and an exception with priority ERROR
113      *
114      * @param msg Message
115      * @param t Exception
116      */

117     public void error(String JavaDoc msg, Throwable JavaDoc t) {
118         log.error(msg, t);
119     }
120
121     /**
122      * Activates bean, creates log for base session.
123      *
124      * @throws javax.ejb.EJBException on error
125      * @throws java.rmi.RemoteException on error
126      */

127     public void ejbActivate() throws javax.ejb.EJBException JavaDoc, java.rmi.RemoteException JavaDoc {
128         log = Logger.getLogger(this.getClass());
129     }
130
131     /**
132      * Removes bean, does nothing for base session.
133      *
134      * @throws javax.ejb.EJBException on error
135      * @throws java.rmi.RemoteException on error
136      */

137     public void ejbRemove() throws javax.ejb.EJBException JavaDoc, java.rmi.RemoteException JavaDoc {
138     }
139
140     /**
141      * Passivates bean, does nothing for base session.
142      *
143      * @throws javax.ejb.EJBException on error
144      * @throws java.rmi.RemoteException on error
145      */

146     public void ejbPassivate() throws javax.ejb.EJBException JavaDoc, java.rmi.RemoteException JavaDoc {
147     }
148
149     /**
150      * Sets current session context
151      *
152      * @param ctx current session context
153      *
154      * @throws javax.ejb.EJBException on error
155      * @throws java.rmi.RemoteException on error
156      */

157     public void setSessionContext(final javax.ejb.SessionContext JavaDoc ctx)
158         throws javax.ejb.EJBException JavaDoc, java.rmi.RemoteException JavaDoc {
159         this.ctx = ctx;
160     }
161
162     /**
163      * Get session contect
164      *
165      * @return current session context
166      */

167     public SessionContext JavaDoc getSessionContext() {
168         return ctx;
169     }
170
171     /**
172      * return the environment entries locator
173      * @return return the environment entries locator
174      */

175     protected ServiceLocator getLocator() {
176         return ServiceLocator.getInstance();
177     }
178     
179 }
180
Popular Tags