org.springframework.jndi

Class JndiLocatorSupport

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String CONTAINER_PREFIX
      JNDI prefix used in a Java EE container.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      protected java.lang.String convertJndiName(java.lang.String jndiName)
      Convert the given JNDI name into the actual JNDI name to use.
      boolean isResourceRef()
      Return whether the lookup occurs in a Java EE container.
      protected java.lang.Object lookup(java.lang.String jndiName)
      Perform an actual JNDI lookup for the given name via the JndiTemplate.
      protected <T> T lookup(java.lang.String jndiName, java.lang.Class<T> requiredType)
      Perform an actual JNDI lookup for the given name via the JndiTemplate.
      void setResourceRef(boolean resourceRef)
      Set whether the lookup occurs in a Java EE container, i.e.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CONTAINER_PREFIX

        public static final java.lang.String CONTAINER_PREFIX
        JNDI prefix used in a Java EE container.
        See Also:
        Constant Field Values
    • Constructor Detail

      • JndiLocatorSupport

        public JndiLocatorSupport()
    • Method Detail

      • setResourceRef

        public void setResourceRef(boolean resourceRef)
        Set whether the lookup occurs in a Java EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it. Default is "false".

        Note: Will only get applied if no other scheme (e.g. "java:") is given.

      • isResourceRef

        public boolean isResourceRef()
        Return whether the lookup occurs in a Java EE container.
      • lookup

        protected java.lang.Object lookup(java.lang.String jndiName)
                                   throws javax.naming.NamingException
        Perform an actual JNDI lookup for the given name via the JndiTemplate.

        If the name doesn't begin with "java:comp/env/", this prefix is added if "resourceRef" is set to "true".

        Parameters:
        jndiName - the JNDI name to look up
        Returns:
        the obtained object
        Throws:
        javax.naming.NamingException - if the JNDI lookup failed
        See Also:
        setResourceRef(boolean)
      • lookup

        protected <T> T lookup(java.lang.String jndiName,
                               @Nullable
                               java.lang.Class<T> requiredType)
                        throws javax.naming.NamingException
        Perform an actual JNDI lookup for the given name via the JndiTemplate.

        If the name doesn't begin with "java:comp/env/", this prefix is added if "resourceRef" is set to "true".

        Parameters:
        jndiName - the JNDI name to look up
        requiredType - the required type of the object
        Returns:
        the obtained object
        Throws:
        javax.naming.NamingException - if the JNDI lookup failed
        See Also:
        setResourceRef(boolean)
      • convertJndiName

        protected java.lang.String convertJndiName(java.lang.String jndiName)
        Convert the given JNDI name into the actual JNDI name to use.

        The default implementation applies the "java:comp/env/" prefix if "resourceRef" is "true" and no other scheme (e.g. "java:") is given.

        Parameters:
        jndiName - the original JNDI name
        Returns:
        the JNDI name to use
        See Also:
        CONTAINER_PREFIX, setResourceRef(boolean)