01: package org.lateralnz.demo.ejb;
02:
03: import java.util.List;
04:
05: import javax.ejb.SessionBean;
06: import javax.ejb.SessionContext;
07: import javax.ejb.CreateException;
08: import javax.naming.Context;
09: import javax.naming.InitialContext;
10:
11: import org.lateralnz.common.util.JNDIUtils;
12: import org.lateralnz.common.util.StringUtils;
13:
14: public class BasicEJB implements SessionBean {
15:
16: private static final String ENV_STR = "java:comp/env";
17: private static List list = null;
18: private SessionContext sessionContext;
19:
20: public void ejbCreate() throws CreateException {
21: if (list == null) {
22: try {
23: Context initCtx = JNDIUtils.getContext("local_ejb");
24: Context envCtx = (Context) initCtx.lookup(this .ENV_STR);
25: String csv = (String) envCtx.lookup("mylist");
26:
27: list = StringUtils.toList(csv, ",");
28: } catch (Exception e) {
29: e.printStackTrace();
30: throw new CreateException(e.getMessage());
31: }
32: }
33: }
34:
35: public void ejbActivate() {
36: }
37:
38: public void ejbPassivate() {
39: }
40:
41: public void ejbRemove() {
42: }
43:
44: public void setSessionContext(SessionContext sctx) {
45: sessionContext = sctx;
46: }
47:
48: public int getRandom(int multiplier) {
49: return (int) (Math.random() * multiplier);
50: }
51:
52: public List getList() {
53: return list;
54: }
55: }
|