| 1 17 18 package org.sape.carbon.services.ejb; 19 20 21 import java.util.Hashtable ; 22 23 import javax.naming.Context ; 24 import javax.naming.InitialContext ; 25 import javax.naming.NamingException ; 26 27 37 public class InitialContextUtility { 38 41 private InitialContextUtility() { 42 } 43 44 45 64 public static Context getInitialContext(String initialContextFactory, 65 String providerUrl, 66 String principal, 67 String credentials) 68 throws NamingException { 69 70 Context context = null; 72 Hashtable environment = new Hashtable (); 73 74 if (null != initialContextFactory) { 78 environment.put(Context.INITIAL_CONTEXT_FACTORY, 79 initialContextFactory); 80 } 81 if (null != providerUrl) { 82 environment.put(Context.PROVIDER_URL, providerUrl); 83 } 84 if (null != principal) { 85 environment.put(Context.SECURITY_PRINCIPAL, principal); 86 } 87 if (null != credentials) { 88 environment.put(Context.SECURITY_CREDENTIALS, credentials); 89 } 90 91 if (environment.size() > 0) { 94 context = new InitialContext (environment); 95 } else { 96 context = new InitialContext (); 97 } 98 99 return context; 101 } 102 } 103 | Popular Tags |