ovm.polyd
Class Descriptor<T>

java.lang.Object
  extended by ovm.polyd.Descriptor<T>

public class Descriptor<T>
extends java.lang.Object

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.

See Also:
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

Descriptor

public 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.

Parameters:
interf - the PolyD interface
bodies - the classes that will be used by bodies when building
Method Detail

setDispatching

public void setDispatching(java.lang.Class policyClass)
Sets the default dispatching policy of this Descriptor

Parameters:
policyClass - the policy, must be a subclass of Dispatching

setInvocation

public void setInvocation(java.lang.Class invocationClass)
Sets the default invocation policy of this Descriptor

Parameters:
invocationClass - the policy, must be a subclass of Invocation

setMissingHandling

public void setMissingHandling(Missing mi)
Sets the default missing method handling of this Descriptor

Parameters:
mi - the way in which missing methods should be dealt with

setMethodDispatching

public void setMethodDispatching(java.lang.reflect.Method mt,
                                 java.lang.Class policyClass)
Sets the dispatching policy of a single prototype.

Parameters:
mt - the desired prototype in the interface
policyClass - the policy, must be a subclass of Dispatching

setMethodInvocation

public void setMethodInvocation(java.lang.reflect.Method mt,
                                java.lang.Class invocationClass)
Sets the invocation policy of a single prototype.

Parameters:
mt - the desired prototype in the interface
invocationClass - the policy, must be a subclass of Invocation

setMethodMissingHandling

public void setMethodMissingHandling(java.lang.reflect.Method mt,
                                     Missing mh)
Sets the missing method handling of a single prototype.

Parameters:
mt - the desired prototype in the interface
mh - the way in which missing methods should be dealt with

setMethodName

public void setMethodName(java.lang.reflect.Method mt,
                          java.lang.String nm)
Sets the alternate name of a prototype.

Parameters:
mt - the desired prototype in the interface
nm - the new name

setMethodAsClasses

public void setMethodAsClasses(java.lang.reflect.Method mt,
                               java.lang.Class[] as)
Sets the list of forced classes of a prototype.

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.

Parameters:
mt - the desired prototype in the interface
as - the list of forced classes

setMethodRawClasses

public void setMethodRawClasses(java.lang.reflect.Method mt,
                                boolean[] raw)
Sets the list of raw arguments in the prototype.

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.

Parameters:
mt - the desired prototype in the interface
raw - an indication of whether each argument is raw or not

setMethodNullDefaults

public void setMethodNullDefaults(java.lang.reflect.Method mt,
                                  java.lang.Class[] nul)
Sets the list of defaults for null arguments in the prototype.

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.

Parameters:
mt - the desired prototype in the interface
nul - the list of defaults for null arguments

setMethodPreload

public void setMethodPreload(java.lang.reflect.Method mt,
                             java.lang.Object[][] prel)
Sets the list of defaults for null arguments in the prototype.

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.

Parameters:
mt - the desired prototype in the interface
prel - the array of arrays of arguments that should be preloaded

setSelfField

public void setSelfField(java.lang.reflect.Field f)
Marks this field as a self field.

The field will be automatically initialized at dispatcher-creation time.

Parameters:
f - The self field, contained in one of the bodies

register

public Factory register()
Generates a new Factory, registering this Descriptor.

The factory can then be used to create new dispatchers.

Returns:
the new Factory

registerSpecial

public void registerSpecial()
Deprecated. Use register() instead.

Registers this 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.