Package javax.naming

Examples of javax.naming.Context


    private URL jettyEnvXmlUrl;

    protected void createEnvContext ()
    throws NamingException
    {
        Context context = new InitialContext();
        compCtx =  (Context)context.lookup ("java:comp");
        envCtx = compCtx.createSubcontext("env");
        if (Log.isDebugEnabled())
            Log.debug("Created java:comp/env for webapp "+getWebAppContext().getContextPath());
    }
View Full Code Here


        compCtx.destroySubcontext("env");
       
        //unbind any NamingEntries that were configured in this webapp's name space
        try
        {
            Context scopeContext = NamingEntryUtil.getContextForScope(getWebAppContext());
            scopeContext.destroySubcontext(NamingEntry.__contextName);
        }
        catch (NameNotFoundException e)
        {
            Log.ignore(e);
            Log.debug("No naming entries configured in environment for webapp "+getWebAppContext());
View Full Code Here

    {
      throw new SQLException("JNDI DataSource is invalid; no connection path is defined.");
    }
    try
    {
      final Context ctx = getInitialContext();
      final DataSource ds = findDataSource(ctx, connectionPath);

      final String realUser;
      final String realPassword;
      if (username != null)
View Full Code Here

     * @throws NamingException If something goes wrong
     */
    public PooledConnection create() throws Exception
    {
        long started = System.currentTimeMillis();
        Context context;
        if (ctxclass.equalsIgnoreCase("ldap")) {
          context = new InitialLdapContext(properties, null);
        } else if (ctxclass.equalsIgnoreCase("directory")) {
          context = new InitialDirContext(properties);
        } else {
View Full Code Here

    /**
     * Performs an absolute list on the context
     */
    public void testCreateDestroyContexts() throws NamingException {
        Context child = this.ic.createSubcontext("TestChildContext");
        assertNotNull("Created subcontext TestChildContext must not be null",
                child);
        NamingEnumeration listing = child.list("");
        assertTrue("Listing on new child context is empty", !listing
                .hasMoreElements());
        listing.close();
        this.ic.destroySubcontext("java:/comp/env/TestChildContext");
    }
View Full Code Here

    /**
     * Attempts a simple bind
     */
    public void testSimpleBind() throws NamingException {
        Context child = this.ic.createSubcontext("TestBindContext");
        assertNotNull("Created subcontext TestBindContext must not be null",
                child);
        child.bind("bindInteger", new Integer(80));
        Object lookupInt = this.ic.lookup("TestBindContext/bindInteger");
        assertNotNull(
                "java:/comp/env/TestBindContext/bindInteger should be non-null",
                lookupInt);
        assertEquals("java:/comp/env/TestBindContext/bindInteger", lookupInt,
View Full Code Here

    /**
     * Attempts a rebind
     */
    public void testSimpleRebind() throws NamingException {
        Context child = this.ic.createSubcontext("TestRebindContext");
        assertNotNull("Created subcontext TestRebindContext must not be null",
                child);
        Context rebindChild = child.createSubcontext("ChildRebind");
        assertNotNull("Created subcontext rebindChild must not be null",
                rebindChild);
        rebindChild.rebind(
                "java:/comp/env/TestRebindContext/ChildRebind/integer",
                new Integer(25));
        rebindChild.close();
        child.close();

        Object lookupInt = this.ic
                .lookup("java:/comp/env/TestRebindContext/ChildRebind/integer");
        assertNotNull(
View Full Code Here

      if ( jndiName == null) {
         return;
      } // end of if ()
     
      // Do we have JNDI at all?
      Context ctx = null;
      try {
         ctx =  new InitialContext();
      } catch (NamingException e) {
         throw new IllegalStateException("No NamingContext available, trying to run with a jndiName in a server withouth jndi is not valid: "+e);
      } // end of try-catch
View Full Code Here

      throw new IllegalArgumentException(
        "Unknown database name : " + Util.quote(aDbName)
      );     
    }
    try {
      Context initialContext = new InitialContext();
      if ( initialContext == null ) {
        fLogger.severe(
          "DataSource problem. InitialContext is null. Db : " + Util.quote(dbConnString)
        );
      }
      DataSource datasource = (DataSource)initialContext.lookup(dbConnString);
      if ( datasource == null ){
        fLogger.severe("Datasource is null for : " + dbConnString);
      }
      result = datasource.getConnection();
    }
View Full Code Here

            serverPolicy = ((JMSServerTransport)transport).getJMSServerBehaviourPolicy();
        }

        // get JMS connection resources and destination
        //
        Context context = JMSUtils.getInitialContext(addrDetails);
        Connection connection = null;
       
        if (JMSConstants.JMS_QUEUE.equals(addrDetails.getDestinationStyle().value())) {
            QueueConnectionFactory qcf =
                (QueueConnectionFactory)context.lookup(addrDetails.getJndiConnectionFactoryName());
            if (addrDetails.isSetConnectionUserName()) {
                connection = qcf.createQueueConnection(addrDetails.getConnectionUserName(),
                                                       addrDetails.getConnectionPassword());
            } else {
                connection = qcf.createQueueConnection();
            }
        } else {
            TopicConnectionFactory tcf =
                (TopicConnectionFactory)context.lookup(addrDetails.getJndiConnectionFactoryName());
            if (addrDetails.isSetConnectionUserName()) {
                connection = tcf.createTopicConnection(addrDetails.getConnectionUserName(),
                                                       addrDetails.getConnectionPassword());
            } else {
                connection = tcf.createTopicConnection();
            }
        }

        connection.start();

        Destination requestDestination =
                (Destination)context.lookup(
                                           addrDetails.getJndiDestinationName());

        Destination replyDestination = (null != addrDetails.getJndiReplyDestinationName())
            ? (Destination)context.lookup(addrDetails.getJndiReplyDestinationName()) : null;

        // create session factory to manage session, reply destination,
        // producer and consumer pooling
        //
           
View Full Code Here

TOP

Related Classes of javax.naming.Context

Copyright © 2018 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.