Package javax.naming

Examples of javax.naming.Context


        // sets the context
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");

        // gets the initialcontext
        Context initialContext = new InitialContext();

        // gets the database
       return (DataSource) initialContext.lookup(dsName);
    }
View Full Code Here


         }
         catch (Exception ignore)
         {        
         }
        
         Context ic = null;
        
         try
         {
            ic = providerAdaptor.getInitialContext();
           
            Object obj = ic.lookup(providerAdaptor.getFactoryRef());
           
            if (!(obj instanceof XAConnectionFactory))
            {
               throw new IllegalArgumentException("Connection factory from jms provider is not a XAConnectionFactory");
            }
           
            XAConnectionFactory connectionFactory = (XAConnectionFactory)obj;
           
            if (username == null)
            {
               conn = connectionFactory.createXAConnection();
            }
            else
            {
               conn = connectionFactory.createXAConnection(username, password);
            }
           
            XASession session = conn.createXASession();
           
            res = session.getXAResource();
           
            //Note the connection is closed the next time the xaresource is created or by the finalizer
           
         }
         catch (Exception e)
         {
            log.warn("Cannot create XAResource", e);
           
            hasMore = false;
         }
         finally
         {
            if (ic != null)
            {
               try
               {
                  ic.close();
               }
               catch (Exception ignore)
               {              
               }
            }
View Full Code Here

        int i = 0;
        String msg = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss");

        Context initialContext = getInitialContext();
        boolean clusteringEnabled = false;

        ClusterRemote statelessBean = (ClusterRemote) initialContext.lookup("org.ow2.easybeans.examples.cluster.ClusterBeanAN"
                + "_" + ClusterRemote.class.getName() + "@Remote");

        if (statelessBean instanceof CMIProxy) {
            clusteringEnabled = true;
            System.out.println("Clustering is enabled.");
View Full Code Here

        int i = 0;
        String msg = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss");

        Context initialContext = getInitialContext();
        boolean clusteringEnabled = false;
        ClusterRemote statelessBean = (ClusterRemote) initialContext.lookup("clusterBeanConfiguredByXML");

        if (statelessBean instanceof CMIProxy) {
            clusteringEnabled = true;
            System.out.println("Clustering is enabled.");
        }
View Full Code Here

     * Execute the client code.
     * @param args the client arguments
     */
    public static void main(final String[] args) {

        Context initialContext = null;

        try {
            initialContext = getInitialContext();
        } catch (NamingException e) {
            System.err.println("Cannot get InitialContext: " + e);
            System.exit(2);
        }

        // Get bean configured with annotation
        final BusinessInterface poolBeanAnnotation;
        try {
            poolBeanAnnotation = (BusinessInterface) initialContext.lookup("poolBeanConfiguredByAnnotation");
        } catch (NamingException e) {
            System.err.println("Cannot get bean: " + e);
            System.exit(2);
            return;
        }

        // Get bean configured with XML
        final BusinessInterface poolBeanXML;
        try {
            poolBeanXML = (BusinessInterface) initialContext.lookup("poolBeanConfiguredByXML");
        } catch (NamingException e) {
            System.err.println("Cannot get bean: " + e);
            System.exit(2);
            return;
        }
View Full Code Here

     * @throws NamingException if context is not found
     */
    public static void initJMS() throws JMSException, NamingException {

        // Get context
        Context initialContext = getInitialContext();

        // Get factory
        QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) initialContext
        .lookup(QUEUE_CONNECTION_FACTORY);

        // Lookup the Queues through their JNDI name
        Queue annotationQueue = (Queue) initialContext.lookup(SAMPLE_QUEUE_MDB_ANNOTATION);
        Queue xmlQueue = (Queue) initialContext.lookup(SAMPLE_QUEUE_MDB_XML);

        // Create connection
        queueConnection = queueConnectionFactory.createQueueConnection();

        // Create session
View Full Code Here

            logger.error("Cannot find the JNDI name {0}", name, e);
        }
        if (o == null) {
            logger.error("No object was found for JNDI name {0}", name);
        }
        Context ctx = null;
        if (o instanceof Context) {
            ctx = (Context) o;
        } else {
            logger.error("Object not instance of context. Object = {0}", o);
        }
View Full Code Here

        // initial context factory ?
        if (EASYBEANS_INITIAL_FACTORY != null) {
            this.rmiClientEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, EASYBEANS_INITIAL_FACTORY);
        }

        Context ictx = null;
        try {
            ictx = new InitialContext(this.rmiClientEnvironment);
        } catch (NamingException ne) {
            throw new IllegalStateException(ne);
        }

        // Lookup server object
        Object serverObject = null;
        try {
            serverObject = ictx.lookup(RMIServerRPC.RPC_JNDI_NAME);
        } catch (NamingException ne) {
            throw new IllegalStateException(ne);
        }
        // Get a connection to the RPC server
        RMIServerRPC server = (RMIServerRPC) PortableRemoteObject.narrow(serverObject, RMIServerRPC.class);
View Full Code Here

     * @param args the arguments (not required)
     * @throws Exception if exception is found.
     */
    public static void main(final String[] args) throws Exception {

        Context initialContext = getInitialContext();

        ISingletonShared singleton1 = (ISingletonShared) initialContext
                .lookup("SingletonBean1");

        ISingletonShared singleton2 = (ISingletonShared) initialContext
        .lookup("SingletonBean2");


        System.out.println("before: " + singleton1.getShared());

View Full Code Here

     * Main method.
     * @param args the arguments (not required)
     * @throws Exception if exception is found.
     */
    public static void main(final String[] args) throws Exception {
        Context ictx = getInitialContext();

        // JNDI name was specified as mappedName attribute in the stateless bean
        StatelessRemote statelessBean = (StatelessRemote) ictx.lookup("securityBean");

        // Not authenticated but method can be called
        System.out.println("Calling methods that everybody can call...");
        statelessBean.allRolesAllowed();

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.