1 package ejava.examples.jndidemo.ejb;
2
3 import javax.annotation.PostConstruct;import javax.annotation.Resource;
4
5 import javax.ejb.EJB;
6 import javax.ejb.SessionContext;
7 import javax.ejb.Stateful;
8 import javax.naming.InitialContext;
9 import javax.naming.NamingException;
10 import javax.persistence.EntityManager;
11 import javax.persistence.PersistenceContext;
12 import javax.persistence.PersistenceContextType;
13 import javax.sql.DataSource;
14
15 import ejava.util.jndi.JNDIUtil;
16
17
18
19
20
21
22
23 @Stateful(name="BakeScheduler")
24
25
26
27
28
29
30
31 @PersistenceContext(unitName="jndidemo",
32 name="persistence/jndidemo",
33 type=PersistenceContextType.EXTENDED)
34 public class BakeSchedulerEJB
35 extends SchedulerBase implements BakeSchedulerRemote {
36
37 public String getName() { return "BakeSchedulerEJB"; }
38
39
40
41
42
43
44 @PersistenceContext(
45 unitName="jndidemo",
46 type=PersistenceContextType.EXTENDED)
47 private EntityManager em;
48
49
50
51
52
53
54 @Resource(name="persistence/jndidemo")
55 private EntityManager em2;
56
57
58
59
60
61 @Resource(mappedName="java:jboss/datasources/ExampleDS")
62 private DataSource ds;
63
64
65
66
67
68 @Resource
69 protected void setSessionContext(SessionContext ctx) {
70 super.ctx = ctx;
71 }
72
73
74
75
76
77 protected CookLocal cook;
78
79
80
81
82
83
84 @EJB(name="ejb/cook")
85 protected CookLocal cook2;
86
87
88
89
90
91 @Resource(name="vals/message")
92 String message;
93
94 @PostConstruct
95 public void init() {
96 log.info("******************* BakeScheduler Created ******************");
97 log.debug("ctx=" + ctx);
98 log.debug("em=" + em);
99 log.debug("em2=" + em2);
100 log.debug("ds=" + ds);
101
102 log.debug("message=" + message);
103 log.debug("cook=" + cook);
104 log.debug("cook2=" + cook2);
105 log.debug("ejb/cook=" + ctx.lookup("ejb/cook"));
106 cook = (CookLocal)ctx.lookup("ejb/cook");
107 try {
108 log.debug(new JNDIUtil().dump(new InitialContext(), "java:comp/env"));
109 } catch (NamingException ex) { log.error("" + ex); }
110 }
111 }