User: user57  
  Date: 02/04/04 14:21:18

  Modified:    src/main/org/jboss/net/protocol URLStreamHandlerFactory.java
  Added:       src/main/org/jboss/net/protocol DelegatingURLConnection.java
  Log:
   o Added helper class for delegate URLConnection impls
   o Added URLStreamHandlerFactory.preload() to init the URL handler map
     for all JBoss specific protocols (in case the factory is changed)
  
  Revision  Changes    Path
  1.2       +32 -0     
jboss-common/src/main/org/jboss/net/protocol/URLStreamHandlerFactory.java
  
  Index: URLStreamHandlerFactory.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss-common/src/main/org/jboss/net/protocol/URLStreamHandlerFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- URLStreamHandlerFactory.java      26 Feb 2002 01:28:37 -0000      1.1
  +++ URLStreamHandlerFactory.java      4 Apr 2002 22:21:18 -0000       1.2
  @@ -9,8 +9,11 @@
   
   package org.jboss.net.protocol;
   
  +import java.net.URL;
   import java.net.URLStreamHandler;
   
  +import org.jboss.logging.Logger;
  +
   /**
    * A factory for loading JBoss specific protocols.  This is based
    * on Sun's URL mechanism, in that <tt>Handler</tt> classes will be 
  @@ -21,12 +24,18 @@
    *    default URL logic to function when setting the
    *    <tt>java.protocol.handler.pkgs</tt> system property.
    *
  - * @version <tt>$Revision: 1.1 $</tt>
  + * <p>Use {@link preload} to force the URL handler map to load the
  + *    handlers for each protocol listed in {@link #PROTOCOLS}.
  + *
  + * @version <tt>$Revision: 1.2 $</tt>
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
    */
   public class URLStreamHandlerFactory
      implements java.net.URLStreamHandlerFactory
   {
  +   /** Class logger. */
  +   private static final Logger log = 
Logger.getLogger(URLStreamHandlerFactory.class);
  +
      /** The package prefix where JBoss protocol handlers live. */
      public static final String PACKAGE_PREFIX = "org.jboss.net.protocol";
   
  @@ -61,5 +70,28 @@
         catch (Exception ignore) {}
   
         return handler;
  +   }
  +
  +   /** A list of JBoss specific protocols for preloading. */
  +   public static final String PROTOCOLS[] = {
  +      "resource",
  +      "file",
  +      "njar",
  +   };
  +
  +   /**
  +    * Preload the JBoss specific protocol handlers, to that URL knows about 
  +    * them even if the handler factory is changed.
  +    */
  +   public static void preload() {
  +      for (int i=0; i<PROTOCOLS.length; i++) {
  +         try {
  +            URL url = new URL(PROTOCOLS[i], "", -1, "");
  +            log.trace("Loaded protocol: " + PROTOCOLS[i]);
  +         }
  +         catch (Exception e) {
  +            log.warn("Failed to load protocol: " + PROTOCOLS[i], e);
  +         }
  +      }
      }
   }
  
  
  
  1.1                  
jboss-common/src/main/org/jboss/net/protocol/DelegatingURLConnection.java
  
  Index: DelegatingURLConnection.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.net.protocol;
  
  import java.io.IOException;
  import java.io.InputStream;
  
  import java.net.URLConnection;
  import java.net.URL;
  import java.net.MalformedURLException;
  
  import java.security.Permission;
  
  /**
   * An delegating URLConnection support class.
   *
   * @version <tt>$Revision: 1.1 $</tt>
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   */
  public class DelegatingURLConnection
     extends URLConnection
  {
     protected URL delegateUrl;
     protected URLConnection delegateConnection;
  
     public DelegatingURLConnection(final URL url)
        throws MalformedURLException, IOException
     {
        super(url);
        
        delegateUrl = makeDelegateUrl(url);
        delegateConnection = makeDelegateUrlConnection(delegateUrl);
     }
  
     protected URL makeDelegateUrl(final URL url)
        throws MalformedURLException, IOException
     {
        return url;
     }
  
     protected URLConnection makeDelegateUrlConnection(final URL url)
        throws IOException
     {
        return url.openConnection();
     }
  
     public void connect() throws IOException {
        delegateConnection.connect();
     }
  
     public Object getContent() throws IOException {
        return delegateConnection.getContent();
     }
  
     public String getContentType() {
        return delegateConnection.getContentType();
     }
  
     public InputStream getInputStream() throws IOException {
        return delegateConnection.getInputStream();
     }
  
     public String getHeaderField(final String name) {
        return delegateConnection.getHeaderField(name);
     }
  
     public Permission getPermission() throws IOException {
        return delegateConnection.getPermission();
     }
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to