Class ContextUtil

    • Constructor Detail

      • ContextUtil

        public ContextUtil()
    • Method Detail

      • lookupOrCreateSubContext

        public static ContextInterface lookupOrCreateSubContext​(ContextInterface parentContext,
                                                                String name)
                                                         throws NamingException,
                                                                RemoteException
        Lookup or create a sub-context in the parentContext with the name as its path. The path can be absolute or relative. The terminating part of the name will be used as the key under which the created subcontext will be registered.
        Parameters:
        parentContext - ContextInterface; the parent context
        name - String; the name to register the new subcontext
        Returns:
        ContextInterface; the newly created subcontext
        Throws:
        NamingException - when terminating key in the name is blank or contains "/" character(s)
        RemoteException - on a network error when the Context is used over RMI
      • lookupSubContext

        public static ContextInterface lookupSubContext​(ContextInterface parentContext,
                                                        String name)
                                                 throws NamingException,
                                                        RemoteException
        Lookup a sub-context in the parentContext with the name as its path. The path can be absolute or relative. The terminating part of the name will be used as the key under which the created subcontext will be registered.
        Parameters:
        parentContext - ContextInterface; the parent context
        name - String; the name to register the new subcontext
        Returns:
        ContextInterface; the newly created subcontext
        Throws:
        NamingException - when terminating key in the name is blank or contains "/" character(s)
        RemoteException - on a network error when the Context is used over RMI
      • destroySubContext

        public static void destroySubContext​(ContextInterface parentContext,
                                             String name)
                                      throws NamingException,
                                             RemoteException
        Destroy a sub-context in the parentContext with the name as its path. The path can be absolute or relative. The terminating part of the name will be used as the key under for the subcontext to be removed.
        Parameters:
        parentContext - ContextInterface; the parent context
        name - String; the name to use to find the subcontext to remove
        Throws:
        NamingException - when terminating key in the name is blank or contains "/" character(s)
        RemoteException - on a network error when the Context is used over RMI
      • resolveKeys

        public static List<String> resolveKeys​(ContextInterface startContext,
                                               Object object)
                                        throws NamingException,
                                               RemoteException
        Resolve the key(s) for an object for a given context. This can be an expensive operation if the context is large. An object can be registered zero or more times in the context, so a List of keys under which the object is registered will be returned. The keys are relative to the startContext. The method starts with the given context. It is possible to look up null objects in the Context.
        Parameters:
        startContext - ContextInterface; the context to start the search
        object - Object; the object to look up in the tree under the startContext
        Returns:
        List<String>; the list of keys that are bound to the object, or an empty list if no bindings for the object were found
        Throws:
        NamingException - when an error occurs during searching
        RemoteException - on a network error when the Context is used over RMI
      • toText

        public static String toText​(ContextInterface ctx)
        recursively print the context in human-readable format to a String.
        Parameters:
        ctx - the context to print
        Returns:
        a human-readable String with the context tree