Package javax.naming

Examples of javax.naming.InitialContext


        if (context != null) {
            ContextBindings.bindClassLoader(context, null, Thread.currentThread().getContextClassLoader());
        }
        try {
            String jndiName = resolveJndiName(resourceName, (context == null));
            Object o = new InitialContext().lookup(jndiName);
            try {
                for (Iterator it = datasourceMappers.iterator(); it.hasNext();) {
                    DatasourceAccessor accessor = (DatasourceAccessor) it.next();
                    if (accessor.reset(o)) {
                        return true;
View Full Code Here


        if (context != null) {
            ContextBindings.bindClassLoader(context, null, Thread.currentThread().getContextClassLoader());
        }
        try {
            String jndiName = resolveJndiName(resourceName, (context == null));
            Object o = new InitialContext().lookup(jndiName);

            if (o instanceof DataSource) {
                return (DataSource) o;
            } else {
                return null;
View Full Code Here

   public void testDataSource() throws Exception
   {
      PortalContainer container = PortalContainer.getInstance();
      container.getComponentInstanceOfType(InitialContextInitializer.class);
      DataSource ds = (DataSource)new InitialContext().lookup("jdbcexo");
      assertNotNull(ds);
      Connection conn = ds.getConnection();
      DatabaseMetaData databaseMD = conn.getMetaData();
      String db = databaseMD.getDatabaseProductName() + " " + databaseMD.getDatabaseProductVersion() + "." +
         databaseMD.getDatabaseMajorVersion() + "." +  databaseMD.getDatabaseMinorVersion();
View Full Code Here

  }
 
  private Object getClusteredCache() {
    if (this.enabled && this.cacheManagerName != null) {
      try {
        Context ctx = new InitialContext();
        return ctx.lookup(this.cacheManagerName);
      } catch (NamingException e) {
        return null;
      }
    }
    return null;
View Full Code Here

        }

        try {         
            // begin the transaction
            InitialContext ctx = new InitialContext();
            this.userTxn = (UserTransaction)ctx.lookup(jndi);
             this.userTxn.begin();
        } catch (Exception e) {
            throw new TransactionRuntimeException(e);
        }       
    }
View Full Code Here

   */
  public void destroy()
  {
    logger.info("[destroy] Shuting down CentraView.");
    SettingsInterface settings = Settings.getInstance();
    InitialContext initCtx = settings.getInitCtx();
    try {
      if (initCtx != null) {
        initCtx.close();
        initCtx = null;
      }
    } catch (NamingException e) {
      logger.error("[destroy] closing initialContext Exception thrown.", e);
    }
View Full Code Here

  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException
  {
    logger.debug("[init] Starting Up.");
    Properties inProps = new Properties();
    SettingsInterface settings = Settings.getInstance();
    InitialContext initCtx = null;
    String host = CVUtility.getHostName(servlet.getServletContext());
    // use log4j Mapped diagnostic context to uniquely identify
    // each hosts log entries.
    MDC.put("HOSTNAME", host);
    try {
      java.io.InputStream propertiesInputStream = servlet.getServletContext().getResourceAsStream("/WEB-INF/classes/CentraView.properties");
      if (propertiesInputStream != null) {
        inProps.load(propertiesInputStream);
      } else {
        throw new UnavailableException("Cannot create CentraView.properties InputStream.");
      }
      initCtx = new InitialContext(inProps);
    } catch (java.io.IOException e1) {
      // catch the IOException if the properties file can't be found or read.
      logger.error("[init] Cannot read/find CentraView.properties.", e1);
      throw new UnavailableException("Cannot load CentraView.properties file.");
    } catch (NamingException e) {
View Full Code Here

    }

    public Connection getConnection() throws QueryTestFailedException {
  validate();
  try {
      InitialContext ctx = new InitialContext();
      DataSource source = (DataSource) ctx.lookup(jndi_name);

      if (source == null) {
    String msg = "Unable to find jndi source " + jndi_name;//$NON-NLS-1$

    QueryTestFailedException mme = new QueryTestFailedException(msg);//$NON-NLS-1$
View Full Code Here

    * @throws Exception
    */
   public void testDataSourceIntegration() throws Exception
   {
      props = null;
      Context context = new InitialContext();
      try
      {
         Object obj = context.lookup(JNDI_NAME);
         assertNull(JNDI_NAME + " not bound", obj);
      }
      catch (NameNotFoundException n)
      {
         // expected
      }
      props = UnitTestDatabaseManager.getTestDbProperties();
      cache = (CacheSPI) new UnitTestCacheFactory<Object, Object>().createCache(false, getClass());
      cache.getConfiguration().setCacheMode("local");
      cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
      cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(props));
      cache.create();


      MockDataSource ds = new MockDataSource(props);
      context.bind(JNDI_NAME, ds);
      assertNotNull(JNDI_NAME + " bound", context.lookup(JNDI_NAME));
      cache.start();

      assertNotNull("Cache has a cache loader", cache.getCacheLoaderManager().getCacheLoader());
   }
View Full Code Here

   }

   @AfterMethod(alwaysRun = true)
   public void tearDown() throws Exception
   {
      Context ctx = new InitialContext();
      ctx.unbind(JNDI_NAME);
      if (cache != null)
      {
         TestingUtil.killCaches(cache);
         UnitTestDatabaseManager.shutdownInMemoryDatabase(props);
         cache = null;
View Full Code Here

TOP

Related Classes of javax.naming.InitialContext

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.