|
Table of Contents
A Brief Introduction to Around MetaobjectsThis short introduction is targered to people who want to create one or more arounds metaobjects in Reflex. It describes what should be done in order to create and configure them, and how they could be composed when interacting at some program point. What is an Around Metaobject?An around metaobject is a metaobject that can replace an ocurrence of a certain operation, in other words, an “around” method in the metaobject is executed instead of that ocurrence. Reflex provides the ability to execute the original ocurrence and change (if desired) the parameters passed to it (similarly to AspectJ's proceed statement). Around Metaobject Creation
First, we need to know how to create an around metaobject. Reflex considers a metaobject to be an around metabject if its “around” method (the name of this method can be chosen freely) takes as one of its parameters an import reflex.api.mop.IExecutionPointClosure; public class AroundMO{ /** * Around method */ public Object aroundMethod(IExecutionPointClosure aClosure){ //around code here } }
In the code above, there is a simple class, which represents an around metaobject: this is because its around method takes an package reflex.api.mop; public interface IExecutionPointClosure { public Object proceed(); public void setArg(int aIndex, Object aValue); }
The first method allows the metaobject to invoke the original occurrence of the operation and the second one can be used before the invocation of the former in order to change the parameters that will be passed when Around Metaobject Configuration
At the moment, we have defined the around metaobject. Now we have to configure a link to work with the metaobject. The relevant part of the link's configuration is the specification of the Link theLink = ...; theLink.setCall(new CallDescriptor( AroundMO.class.getName(), "aroundMethod", Parameter.CLOSURE) );
With this code, we configure Reflex to call the Around Metaobjects CompositionIn some scenarios, we may have more than one link bound to an around metaobject acting at the same program point. Such an interaction between links can't be resolved automaticaly. To solve this, Reflex provides two operators to specify the rules that dictates how those links will be composed (you can also define your own operators):
In this introduction we are interested in the second operator: API.rules().addRule(new Wrap(L1, L2));
As you can see, Further Information
A complete (and compilable) example of all the items we have seen here (around metaobjects and composition rules) can be found in the |