Commit 794b11d4 authored by Philippe Merle's avatar Philippe Merle
Browse files

Added support for the org.objectweb.fractal.fraclet.extensions.Membrane annotation.

This annotation allows to configure the membrane associated to a content class.
parent a1a80371
......@@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.List;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.fraclet.extensions.Membrane;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.conf.JDKLevel;
import org.objectweb.fractal.juliac.conf.JuliacConfig;
......@@ -184,10 +185,10 @@ public class JuliacComponent
StringBuilder juliacOptLevel = new StringBuilder();
for(MembraneProvider jgc : juliacGeneratorClassProviders) {
juliacOptLevel.append(jgc.getMembraneClass().getCanonicalName());
juliacOptLevel.append(':');
juliacOptLevel.append(jgc.getMembraneClass().getCanonicalName());
}
jcfg.setOptLevel(juliacOptLevel.substring(0, juliacOptLevel.length() - 1));
jcfg.setOptLevel(juliacOptLevel.substring(1)); // remove first ':'
// use the current thread's context class loader where FraSCAti is loaded
// to load Juliac plugins instead of the class loader where Juliac was loaded.
......@@ -341,8 +342,36 @@ public class JuliacComponent
// Generate all the membranes to generate.
for(MembraneDescription md : membranesToGenerate) {
try {
String membraneDesc = md.membraneDesc;
if(md.contentDesc instanceof String) {
String className = (String)md.contentDesc;
Class<?> clazz = null;
try {
clazz = jcfg.getClassLoader().loadClass(className);
} catch(Exception e) {
severe(new FactoryException("Cannot load class " + className, e));
}
// Is the content class annotated with @org.objectweb.fractal.fraclet.extensions.Membrane?
Membrane membrane = clazz.getAnnotation(Membrane.class);
if(membrane != null) {
// The content class is annotated with @Membrane.
// Is its 'controllerDesc' attribute defined?
clazz = membrane.controllerDesc();
if(clazz != null) {
// Yes, then this controlledDesc is annotated with @Membrane.
membrane = clazz.getAnnotation(Membrane.class);
// Add to Juliac a binding between the membrane name and the membrane class
// else Juliac could not know the membrane class.
jcfg.getJulietLoader().put(membrane.desc(), clazz);
}
// Change the membraneDesc to use to instantiate the component.
membraneDesc = membrane.desc();
}
}
jc.getFCSourceCodeGenerator(md.membraneDesc)
.generate(md.componentType, md.membraneDesc, md.contentDesc);
.generate(md.componentType, membraneDesc, md.contentDesc);
} catch (Exception e) {
severe(new FactoryException("Cannot generate component code with Juliac", e));
return;
......
......@@ -37,11 +37,14 @@ import org.objectweb.fractal.api.factory.GenericFactory;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.fraclet.extensions.Membrane;
import org.objectweb.fractal.util.Fractal;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.component.factory.api.ComponentFactory;
import org.ow2.frascati.component.factory.api.FactoryException;
import org.ow2.frascati.component.factory.api.MembraneGeneration;
......@@ -225,9 +228,6 @@ public class ComponentFactoryImpl
Object contentClass) throws FactoryException
{
String logMessage = "create component componentType='" + componentType + "' membraneDesc='" + membraneDesc + "' contentClass='" + contentClass + "'";
Object[] controllerDesc = new Object[] { this.classLoaderForNewInstance, membraneDesc };
logDo(logMessage);
GenericFactory genericFactory = this.genericFactories.get(membraneDesc);
......@@ -238,6 +238,31 @@ public class ComponentFactoryImpl
Component component = null;
try {
if(contentClass instanceof String) {
String className = (String)contentClass;
// Load the content class.
Class<?> clazz = null;
try {
clazz = this.classLoaderForNewInstance.loadClass(className);
} catch(Exception e) {
severe(new FactoryException("Cannot load class '" + className + "'", e));
}
// Is this content class annotated with @org.objectweb.fractal.fraclet.extensions.Membrane?
Membrane membrane = clazz.getAnnotation(Membrane.class);
if(membrane != null) {
// The content class is annotated with @Membrane.
// Is its 'controllerDesc' attribute defined?
if(membrane.controllerDesc() != null) {
// Yes, then this controlledDesc is annotated with @Membrane.
membrane = membrane.controllerDesc().getAnnotation(Membrane.class);
}
// Change the membraneDesc to use to instantiate the component.
membraneDesc = membrane.desc();
}
}
// Instantiate the component.
Object[] controllerDesc = new Object[] { this.classLoaderForNewInstance, membraneDesc };
component = genericFactory.newFcInstance(componentType, controllerDesc, contentClass);
} catch (InstantiationException ie) {
throw new FactoryException("Error when " + logMessage, ie);
......
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