Class URLHandlersStreamHandlerProxy
- All Implemented Interfaces:
InvocationHandler,URLStreamHandlerSetter
This class implements a stream handler proxy. When the stream handler proxy instance is created, it is associated with a particular protocol and will answer all future requests for handling of that stream type. It does not directly handle the stream handler requests, but delegates the requests to an underlying stream handler service.
The proxy instance for a particular protocol is used for all framework instances that may contain their own stream handler services. When performing a stream handler operation, the proxy retrieves the handler service from the framework instance associated with the current call stack and delegates the call to the handler service.
The proxy will create simple stream handler service trackers for each framework instance. The trackers will listen to service events in its respective framework instance to maintain a reference to the "best" stream handler service at any given time.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Methodprivate static final Methodprivate static final Methodprivate static final Methodprivate static final Methodprivate final SecureActionprivate final URLStreamHandlerprivate final URLprivate static final ThreadLocal<Thread> private final Stringprivate final Objectprivate static final Methodprivate static final Methodprivate static final Methodprivate static final Class<?>[]private static final Methodprivate static final Class<?>[] -
Constructor Summary
ConstructorsConstructorDescriptionURLHandlersStreamHandlerProxy(Object service, SecureAction action) URLHandlersStreamHandlerProxy(String protocol, SecureAction action, URLStreamHandler builtIn, URL builtInURL) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected intprotected InetAddressgetHostAddress(URL url) private ObjectPrivate method to retrieve the stream handler service from the framework instance associated with the current call stack.protected intprotected booleanhostsEqual(URL url1, URL url2) protected URLConnectionopenConnection(URL url) protected URLConnectionopenConnection(URL url, Proxy proxy) protected voidprivate static Methodreflect(SecureAction action, String name, Class<?>... classes) private static voidRethrows the given exception if it is anIOException, or theIOExceptionthrown by a stream handler method invoked through reflection, which is wrapped in anInvocationTargetException, so that callers get the same exception as with a direct invocation of the handler.protected booleanvoidDeprecated.voidsetURL(URL url, String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref) protected StringtoExternalForm(URL url) private StringtoExternalForm(URL url, Object svc) (package private) static URLStreamHandlerwrap(String protocol, SecureAction action, URLStreamHandler builtIn, URL builtInURL)
-
Field Details
-
URL_PROXY_CLASS
-
STRING_TYPES
-
EQUALS
-
GET_DEFAULT_PORT
-
GET_HOST_ADDRESS
-
HASH_CODE
-
HOSTS_EQUAL
-
OPEN_CONNECTION
-
OPEN_CONNECTION_PROXY
-
SAME_FILE
-
TO_EXTERNAL_FORM
-
m_service
-
m_action
-
m_builtIn
-
m_builtInURL
-
m_protocol
-
m_loopCheck
-
-
Constructor Details
-
URLHandlersStreamHandlerProxy
public URLHandlersStreamHandlerProxy(String protocol, SecureAction action, URLStreamHandler builtIn, URL builtInURL) -
URLHandlersStreamHandlerProxy
URLHandlersStreamHandlerProxy(Object service, SecureAction action)
-
-
Method Details
-
reflect
-
wrap
static URLStreamHandler wrap(String protocol, SecureAction action, URLStreamHandler builtIn, URL builtInURL) -
equals
- Overrides:
equalsin classURLStreamHandler
-
getDefaultPort
protected int getDefaultPort()- Overrides:
getDefaultPortin classURLStreamHandler
-
getHostAddress
- Overrides:
getHostAddressin classURLStreamHandler
-
hashCode
- Overrides:
hashCodein classURLStreamHandler
-
hostsEqual
- Overrides:
hostsEqualin classURLStreamHandler
-
openConnection
- Specified by:
openConnectionin classURLStreamHandler- Throws:
IOException
-
openConnection
- Overrides:
openConnectionin classURLStreamHandler- Throws:
IOException
-
rethrowIOException
Rethrows the given exception if it is anIOException, or theIOExceptionthrown by a stream handler method invoked through reflection, which is wrapped in anInvocationTargetException, so that callers get the same exception as with a direct invocation of the handler.- Parameters:
ex- the exception caught while invoking a stream handler method- Throws:
IOException- the exception itself or the cause of the invocation exception
-
parseURL
- Overrides:
parseURLin classURLStreamHandler
-
sameFile
- Overrides:
sameFilein classURLStreamHandler
-
setURL
public void setURL(URL url, String protocol, String host, int port, String authority, String userInfo, String path, String query, String ref) - Specified by:
setURLin interfaceURLStreamHandlerSetter- Overrides:
setURLin classURLStreamHandler- See Also:
-
setURL
@Deprecated public void setURL(URL url, String protocol, String host, int port, String file, String ref) Deprecated.- Specified by:
setURLin interfaceURLStreamHandlerSetter- Overrides:
setURLin classURLStreamHandler- See Also:
-
toExternalForm
- Overrides:
toExternalFormin classURLStreamHandler
-
toExternalForm
-
getStreamHandlerService
Private method to retrieve the stream handler service from the framework instance associated with the current call stack. A simple service tracker is created and cached for the associated framework instance when this method is called.
- Returns:
- the stream handler service from the framework instance associated with the current call stack or null is no service is available.
-
invoke
- Specified by:
invokein interfaceInvocationHandler- Throws:
Throwable
-