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