InfoCenter Home >
4: Developing applications >
4.6: Java Technologies >
4.6.2: JNDI (Java Naming and Directory Interface) overview >
4.6.2.4: JNDI helpers and utilities >
4.6.2.4.1: JNDI helper class

4.6.2.4.1: JNDI helper class

The class com.ibm.websphere.naming.JndiHelpers contains static methods to simplify common tasks. Refer to the API documentation for more information.

JNDI helper methods provide assistance with:

  • Recursively creating subcontexts.
    [...]
    import com.ibm.websphere.naming.JndiHelper;
    [...]
    try {
    Context startingContext = new InitialContext();
    startingContext = startingContext.lookup("com/mycompany");
    
    // Creates each intermediate subcontext, if necessary, as well as leaf context.
    // AlreadyBoundException is not thrown.
    
    JndiHelper.recursiveCreateSubcontext(startingContext, "apps/accounting");
    
    }
    catch (NamingException e)
    // Handle  error.
    }
    [...]
    
  • Rebinding objects and creating intermediate contexts that do not already exist.
    [...]
    import com.ibm.websphere.naming.JndiHelper;
    [...]
    try {
    Context startingContext = new InitialContext();
    
    // Creates each intermediate subcontext, if necessary, and rebinds object.
    
    JndiHelper.recursiveRebind(startingContext, "com/mycompany/apps/accounting", someObject);
    
    }
    catch (NamingException e)
    // Handle  error.
    }
    [...]
    
  • Binding objects and throwing a NameAlreadyBoundException if the object is already bound.

    There are two versions of this JndiHelper method:

    public static void recursiveBind(Context startingContext, Name name, Object obj)
    
    public static void recursiveBind(Context startingContext, String name, Object obj)
    
    
    [...] import com.ibm.websphere.naming.JndiHelper; [...] try { Context startingContext = new InitialContext(); // Creates each intermediate subcontext, if necessary, and binds object. JndiHelper.recursiveBind(startingContext, "com/mycompany/apps/accounting", someObject); } catch (NamingException e) // Handle error. } } catch (Exception e) // Handle other errors. } [...]

Go to previous article: JNDI helpers and utilities Go to next article: JNDI Name Space Dump utility

 

 
Go to previous article: JNDI helpers and utilities Go to next article: JNDI Name Space Dump utility