|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.meta.reflect.proxy.ReferenceHandler<T>
T
- The type of the referenced object.public class ReferenceHandler<T>
A reference handler is the standard implementation of
the Reference
interface.
Implementation notes:
The copy method cannot be a varargs method. The mutator methods
are only matched on their name, regardless of declaring class.
There are potential issues with equals
because the original
class information is lost for proxies, i.e. the class becomes
java.lang.reflect.Proxy
.
ReferenceInvocationHandler
,
ProxyFactory.getSharedObject(Object, String, Class[], String...)
Field Summary | |
---|---|
private Method |
copyMethod
The copy method. |
private ProxyFactory |
factory
The proxy factory used. |
private Class<?>[] |
interfaces
All interfaces implemented by reference , including
the adapted Reference interface at index zero. |
private Set<String> |
mutatorMethods
The names of the mutator methods that will force a copy of reference before executed. |
private T |
reference
The actual referenced object. |
private int |
referenceCount
The number of references to reference . |
Constructor Summary | |
---|---|
|
ReferenceHandler(ProxyFactory factory,
T reference,
String copyMethod,
Class<?>[] parameterTypes,
String... mutatorMethods)
Constructor, which creates this reference to manage the referenced object supplied as reference . |
|
ReferenceHandler(ProxyFactory factory,
T reference,
String copyMethod,
String... mutatorMethods)
Constructor, which creates this reference to manage the referenced object supplied as reference . |
private |
ReferenceHandler(ReferenceHandler<T> handler)
Constructor, which creates this reference to manage a copy of the referenced object managed by handler . |
Method Summary | |
---|---|
T |
addReference()
Increases the reference count for the referenced object. |
Reference<T> |
copyIfMutator(Method method)
Performs the actual copying of the referenced object if method is a mutator method and returns
a new reference containing the copy with a reference
count of one. |
boolean |
copyMethod(Method method)
Returns true if the method supplied as method
is the copy method used to copy the referenced
object, false if not. |
T |
getReference()
Returns the referenced object. |
T |
toProxy()
Creates a new proxy instance using this reference handler. |
String |
toString()
Returns the string representation of this handler. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final Method copyMethod
Never null.
private final ProxyFactory factory
Never null.
private final Class<?>[] interfaces
reference
, including
the adapted Reference
interface at index zero. Never null.
private final Set<String> mutatorMethods
reference
before executed. The names do not include information about the declaring class!
Never null, and never empty.
private T reference
Never null.
private int referenceCount
reference
.
Constructor Detail |
---|
public ReferenceHandler(ProxyFactory factory, T reference, String copyMethod, Class<?>[] parameterTypes, String... mutatorMethods) throws Exception
reference
. The reference count is set to 1.
factory
- The proxy factory to create the proxies; cannot
be null.reference
- The referenced object; cannot be null.copyMethod
- The name of the copy method to use; cannot
be null. Must be declared in the class of
reference
, but will be made accessible
if not already.parameterTypes
- The formal parameter types of copyMethod
,
if any, ignoring primitive types; can be null.mutatorMethods
- The names of the mutator methods that will
force a copy of reference
before executed;
cannot be null or empty.
NullPointerException
- If factory
, reference
, or
copyMethod
are null.
IllegalArgumentException
- If mutatorMethods
is empty, or
if the copy method is a vararg method.
Exception
- If no such copy method exists.public ReferenceHandler(ProxyFactory factory, T reference, String copyMethod, String... mutatorMethods) throws Exception
reference
. The reference count is set to 1.
factory
- The proxy factory to create the proxies; cannot
be null.reference
- The referenced object; cannot be null.copyMethod
- The name of the no-arg copy method to use;
cannot be null. Must be declared in the class of
reference
, but will be made accessible
if not already.mutatorMethods
- The names of the mutator methods that will
force a copy of reference
before executed;
cannot be null or empty.
NullPointerException
- If either argument is null.
IllegalArgumentException
- If mutatorMethods
is empty.
Exception
- If no such copy method exists.private ReferenceHandler(ReferenceHandler<T> handler) throws Exception
handler
. The reference count is set to 1.
handler
- The reference handler to copy; cannot be null.
NullPointerException
- If handler
is null.
Exception
- If the copying fails.Method Detail |
---|
public T addReference()
Reference
referenced
object.
addReference
in interface Reference<T>
public Reference<T> copyIfMutator(Method method) throws Exception
Reference
method
is a mutator method and returns
a new reference containing the copy with a reference
count of one. The reference count for this reference
will at the same time be decreased by one.
If method
is not a mutator method, this
reference is simply returned.
copyIfMutator
in interface Reference<T>
method
- The method to test; cannot be null.
NullPointerException
- If method
is null.
Exception
- If the copying fails.public boolean copyMethod(Method method)
Reference
method
is the copy method used to copy the referenced
object, false if not.
copyMethod
in interface Reference<T>
method
- The method to test; cannot be null.
method
is the method used
to copy objects of the referenced object type,
false if not.public T getReference()
Reference
getReference
in interface Reference<T>
public T toProxy()
This method does not alter the reference count of this reference.
public String toString()
toString
in class Object
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |