T
- the superclass typepublic class ProxyFactory<T> extends AbstractProxyFactory<T>
InvocationHandler
.
Typical usage looks like:
ProxyFactory<SimpleClass> proxyFactory = new ProxyFactory<SimpleClass>(SimpleClass.class); SimpleClass instance = proxyFactory.newInstance(new SimpleDispatcher());This will create a proxy for SimpleClass, and return a new instance that handles invocations using the InvocationDispatcher SimpleDispatcher.
Invocations on these proxies are very efficient, as no reflection is involved.
Modifier and Type | Class and Description |
---|---|
class |
ProxyFactory.ProxyConstructorBodyCreator
Generates a proxy constructor that delegates to super(), and then sets the constructed flag to true.
|
class |
ProxyFactory.ProxyMethodBodyCreator
Overrides superclass methods and forwards calls to the dispatcher.
|
class |
ProxyFactory.WriteReplaceBodyCreator
Generates the writeReplace method if advanced serialization is enabled.
|
Modifier and Type | Field and Description |
---|---|
static String |
CONSTRUCTED_GUARD
this field on the generated class stores if the constructor has been completed yet.
|
static String |
INVOCATION_HANDLER_FIELD
Name of the field that holds the generated dispatcher on the generated proxy
|
reflectionMetadataSource
classFile
Constructor and Description |
---|
ProxyFactory(ProxyConfiguration<T> proxyConfiguration)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
generateClass()
Generate the class.
|
MethodBodyCreator |
getDefaultMethodOverride()
Returns the default
MethodBodyCreator to use when creating overridden methods. |
InvocationHandler |
getInvocationHandler(Object proxy)
Returns the invocation handler for a proxy created from this factory.
|
static InvocationHandler |
getInvocationHandlerStatic(Object proxy)
Gets the
InvocationHandler for a given proxy instance. |
T |
newInstance(InvocationHandler handler)
Create a new proxy, initialising it with the given invocation handler.
|
void |
setInvocationHandler(Object proxy,
InvocationHandler handler)
Sets the invocation handler for a proxy created from this factory.
|
static void |
setInvocationHandlerStatic(Object proxy,
InvocationHandler handler)
Sets the invocation handler for a proxy.
|
void |
setSerializableProxyClass(Class<? extends SerializableProxy> serializableProxyClass)
Sets the
SerializableProxy class to emit from the proxies writeReplace method. |
afterClassLoad, cleanup, finalizeStaticConstructor, getCachedMethods, loadMethodIdentifier
addInterface, addInterface, createConstructorDelegates, createConstructorDelegates, getDefaultConstructorOverride, overrideAllMethods, overrideAllMethods, overrideEquals, overrideEquals, overrideFinalize, overrideFinalize, overrideHashcode, overrideHashcode, overrideMethod, overrideMethod, overridePublicMethods, overridePublicMethods, overrideToString, overrideToString
buildClassDefinition, defineClass, getClassLoader, getClassName, getProtectionDomain, getSuperClass, getSuperClassName, isProxyClassDefined, isProxyClassDefined, newInstance
public static final String INVOCATION_HANDLER_FIELD
public static final String CONSTRUCTED_GUARD
public ProxyFactory(ProxyConfiguration<T> proxyConfiguration)
proxyConfiguration
- The configuration to use to build the proxypublic T newInstance(InvocationHandler handler) throws InstantiationException, IllegalAccessException
handler
- the invocation handler to useIllegalAccessException
- if the constructor is not accessibleInstantiationException
- if instantiation failed due to an exceptionprotected void generateClass()
generateClass
in class AbstractClassFactory<T>
public void setSerializableProxyClass(Class<? extends SerializableProxy> serializableProxyClass)
SerializableProxy
class to emit from the proxies writeReplace method. If this is set to null (the
default) then no writeReplace method will be generated. The proxy may still be serializable, providing that the
superclass and InvocationHandler
are both serializable.
serializableProxyClass
- the proxy classIllegalStateException
- If the proxy class has already been generatedSerializableProxy
,
DefaultSerializableProxy
public MethodBodyCreator getDefaultMethodOverride()
AbstractSubclassFactory
MethodBodyCreator
to use when creating overridden methods.getDefaultMethodOverride
in class AbstractSubclassFactory<T>
public void setInvocationHandler(Object proxy, InvocationHandler handler)
proxy
- the proxy to modifyhandler
- the handler to usepublic InvocationHandler getInvocationHandler(Object proxy)
proxy
- the proxypublic static void setInvocationHandlerStatic(Object proxy, InvocationHandler handler)
setInvocationHandler(Object, InvocationHandler)
, however it will work on any proxy, not just proxies from a
specific factory.proxy
- the proxy to modifyhandler
- the handler to usepublic static InvocationHandler getInvocationHandlerStatic(Object proxy)
InvocationHandler
for a given proxy instance. This method is less efficient than
getInvocationHandler(Object)
, however it will work for any proxy, not just proxies from a specific factory
instance.proxy
- the proxyCopyright © 2012 JBoss by Red Hat. All Rights Reserved.