com.ibm.websphere.naming

Class JndiHelper

  1. java.lang.Object
  2. extended bycom.ibm.websphere.naming.JndiHelper

  1. public class JndiHelper
  2. 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.

Nested Class Summary

Modifier and Type Class and Description
  1. protected static class
JndiHelper.Operation

Constructor Summary

Modifier Constructor and Description
  1. protected
JndiHelper()
Protected empty constructor which prevents anyone from creating an instance of this class.

Method Summary

Modifier and Type Method and Description
  1. protected static
  2. void
batchCreateSubcontextsDriver(WsnBatchModeContext startingContext,javax.naming.Name name)
  1. protected static
  2. javax.naming.Context
createSubcontextsDriver(javax.naming.Context startingContext,javax.naming.Name name)
  1. protected static
  2. javax.naming.Context
getSubcontextFromBatchResults(javax.naming.Context startingContext,java.util.Enumeration vEnum,int numCtx)
  1. static
  2. java.lang.String
normalizeHostname(java.util.Hashtable env)
Returns a normalized form of the local hostname for consistent use in the NameSpace.
  1. static
  2. 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.
  1. static
  2. 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.
  1. static
  2. 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.
  1. static
  2. void
recursiveBind(javax.naming.Context startingContext,java.lang.String name,java.lang.Object obj)
String form of the recursiveBind(Context, Name, Object) method.
  1. static
  2. 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.
  1. static
  2. javax.naming.Context
recursiveCreateSubcontext(javax.naming.Context startingContext,java.lang.String name)
String form of the recursiveCreateSubcontext(Context, Name) method.
  1. static
  2. 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.
  1. static
  2. 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

Constructor Detail

JndiHelper

  1. protected JndiHelper()
Protected empty constructor which prevents anyone from creating an instance of this class. This class only provides static methods, so an instance is never needed.

Method Detail

recursiveCreateSubcontext

  1. public static javax.naming.Context recursiveCreateSubcontext( javax.naming.Context startingContext,
  2. java.lang.String name)
  3. 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

  1. public static javax.naming.Context recursiveCreateSubcontext( javax.naming.Context startingContext,
  2. javax.naming.Name name)
  3. 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:

batchCreateSubcontextsDriver

  1. protected static void batchCreateSubcontextsDriver( WsnBatchModeContext startingContext,
  2. javax.naming.Name name)
  3. throws javax.naming.NamingException
Throws:
javax.naming.NamingException

createSubcontextsDriver

  1. protected static javax.naming.Context createSubcontextsDriver( javax.naming.Context startingContext,
  2. javax.naming.Name name)
  3. throws javax.naming.NamingException
Throws:
javax.naming.NamingException

recursiveRebind

  1. public static void recursiveRebind( javax.naming.Context startingContext,
  2. java.lang.String name,
  3. java.lang.Object obj)
  4. 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

  1. public static void recursiveRebind( javax.naming.Context startingContext,
  2. javax.naming.Name name,
  3. java.lang.Object obj)
  4. 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:

recursiveBind

  1. public static void recursiveBind( javax.naming.Context startingContext,
  2. java.lang.String name,
  3. java.lang.Object obj)
  4. 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

  1. public static void recursiveBind( javax.naming.Context startingContext,
  2. javax.naming.Name name,
  3. java.lang.Object obj)
  4. 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:

getSubcontextFromBatchResults

  1. protected static javax.naming.Context getSubcontextFromBatchResults( javax.naming.Context startingContext,
  2. java.util.Enumeration vEnum,
  3. int numCtx)
  4. throws javax.naming.NamingException
Parameters:
startingContext -
vEnum -
numCtx -
Returns:
Throws:
javax.naming.NamingException

normalizeHostname

  1. public static java.lang.String normalizeHostname( java.util.Hashtable env)
  2. 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:

normalizeHostname

  1. public static java.lang.String normalizeHostname( java.util.Hashtable env,
  2. java.lang.String hostname)
  3. 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:

normalizeHostname

  1. public static java.lang.String normalizeHostname( java.util.Hashtable env,
  2. java.net.InetAddress ipAddress)
  3. 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: