KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jndi > JNDIProperties


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.jndi;
8
9 import java.util.Hashtable JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Properties JavaDoc;
13 import javax.naming.Context JavaDoc;
14
15 /**
16  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
17  */

18
19 public class JNDIProperties {
20
21     public final static String JavaDoc DEFAULT_HOST = "localhost";
22     public final static int DEFAULT_PORT = 1099;
23     public final static String JavaDoc DEFAULT_SCHEME = "jrmp";
24     public final static String JavaDoc PROVIDER_URL = DEFAULT_SCHEME + "://" + DEFAULT_HOST + ":" + DEFAULT_PORT;
25     public final static String JavaDoc URL_PKG_PREFIXES = JNDIProperties.class.getPackage().getName() + ".url";
26     public final static String JavaDoc INITIAL_CONTEXT_FACTORY = JNDIProperties.class.getPackage().getName() + ".InitialContextFactoryImpl";
27
28     private static Properties JavaDoc DEFAULT_ENVIRONMENT = new Properties JavaDoc();
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 JavaDoc env = (Properties JavaDoc)DEFAULT_ENVIRONMENT.clone();
37
38     public static Hashtable JavaDoc getDefaultEnvironment() {
39         return (Hashtable JavaDoc) DEFAULT_ENVIRONMENT.clone();
40     }
41
42     /**
43      * merge env with the default environment
44      */

45     public static Hashtable JavaDoc mergeEnvironment(Hashtable JavaDoc _env) {
46         for(Iterator JavaDoc iterator = _env.entrySet().iterator(); iterator.hasNext();){
47             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)iterator.next();
48             env.put(entry.getKey().toString(),entry.getValue().toString());
49         }
50         return (Hashtable JavaDoc)env.clone();
51     }
52
53     public static Properties JavaDoc env(){
54         return env;
55     }
56
57     /**
58      * 根据 providerURL 得到调用协议,用来远程调用
59      * @return
60      */

61     public static String JavaDoc getProviderURL(){
62         return env.getProperty(Context.PROVIDER_URL);
63     }
64
65     public static Hashtable JavaDoc cloneEnvironment(Hashtable JavaDoc env) {
66         return (Hashtable JavaDoc) env.clone();
67     }
68 }
69
Popular Tags