You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/10/05 03:01:31 UTC

svn commit: r582048 - in /geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell: GShell.java URLHandlerFactory.java url/ url/DefaultURLHandlerFactory.java url/URLHandlerFactory.java

Author: jdillon
Date: Thu Oct  4 18:01:30 2007
New Revision: 582048

URL: http://svn.apache.org/viewvc?rev=582048&view=rev
Log:
Support pluggable URLHandlerFactory impls, disable default creation for now

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/DefaultURLHandlerFactory.java   (contents, props changed)
      - copied, changed from r582016, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/URLHandlerFactory.java   (contents, props changed)
      - copied, changed from r582016, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java
Removed:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java?rev=582048&r1=582047&r2=582048&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java Thu Oct  4 18:01:30 2007
@@ -26,6 +26,7 @@
 import org.apache.geronimo.gshell.shell.Environment;
 import org.apache.geronimo.gshell.shell.InteractiveShell;
 import org.apache.geronimo.gshell.shell.ShellInfo;
+import org.apache.geronimo.gshell.url.URLHandlerFactory;
 import org.codehaus.plexus.ContainerConfiguration;
 import org.codehaus.plexus.DefaultContainerConfiguration;
 import org.codehaus.plexus.DefaultPlexusContainer;
@@ -81,8 +82,11 @@
             config.setClassWorld(classWorld);
             container = new DefaultPlexusContainer(config);
 
+            //
+            // TODO: Disabled for now, re-hookup once rfile bits are ready
+            //
             // Get our URL handler factory installed
-            container.lookup(URLHandlerFactory.class);
+            // container.lookup(URLHandlerFactory.class);
 
             // We first need to stuff in the IO context for the new shell instance
             IOLookup.set(container, io);

Copied: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/DefaultURLHandlerFactory.java (from r582016, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/DefaultURLHandlerFactory.java?p2=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/DefaultURLHandlerFactory.java&p1=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java&r1=582016&r2=582048&rev=582048&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/DefaultURLHandlerFactory.java Thu Oct  4 18:01:30 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell;
+package org.apache.geronimo.gshell.url;
 
 import java.net.URL;
 import java.net.URLStreamHandler;
@@ -34,6 +34,7 @@
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.geronimo.gshell.url.URLHandlerFactory;
 
 /**
  * Provides access to URL internals.
@@ -41,10 +42,10 @@
  * @version $Rev$ $Date$
  */
 @Component(role=URLHandlerFactory.class, instantiationStrategy="singleton-keep-alive")
-public final class URLHandlerFactory
-    implements Initializable
+public class DefaultURLHandlerFactory
+    implements URLHandlerFactory,Initializable
 {
-    private static URLHandlerFactory SINGLETON;
+    private static DefaultURLHandlerFactory SINGLETON;
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -53,7 +54,7 @@
     @Requirement(role=URLStreamHandler.class)
     private Map<String,URLStreamHandler> handlers;
 
-    public URLHandlerFactory() {
+    public DefaultURLHandlerFactory() {
         // Just sanity check that only one of these puppies gets constructed... ever
         synchronized (URLHandlerFactory.class) {
             if (SINGLETON != null) {
@@ -66,7 +67,7 @@
     public void initialize() throws InitializationException {
         try {
             URL.setURLStreamHandlerFactory(factory);
-            
+
             log.debug("URL stream handler factory installed");
         }
         catch (Throwable t) {
@@ -89,7 +90,7 @@
         factory.register(protocol, handler);
     }
 
-    public URLStreamHandler getHandler(final String protocol) {
+    public URLStreamHandler create(final String protocol) {
         return factory.getHandler(protocol);
     }
 
@@ -194,10 +195,10 @@
 
                 return handler;
             }
-            
+
             // Try to get the stream handler from the registered package list
             Class<?> type = findProtocolHandler(protocol);
-            
+
             if (type == null) {
                 throw new IllegalArgumentException("Unknown protocol: " + protocol);
             }
@@ -232,12 +233,12 @@
         private synchronized Map<String,URLStreamHandler> handlers() {
             return Collections.unmodifiableMap(handlers);
         }
-        
+
         private Class<?> findProtocolHandler(final String protocol) {
             assert protocol != null;
 
             log.trace("Finding protocol handler: {}", protocol);
-            
+
             ClassLoader cl = Thread.currentThread().getContextClassLoader();
             if (cl == null) {
                 cl = ClassLoader.getSystemClassLoader();
@@ -255,4 +256,4 @@
             return null;
         }
     }
-}
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/DefaultURLHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/DefaultURLHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/DefaultURLHandlerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/URLHandlerFactory.java (from r582016, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/URLHandlerFactory.java?p2=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/URLHandlerFactory.java&p1=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java&r1=582016&r2=582048&rev=582048&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/URLHandlerFactory.java Thu Oct  4 18:01:30 2007
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell;
+package org.apache.geronimo.gshell.url;
 
 import java.net.URL;
 import java.net.URLStreamHandler;
@@ -40,219 +40,11 @@
  *
  * @version $Rev$ $Date$
  */
-@Component(role=URLHandlerFactory.class, instantiationStrategy="singleton-keep-alive")
-public final class URLHandlerFactory
-    implements Initializable
+public interface URLHandlerFactory
 {
-    private static URLHandlerFactory SINGLETON;
+    void register(String protocol, URLStreamHandler handler);
 
-    private final Logger log = LoggerFactory.getLogger(getClass());
+    URLStreamHandler create(String protocol);
 
-    private final Factory factory = new Factory();
-
-    @Requirement(role=URLStreamHandler.class)
-    private Map<String,URLStreamHandler> handlers;
-
-    public URLHandlerFactory() {
-        // Just sanity check that only one of these puppies gets constructed... ever
-        synchronized (URLHandlerFactory.class) {
-            if (SINGLETON != null) {
-                throw new IllegalStateException("Singleton instance already constructed");
-            }
-            SINGLETON = this;
-        }
-    }
-
-    public void initialize() throws InitializationException {
-        try {
-            URL.setURLStreamHandlerFactory(factory);
-            
-            log.debug("URL stream handler factory installed");
-        }
-        catch (Throwable t) {
-            throw new InitializationException("Failed to install URL stream handler factory", t);
-        }
-
-        // Log the initial handlers which were injected
-        if (!handlers.isEmpty()) {
-            log.debug("Initial URL stream handlers:");
-            for (Map.Entry entry : handlers.entrySet()) {
-                log.debug("    {} -> {}", entry.getKey(), entry.getValue());
-            }
-        }
-        else {
-            log.warn("No URL stream handlers are currently registered; somethings probably misconfigured");
-        }
-    }
-
-    public void register(final String protocol, final URLStreamHandler handler) {
-        factory.register(protocol, handler);
-    }
-
-    public URLStreamHandler getHandler(final String protocol) {
-        return factory.getHandler(protocol);
-    }
-
-    public Map<String,URLStreamHandler> handlers() {
-        return factory.handlers();
-    }
-
-    /*
-    public static void forceInstall() throws Error, SecurityException {
-        if (!installed) {
-            // This way is "naughty" but works great
-            Throwable t = (Throwable) AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    try {
-                        // get a reference to the URL stream handler lock... we need to
-                        // synchronize on this field to be safe
-                        Field streamHandlerLockField = URL.class.getDeclaredField("streamHandlerLock");
-                        streamHandlerLockField.setAccessible(true);
-                        Object streamHandlerLock = streamHandlerLockField.get(null);
-
-                        synchronized (streamHandlerLock) {
-                            // get a reference to the factory field and change the permissions
-                            // to make it accessable (factory is a package protected field)
-                            Field factoryField = URL.class.getDeclaredField("factory");
-                            factoryField.setAccessible(true);
-
-                            // get a reference to the handlers field and change the permissions
-                            // to make it accessable (handlers is a package protected field)
-                            Field handlersField = URL.class.getDeclaredField("handlers");
-                            handlersField.setAccessible(true);
-
-                            // the the handlers map first
-                            Map handlers = (Map) handlersField.get(null);
-
-                            // set the factory field to our factory
-                            factoryField.set(null, factory);
-
-                            // clear the handlers
-                            handlers.clear();
-                        }
-                    } catch (Throwable e) {
-                        return e;
-                    }
-                    return null;
-                }
-            });
-
-            if (t != null) {
-                if (t instanceof SecurityException) {
-                    throw (SecurityException) t;
-                } else if (t instanceof Error) {
-                    throw (Error) t;
-                }
-                throw new Error("Unknown error while force installing URL factory", t);
-            }
-            installed = true;
-        }
-    }
-    */
-
-    //
-    // Factory
-    //
-
-    private class Factory
-        implements URLStreamHandlerFactory
-    {
-        private final List<String> handlerPackages = new LinkedList<String>();
-
-        private Factory() {
-            // Add the packages listed in the standard system property
-            String systemPackages = System.getProperty("java.protocol.handler.pkgs");
-
-            if (systemPackages != null) {
-                StringTokenizer stok = new StringTokenizer(systemPackages, "|");
-
-                while (stok.hasMoreTokens()) {
-                    handlerPackages.add(stok.nextToken().trim());
-                }
-            }
-
-            // Always add the sun handlers
-            handlerPackages.add("sun.net.www.protocol");
-        }
-
-        public URLStreamHandler createURLStreamHandler(String protocol) {
-            assert protocol != null;
-
-            protocol = protocol.trim();
-
-            log.trace("Create URL stream handler: {}", protocol);
-
-            URLStreamHandler handler;
-
-            // First check the registered handlers
-            synchronized (this) {
-                handler = handlers.get(protocol);
-            }
-
-            if (handler != null) {
-                log.trace("Using registered handler: {}", handler);
-
-                return handler;
-            }
-            
-            // Try to get the stream handler from the registered package list
-            Class<?> type = findProtocolHandler(protocol);
-            
-            if (type == null) {
-                throw new IllegalArgumentException("Unknown protocol: " + protocol);
-            }
-
-            try {
-                return (URLStreamHandler) type.newInstance();
-            }
-            catch (Exception e) {
-                throw new IllegalArgumentException("Failed to construct handler for protocol: " + protocol, e);
-            }
-        }
-
-        private synchronized void register(final String protocol, final URLStreamHandler handler) {
-            assert protocol != null;
-            assert handler != null;
-
-            if (handlers.containsKey(protocol)) {
-                throw new IllegalStateException("Protocol already has a registered handler: " + protocol);
-            }
-
-            handlers.put(protocol, handler);
-
-            log.debug("Registered {} -> {}", protocol, handler);
-        }
-
-        private synchronized URLStreamHandler getHandler(final String protocol) {
-            assert protocol != null;
-
-            return handlers.get(protocol);
-        }
-
-        private synchronized Map<String,URLStreamHandler> handlers() {
-            return Collections.unmodifiableMap(handlers);
-        }
-        
-        private Class<?> findProtocolHandler(final String protocol) {
-            assert protocol != null;
-
-            log.trace("Finding protocol handler: {}", protocol);
-            
-            ClassLoader cl = Thread.currentThread().getContextClassLoader();
-            if (cl == null) {
-                cl = ClassLoader.getSystemClassLoader();
-            }
-
-            for (String pkg : handlerPackages) {
-                String classname = pkg + "." + protocol + ".Handler";
-
-                try {
-                    return cl.loadClass(classname);
-                }
-                catch (Throwable ignore) {}
-            }
-
-            return null;
-        }
-    }
+    Map<String,URLStreamHandler> handlers();
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/URLHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/URLHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/url/URLHandlerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain