1 23 24 package com.sun.ejb.portable; 25 26 import java.util.Properties ; 27 import java.io.FileInputStream ; 28 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 import javax.naming.NameNotFoundException ; 32 33 import javax.ejb.spi.HandleDelegate ; 34 import javax.ejb.EJBException ; 35 36 44 public class HandleDelegateUtil 45 { 46 47 private static final String JNDI_PROPERTY_FILE_NAME = 48 "com.sun.ejb.portable.jndi.propertyfilename"; 49 50 private static boolean checkedJndiProperties = false; 53 54 private static Properties jndiProperties = null; 56 57 static HandleDelegate getHandleDelegate() 58 throws NamingException 59 { 60 HandleDelegate handleDelegate; 61 try { 62 InitialContext ctx = new InitialContext (); 63 handleDelegate = (HandleDelegate ) 64 ctx.lookup("java:comp/HandleDelegate"); 65 } catch(NamingException ne) { 66 67 Properties props = null; 73 try { 74 props = getJndiProperties(); 75 } catch(Exception e) { 76 NamingException ne2 = new NamingException 79 ("Error while accessing " + JNDI_PROPERTY_FILE_NAME + 80 " : " + e.getMessage()); 81 ne2.initCause(e); 82 throw ne2; 83 } 84 85 if( props == null ) { 86 NamingException ne3 = new NamingException 88 ("java:comp/HandleDelegate not found. Unable to " + 89 " use jndi property file override since " + 90 JNDI_PROPERTY_FILE_NAME + " has NOT been set"); 91 ne3.initCause(ne); 92 throw ne3; 93 } 94 95 try { 96 InitialContext ctx = new InitialContext (props); 97 handleDelegate = (HandleDelegate ) 98 ctx.lookup("java:comp/HandleDelegate"); 99 } catch(NamingException ne4) { 100 NamingException overrideEx = 101 new NamingException ("Unable to lookup HandleDelegate " + 102 "with override properties = " + 103 props.toString()); 104 overrideEx.initCause(ne4); 105 throw overrideEx; 106 } 107 } 108 109 return handleDelegate; 110 } 111 112 117 private static Properties getJndiProperties() 118 throws Exception 119 { 120 121 synchronized(HandleDelegateUtil.class) { 122 if( !checkedJndiProperties ) { 123 try { 124 String jndiPropertyFileName = 125 System.getProperty(JNDI_PROPERTY_FILE_NAME); 126 127 if( jndiPropertyFileName != null ) { 128 FileInputStream fis = 129 new FileInputStream (jndiPropertyFileName); 130 jndiProperties = new Properties (); 131 jndiProperties.load(fis); 132 } 136 } finally { 137 checkedJndiProperties = true; 140 } 141 } 142 } 143 144 return jndiProperties; 145 } 146 147 148 } 149 | Popular Tags |