com.evasion.sam.ejb.JNDIClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of evasion-sam-modul Show documentation
Show all versions of evasion-sam-modul Show documentation
API de l'application modulaire evasion-en-ligne
/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
package com.evasion.sam.ejb;
import com.evasion.sam.jaas.EvasionEJBLoginModule;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.transaction.UserTransaction;
/**
*
* @author sebastien
*/
public class JNDIClient {
/**
* LOGGER.
*/
private static final Logger LOGGER = Logger.getLogger(EvasionEJBLoginModule.class.getName());
private Context ctx;
public JNDIClient(String providerUrl) {
Map properties = new HashMap(2);
properties.put(Context.PROVIDER_URL, providerUrl); // "iiop://127.0.0.1:3700"
try {
ctx = new InitialContext(new Hashtable(properties));
} catch (NamingException ex) {
LOGGER.log(Level.SEVERE, "JNDI Exception ", ex);
}
}
public Object lookup(String name) {
try {
return ctx.lookup(name);
} catch (NamingException ex) {
LOGGER.log(Level.SEVERE, "JNDI lookup Exception ", ex);
}
return null;
}
public UserTransaction getTransaction() {
try {
return (UserTransaction) ctx.lookup("java:comp/UserTransaction");
} catch (NamingException ex) {
LOGGER.log(Level.SEVERE, "JNDI lookup Exception ", ex);
return null;
}
}
}