1 6 7 package org.jfox.jndi; 8 9 import java.util.Hashtable ; 10 import java.util.Iterator ; 11 import java.util.Map ; 12 import java.util.Properties ; 13 import javax.naming.Context ; 14 15 18 19 public class JNDIProperties { 20 21 public final static String DEFAULT_HOST = "localhost"; 22 public final static int DEFAULT_PORT = 1099; 23 public final static String DEFAULT_SCHEME = "jrmp"; 24 public final static String PROVIDER_URL = DEFAULT_SCHEME + "://" + DEFAULT_HOST + ":" + DEFAULT_PORT; 25 public final static String URL_PKG_PREFIXES = JNDIProperties.class.getPackage().getName() + ".url"; 26 public final static String INITIAL_CONTEXT_FACTORY = JNDIProperties.class.getPackage().getName() + ".InitialContextFactoryImpl"; 27 28 private static Properties DEFAULT_ENVIRONMENT = new Properties (); 29 static { 30 DEFAULT_ENVIRONMENT.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); 31 DEFAULT_ENVIRONMENT.put(Context.PROVIDER_URL, PROVIDER_URL); 32 DEFAULT_ENVIRONMENT.put(Context.URL_PKG_PREFIXES, URL_PKG_PREFIXES); 33 DEFAULT_ENVIRONMENT.put(Context.OBJECT_FACTORIES, INITIAL_CONTEXT_FACTORY); 34 }; 35 36 private static Properties env = (Properties )DEFAULT_ENVIRONMENT.clone(); 37 38 public static Hashtable getDefaultEnvironment() { 39 return (Hashtable ) DEFAULT_ENVIRONMENT.clone(); 40 } 41 42 45 public static Hashtable mergeEnvironment(Hashtable _env) { 46 for(Iterator iterator = _env.entrySet().iterator(); iterator.hasNext();){ 47 Map.Entry entry = (Map.Entry )iterator.next(); 48 env.put(entry.getKey().toString(),entry.getValue().toString()); 49 } 50 return (Hashtable )env.clone(); 51 } 52 53 public static Properties env(){ 54 return env; 55 } 56 57 61 public static String getProviderURL(){ 62 return env.getProperty(Context.PROVIDER_URL); 63 } 64 65 public static Hashtable cloneEnvironment(Hashtable env) { 66 return (Hashtable ) env.clone(); 67 } 68 } 69 | Popular Tags |