1 22 package org.jboss.tutorial.jboss_resource_ref.bean; 23 24 import javax.naming.Context ; 25 import javax.naming.InitialContext ; 26 import javax.naming.NamingException ; 27 28 import javax.ejb.Remove ; 29 30 import org.apache.log4j.Logger; 31 import org.jboss.ejb3.Container; 32 33 39 public class TestENCBean implements TestENC 40 { 41 Logger log = Logger.getLogger(getClass()); 42 43 public void accessENC() throws NamingException 44 { 45 Context initCtx = new InitialContext (); 47 Context myEnv = (Context ) initCtx.lookup(Container.ENC_CTX_NAME + "/env"); 48 49 testJdbcDataSource(initCtx, myEnv); 51 testMail(initCtx, myEnv); 52 testJMS(initCtx, myEnv); 53 testResourceEnvEntries(initCtx, myEnv); 54 } 55 56 private void testJdbcDataSource(Context initCtx, Context myEnv) throws NamingException 57 { 58 Object obj = myEnv.lookup("jdbc/DefaultDS"); 60 if ((obj instanceof javax.sql.DataSource ) == false) 61 throw new NamingException ("jdbc/DefaultDS is not a javax.sql.DataSource"); 62 log.info("Found data source resource ref"); 63 } 64 65 private void testMail(Context initCtx, Context myEnv) throws NamingException 66 { 67 Object obj = myEnv.lookup("mail/DefaultMail"); 69 if ((obj instanceof javax.mail.Session ) == false) 70 throw new NamingException ("DefaultMail is not a javax.mail.Session"); 71 log.info("Found mail resource ref"); 72 } 73 74 private void testJMS(Context initCtx, Context myEnv) throws NamingException 75 { 76 Object obj = myEnv.lookup("jms/QueFactory"); 78 if ((obj instanceof javax.jms.QueueConnectionFactory ) == false) 79 throw new NamingException ("mail/DefaultMail is not a javax.jms.QueueConnectionFactory"); 80 log.info("Found jms queue resource ref"); 81 } 82 83 private void testResourceEnvEntries(Context initCtx, Context myEnv) throws NamingException 84 { 85 Object obj = myEnv.lookup("res/aQueue"); 86 if ((obj instanceof javax.jms.Queue ) == false) 87 throw new NamingException ("res/aQueue is not a javax.jms.Queue"); 88 log.info("Found jms queue resource env ref"); 89 } 90 91 @Remove 92 public void remove() 93 { 94 95 } 96 } 97 | Popular Tags |