Class URLHandlersStreamHandlerProxy
- java.lang.Object
-
- java.net.URLStreamHandler
-
- org.apache.felix.framework.URLHandlersStreamHandlerProxy
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
,URLStreamHandlerSetter
public class URLHandlersStreamHandlerProxy extends java.net.URLStreamHandler implements URLStreamHandlerSetter, java.lang.reflect.InvocationHandler
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
Fields Modifier and Type Field Description private static java.lang.reflect.Method
EQUALS
private static java.lang.reflect.Method
GET_DEFAULT_PORT
private static java.lang.reflect.Method
GET_HOST_ADDRESS
private static java.lang.reflect.Method
HASH_CODE
private static java.lang.reflect.Method
HOSTS_EQUAL
private SecureAction
m_action
private java.net.URLStreamHandler
m_builtIn
private java.net.URL
m_builtInURL
private static java.lang.ThreadLocal
m_loopCheck
private java.lang.String
m_protocol
private java.lang.Object
m_service
private static java.lang.reflect.Method
OPEN_CONNECTION
private static java.lang.reflect.Method
OPEN_CONNECTION_PROXY
private static java.lang.reflect.Method
SAME_FILE
private static java.lang.Class[]
STRING_TYPES
private static java.lang.reflect.Method
TO_EXTERNAL_FORM
private static java.lang.Class[]
URL_PROXY_CLASS
-
Constructor Summary
Constructors Modifier Constructor Description private
URLHandlersStreamHandlerProxy(java.lang.Object service, SecureAction action)
URLHandlersStreamHandlerProxy(java.lang.String protocol, SecureAction action, java.net.URLStreamHandler builtIn, java.net.URL builtInURL)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
equals(java.net.URL url1, java.net.URL url2)
protected int
getDefaultPort()
protected java.net.InetAddress
getHostAddress(java.net.URL url)
private java.lang.Object
getStreamHandlerService()
Private method to retrieve the stream handler service from the framework instance associated with the current call stack.protected int
hashCode(java.net.URL url)
protected boolean
hostsEqual(java.net.URL url1, java.net.URL url2)
java.lang.Object
invoke(java.lang.Object obj, java.lang.reflect.Method method, java.lang.Object[] params)
protected java.net.URLConnection
openConnection(java.net.URL url)
protected java.net.URLConnection
openConnection(java.net.URL url, java.net.Proxy proxy)
protected void
parseURL(java.net.URL url, java.lang.String spec, int start, int limit)
protected boolean
sameFile(java.net.URL url1, java.net.URL url2)
void
setURL(java.net.URL url, java.lang.String protocol, java.lang.String host, int port, java.lang.String file, java.lang.String ref)
void
setURL(java.net.URL url, java.lang.String protocol, java.lang.String host, int port, java.lang.String authority, java.lang.String userInfo, java.lang.String path, java.lang.String query, java.lang.String ref)
protected java.lang.String
toExternalForm(java.net.URL url)
private java.lang.String
toExternalForm(java.net.URL url, java.lang.Object svc)
-
-
-
Field Detail
-
URL_PROXY_CLASS
private static final java.lang.Class[] URL_PROXY_CLASS
-
STRING_TYPES
private static final java.lang.Class[] STRING_TYPES
-
EQUALS
private static final java.lang.reflect.Method EQUALS
-
GET_DEFAULT_PORT
private static final java.lang.reflect.Method GET_DEFAULT_PORT
-
GET_HOST_ADDRESS
private static final java.lang.reflect.Method GET_HOST_ADDRESS
-
HASH_CODE
private static final java.lang.reflect.Method HASH_CODE
-
HOSTS_EQUAL
private static final java.lang.reflect.Method HOSTS_EQUAL
-
OPEN_CONNECTION
private static final java.lang.reflect.Method OPEN_CONNECTION
-
OPEN_CONNECTION_PROXY
private static final java.lang.reflect.Method OPEN_CONNECTION_PROXY
-
SAME_FILE
private static final java.lang.reflect.Method SAME_FILE
-
TO_EXTERNAL_FORM
private static final java.lang.reflect.Method TO_EXTERNAL_FORM
-
m_service
private final java.lang.Object m_service
-
m_action
private final SecureAction m_action
-
m_builtIn
private final java.net.URLStreamHandler m_builtIn
-
m_builtInURL
private final java.net.URL m_builtInURL
-
m_protocol
private final java.lang.String m_protocol
-
m_loopCheck
private static final java.lang.ThreadLocal m_loopCheck
-
-
Constructor Detail
-
URLHandlersStreamHandlerProxy
public URLHandlersStreamHandlerProxy(java.lang.String protocol, SecureAction action, java.net.URLStreamHandler builtIn, java.net.URL builtInURL)
-
URLHandlersStreamHandlerProxy
private URLHandlersStreamHandlerProxy(java.lang.Object service, SecureAction action)
-
-
Method Detail
-
equals
protected boolean equals(java.net.URL url1, java.net.URL url2)
- Overrides:
equals
in classjava.net.URLStreamHandler
-
getDefaultPort
protected int getDefaultPort()
- Overrides:
getDefaultPort
in classjava.net.URLStreamHandler
-
getHostAddress
protected java.net.InetAddress getHostAddress(java.net.URL url)
- Overrides:
getHostAddress
in classjava.net.URLStreamHandler
-
hashCode
protected int hashCode(java.net.URL url)
- Overrides:
hashCode
in classjava.net.URLStreamHandler
-
hostsEqual
protected boolean hostsEqual(java.net.URL url1, java.net.URL url2)
- Overrides:
hostsEqual
in classjava.net.URLStreamHandler
-
openConnection
protected java.net.URLConnection openConnection(java.net.URL url) throws java.io.IOException
- Specified by:
openConnection
in classjava.net.URLStreamHandler
- Throws:
java.io.IOException
-
openConnection
protected java.net.URLConnection openConnection(java.net.URL url, java.net.Proxy proxy) throws java.io.IOException
- Overrides:
openConnection
in classjava.net.URLStreamHandler
- Throws:
java.io.IOException
-
parseURL
protected void parseURL(java.net.URL url, java.lang.String spec, int start, int limit)
- Overrides:
parseURL
in classjava.net.URLStreamHandler
-
sameFile
protected boolean sameFile(java.net.URL url1, java.net.URL url2)
- Overrides:
sameFile
in classjava.net.URLStreamHandler
-
setURL
public void setURL(java.net.URL url, java.lang.String protocol, java.lang.String host, int port, java.lang.String authority, java.lang.String userInfo, java.lang.String path, java.lang.String query, java.lang.String ref)
- Specified by:
setURL
in interfaceURLStreamHandlerSetter
- Overrides:
setURL
in classjava.net.URLStreamHandler
- See Also:
- "java.net.URLStreamHandler.setURL(URL,String,String,int,String,String,String,String)"
-
setURL
public void setURL(java.net.URL url, java.lang.String protocol, java.lang.String host, int port, java.lang.String file, java.lang.String ref)
- Specified by:
setURL
in interfaceURLStreamHandlerSetter
- Overrides:
setURL
in classjava.net.URLStreamHandler
- See Also:
- "java.net.URLStreamHandler.setURL(URL,String,String,int,String,String)"
-
toExternalForm
protected java.lang.String toExternalForm(java.net.URL url)
- Overrides:
toExternalForm
in classjava.net.URLStreamHandler
-
toExternalForm
private java.lang.String toExternalForm(java.net.URL url, java.lang.Object svc)
-
getStreamHandlerService
private java.lang.Object 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
public java.lang.Object invoke(java.lang.Object obj, java.lang.reflect.Method method, java.lang.Object[] params) throws java.lang.Throwable
- Specified by:
invoke
in interfacejava.lang.reflect.InvocationHandler
- Throws:
java.lang.Throwable
-
-