Example usage for javax.naming InitialContext InitialContext

List of usage examples for javax.naming InitialContext InitialContext

Introduction

In this page you can find the example usage for javax.naming InitialContext InitialContext.

Prototype

public InitialContext() throws NamingException 

Source Link

Document

Constructs an initial context.

Usage

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.JndiJdbcReportDataSourceServiceFactory.java

public JndiJdbcReportDataSourceServiceFactory() {
    try {/*  w ww  .ja va2s.c o m*/

        // Set the context here, as it is a heavyweight constructor

        ctx = new InitialContext();
    } catch (NamingException e) {
        log.error(e);
        throw new JSException(e);
    }
}

From source file:com.plexobject.testplayer.dao.hibernate.HibernateUtil.java

/**
 * Returns the global SessionFactory either from a static variable or a JNDI
lookup.// w w  w  .  j a  v  a2s  .c o m
 *
 * @return SessionFactory
 */
public static SessionFactory getSessionFactory() {
    String sfName = configuration.getProperty(Environment.SESSION_FACTORY_NAME);
    if (sfName != null) {
        log.debug("Looking up SessionFactory in JNDI");
        try {
            return (SessionFactory) new InitialContext().lookup(sfName);
        } catch (NamingException ex) {
            throw new RuntimeException(ex);
        }
    } else if (sessionFactory == null) {
        rebuildSessionFactory();
    }
    return sessionFactory;
}

From source file:Employee.java

 @PostConstruct
public void jndiInject(InvocationContext invocation) {
   Object target = invocation.getTarget();
   Field[] fields = target.getClass().getDeclaredFields();
   Method[] methods = target.getClass().getDeclaredMethods();

   // find all @JndiInjected fields methods and set them
   try {/* w w  w.  j  av  a 2  s .c o m*/
      InitialContext ctx = new InitialContext();
      for (Method method : methods) {
         JndiInjected inject = method.getAnnotation(JndiInjected.class);
         if (inject != null) {
            Object obj = ctx.lookup(inject.value());
            method.setAccessible(true);
            method.invoke(target, obj);
         }
      }
      for (Field field : fields) {
         JndiInjected inject = field.getAnnotation(JndiInjected.class);
         if (inject != null) {
            Object obj = ctx.lookup(inject.value());
            field.setAccessible(true);
            field.set(target, obj);
         }
      }
      invocation.proceed();
   } catch (Exception ex) {
      throw new EJBException("Failed to execute @JndiInjected", ex);
   }
}

From source file:io.coala.dsol.util.ExperimentBuilder.java

/**
 * {@link ExperimentBuilder} constructor
 * /* w  ww  . ja v a 2s. c  om*/
 * @param context
 * @throws NamingException
 */
public ExperimentBuilder(final String context) throws NamingException {
    super(new InitialContext().createSubcontext(EXPERIMENT_CONTEXT_PREFIX + context));
}

From source file:com.pymmasoftware.platform.login.loginmodule.DroolsLoginModule.java

@Override
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState,
        Map<String, ?> options) {
    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = sharedState;
    this.options = options;

    try {/*  w  ww . j ava 2  s  .  co m*/
        if (env == null) {
            env = (Context) new InitialContext().lookup("java:comp/env");
            if (dataSource == null) {
                dataSource = (DataSource) env.lookup("jdbc/URDroolsDS");
            }
        }
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}

From source file:io.apiman.gateway.engine.ispn.InfinispanRegistry.java

/**
 * @return gets the registry cache/*  ww w .j  a  v  a  2  s  . c  om*/
 */
private Cache<Object, Object> getCache() {
    if (cache != null) {
        return cache;
    }

    try {
        InitialContext ic = new InitialContext();
        CacheContainer container = (CacheContainer) ic.lookup(cacheContainer);
        cache = container.getCache(cacheName);
        return cache;
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.example.switchyard.idempotent.jpa.IdempotentJpaConsumer.java

private static BeanManager getBeanManager() {
    try {/* www .  ja v a2 s  .  c  om*/
        return (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.autentia.intra.util.ConfigurationUtil.java

/**
 * Constructor//from   w  ww  .  j a v  a  2 s  .  c  o m
 *
 * @param jndiPathVar JNDI variable in which configuration directory is stored
 * @param file        path to configuration file
 */
public ConfigurationUtil(String jndiPathVar, String file) throws ConfigurationException, NamingException {
    Context ctx = new InitialContext();
    configDir = (String) ctx.lookup(jndiPathVar);
    if (!configDir.endsWith("/") && !configDir.endsWith("\\")) {
        configDir += "/";
    }
    config = new PropertiesConfiguration(configDir + file);
}

From source file:net.przemkovv.sphinx.config.JpaConfig.java

@Bean
public EntityManagerFactory entityManagerFactory() throws NamingException {
    logger.debug("Bean initialization: EntityManagerFactory");
    Context ctx = new InitialContext();
    return (EntityManagerFactory) ctx.lookup("java:comp/env/persistence/net.przemkovv.sphinx_PU");
}

From source file:com.wso2telco.dep.verificationhandler.verifier.DatabaseUtils.java

/**
 * Initialize data source.//from   w w w.  ja  v  a  2s  .  com
 *
 * @throws NamingException the naming exception
 */
public static void initializeDataSource() throws NamingException {
    if (statDatasource != null) {
        return;
    }

    String statdataSourceName = "jdbc/WSO2AM_STATS_DB";

    if (statdataSourceName != null) {
        try {
            Context ctx = new InitialContext();
            statDatasource = (DataSource) ctx.lookup(statdataSourceName);
        } catch (NamingException e) {
            log.error(e);
            throw e;
        }

    }
}