Commit 46184bfe authored by Lionel Seinturier's avatar Lionel Seinturier

FCOOCtrlNoIntentSourceCodeGenerator for scaPrimitive and scaComposite...

FCOOCtrlNoIntentSourceCodeGenerator for scaPrimitive and scaComposite membranes with no intent interceptor (feature requested by Nicolas P.)
parent 476733e6
Tinfi 1.1.1
-----------
* move to sca-model 2.0.0
* FCOOCtrlNoIntentSourceCodeGenerator for scaPrimitive and scaComposite
membranes with no intent interceptor (feature requested by Nicolas P.)
Tinfi 1.1
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ow2.frascati.tinfi</groupId>
<artifactId>frascati-tinfi-parent</artifactId>
<version>1.1.1-SNAPSHOT</version>
</parent>
<groupId>org.ow2.frascati.tinfi.examples</groupId>
<artifactId>frascati-tinfi-sca-helloworld-no-intent</artifactId>
<packaging>jar</packaging>
<name>SCA ADL Advanced Example HelloWorld No Intent</name>
<!-- ================================================== -->
<!-- Properties used for lauching the application. -->
<!-- See Tinfi top-level module for profile definition. -->
<!-- tinfi.run.component: component ADL type -->
<!-- tinfi.run.interface: component server interface -->
<!-- ================================================== -->
<properties>
<tinfi.run.component>HelloWorld</tinfi.run.component>
<tinfi.run.interface>r</tinfi.run.interface>
</properties>
<!-- ============================= -->
<!-- Dependency for generated code -->
<!-- ============================= -->
<dependencies>
<dependency>
<groupId>org.ow2.frascati.tinfi</groupId>
<artifactId>frascati-tinfi-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.objectweb.fractal.juliac</groupId>
<artifactId>maven-juliac-plugin</artifactId>
<version>${juliac.version}</version>
<executions>
<execution>
<id>juliac-compile</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<srcs><src>src/main/java</src></srcs>
<opts>
<opt>org.ow2.frascati.tinfi.emf.EMFParserSourceCodeGenerator</opt>
<opt>org.ow2.frascati.tinfi.opt.oo.FCOOCtrlNoIntentSourceCodeGenerator</opt>
<opt>OO</opt>
</opts>
<mixins>
<mixin>org.ow2.frascati.tinfi:frascati-tinfi-mixins:${project.version}:sources</mixin>
<mixin>org.objectweb.fractal.julia:julia-mixins:${julia.version}:sources</mixin>
</mixins>
<adls><adl>HelloWorld</adl></adls>
<modules>
<module>org.ow2.frascati.tinfi:frascati-tinfi-oo:${project.version}</module>
<module>org.ow2.frascati.tinfi:frascati-tinfi-emf:${project.version}</module>
<module>org.objectweb.fractal.juliac:juliac-jdt:${juliac.version}</module>
<module>org.objectweb.fractal.juliac:juliac-spoon:${juliac.version}</module>
</modules>
<!-- debug>true</debug -->
</configuration>
</plugin>
</plugins>
</build>
</project>
/***
* OW2 FraSCAti Assembly Factory Examples : HelloWorld
* Copyright (C) 2008 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*/
package example.hw;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
public class ClientImpl implements Runnable {
public ClientImpl() {
Console.println("CLIENT created");
}
@Init
public void init() {
Console.println("CLIENT initialized");
}
public void run() {
s.print("hello world");
}
private PrinterItf s;
@Reference
public void setPrintService(PrinterItf service){
this.s = service;
}
}
\ No newline at end of file
/***
* OW2 FraSCAti Assembly Factory Examples : HelloWorld
* Copyright (C) 2008 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*/
package example.hw;
import java.io.PrintStream;
public class Console {
public static PrintStream ps = System.err;
public static void println( String msg ) {
ps.println(msg);
}
}
/***
* OW2 FraSCAti Assembly Factory Examples : HelloWorld
* Copyright (C) 2008 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*/
package example.hw;
public interface PrinterItf {
void print(String msg);
}
\ No newline at end of file
/***
* OW2 FraSCAti Assembly Factory Examples : HelloWorld
* Copyright (C) 2008 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: Damien.Fournier@inria.fr
*
* Author: Damien Fournier
*/
package example.hw;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Service;
@Service(interfaces={PrinterItf.class})
public class ServerImpl implements PrinterItf {
private String header;
private int count;
public ServerImpl() {
Console.println("SERVER created");
}
public void print(final String msg) {
Console.println("Server: begin printing...");
for (int i = 0 ; i < (count) ; ++i) {
Console.println(((header) + msg));
}
Console.println("Server: print done.");
}
public String getHeader() {
return header;
}
@Property
public void setHeader(final String header) {
this.header = header;
}
public int getCount() {
return count;
}
@Property
public void setCount(final String count) {
this.count = Integer.valueOf(count);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- Assembly Factory Examples : HelloWorld -->
<!-- Copyright (C) 2008-2009 INRIA, USTL -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: Damien.Fournier@inria.fr -->
<!-- -->
<!-- Author: Damien Fournier -->
<composite
name="HelloWorld"
xmlns="http://www.osoa.org/xmlns/sca/1.0"
>
<service name="r" promote="client/r">
<interface.java interface="java.lang.Runnable" />
</service>
<component name="client">
<service name="r">
<interface.java interface="java.lang.Runnable" />
</service>
<reference name="printService" target="server/s" >
<interface.java interface="example.hw.PrinterItf" />
</reference>
<implementation.java class="example.hw.ClientImpl" />
</component>
<component name="server">
<service name="s">
<interface.java interface="example.hw.PrinterItf" />
</service>
<implementation.java class="example.hw.ServerImpl" />
<property name="header">-></property>
<property name="count">1</property>
</component>
</composite>
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2008-2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package example.hw;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import junit.framework.Assert;
import org.junit.Test;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.ow2.frascati.tinfi.TinfiDomain;
/**
* Automate the launching of the HelloWorld example and check that the example
* runs as expected.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
*/
public class HelloWorldTestCase {
@Test
public void testHelloWorld()
throws
IOException, IllegalArgumentException, ClassNotFoundException,
InstantiationException, IllegalAccessException,
java.lang.InstantiationException, InstantiationException,
IllegalLifeCycleException, NoSuchInterfaceException {
final String prefix = "helloworld-no-intent-composite-";
final String adl = "HelloWorld";
/*
* Use the Console class to direct the output of the example to a
* temporary file.
*/
File tmp = File.createTempFile(prefix,".txt");
PrintStream ps = new PrintStream(tmp);
Console.ps = ps;
Runnable r = TinfiDomain.getService(adl,Runnable.class,"r");
r.run();
ps.close();
/*
* Dump the content of the temporay file to the console for visual
* check.
*/
FileReader fr = new FileReader(tmp);
int b;
while( (b=fr.read()) != -1 ) {
char c = (char) b;
System.err.print(c);
}
fr.close();
File tmpExpected = File.createTempFile(prefix,".txt");
ps = new PrintStream(tmpExpected);
for (String expected : expecteds) {
ps.println(expected);
}
ps.close();
/*
* Compare the output with the expected result.
*/
fr = new FileReader(tmp);
FileReader frExpected = new FileReader(tmpExpected);
int i=0,line=1,col=1;
while( (b=fr.read()) != -1 ) {
char c = (char) b;
char e = (char) frExpected.read();
if( c != e ) {
String msg = "Unexpected character at line "+line+", column "+col;
System.err.println();
System.err.println("Expected output is: ");
for (String expected : expecteds) {
System.err.println(expected);
}
Assert.fail(msg);
}
i++;
if( c == '\n' ) {
line++;
col=1;
}
else {
col++;
}
}
frExpected.close();
fr.close();
/*
* Delete temporary files.
*/
tmp.delete();
tmpExpected.delete();
}
final static private String[] expecteds =
new String[]{
"CLIENT created",
"CLIENT initialized",
"SERVER created",
"Server: begin printing...",
"->hello world",
"Server: print done.",
};
}
......@@ -15,6 +15,7 @@
<modules>
<module>helloworld-composite</module>
<module>helloworld-no-intent</module>
<module>helloworld-pojo</module>
<module>ultra-merge-helloworld</module>
</modules>
......
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2007-2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.ow2.frascati.tinfi.opt.oo;
import org.objectweb.fractal.juliac.ITBasedClassGenerator;
import org.objectweb.fractal.juliac.JuliacConfig;
import org.objectweb.fractal.juliac.proxy.InterceptorClassGenerator;
import org.objectweb.fractal.juliac.proxy.InterceptorSourceCodeGenerator;
/**
* Source code generator for scaPrimitive and scaComposite membranes with no
* intent interceptors.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.1.1
*/
public class FCOOCtrlNoIntentSourceCodeGenerator
extends FCOOCtrlSourceCodeGenerator {
@Override
protected void registerIntentInterceptorSourceCodeGenerator(
JuliacConfig jconf ) {
jconf.putInterceptorSourceCodeGenerator(
"org.ow2.frascati.tinfi.asm.SCAIntentInterceptorCodeGenerator",
SCANoIntentInterceptorSourceCodeGenerator.class.getName() );
}
/**
* Return the class generator for interceptors.
*/
@Override
protected ITBasedClassGenerator getInterceptorClassGenerator(
InterceptorSourceCodeGenerator[] iscgs ) {
return new InterceptorClassGenerator(iscgs,jc);
}
}
......@@ -25,7 +25,6 @@ package org.ow2.frascati.tinfi.opt.oo;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
......@@ -91,6 +90,12 @@ extends org.objectweb.fractal.juliac.opt.oo.FCOOCtrlSourceCodeGenerator {
jconf.putInterceptorSourceCodeGenerator(
"org.ow2.frascati.tinfi.asm.SCAContentInterceptorCodeGenerator",
SCAContentInterceptorSourceCodeGenerator.class.getName() );
registerIntentInterceptorSourceCodeGenerator(jconf);
}
protected void registerIntentInterceptorSourceCodeGenerator(
JuliacConfig jconf ) {
jconf.putInterceptorSourceCodeGenerator(
"org.ow2.frascati.tinfi.asm.SCAIntentInterceptorCodeGenerator",
SCAIntentInterceptorSourceCodeGenerator.class.getName() );
......@@ -188,36 +193,11 @@ extends org.objectweb.fractal.juliac.opt.oo.FCOOCtrlSourceCodeGenerator {
}
/**
* Return the interceptor class generator for the specified controller
* descriptor. Return <code>null</code> if the specified controller
* descriptor is not associated with an interceptor source code generator.
* Return the class generator for interceptors.
*/
@Override
protected ITBasedClassGenerator getInterceptorClassGenerator(
String ctrldesc, Map<?,?> context )
throws ClassNotFoundException {
if( ! ctrldesc.startsWith("sca") ) {
/*
* For non SCA controller descriptors, use the regular
* InterceptorClassGenerator class defined by the super method.
*/
ITBasedClassGenerator itcg =
super.getInterceptorClassGenerator(ctrldesc,context);
return itcg;
}
// Get the interceptor source code generators from the Julia config file
boolean mergeable = false;
InterceptorSourceCodeGenerator[] scgs =
getInterceptorSourceCodeGenerator(ctrldesc,context,mergeable);
if( scgs == null ) {
// No interceptor
return null;
}
// InterceptorClassGenerator specific for SCA components
InterceptorClassGenerator icg = new InterceptorClassGenerator(scgs,jc);
return icg;
InterceptorSourceCodeGenerator[] iscgs ) {
return new InterceptorClassGenerator(iscgs,jc);
}
}
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.ow2.frascati.tinfi.opt.oo;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.desc.MembraneDesc;
import org.objectweb.fractal.juliac.proxy.AbstractInterceptorSourceCodeGenerator;
import org.objectweb.fractal.juliac.ucf.UnifiedClass;
import org.objectweb.fractal.juliac.visit.MethodSourceCodeVisitor;
import org.ow2.frascati.tinfi.TinfiComponentInterceptor;
/**
* This class generates the source code of Tinfi interceptors which are
* associated with scaPrimitive and scaComposite membranes with no intent
* interceptors.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.1.1
*/
public class SCANoIntentInterceptorSourceCodeGenerator
extends AbstractInterceptorSourceCodeGenerator {
public SCANoIntentInterceptorSourceCodeGenerator() {
super();
}
public SCANoIntentInterceptorSourceCodeGenerator(
InterfaceType it, MembraneDesc<?> membraneDesc, boolean mergeable,
Juliac jc ) {
super(it,membraneDesc,mergeable,jc);
}
/**
* Return the name of the suffix which is appended to generated class names.
*/
public String getClassNameSuffix() {
return "SCA";
}
/**
* Return <code>true</code> if some code must be generated by the current
* source code generator.
*/
public boolean match() {
// Match all interfaces, including control ones
return true;
}
@Override
public void setMergeable( boolean mergeable ) {
if(mergeable) {
String msg = "This generator can not generate mergeable code";
throw new IllegalArgumentException(msg);
}
}
@Override
public String[] getImplementedInterfaceNames() {
return new String[]{it.getFcItfSignature()};
}
@Override
public String getSuperClassName() {
return TinfiComponentInterceptor.class.getName();