View Javadoc
1   package ejava.examples.jndidemo;
2   
3   import javax.annotation.Resource;
4   
5   import javax.ejb.EJB;
6   import javax.enterprise.inject.Produces;
7   import javax.persistence.EntityManager;
8   import javax.persistence.PersistenceContext;
9   import javax.sql.DataSource;
10  
11  
12  /**
13   * This class implements a set of CDI producer fields and methods that are
14   * used to inject resources into beans within the application.
15   */
16  public class SchedulerResources {
17  	/**
18  	 * Gets a DataSource from the JNDI tree based on a JNDI name
19  	 * and produces it for any bean injecting a DataSource qualified 
20  	 * with @JndiDemo
21  	 */
22      @Resource(mappedName="java:jboss/datasources/ExampleDS")
23  	@Produces
24      @JndiDemo
25      public DataSource ds;
26  	
27      /**
28       * Gets a persistence context based on the persistence unit name and
29       * produces it for any bean injecting an EntityManager qualified
30       * with a @JndiDemo. 
31       */
32  	@PersistenceContext(unitName="jndidemo")
33  	@Produces
34  	@JndiDemo
35  	public EntityManager em;
36  
37  	/**
38  	 * A String for any bean injecting a String qualified by @JndiDemo 
39  	 * annotation. 
40  	 */
41  	@Produces
42  	@JndiDemo
43  	public String message="Hello CDI!!!";
44  
45  	/**
46  	 * Gets a CookEJB for any bean injecting a Scheduler
47  	 */
48      @EJB(lookup="java:app/jndiDemoEJB/CookEJB!ejava.examples.jndidemo.ejb.CookLocal")
49      @Produces
50      @Cook
51  	public Scheduler cook; 
52  }