org.apache.geronimo.system.url
Class GeronimoURLFactory

java.lang.Object
  extended byorg.apache.geronimo.system.url.GeronimoURLFactory
All Implemented Interfaces:
org.apache.geronimo.gbean.GBeanLifecycle

public class GeronimoURLFactory
extends Object
implements org.apache.geronimo.gbean.GBeanLifecycle

This service replaces the URLStreamHandlerFactory used in URL, which gives Geronimo complete control over the URLs creted in the server. This allows us to replace the broken implementation of the "file" protocol.

Version:
$Revision: 1.5 $ $Date: 2004/06/05 07:53:22 $

Field Summary
static org.apache.geronimo.gbean.GBeanInfo GBEAN_INFO
           
 
Constructor Summary
GeronimoURLFactory()
           
 
Method Summary
 void doFail()
           
 void doStart()
           
 void doStop()
           
static void forceInstall()
          Installs the factory into directly URL's private and package protected fields using Field.setAccessable(true).
static org.apache.geronimo.gbean.GBeanInfo getGBeanInfo()
           
 URLStreamHandler getRegisteredHandler(String protocol)
          Gets the handler registered for the specified protocol
 Map getRegisteredHandlers()
          Gets a map of all registered handlers keyed by protocol name.
static void install()
          Installs the factory into URL using the setURLStreamHandlerFactory method.
static boolean isInstalled()
          Is our factory installed?
 void registerHandler(String protocol, URLStreamHandler handler)
          Assigns the handler to the specified protocol.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GBEAN_INFO

public static final org.apache.geronimo.gbean.GBeanInfo GBEAN_INFO
Constructor Detail

GeronimoURLFactory

public GeronimoURLFactory()
Method Detail

doStart

public void doStart()
             throws org.apache.geronimo.gbean.WaitingException,
                    Exception
Specified by:
doStart in interface org.apache.geronimo.gbean.GBeanLifecycle
Throws:
org.apache.geronimo.gbean.WaitingException
Exception

doStop

public void doStop()
            throws org.apache.geronimo.gbean.WaitingException,
                   Exception
Specified by:
doStop in interface org.apache.geronimo.gbean.GBeanLifecycle
Throws:
org.apache.geronimo.gbean.WaitingException
Exception

doFail

public void doFail()
Specified by:
doFail in interface org.apache.geronimo.gbean.GBeanLifecycle

registerHandler

public void registerHandler(String protocol,
                            URLStreamHandler handler)
Assigns the handler to the specified protocol.

Parameters:
protocol - the prototcol name
handler - the url handler for the protocol
Throws:
IllegalStateException - if a handler is alreayd assigned to the protocol

getRegisteredHandler

public URLStreamHandler getRegisteredHandler(String protocol)
Gets the handler registered for the specified protocol

Parameters:
protocol - the protocol name
Returns:
the registered handler or null if no handler is registerd for the protocol

getRegisteredHandlers

public Map getRegisteredHandlers()
Gets a map of all registered handlers keyed by protocol name.

Returns:
a map from protocol name to handler

isInstalled

public static boolean isInstalled()
Is our factory installed?

Returns:
true if our factory is installed; false otherwise

install

public static void install()
                    throws Error,
                           SecurityException
Installs the factory into URL using the setURLStreamHandlerFactory method. This will fail is some other code already installed a factory.

This should be called from your main method to assure the factory is installed before another code has a chance to take the slot.

Throws:
Error - if the application has already set a factory
SecurityException - if a security manager exists and its checkSetFactory method doesn't allow the operation

forceInstall

public static void forceInstall()
                         throws Error,
                                SecurityException
Installs the factory into directly URL's private and package protected fields using Field.setAccessable(true). This is the "naughty" way of installing a factory but works on most platforms. If the platform is not using Sun's implementation of URL, this code is likely to not work, but all known platforms use Sun's URL code.

You should not use this method unless you absolutely have to.

Throws:
Error - if the application has already set a factory
SecurityException - if a security manager exists and its checkSetFactory method doesn't allow the operation

getGBeanInfo

public static org.apache.geronimo.gbean.GBeanInfo getGBeanInfo()


Copyright © 2003-2005 Apache Software Foundation. All Rights Reserved.