TRAP/J 2.1 Manual

Writing Delegates

Before we begin, please make sure that you have a "delegates" package inside your application's root package.

Delegate Structure

In order for TRAP/J to recognize them, delegates must implement the edu.fiu.cis.acrl.reflect.Delegate_Interface interface. However, you'll notice that the Delegate_Interface does not specify any methods to implement. That is because the Delegate_Interface is used merely as a subtyping mechanism. The methods you must implement when implementing the Delegate_Interface are those in the adaptable classes of your Adapt-Ready application. A properly written delegate will look like the following example:

package rootpackage.delegates;

public class MyDelegate implements edu.fiu.cis.acrl.reflect.Delegate_Interface
{
    public void myMethod1(int a, int b, Object ref)
    {
        // alternative implementation for myMethod1
    }

    public java.util.List<Integer> myMethod2(Set<Integer> set, boolean b, Object ref)
    {
        // alternative implementation for myMethod2
    }
}

The method signatures in your delegate must match the method signatures of the methods you are re-implementing, except for the addition of another parameter: an Object reference. This is essentially a reference to the original object instance calling the method. With this reference, you can access any method or instance fields of the original instance by casting it to the type of the class to which the method belongs.

Your delegate can contain alternative implementations for any collection of methods in an adaptable class. For example, you can choose to adapt all the methods by providing an alternative implementation for all the methods in the class, or you may choose to adapt just two methods as shown in the example above.

Once you've finished writing your delegate, compile it and then it's ready for use with the TRAP/J Composer.

« TRAP/J Composer Interface Table of Contents
TRAP/J Home
Composing »