public abstract class AbstractILFactory extends Object implements InvocationLayerFactory
InvocationLayerFactory
that
provides a convenient way for subclasses to create proxies and
invocation dispatchers for remote objects. A subclass must provide an
implementation for at least the createInvocationHandler
and createInvocationDispatcher
methods. A subclass can override the
getProxyInterfaces
method if its proxies
need to implement a different set of interfaces than the default
set (all remote interfaces of the remote object).InvocationLayerFactory.Instances
Modifier | Constructor and Description |
---|---|
protected |
AbstractILFactory()
Constructs an
AbstractILFactory instance with a
null class loader. |
protected |
AbstractILFactory(ClassLoader loader)
Constructs an
AbstractILFactory instance with the
specified class loader. |
Modifier and Type | Method and Description |
---|---|
InvocationLayerFactory.Instances |
createInstances(Remote impl,
ObjectEndpoint oe,
ServerCapabilities caps)
Returns a compatible proxy and invocation dispatcher for a remote
object being exported.
|
protected abstract InvocationDispatcher |
createInvocationDispatcher(Collection methods,
Remote impl,
ServerCapabilities caps)
Returns an invocation dispatcher to receive incoming remote calls
for the specified methods to the specified remote object, for a
server and transport with the specified capabilities.
|
protected abstract InvocationHandler |
createInvocationHandler(Class[] interfaces,
Remote impl,
ObjectEndpoint oe)
Returns an invocation handler to use with a
Proxy instance
implementing the specified interfaces, communicating with the
specified remote object using the specified object endpoint. |
boolean |
equals(Object obj)
Compares the specified object with this invocation layer factory for
equality.
|
protected ClassLoader |
getClassLoader()
Returns the class loader specified during construction.
|
protected Class[] |
getExtraProxyInterfaces(Remote impl)
Returns a new array containing any additional interfaces that the
proxy should implement, beyond the interfaces obtained by passing
impl to the getRemoteInterfaces method. |
protected Collection |
getInvocationDispatcherMethods(Remote impl)
Returns a new, modifiable collection of
Method objects,
containing all remote methods for which the invocation
dispatcher should accept incoming remote calls. |
protected Class[] |
getProxyInterfaces(Remote impl)
Returns a new array containing the interfaces for the proxy to
implement.
|
protected Class[] |
getRemoteInterfaces(Remote impl)
Returns a new array containing the remote interfaces that should be
implemented by the proxy.
|
int |
hashCode()
Returns a hash code value for this factory.
|
String |
toString()
Returns a string representation for this factory.
|
protected AbstractILFactory()
AbstractILFactory
instance with a
null
class loader.protected AbstractILFactory(ClassLoader loader)
AbstractILFactory
instance with the
specified class loader. The createInstances
method uses the specified loader to define a proxy
class.loader
- the class loader, or null
protected final ClassLoader getClassLoader()
protected Class[] getProxyInterfaces(Remote impl) throws ExportException
AbstractILFactory
implements this method to return
an array containing all of the interfaces obtained by passing
impl
to the getRemoteInterfaces
method plus the interfaces obtained by calling
the getExtraProxyInterfaces
method,
in that order, with duplicate interfaces (that is, duplicates after
the first occurrence of an interface) eliminated.
A subclass can override this method if its proxies need to implement a different set of interfaces than the default.
impl
- the remote objectExportException
- if there is a problem obtaining the
proxy interfaces or if impl
does not satisfy
the requirements of this factoryNullPointerException
- if impl
is null
protected Class[] getRemoteInterfaces(Remote impl) throws ExportException
RemoteException
or one of its superclasses
in their throws
clauses.
AbstractILFactory
implements this method to return
an array containing the following ordered list of interfaces:
impl's
class starting
with java.lang.Object
and following with each direct
subclass to the direct superclass of impl
's class, all
of the direct superinterfaces of the given superclass that extend
Remote
and that do not appear previously in the list, in
declaration order (the order in which they are declared in the
class's implements
clause), followed by
impl
's
class that extend Remote
and that do not appear previously
in the list, in declaration order.
ExportException
if any method of those
interfaces does not have a conforming throws
clause.
A subclass can override this method if its proxies need a set of remote interfaces other than the default.
impl
- the remote objectimpl
NullPointerException
- if impl
is null
ExportException
- if there is a problem obtaining the remote
interfaces or if impl
does not satisfy the
requirements of this factoryprotected Class[] getExtraProxyInterfaces(Remote impl) throws ExportException
impl
to the getRemoteInterfaces
method.
AbstractILFactory
implements this method to return
an array containing the RemoteMethodControl
interface.
A subclass can override this method if its proxies need to implement a different set of extra interfaces than the default.
impl
- the remote objectNullPointerException
- if impl
is null
ExportException
- if there is a problem obtaining the additional
interfaces or if impl
does not satisfy the
requirements of this factoryprotected Collection getInvocationDispatcherMethods(Remote impl) throws ExportException
Method
objects,
containing all remote methods for which the invocation
dispatcher should accept incoming remote calls.
AbstractILFactory
implements this method to return a
Set
containing all of the methods of the interfaces obtained
by passing impl
to the getRemoteInterfaces
method and satisfying the following
requirements:
checkPackageAccess
method is invoked with the package
name of the interface; this invocation may throw a
SecurityException
.
checkPermission
method is invoked with the permission
(@link ExportPermission} constructed with the string
"exportRemoteInterface." concatenated with the fully qualified
interface name; this invocation may throw a
SecurityException
. If the security check passes, each
Method
object of the non-public interface has its
accessibility flag set to suppress language access checks.
A subclass can override this method if it needs to control the selection of the set of methods for the dispatcher to handle, or if it needs to control the implementation of the collection returned.
impl
- the remote objectNullPointerException
- if impl
is null
ExportException
- if there is a problem obtaining the remote
methods or if impl
does not satisfy the
requirements of this factoryprotected abstract InvocationHandler createInvocationHandler(Class[] interfaces, Remote impl, ObjectEndpoint oe) throws ExportException
Proxy
instance
implementing the specified interfaces, communicating with the
specified remote object using the specified object endpoint.
A subclass must override this method to create an
InvocationHandler
for the specified interfaces, remote
object, and object endpoint.
interfaces
- an array of proxy interfacesimpl
- a remote object this invocation handler
is being created foroe
- an object endpoint used to communicate with
the remote objectExportException
- if there is a problem creating the
invocation handlerNullPointerException
- if any argument is null
,
or if interfaces
contains a null
elementprotected abstract InvocationDispatcher createInvocationDispatcher(Collection methods, Remote impl, ServerCapabilities caps) throws ExportException
A subclass must override this method to create an
InvocationDispatcher
for the specified methods, remote
object, and server capabilities.
methods
- a collection of Method
instances for the
remote methodsimpl
- a remote object that the dispatcher is being created forcaps
- the transport capabilities of the serverExportException
- if there is a problem creating the
dispatcherIllegalArgumentException
- if methods
contains
an element that is not a Method
instanceNullPointerException
- if any argument is null
,
or if methods
contains a null
elementpublic InvocationLayerFactory.Instances createInstances(Remote impl, ObjectEndpoint oe, ServerCapabilities caps) throws ExportException
InvocationLayerFactory.Instances
container object. The proxy sends
calls to the remote object using the supplied
ObjectEndpoint
.
The returned proxy implements an implementation-specific set of
remote interfaces of impl
and may implement additional
implementation-specific interfaces.
A given Exporter
implementation should only call this
method once per export. An invocation dispatcher constructed for a
previous export should not be reused.
AbstractILFactory
implements this method to return a
Proxy
instance where:
null
, the proxy's class is defined by the specified
loader. Otherwise, if a security manager exists, its checkPermission
method is invoked
with the RuntimePermission
("getClassLoader")
permission; this invocation may throw a
SecurityException
. If the above security check
succeeds, the proxy's class is defined by the class loader of
impl
's class.
getProxyInterfaces
method, passing
impl
as the argument. If a security manager exists,
for each interface returned from the getProxyInterfaces
method, the security manager's checkPackageAccess
method is
invoked with the package name of the interface. Such an invocation
may throw a SecurityException
.
createInvocationHandler
method,
passing the proxy interfaces (as above), impl
, and
oe
as arguments.
The returned invocation dispatcher is obtained by calling the
createInvocationDispatcher
method, passing a collection of methods, impl
, and
caps
as arguments. The collection of methods is
obtained by calling the getInvocationDispatcherMethods
method, passing impl
as
the argument.
createInstances
in interface InvocationLayerFactory
impl
- the remote object that the proxy is being
created foroe
- the object endpoint used to communicate with
the remote objectcaps
- the transport capabilities of the serverInstances
objectNullPointerException
- if any argument is null
ExportException
- if there is a problem creating the proxy or
dispatcherpublic int hashCode()
public boolean equals(Object obj)
AbstractILFactory
implements this method to return
true
if and only if the specified object has the same
class as this object and the loader in the specified object is equal
to the loader in this object.
A subclass should override this method if it adds instance state that affects equality.