|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectovm.polyd.Descriptor<T>
public class Descriptor<T>
Accumulates information about the new dispatcher. Use a Descriptor
to build dispatchers manually,
rather than using annotations.
This class is not normally accessed directly, and it is of use only when using the pre-5.0 version of PolyD. Here is a quick example of its use, please refer to the manual for more information.
Descriptor d1=new Descriptor(Interf.class,new Class[] {BodyA.class,BodyB.class});
d1.setDispatching(MultiDisp.class);
mt=Dance.class.getMethod("visit",new Class[]{Place.class});
d1.setMissingHandling(mt,Missing.Ignore);
d1.setMethodNullDefaults(mt3,new Class[]{null,Object.class,null});
f=Body.class.getField("self");
d1.setSelfField(f);
Factory fact=d1.register();
Interf disp1=fact.getDispatcher1(bod1);
disp1.theMessage(arg1,arg2);
In order to create a dispatcher manually, first create a new descriptor specifying the interface and the list of classes that will be used by the bodies. Then set the various attributes for the whole interface. You can then add individual attributes for the messages, and prepare the "self" fields.
Once the descriptor is ready, register it obtaining a factory. Then instantiate the factory as many times as needed, obtaining the required dispatchers.
Factory
Constructor Summary | |
---|---|
Descriptor(java.lang.Class<T> interf,
java.lang.Class[] bodies)
Creates a new Descriptor , given the interface and
the list of classes that will be used by the bodies. |
Method Summary | |
---|---|
Factory |
register()
Generates a new Factory , registering this Descriptor |
void |
registerSpecial()
Deprecated. Use register() instead. |
void |
setDispatching(java.lang.Class policyClass)
Sets the default dispatching policy of this Descriptor |
void |
setInvocation(java.lang.Class invocationClass)
Sets the default invocation policy of this Descriptor |
void |
setMethodAsClasses(java.lang.reflect.Method mt,
java.lang.Class[] as)
Sets the list of forced classes of a prototype. |
void |
setMethodDispatching(java.lang.reflect.Method mt,
java.lang.Class policyClass)
Sets the dispatching policy of a single prototype. |
void |
setMethodInvocation(java.lang.reflect.Method mt,
java.lang.Class invocationClass)
Sets the invocation policy of a single prototype. |
void |
setMethodMissingHandling(java.lang.reflect.Method mt,
Missing mh)
Sets the missing method handling of a single prototype. |
void |
setMethodName(java.lang.reflect.Method mt,
java.lang.String nm)
Sets the alternate name of a prototype. |
void |
setMethodNullDefaults(java.lang.reflect.Method mt,
java.lang.Class[] nul)
Sets the list of defaults for null arguments in the prototype. |
void |
setMethodPreload(java.lang.reflect.Method mt,
java.lang.Object[][] prel)
Sets the list of defaults for null arguments in the prototype. |
void |
setMethodRawClasses(java.lang.reflect.Method mt,
boolean[] raw)
Sets the list of raw arguments in the prototype. |
void |
setMissingHandling(Missing mi)
Sets the default missing method handling of this Descriptor |
void |
setSelfField(java.lang.reflect.Field f)
Marks this field as a self field. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Descriptor(java.lang.Class<T> interf, java.lang.Class[] bodies)
Descriptor
, given the interface and
the list of classes that will be used by the bodies.
interf
- the PolyD interfacebodies
- the classes that will be used by bodies when buildingMethod Detail |
---|
public void setDispatching(java.lang.Class policyClass)
Descriptor
policyClass
- the policy, must be a subclass of Dispatching
public void setInvocation(java.lang.Class invocationClass)
Descriptor
invocationClass
- the policy, must be a subclass of Invocation
public void setMissingHandling(Missing mi)
Descriptor
mi
- the way in which missing methods should be dealt withpublic void setMethodDispatching(java.lang.reflect.Method mt, java.lang.Class policyClass)
mt
- the desired prototype in the interfacepolicyClass
- the policy, must be a subclass of Dispatching
public void setMethodInvocation(java.lang.reflect.Method mt, java.lang.Class invocationClass)
mt
- the desired prototype in the interfaceinvocationClass
- the policy, must be a subclass of Invocation
public void setMethodMissingHandling(java.lang.reflect.Method mt, Missing mh)
mt
- the desired prototype in the interfacemh
- the way in which missing methods should be dealt withpublic void setMethodName(java.lang.reflect.Method mt, java.lang.String nm)
mt
- the desired prototype in the interfacenm
- the new namepublic void setMethodAsClasses(java.lang.reflect.Method mt, java.lang.Class[] as)
The as
argument to this routine is an
array of classes, of size equal to the number of
parameters of the prototype. The non-null elements
of the array will alter the interpretation of the
dynamic class of the corresponding prototype argument
during dispatching. For each non-null element, the
dynamic class of the argument will be ignored, and
the element of the array will be used instead in
order to select the most appropriate method.
mt
- the desired prototype in the interfaceas
- the list of forced classespublic void setMethodRawClasses(java.lang.reflect.Method mt, boolean[] raw)
Arguments that are marked as raw are treated in a special way during dispatching: they will be passed as they are to the selection mechanism, and they will not be used as actual arguments during the call to the selected method.
Raw arguments can be used to annotate individual call sites, or to discriminate on more information than just the dynamic class of the message arguments.
If an argument is marked as raw, it cannot be
forced using the As
tag,
and it cannot be used together with the
IfNull
tag. A raw argument can
be any object or an int
, but no other
primitive type.
This method must be called before setting As, IfNull, or Preload properties.
mt
- the desired prototype in the interfaceraw
- an indication of whether each argument is raw or notpublic void setMethodNullDefaults(java.lang.reflect.Method mt, java.lang.Class[] nul)
The nul
argument to this routine is an
array of classes, of size equal to the number of
parameters of the prototype. The non-null elements
of the array will supply a default interpretation for
those arguments that are found, at runtime, to be null
.
mt
- the desired prototype in the interfacenul
- the list of defaults for null argumentspublic void setMethodPreload(java.lang.reflect.Method mt, java.lang.Object[][] prel)
The nul
argument to this routine is an
array of classes, of size equal to the number of
parameters of the prototype. The non-null elements
of the array will supply a default interpretation for
those arguments that are found, at runtime, to be null
.
Preload can be used for raw arguments as well, but due
to restrictions in the handling of annotations by Java,
only raw arguments that happen to be classes can be
initialized using annotations. Using this routine, no
limitations exist.
mt
- the desired prototype in the interfaceprel
- the array of arrays of arguments that should be preloadedpublic void setSelfField(java.lang.reflect.Field f)
The field will be automatically initialized at dispatcher-creation time.
f
- The self field, contained in one of the bodiespublic Factory register()
Factory
, registering this Descriptor.
The factory can then be used to create new dispatchers.
- Returns:
- the new
Factory
public void registerSpecial()
register()
instead.
Descriptor
as a special dispatcher
(see manual for details).
This method could be removed from future versions of PolyD,
and its use is not recommended.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |