|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.perisic.shadow.Shadowable
A common base class for all shadowable objects.
Basically adding a shadow to an
object obj
means that a method call to obj
will be executed
in the shadow instead in obj
. If the shadow does not define the method
it will be passed to obj
. If obj
is shadowed by more than
one shadow the most recently added shadow will be tried first.
call(java.lang.String, java.lang.Object...)
.
Shadow
Constructor Summary | |
---|---|
Shadowable()
When constructed the instances of the class shadows of this class and all parent classes are added to this object. |
Method Summary | |
---|---|
static void |
addShadow(java.lang.Class owner,
java.lang.Class shadow)
An instance of shadow is added whenever an owner object
is instantiated. |
void |
addShadow(Shadow shadow)
Add a shadow to this object. |
static java.lang.Class[] |
allShadowedClasses()
Gets all classes that have been shadowed. |
java.lang.Object |
call(java.lang.String methodName,
java.lang.Object... args)
Executes the method methodName with the arguments args . |
static java.util.Vector<java.lang.Class> |
getClassShadows(java.lang.Class owner)
Gets a vector of all shadows that belong to the class owner . |
java.util.Vector<Shadow> |
getShadows()
Gets all shadows that shadow this object. |
static boolean |
removeShadow(java.lang.Class owner,
java.lang.Class shadow)
Removes the class shadow that has been added to the class
owner . |
boolean |
removeShadow(Shadow shadow)
Removes a shadow from this object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Shadowable()
Method Detail |
---|
public void addShadow(Shadow shadow)
shadow
- The shadow that is added to this object.call(java.lang.String, java.lang.Object...)
public static void addShadow(java.lang.Class owner, java.lang.Class shadow)
shadow
is added whenever an owner
object
is instantiated. The order in that the shadows
are added to the object is the same order as the shadow classes are
added to owner
.
owner
- The class that is to be shadowedshadow
- The class that shadows owner
public static boolean removeShadow(java.lang.Class owner, java.lang.Class shadow)
shadow
that has been added to the class
owner
. Note: the shadow objects that have been
already added to instances of owner
are not removed.
To remove shadows from objects use removeShadow(Shadow)
owner
- the class that is shadowedshadow
- the shadow to be removed from the class
owner
has been shadowed by shadow
public static java.util.Vector<java.lang.Class> getClassShadows(java.lang.Class owner)
owner
.
This may be used to manipulate the class shadows manually by changing the
the vector.
owner
- the class whose shadows are returned
owner
public static java.lang.Class[] allShadowedClasses()
public boolean removeShadow(Shadow shadow)
shadow
public java.util.Vector<Shadow> getShadows()
public java.lang.Object call(java.lang.String methodName, java.lang.Object... args)
methodName
with the arguments args
.
When the method is shadowed (that means when the object has a Shadow
object added and the Shadow
object defines the method),
then the method defined
in the shadow object is executed instead of the method in this object.
If an object has more than one shadow added, the last shadow added to the method is checked first.
If the method is not found in the shadows and in the object itself a
ShadowException
with a NoSuchMethodException
as cause
is thrown.
It the method is found but throws an exception, a ShadowException
is thrown where the cause is the exception originally thrown by the method.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |