Class NamingContextListener

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.util.EventListener, ContainerListener, LifecycleListener

    public class NamingContextListener
    extends java.lang.Object
    implements LifecycleListener, ContainerListener, java.beans.PropertyChangeListener
    Helper class used to initialize and populate the JNDI context associated with each context and server.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.naming.Context compCtx
      Comp context.
      protected java.lang.Object container
      Associated container.
      protected javax.naming.Context envCtx
      Env context.
      protected boolean initialized
      Initialized flag.
      protected java.lang.String name
      Name of the associated naming context.
      protected NamingContext namingContext
      Associated JNDI context.
      protected NamingResourcesImpl namingResources
      Associated naming resources.
      protected java.util.HashMap<java.lang.String,​javax.management.ObjectName> objectNames
      Objectnames Map.
      protected static StringManager sm
      The string manager for this class.
    • Field Detail

      • sm

        protected static final StringManager sm
        The string manager for this class.
      • name

        protected java.lang.String name
        Name of the associated naming context.
      • container

        protected java.lang.Object container
        Associated container.
      • initialized

        protected boolean initialized
        Initialized flag.
      • namingContext

        protected NamingContext namingContext
        Associated JNDI context.
      • compCtx

        protected javax.naming.Context compCtx
        Comp context.
      • envCtx

        protected javax.naming.Context envCtx
        Env context.
      • objectNames

        protected java.util.HashMap<java.lang.String,​javax.management.ObjectName> objectNames
        Objectnames Map.
    • Constructor Detail

      • NamingContextListener

        public NamingContextListener()
        Default constructor.
    • Method Detail

      • getExceptionOnFailedWrite

        public boolean getExceptionOnFailedWrite()
        Return whether or not an attempt to modify the JNDI context will trigger an exception.
        Returns:
        whether or not an attempt to modify the JNDI context will trigger an exception
      • setExceptionOnFailedWrite

        public void setExceptionOnFailedWrite​(boolean exceptionOnFailedWrite)
        Controls whether or not an attempt to modify the JNDI context will trigger an exception or if the request will be ignored.
        Parameters:
        exceptionOnFailedWrite - The new value
      • getName

        public java.lang.String getName()
        Return the "name" property.
        Returns:
        the "name" property
      • setName

        public void setName​(java.lang.String name)
        Set the "name" property.
        Parameters:
        name - The new name
      • getEnvContext

        public javax.naming.Context getEnvContext()
        Return the naming environment context.
        Returns:
        the naming environment context
      • containerEvent

        @Deprecated
        public void containerEvent​(ContainerEvent event)
        Deprecated.
        The ContainerListener interface and implementing methods will be removed from this class for Tomcat 10 onwards.
        NO-OP.
        Specified by:
        containerEvent in interface ContainerListener
        Parameters:
        event - ContainerEvent that has occurred
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent event)
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
      • createObjectName

        protected javax.management.ObjectName createObjectName​(ContextResource resource)
                                                        throws javax.management.MalformedObjectNameException
        Create an ObjectName for this ContextResource object.
        Parameters:
        resource - The resource
        Returns:
        ObjectName The object name
        Throws:
        javax.management.MalformedObjectNameException - if a name cannot be created
      • addEjb

        public void addEjb​(ContextEjb ejb)
        Set the specified EJBs in the naming context.
        Parameters:
        ejb - the EJB descriptor
      • addEnvironment

        public void addEnvironment​(ContextEnvironment env)
        Set the specified environment entries in the naming context.
        Parameters:
        env - the environment entry
      • addLocalEjb

        public void addLocalEjb​(ContextLocalEjb localEjb)
        Set the specified local EJBs in the naming context.
        Parameters:
        localEjb - the local EJB descriptor (unused)
      • addMessageDestinationRef

        public void addMessageDestinationRef​(MessageDestinationRef mdr)
        Set the specified message destination refs in the naming context.
        Parameters:
        mdr - the message destination ref descriptor (unused)
      • addService

        public void addService​(ContextService service)
        Set the specified web service in the naming context.
        Parameters:
        service - the web service descriptor
      • addResource

        public void addResource​(ContextResource resource)
        Set the specified resources in the naming context.
        Parameters:
        resource - the resource descriptor
      • addContainerPoolName

        protected void addContainerPoolName​(javax.naming.Reference ref,
                                            ContextResource resource)
        Pass a container-managed JNDI resource that the Tomcat JDBC connection pool will build, and that does not name itself, a container-unique pool registration name through the pool factory's object_name attribute.
        Parameters:
        ref - the reference created for the resource
        resource - the resource descriptor
      • generatePoolName

        protected java.lang.String generatePoolName​(ContextResource resource)
        Generate the unique connection pool name for a resource of this container.

        Webapp resources are named <domain>/<host>/<context>/<jndiName> and global resources <domain>/<jndiName>, where the JNDI name of a global resource is already unique within the Server's global namespace. Only the slash separator is used, a character with no meaning in a JMX object name or in a naming path; the pool's JNDI factory stores the name through ObjectName.quote(String) exactly as it stores any configured object_name. The generation is deterministic: the same configuration always yields the same name, across rebinds and context reloads.

        Parameters:
        resource - the resource descriptor
        Returns:
        the generated name, or null if this container's position does not allow a stable unique name to be generated
      • addResourceEnvRef

        public void addResourceEnvRef​(ContextResourceEnvRef resourceEnvRef)
        Set the specified resources in the naming context.
        Parameters:
        resourceEnvRef - the resource reference
      • addResourceLink

        public void addResourceLink​(ContextResourceLink resourceLink)
        Set the specified resource link in the naming context.
        Parameters:
        resourceLink - the resource link
      • removeEjb

        public void removeEjb​(java.lang.String name)
        Remove the specified EJB from the naming context.
        Parameters:
        name - the name of the EJB which should be removed
      • removeEnvironment

        public void removeEnvironment​(java.lang.String name)
        Remove the specified environment entry from the naming context.
        Parameters:
        name - the name of the environment entry which should be removed
      • removeLocalEjb

        public void removeLocalEjb​(java.lang.String name)
        Remove the specified local EJB from the naming context.
        Parameters:
        name - the name of the EJB which should be removed
      • removeMessageDestinationRef

        public void removeMessageDestinationRef​(java.lang.String name)
        Remove the specified message destination ref from the naming context.
        Parameters:
        name - the name of the message destination ref which should be removed
      • removeService

        public void removeService​(java.lang.String name)
        Remove the specified web service from the naming context.
        Parameters:
        name - the name of the web service which should be removed
      • removeResource

        public void removeResource​(java.lang.String name)
        Remove the specified resource from the naming context.
        Parameters:
        name - the name of the resource which should be removed
      • removeResourceEnvRef

        public void removeResourceEnvRef​(java.lang.String name)
        Remove the specified resource environment reference from the naming context.
        Parameters:
        name - the name of the resource environment reference which should be removed
      • removeResourceLink

        public void removeResourceLink​(java.lang.String name)
        Remove the specified resource link from the naming context.
        Parameters:
        name - the name of the resource link which should be removed