Class URLStreamHandlerFactory

  • All Implemented Interfaces:
    java.net.URLStreamHandlerFactory

    public class URLStreamHandlerFactory
    extends java.lang.Object
    implements java.net.URLStreamHandlerFactory
    A factory for loading URL protocol handlers. This is based on Sun's URL mechanism, in that Handler classes will be searched for in the packages specified by the java.protocol.handler.pkgs property are searched for classes matching the protocol + ".Handler" classname. The default JBoss package "org.jboss.net.protocol" is searched even if not specified in the java.protocol.handler.pkgs property.

    This factory is installed by the default server implementaion to ensure that protocol handlers not in the system classpath are located. The thread context class is used first followed by the Class.forName method.

    Version:
    $Revision$
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.ThreadLocal createURLStreamHandlerProtocol
      This thread local is used to prevent recursion in the createURLStreamHandler method.
      private static java.util.Map handlerMap
      A map of protocol names to handlers.
      private java.lang.String[] handlerPkgs
      The current packages prefixes determined from the java.protocol.handler.pkgs property + the org.jboss.net.protocol default package.
      private java.lang.String lastHandlerPkgs
      The last java.protocol.handler.pkgs value.
      private static org.jboss.logging.Logger log
      Class logger.
      static java.lang.String PACKAGE_PREFIX
      The package prefix where JBoss protocol handlers live.
      static java.lang.String[] PROTOCOLS
      A list of JBoss specific protocols for preloading.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void checkHandlerPkgs()
      See if the java.protocol.handler.pkgs system property has changed and if it has, parse it to update the handlerPkgs array.
      static void clear()
      Clear the current protocol to handler map.
      java.net.URLStreamHandler createURLStreamHandler​(java.lang.String protocol)
      Search the handlerPkgs for URLStreamHandler classes matching the pkg + protocol + ".Handler" naming convention.
      static void preload()
      Preload the JBoss specific protocol handlers, so that URL knows about them even if the handler factory is changed.
      • Methods inherited from class java.lang.Object

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

      • log

        private static final org.jboss.logging.Logger log
        Class logger.
      • PACKAGE_PREFIX

        public static final java.lang.String PACKAGE_PREFIX
        The package prefix where JBoss protocol handlers live.
        See Also:
        Constant Field Values
      • handlerMap

        private static java.util.Map handlerMap
        A map of protocol names to handlers. Since there can only be one URLStreamHandlerFactory installed, this is a static map that may be cleared.
      • createURLStreamHandlerProtocol

        private static java.lang.ThreadLocal createURLStreamHandlerProtocol
        This thread local is used to prevent recursion in the createURLStreamHandler method. Resolving the protocol handler class can end up creating a new URL which can loop back into this factory with a stack like:
              URLStreamHandlerFactory that use the TCL. See bug#669043
              createURLStreamHandler():146, URLStreamHandlerFactory.java
              getURLStreamHandler():1057, URL.java
              ():405, URL.java
              ():329, URL.java
              ():321, URL.java
              ():540, URLClassPath.java
              run():319, URLClassPath.java
              doPrivileged():-1, AccessController.java
              getLoader():308, URLClassPath.java
              getLoader():285, URLClassPath.java
              findResource():136, URLClassPath.java
              run():351, URLClassLoader.java
              doPrivileged():-1, AccessController.java
              findResource():348, URLClassLoader.java
              getResource():780, ClassLoader.java
              getResourceLocally():250, UnifiedClassLoader.java
              getResourceFromClassLoader():333, UnifiedLoaderRepository3.java
              getResource():243, UnifiedLoaderRepository3.java
              getResource():228, UnifiedClassLoader3.java
             
        So we detect recursion based on the protocol value matches the current createURLStreamHandlerProtocol setting.
      • handlerPkgs

        private java.lang.String[] handlerPkgs
        The current packages prefixes determined from the java.protocol.handler.pkgs property + the org.jboss.net.protocol default package.
      • lastHandlerPkgs

        private java.lang.String lastHandlerPkgs
        The last java.protocol.handler.pkgs value. Used to determine if the java.protocol.handler.pkgs property has changed since handlerPkgs was last built.
      • PROTOCOLS

        public static final java.lang.String[] PROTOCOLS
        A list of JBoss specific protocols for preloading.
    • Constructor Detail

      • URLStreamHandlerFactory

        public URLStreamHandlerFactory()
    • Method Detail

      • preload

        public static void preload()
        Preload the JBoss specific protocol handlers, so that URL knows about them even if the handler factory is changed.
      • clear

        public static void clear()
        Clear the current protocol to handler map. The map will be rebuilt as protocol handlers are requested.
      • createURLStreamHandler

        public java.net.URLStreamHandler createURLStreamHandler​(java.lang.String protocol)
        Search the handlerPkgs for URLStreamHandler classes matching the pkg + protocol + ".Handler" naming convention.
        Specified by:
        createURLStreamHandler in interface java.net.URLStreamHandlerFactory
        Parameters:
        protocol - The protocol to create a stream handler for
        Returns:
        The protocol handler or null if not found
      • checkHandlerPkgs

        private void checkHandlerPkgs()
        See if the java.protocol.handler.pkgs system property has changed and if it has, parse it to update the handlerPkgs array.