Class NamingUtils


  • public class NamingUtils
    extends Object
    Common utility functions used by the naming implementation.
    Author:
    John E. Bailey
    • Method Detail

      • getLastComponent

        public static String getLastComponent​(Name name)
        Get the last component of a name.
        Parameters:
        name - the name
        Returns:
        the last component
      • isEmpty

        public static boolean isEmpty​(Name name)
        Determine if a name is empty, or if ot contains only one component which is the empty string.
        Parameters:
        name - the name
        Returns:
        true if the name is empty or contains one empty component
      • isLastComponentEmpty

        public static boolean isLastComponentEmpty​(Name name)
        Determine whether the last component is empty.
        Parameters:
        name - the name to test
        Returns:
        true if the last component is empty, or if the name is empty
      • nameNotFoundException

        public static NameNotFoundException nameNotFoundException​(String name,
                                                                  Name contextName)
        Create a name-not-found exception.
        Parameters:
        name - the name
        contextName - the context name
        Returns:
        the exception
      • nameAlreadyBoundException

        public static NameAlreadyBoundException nameAlreadyBoundException​(Name name)
        Create a name-already-bound exception.
        Parameters:
        name - the name
        Returns:
        the exception
      • emptyNameException

        public static InvalidNameException emptyNameException()
        Create an invalid name exception for an empty name.
        Returns:
        the exception
      • notAContextException

        public static NotContextException notAContextException​(Name name)
        Return a not-context exception for a name.
        Parameters:
        name - the name
        Returns:
        the exception
      • namingException

        public static NamingException namingException​(String message,
                                                      Throwable cause)
        Return a general naming exception with a root cause.
        Parameters:
        message - the message
        cause - the exception cause, or null for none
        Returns:
        the exception
      • namingException

        public static NamingException namingException​(String message,
                                                      Throwable cause,
                                                      Name remainingName)
        Return a general naming exception with a root cause and a remaining name field.
        Parameters:
        message - the message
        cause - the exception cause, or null for none
        remainingName - the remaining name
        Returns:
        the exception
      • cannotProceedException

        public static CannotProceedException cannotProceedException​(Object resolvedObject,
                                                                    Name remainingName)
        Return a cannot-proceed exception.
        Parameters:
        resolvedObject - the resolved object
        remainingName - the remaining name
        Returns:
        the exception
      • namingEnumeration

        public static <T> NamingEnumeration<T> namingEnumeration​(Collection<T> collection)
        Return a naming enumeration over a collection.
        Type Parameters:
        T - the member type
        Parameters:
        collection - the collection
        Returns:
        the enumeration
      • rebind

        public static void rebind​(Context ctx,
                                  String name,
                                  Object value)
                           throws NamingException
        Rebind val to name in ctx, and make sure that all intermediate contexts exist
        Parameters:
        ctx - the parent JNDI Context under which value will be bound
        name - the name relative to ctx where value will be bound
        value - the value to bind.
        Throws:
        NamingException - for any error
      • rebind

        public static void rebind​(Context ctx,
                                  Name name,
                                  Object value)
                           throws NamingException
        Rebind val to name in ctx, and make sure that all intermediate contexts exist
        Parameters:
        ctx - the parent JNDI Context under which value will be bound
        name - the name relative to ctx where value will be bound
        value - the value to bind.
        Throws:
        NamingException - for any error
      • unbind

        public static void unbind​(Context ctx,
                                  String name)
                           throws NamingException
        Unbinds a name from ctx, and removes parents if they are empty
        Parameters:
        ctx - the parent JNDI Context under which the name will be unbound
        name - The name to unbind
        Throws:
        NamingException - for any error
      • unbind

        public static void unbind​(Context ctx,
                                  Name name)
                           throws NamingException
        Unbinds a name from ctx, and removes parents if they are empty
        Parameters:
        ctx - the parent JNDI Context under which the name will be unbound
        name - The name to unbind
        Throws:
        NamingException - for any error