1 package org.lateralnz.demo.ejb; 2 3 import java.util.List ; 4 5 import javax.ejb.SessionBean ; 6 import javax.ejb.SessionContext ; 7 import javax.ejb.CreateException ; 8 import javax.naming.Context ; 9 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 } 29 catch(Exception e) { 30 e.printStackTrace(); 31 throw new CreateException (e.getMessage()); 32 } 33 } 34 } 35 36 public void ejbActivate() {} 37 public void ejbPassivate() {} 38 public void ejbRemove() {} 39 public void setSessionContext(SessionContext sctx) { sessionContext = sctx; } 40 41 public int getRandom(int multiplier) { 42 return (int)(Math.random() * multiplier); 43 } 44 45 public List getList() { 46 return list; 47 } 48 } 49 | Popular Tags |