1 13 14 package org.ejbca.core.ejb; 15 16 import java.io.IOException ; 17 import java.io.InputStream ; 18 import java.util.Hashtable ; 19 import java.util.Properties ; 20 21 import javax.naming.InitialContext ; 22 import javax.naming.NamingException ; 23 24 30 31 public class InitialContextBuilder { 32 33 private final static String PROPERTIES = "ejbca.properties"; 34 35 36 static private InitialContextBuilder instance = null; 37 38 39 private Properties cacheEnv = null; 40 41 42 private InitialContext cacheCtx = null; 43 44 49 static public InitialContextBuilder getInstance() { 50 if( instance == null ) { 51 instance = new InitialContextBuilder(); 52 } 53 return instance; 54 } 55 56 59 private InitialContextBuilder() { 60 try { 63 ClassLoader cl = ClassLoader.getSystemClassLoader(); 64 cacheEnv = new Properties (); 65 InputStream inStream = cl.getResourceAsStream(InitialContextBuilder.PROPERTIES); 66 cacheEnv.load( inStream ); 67 try { inStream.close(); } catch ( IOException ioex ) {} 68 } catch (Exception ex2) { 69 cacheEnv = null; 70 } 71 } 72 73 79 public InitialContext getInitialContext() throws NamingException { 80 return getInitialContext(null); 81 } 82 83 93 public InitialContext getInitialContext(Hashtable env) throws NamingException { 94 if( cacheCtx == null ) { 95 if( env != null ) { 96 cacheCtx = new InitialContext (env); 98 } else if ( cacheEnv != null ) { 99 cacheCtx = new InitialContext (cacheEnv); 101 } else { 102 cacheCtx = new InitialContext (); 104 } 105 } 106 return cacheCtx; 107 } 108 } 109 110 | Popular Tags |