com.ibm.websphere.naming
Class JndiHelper

java.lang.Object
  |
  +--com.ibm.websphere.naming.JndiHelper

public class JndiHelper
extends java.lang.Object

Static JNDI helper methods which can be divided into two categories:

  1. methods for creating subcontexts, binding and rebinding objects to the name space such that intermediate contexts are automatically created if necessary. In general, the caller does not need to be concerned with NameNotFoundException or NameAlreadyBoundExceptions for intermediate contexts when using methods in this class.
  2. methods for normalizing hostnames for consistent use in the WebSphere NameSpace.


Method Summary
static java.lang.String normalizeHostname(java.util.Hashtable env)
          Returns a normalized form of the local hostname for consistent use in the NameSpace.
static java.lang.String normalizeHostname(java.util.Hashtable env, java.net.InetAddress ipAddress)
          Returns a normalized form of the hostname represented by the ipAddress parameter for consistent use in the NameSpace.
static java.lang.String normalizeHostname(java.util.Hashtable env, java.lang.String hostname)
          Returns a normalized form of the hostname parameter for consistent use in the NameSpace.
static void recursiveBind(javax.naming.Context startingContext, javax.naming.Name name, java.lang.Object obj)
          Binds the object with the specified name to the name space such that all intermediate subcontexts in the name are created if they do not already exist.
static void recursiveBind(javax.naming.Context startingContext, java.lang.String name, java.lang.Object obj)
          String form of the recursiveBind(Context, Name, Object) method.
static javax.naming.Context recursiveCreateSubcontext(javax.naming.Context startingContext, javax.naming.Name name)
          Creates a subcontext with the specified name such that all intermediate subcontexts in the name are created if they do not already exist.
static javax.naming.Context recursiveCreateSubcontext(javax.naming.Context startingContext, java.lang.String name)
          String form of the recursiveCreateSubcontext(Context, Name) method.
static void recursiveRebind(javax.naming.Context startingContext, javax.naming.Name name, java.lang.Object obj)
          Rebinds the object with the specified name to the name space such that all intermediate subcontexts in the name are created if they do not already exist.
static void recursiveRebind(javax.naming.Context startingContext, java.lang.String name, java.lang.Object obj)
          String form of the recursiveRebind(Context, Name, Object) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

recursiveCreateSubcontext

public static javax.naming.Context recursiveCreateSubcontext(javax.naming.Context startingContext,
                                                             java.lang.String name)
                                                      throws javax.naming.NamingException
String form of the recursiveCreateSubcontext(Context, Name) method.

Parameters:
startingContext - The context to which the specified name is relative
name - String form of the name of the context to create
Returns:
The newly created context
Throws:
javax.naming.NotContextException - Some object other than a context is bound to the name space with a name that conflicts with the specified name.
javax.naming.NamingException - A naming exception was encountered.
See Also:
recursiveCreateSubcontext(Context, Name)

recursiveCreateSubcontext

public static javax.naming.Context recursiveCreateSubcontext(javax.naming.Context startingContext,
                                                             javax.naming.Name name)
                                                      throws javax.naming.NamingException
Creates a subcontext with the specified name such that all intermediate subcontexts in the name are created if they do not already exist. If any subcontext cannot be created because an object other than a Context is already bound with that name, a NotContextException is thrown.

Parameters:
startingContext - The context to which the specified name is relative
name - The name of the context to create
Returns:
The newly created context
Throws:
javax.naming.NotContextException - Some object other than a context is bound to the name space with a name that conflicts with the specified name.
javax.naming.NamingException - A naming exception was encountered.
See Also:
recursiveCreateSubcontext(Context, String)

recursiveRebind

public static void recursiveRebind(javax.naming.Context startingContext,
                                   java.lang.String name,
                                   java.lang.Object obj)
                            throws javax.naming.NamingException
String form of the recursiveRebind(Context, Name, Object) method.

Parameters:
startingContext - The context to which the specified name is relative
name - String form of the name of the object to rebind
obj - The object to rebind
Throws:
javax.naming.NotContextException - Some object other than a context is bound to the name space with a name that conflicts with the specified name.
javax.naming.NamingException - A naming exception was encountered.
See Also:
recursiveRebind(Context, Name, Object)

recursiveRebind

public static void recursiveRebind(javax.naming.Context startingContext,
                                   javax.naming.Name name,
                                   java.lang.Object obj)
                            throws javax.naming.NamingException
Rebinds the object with the specified name to the name space such that all intermediate subcontexts in the name are created if they do not already exist. If any non-leaf component of the name identifies a bound object which is not a context, a NotContextException is thrown. If no object is already bound with the specified name, the object is bound and no exception is thrown.

Parameters:
startingContext - The context to which the specified name is relative
name - Name of the object to rebind
obj - The object to rebind
Throws:
javax.naming.NotContextException - Some object other than a context is bound to the name space with a name that conflicts with the specified name.
javax.naming.NamingException - A naming exception was encountered.
See Also:
recursiveRebind(Context, String, Object)

recursiveBind

public static void recursiveBind(javax.naming.Context startingContext,
                                 java.lang.String name,
                                 java.lang.Object obj)
                          throws javax.naming.NamingException
String form of the recursiveBind(Context, Name, Object) method.

Parameters:
startingContext - The context to which the specified name is relative
name - String form of the name of the object to bind
obj - The object to bind
Throws:
javax.naming.NotContextException - Some object other than a context is bound to the name space with a name that conflicts with the specified name.
javax.naming.NameAlreadyBoundException - thrown if and only if the leaf name corresponds to an already bound object. Not thrown if an intermediate context is already bound.
javax.naming.NamingException - A naming exception was encountered.
See Also:
recursiveBind(Context, Name, Object)

recursiveBind

public static void recursiveBind(javax.naming.Context startingContext,
                                 javax.naming.Name name,
                                 java.lang.Object obj)
                          throws javax.naming.NamingException
Binds the object with the specified name to the name space such that all intermediate subcontexts in the name are created if they do not already exist. If any non-leaf component of the name identifies a bound object which is not a context, a NotContextException is thrown. If no object is already bound with the specified name, the object is bound and no exception is thrown. If a leaf object with the specified name is already bound, an NameAlreadyBoundException is thrown.

Parameters:
startingContext - The context to which the specified name is relative.
name - Name of the object to bind
obj - The object to bind
Throws:
javax.naming.NotContextException - Some object other than a context is bound to the name space with a name that conflicts with the specified name.
javax.naming.NameAlreadyBoundException - thrown if and only if the leaf name corresponds to an already bound object. Not thrown if an intermediate context is already bound.
javax.naming.NamingException - A naming exception was encountered.
See Also:
recursiveBind(Context, String, Object)

normalizeHostname

public static java.lang.String normalizeHostname(java.util.Hashtable env)
                                          throws javax.naming.NamingException
Returns a normalized form of the local hostname for consistent use in the NameSpace. The env parameter should be the result of a getEnvironment() call on a valid Context. If the env parameter is null, JndiHelper will attempt to get an initial context and use its environment. Two properties of the environment are examined:
  • com.ibm.websphere.naming.hostname.normalizer - contains the name of the class to call for normalization. The class must implement the HostnameNormalizer interface.
  • com.ibm.websphere.naming.syntax - if set to "ins", the escapeDots parameter of the HostnameNormalizer is set to HostnameNormalizer.ESCAPE_DOTS_TRUE.

Websphere supplies a DefaultHostnameNormalizer which operates as follows:

If your environment requires a different normalization algorithm, you can supply your own implementation of the HostnameNormalizer interface. You will need to set com.ibm.websphere.naming.hostname.normalizer to the name of your implementing class. It is recommended that you do this in a jndi.properties file which is in your classpath. For example set com.ibm.websphere.naming.hostname.normalizer=com.mycompany.mySpecialHostnameNormalizer

Note that JndiHelper will cache the name of the hostname normalizer class during the first call to a normalizeHostname method, and will not examine the environment for this property on subsequent calls.

Parameters:
env - Hashtable containing environment properties. If null, this method will attempt to get an initial context and use its environment.
Returns:
String containing the normalized form of the local host name.
Throws:
javax.naming.NamingException - any exceptions from the HostnameNormalizer are returned to the caller.
See Also:
HostnameNormalizer

normalizeHostname

public static java.lang.String normalizeHostname(java.util.Hashtable env,
                                                 java.lang.String hostname)
                                          throws javax.naming.NamingException
Returns a normalized form of the hostname parameter for consistent use in the NameSpace.

Please see normalizeHostname(Hashtable) for additional details.

Parameters:
env - Hashtable containing environment properties. If null, this method will attempt to get an initial context and use its environment.
hostname - String containing the hostname to normalize. If null, a NamingException is thrown. If the hostname is not a known host, a NamingException is thrown with root cause of java.net.UnknownHostException.
Returns:
String containing the normalized form of the input hostname.
Throws:
javax.naming.NamingException - any exceptions from the HostnameNormalizer are returned to the caller.
See Also:
HostnameNormalizer

normalizeHostname

public static java.lang.String normalizeHostname(java.util.Hashtable env,
                                                 java.net.InetAddress ipAddress)
                                          throws javax.naming.NamingException
Returns a normalized form of the hostname represented by the ipAddress parameter for consistent use in the NameSpace.

Please see normalizeHostname(Hashtable) for additional details.

Parameters:
env - Hashtable containing environment properties. If null, this method will attempt to get an initial context and use its environment.
ipAddress - java.net.InetAddress representing the hostname to normalize. If null, a NamingException is thrown.
Returns:
String containing the normalized form of the hostname for the host represented by the input ipAddress.
Throws:
javax.naming.NamingException - any exceptions from the HostnameNormalizer are returned to the caller.
See Also:
HostnameNormalizer


 

WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.