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   */
20  //@Stateless declared by ejb-jar.xml entry
21  public class AidSchedulerEJB extends SchedulerBase
22      implements AidSchedulerLocal, AidSchedulerRemote {
23          
24      //this is injected by ejb-jar.xml entry
25      private EntityManager em;
26      //this is injected by the ejb-jar.xml entry
27      private DataSource ds;
28      //this is injected by ejb-jar.xml entry
29      private String message;
30      //this is injected by ejb-jar.xml entry
31      private HospitalLocal hospital;
32      
33      @Resource 
34      public void setSessionContext(SessionContext ctx) { this.ctx = ctx; }
35      
36      public void init() {
37          log.info("******************* AidScheduler Created ******************");
38          log.debug("ctx=" + ctx);
39          log.debug("ejb/hospital=" + ctx.lookup("ejb/hospital"));
40          log.debug("message=" + message);
41          log.debug("em=" + em);
42          log.debug("ds=" + ds);
43          log.debug("hospital=" + hospital);
44          //peek in java:comp/env
45          try { 
46          	Context enc = (Context) new InitialContext().lookup("java:comp");
47          	log.debug(new JNDIUtil().dump(enc, "env"));
48          } catch (NamingException ex) { log.error("" + ex); }        
49      }
50      
51      public String getName() { return "AidScheduler"; }    
52  }