Commit 02eb13fe authored by Lionel Seinturier's avatar Lionel Seinturier

Let the intercepted interface be introspectable in intent join point.

Associated test.
parent 2894ce4f
Tinfi 0.4.5
-----------
* let the sca-intent-controller control interface be visible
(feature requested by Nicolas D.)
* let the intercepted interface be introspectable in intent join points
(these last two features have been requested by Nicolas D.)
* new example mixing SCA and OSGi components
......
......@@ -23,8 +23,10 @@
package org.ow2.frascati.tinfi.juliac;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.juliac.Utils;
import org.objectweb.fractal.juliac.visit.MethodSourceCodeVisitor;
import org.ow2.frascati.tinfi.TinfiComponentInterceptor;
/**
* This class generates the source code for initializing Fractal components.
......@@ -54,4 +56,19 @@ extends org.objectweb.fractal.juliac.opt.oo.InitializerOOCtrlClassGenerator {
mv.visit (Utils.javaifyContentDesc(contentDesc).toString());
mv.visitln(";");
}
@Override
protected void generateNFICMExternalInterface(
MethodSourceCodeVisitor mv, InterfaceType it,
boolean attrimplgenerated ) {
super.generateNFICMExternalInterface(mv,it,attrimplgenerated);
String itname = it.getFcItfName();
if( ! itname.equals("attribute-controller") ) {
mv.visit (" ((");
mv.visit (TinfiComponentInterceptor.class.getName());
mv.visitln(")intercept).setFcItf(proxy);");
}
}
}
......@@ -25,6 +25,7 @@ package org.ow2.frascati.tinfi.juliac;
import java.lang.reflect.Modifier;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.desc.MembraneDesc;
......@@ -184,21 +185,22 @@ extends AbstractInterceptorSourceCodeGenerator {
IntentJoinPointImpl.class.getName(), null );
// Constructor
String[] args = new String[ paramtypes.length + 4];
String[] args = new String[ paramtypes.length + 5];
args[0] = "java.util.List<"+IntentHandler.class.getName()+"> handlers";
args[1] = ComponentContext.class.getName()+" compctx";
args[2] = proxyclname+" intentTarget";
args[3] = "java.lang.reflect.Method intentMethod";
args[2] = Interface.class.getName()+" itf";
args[3] = proxyclname+" intentTarget";
args[4] = "java.lang.reflect.Method intentMethod";
for (int j = 0; j < paramtypes.length; j++) {
String paramtypename = paramtypes[j].getName();
args[j+4] = paramtypename+" arg"+j;
args[j+5] = paramtypename+" arg"+j;
}
// Constructor body
MethodSourceCodeVisitor mv =
innercv.visitConstructor( Modifier.PUBLIC, null, args, null );
mv.visitBegin();
mv.visit(" super(handlers,compctx,intentTarget,intentMethod");
mv.visit(" super(handlers,compctx,itf,intentTarget,intentMethod");
for (int j = 0; j < paramtypes.length; j++) {
mv.visit(",arg"+j);
}
......@@ -297,18 +299,23 @@ extends AbstractInterceptorSourceCodeGenerator {
mv.visitln("]);");
// Retrieve the component name
// Retrieve the component context
mv.visit (" ");
mv.visit (ComponentContext.class.getName());
mv.visitln(" compctx = getFcCompCtxCtrlItf();");
// Retrieve the interface associated with the interceptor
mv.visit (" ");
mv.visit (Interface.class.getName());
mv.visitln(" itf = getFcItf();");
// IntentJoinPoint instance creation
mv.visit (" ");
mv.visit (IntentJoinPoint.class.getName());
mv.visitln(" ijp = ");
mv.visit (" new IntentJoinPointImplForMethod");
mv.visit (Integer.toString(idx));
mv.visit ("(handlers,compctx,_impl,METHODS[");
mv.visit ("(handlers,compctx,itf,_impl,METHODS[");
mv.visit (Integer.toString(idx));
mv.visit ("]");
UnifiedClass[] ptypes = proxym.getParameterTypes();
......
......@@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Stack;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.julia.InitializationContext;
......@@ -48,29 +49,13 @@ import org.ow2.frascati.tinfi.control.intent.IntentHandler;
*/
public abstract class TinfiComponentInterceptor implements Interceptor {
/**
* The map of intent handlers associated with each component method managed
* by this interceptor. This map is queried by generated subclasses.
*
* @since 0.4
*/
protected Map<Method,List<IntentHandler>> intentHandlersMap;
// -----------------------------------------------------------------------
// References to control interfaces provided by the component
// -----------------------------------------------------------------------
private Component owner;
private ComponentContext compctx;
private SCAContentController cc;
// -----------------------------------------------------------------------
// Partial implementation of the Interceptor (and Controller) interfaces
// Abstract methods are concretized by generated subclasses
// -----------------------------------------------------------------------
public void initFcController( InitializationContext ic ) throws InstantiationException {
public void initFcController( InitializationContext ic )
throws InstantiationException {
owner = (Component) ic.getInterface("component");
}
......@@ -84,13 +69,41 @@ public abstract class TinfiComponentInterceptor implements Interceptor {
protected void initFcClone( TinfiComponentInterceptor clone ) {
clone.intentHandlersMap = intentHandlersMap;
clone.owner = owner;
clone.itf = itf;
}
private Component owner;
private ComponentContext compctx;
private SCAContentController cc;
private Interface itf;
// -----------------------------------------------------------------------
// Methods for managing the reference between the interceptor and its
// associated interface
// -----------------------------------------------------------------------
public void setFcItf( Interface itf ) {
this.itf = itf;
}
public Interface getFcItf() {
return itf;
}
// -----------------------------------------------------------------------
// Methods for managing intents handlers
// Management of intents handlers
// -----------------------------------------------------------------------
/**
* The map of intent handlers associated with each component method managed
* by this interceptor. This map is queried by generated subclasses.
*
* @since 0.4
*/
protected Map<Method,List<IntentHandler>> intentHandlersMap;
/**
* Initialize the intent handlers map by adding an empty ntry for each
* specified method.
......
......@@ -24,6 +24,7 @@
package org.ow2.frascati.tinfi.control.intent;
import org.aopalliance.intercept.MethodInvocation;
import org.objectweb.fractal.api.Interface;
import org.osoa.sca.ComponentContext;
/**
......@@ -39,4 +40,12 @@ public interface IntentJoinPoint extends MethodInvocation {
* Return the component context for which the intent has been defined.
*/
public ComponentContext getComponentContext();
/**
* Return the component interface (service or reference) for which the
* intent has been defined.
*
* @since 0.4.5
*/
public Interface getInterface();
}
......@@ -27,6 +27,7 @@ import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
import java.util.List;
import org.objectweb.fractal.api.Interface;
import org.osoa.sca.ComponentContext;
import org.ow2.frascati.tinfi.TinfiRuntimeException;
......@@ -44,6 +45,7 @@ public class IntentJoinPointImpl implements IntentJoinPoint {
protected int index = 0;
protected ComponentContext intentComponentContext;
protected Interface intentItf;
protected Object intentTarget;
private Method intentMethod;
protected Object[] intentMethodArguments;
......@@ -51,12 +53,14 @@ public class IntentJoinPointImpl implements IntentJoinPoint {
public IntentJoinPointImpl(
List<IntentHandler> handlers,
ComponentContext intentComponentContext,
Interface intentItf,
Object intentTarget,
Method intentMethod,
Object... intentMethodArguments ) {
this.handlers = handlers;
this.intentComponentContext = intentComponentContext;
this.intentItf = intentItf;
this.intentTarget = intentTarget;
this.intentMethod = intentMethod;
this.intentMethodArguments = intentMethodArguments;
......@@ -69,6 +73,16 @@ public class IntentJoinPointImpl implements IntentJoinPoint {
return intentComponentContext;
}
/**
* Return the component interface (service or reference) for which the
* intent has been defined.
*
* @since 0.4.5
*/
public Interface getInterface() {
return intentItf;
}
/**
* Return the method arguments for which the intent has been defined.
*/
......
......@@ -28,9 +28,11 @@ import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.util.Fractal;
import org.osoa.sca.annotations.PolicySets;
import org.ow2.frascati.tinfi.PolicySetsCounterAnnotatedClassItf;
......@@ -94,11 +96,20 @@ public class PolicySetsTestCase extends TestCase {
assertEquals(2,count);
}
public void testIntentJoinPoint() {
public void testIntentJoinPointInterface() {
itf.runAnnotatedMethod();
IntentJoinPoint ijp = countItf.getLastIntentJoinPoint();
Interface itf = ijp.getInterface();
InterfaceType it = (InterfaceType) itf.getFcItfType();
String itName = it.getFcItfName();
assertEquals("r",itName);
}
public void testIntentJoinPointMethod() {
itf.runAnnotatedMethod();
IntentJoinPoint ijp = countItf.getLastIntentJoinPoint();
Method method = ijp.getMethod();
String name = method.getName();
assertEquals("runAnnotatedMethod",name);
String methodName = method.getName();
assertEquals("runAnnotatedMethod",methodName);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment