Nuxeo Enterprise Platform 5.4

org.nuxeo.common.jndi
Class NamingContextFactory

java.lang.Object
  extended by org.nuxeo.common.jndi.NamingContextFactory
All Implemented Interfaces:
javax.naming.spi.InitialContextFactory

public class NamingContextFactory
extends java.lang.Object
implements javax.naming.spi.InitialContextFactory

Creates NamingContext. In case a delegate environment was provided, obtains delegate InitialContext. Delegate context is used by NamingContext for unresolved lookups.

Author:
Alexander Ananiev, Dimitar Gospodinov

Constructor Summary
NamingContextFactory()
           
 
Method Summary
 javax.naming.Context getInitialContext(java.util.Hashtable<?,?> environment)
          Singleton for initial context.
static void revertSetAsInitial()
          Restores the properties changed by setAsInitial().
static void setAsInitial()
          Sets the NamingContextFactory as the initial context factory.
static void setDelegateContext(javax.naming.Context ctx)
          Sets the delegate context.
static void setDelegateEnvironment(java.util.Hashtable<?,?> env)
          Sets the environment of the delegate JNDI context.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamingContextFactory

public NamingContextFactory()
Method Detail

getInitialContext

public javax.naming.Context getInitialContext(java.util.Hashtable<?,?> environment)
                                       throws javax.naming.NamingException
Singleton for initial context. Instantiates and returns root/initial NamingContext object that will be used as starting point for all naming operations. NamingContext is then used by javax.naming.InitialContext object. It also creates the delegate context if the delegate environment is set. NamingContextFactory caches the delegate context once it's created.

Specified by:
getInitialContext in interface javax.naming.spi.InitialContextFactory
Returns:
NamingContext object
Throws:
javax.naming.NamingException
See Also:
InitialContextFactory.getInitialContext(java.util.Hashtable)

setDelegateEnvironment

public static void setDelegateEnvironment(java.util.Hashtable<?,?> env)
Sets the environment of the delegate JNDI context. Normally, this is the environment of the application server. At the very minimum, the environment includes PROVIDER_URL and INITIAL_CONTEXT_FACTORY. NamingContext first tries to look up the object in its local tree. If the object is not found, it will look in the delegate context.

Parameters:
env - JNDI properties of the delegate environment

setDelegateContext

public static void setDelegateContext(javax.naming.Context ctx)
Sets the delegate context. Normally, this is the initial context of the application server. NamingContext first tries to look up the object in its local tree. If the object is not found, it will look in the delegate context. Example: NamingContextFactory.setDelegateContext(new InitialContext());

Parameters:
ctx - delegate context

setAsInitial

public static void setAsInitial()
Sets the NamingContextFactory as the initial context factory. This helper method sets the Context.INITIAL_CONTEXT_FACTORY and Context.URL_PKG_PREFIXES system properties. The second one is needed to be able to handle java:comp context correctly. The method also saves the current values of these properties so they can be restored later on using revertSetAsInitial. This method is normally called from setUp

You can also set these properties directly:

 
  java.naming.factory.initial=org.nuxeo.common.jndi.NamingContextFactory
  java.naming.factory.url.pkgs=org.nuxeo.common.jndi
 
 

Throws:
javax.naming.NamingException

revertSetAsInitial

public static void revertSetAsInitial()
Restores the properties changed by setAsInitial(). This method should be called in tearDown() to clean up all changes to the environment in case if the test is running in the app server.

This method also cleans the initial context.


Nuxeo Enterprise Platform 5.4

Copyright © 2010 Nuxeo SAS. All Rights Reserved.