1 package org.myorg.encconfig.ejb;
2
3 import javax.annotation.PostConstruct;
4 import javax.annotation.Resource;
5 import javax.ejb.EJBException;
6 import javax.ejb.SessionContext;
7 import javax.ejb.Stateless;
8 import javax.jms.ConnectionFactory;
9 import javax.jms.Topic;
10 import javax.naming.InitialContext;
11 import javax.naming.NamingException;
12 import javax.persistence.EntityManager;
13
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 @Stateless
18 public class JNDIAuditorEJB extends AuditorBase
19 implements AuditorRemote {
20 private static final Logger log = LoggerFactory.getLogger(JNDIAuditorEJB.class);
21
22 private Boolean publishJMS;
23 private EntityManager em;
24 private ConnectionFactory cf;
25 private Topic topic;
26 private @Resource SessionContext ctx;
27
28
29
30 public void init() {
31 InitialContext jndi = null;
32 try {
33 jndi=new InitialContext();
34
35
36
37
38
39
40
41
42 } catch (NamingException ex) {
43 log.error("error looking up resources", ex);
44 throw new EJBException("error looking up resources:" + ex);
45 } finally {
46 close(jndi);
47 }
48 super.setLog(log);
49 super.setConnectionFactory(cf);
50 super.setEntityManager(em);
51 super.setTopic(topic);
52 super.setPublishJMS(isPublishJMS());
53 }
54
55 @Override
56 public boolean isPublishJMS() {
57 return publishJMS!=null && publishJMS;
58 }
59 @Override
60 public boolean havePersistenceContext() {
61 return em!=null;
62 }
63 @Override
64 public boolean haveTopic() {
65 return topic!=null;
66 }
67 @Override
68 public boolean haveConnectionFactory() {
69 return cf!=null;
70 }
71
72 @Override
73 public int audit(String message) {
74 return super.audit(message);
75 }
76 }