KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > util > JNDI


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.util;
8
9 import java.io.IOException JavaDoc;
10 import java.io.InputStream JavaDoc;
11 import java.util.Properties JavaDoc;
12
13 import javax.naming.Context JavaDoc;
14
15 import org.apache.log4j.Category;
16
17 /**
18  * Utility class to access environment properties for JNDI.
19  *
20  * @author Laurent Etiemble
21  * @version $Revision: 1.7 $
22  */

23 public abstract class JNDI
24 {
25    /** Log4j Logger */
26    static Category logger = Category.getInstance(JNDI.class);
27
28
29    /** Look-up for a file named jndi.properties in the classpath. If found, it is load into the VM environment. */
30    public static void setJNDIProperties()
31    {
32       try
33       {
34          InputStream JavaDoc in = JNDI.class.getResourceAsStream("/jndi.properties");
35
36          if (in != null)
37          {
38             logger.debug("Found jndi.properties in classpath");
39
40             // Load the jndi.properties file
41
Properties JavaDoc props = new Properties JavaDoc();
42             props.load(in);
43             in.close();
44
45             logger.debug("Setting VM environment");
46
47             // Set up the environment
48
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, props.getProperty(Context.INITIAL_CONTEXT_FACTORY, ""));
49             System.setProperty(Context.URL_PKG_PREFIXES, props.getProperty(Context.URL_PKG_PREFIXES, ""));
50             System.setProperty(Context.PROVIDER_URL, props.getProperty(Context.PROVIDER_URL, ""));
51          }
52       }
53       catch (IOException JavaDoc ioe)
54       {
55          // Ignore it
56
logger.warn("Exception while loading jndi.properties " + ioe.getMessage());
57       }
58    }
59 }
60
Popular Tags