View Javadoc
1   package ejava.examples.jndidemo.ejb;
2   
3   import javax.annotation.Resource;
4   import javax.ejb.SessionContext;
5   import javax.naming.Context;
6   import javax.naming.InitialContext;
7   import javax.naming.NamingException;
8   import javax.persistence.EntityManager;
9   import javax.sql.DataSource;
10  
11  import ejava.util.jndi.JNDIUtil;
12  
13  /**
14   * This class is primarily an example of an EJB mostly configured through 
15   * an external ejb-jar.xml deployment descriptor. There are very few Java
16   * @Annotations defined here. All properties are injected through definitions
17   * in the ejb-jar.xml file.
18   *  
19   * @author jcstaff
20   *
21   */
22  //@Stateless declared by ejb-jar.xml entry
23  public class AidSchedulerEJB extends SchedulerBase
24      implements AidSchedulerLocal, AidSchedulerRemote {
25          
26      //this is injected by ejb-jar.xml entry
27      private EntityManager em;
28      //this is injected by the ejb-jar.xml entry
29      private DataSource ds;
30      //this is injected by ejb-jar.xml entry
31      private String message;
32      //this is injected by ejb-jar.xml entry
33      private HospitalLocal hospital;
34      
35      @Resource 
36      public void setSessionContext(SessionContext ctx) { this.ctx = ctx; }
37      
38      public void init() {
39          log.info("******************* AidScheduler Created ******************");
40          log.debug("ctx=" + ctx);
41          log.debug("ejb/hospital=" + ctx.lookup("ejb/hospital"));
42          log.debug("message=" + message);
43          log.debug("em=" + em);
44          log.debug("ds=" + ds);
45          log.debug("hospital=" + hospital);
46          //peek in java:comp/env
47          try { 
48          	Context enc = (Context) new InitialContext().lookup("java:comp");
49          	log.debug(new JNDIUtil().dump(enc, "env"));
50          } catch (NamingException ex) { log.fatal("" + ex); }        
51      }
52      
53      public String getName() { return "AidScheduler"; }    
54  }