|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| JNDI.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 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;
|
|
| 10 |
import java.io.InputStream;
|
|
| 11 |
import java.util.Properties;
|
|
| 12 |
|
|
| 13 |
import javax.naming.Context;
|
|
| 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 | 0 |
public static void setJNDIProperties() |
| 31 |
{
|
|
| 32 | 0 |
try
|
| 33 |
{
|
|
| 34 | 0 |
InputStream in = JNDI.class.getResourceAsStream("/jndi.properties"); |
| 35 |
|
|
| 36 | 0 |
if (in != null) |
| 37 |
{
|
|
| 38 | 0 |
logger.debug("Found jndi.properties in classpath");
|
| 39 |
|
|
| 40 |
// Load the jndi.properties file
|
|
| 41 | 0 |
Properties props = new Properties();
|
| 42 | 0 |
props.load(in); |
| 43 | 0 |
in.close(); |
| 44 |
|
|
| 45 | 0 |
logger.debug("Setting VM environment");
|
| 46 |
|
|
| 47 |
// Set up the environment
|
|
| 48 | 0 |
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, props.getProperty(Context.INITIAL_CONTEXT_FACTORY, ""));
|
| 49 | 0 |
System.setProperty(Context.URL_PKG_PREFIXES, props.getProperty(Context.URL_PKG_PREFIXES, ""));
|
| 50 | 0 |
System.setProperty(Context.PROVIDER_URL, props.getProperty(Context.PROVIDER_URL, ""));
|
| 51 |
} |
|
| 52 |
} |
|
| 53 |
catch (IOException ioe)
|
|
| 54 |
{
|
|
| 55 |
// Ignore it
|
|
| 56 | 0 |
logger.warn("Exception while loading jndi.properties " + ioe.getMessage());
|
| 57 |
} |
|
| 58 |
} |
|
| 59 |
} |
|
| 60 |
|
|
||||||||||