All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.evasion.sam.ejb.JNDIClient Maven / Gradle / Ivy

There is a newer version: 2.0.0.2
Show newest version
/*
 * 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;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy