Mail Archive Home | fractal-commits List | April 2008 Index
| <-- Date Index --> | <-- Thread Index --> |
An example to demonstrate the use of Juliac for assembling compiled classes packaged in a .jar file (so-called binary components.)
--- trunk/fractaladl/juliac/examples/advanced/README.txt (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/README.txt 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,6 @@
+See the README.txt files contained in the subdirectories for compiling and
+launching the examples.
+
+Two examples (helloworld-bin and ultra-merge-helloworld) can be compiled and
+launched globally from this directory by typing:
+ mvn test
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/README.txt (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/README.txt 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,2 @@
+To compile and run the example:
+ mvn test
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/.classpath (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/.classpath 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="src" path="target/generated-sources/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/juliac-examples-helloworld-bin-code"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/juliac-compiler"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/julia-mixed-oo"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/fractal-api-2.0.2"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/julia-runtime-2.5.2"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/juliac-runtime"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/.project (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/.project 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>juliac-examples-helloworld-bin-assembly</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/pom.xml (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/pom.xml 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,79 @@
+<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.objectweb.fractal.fractaladl.juliac.examples</groupId>
+ <artifactId>helloworld-bin</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.objectweb.fractal.fractaladl.juliac.examples</groupId>
+ <artifactId>helloworld-bin-assembly</artifactId>
+ <packaging>jar</packaging>
+ <name>Assembling</name>
+
+ <!-- =============================================== -->
+ <!-- Juliac properties for launching the application -->
+ <!-- (component and interface) -->
+ <!-- with the juliac:profile (mvn -Pjuliac:run) -->
+ <!-- =============================================== -->
+ <properties>
+ <juliac.run.component>example.hw.HelloWorld</juliac.run.component>
+ <juliac.run.interface>r</juliac.run.interface>
+ </properties>
+
+ <!-- ========================================================= -->
+ <!-- Dependencies for generating and compiling the application -->
+ <!-- ========================================================= -->
+ <dependencies>
+ <dependency>
+ <groupId>org.objectweb.fractal.fractaladl.juliac</groupId>
+ <artifactId>runtime</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.objectweb.fractal.fractaladl.juliac.julia-mixed</groupId>
+ <artifactId>oo</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.objectweb.fractal.fractaladl.juliac.examples</groupId>
+ <artifactId>helloworld-bin-code</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <!-- ==================================== -->
+ <!-- Generate and compile the application -->
+ <!-- ==================================== -->
+ <plugin>
+ <groupId>org.objectweb.fractal.fractaladl.juliac.plugin</groupId>
+ <artifactId>maven-juliac-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>juliac-compile</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <opt>OO</opt>
+ <types>example.hw.HelloWorld</types>
+ <!-- debug>true</debug -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/src/main/resources/example/hw/HelloWorld.fractal (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/src/main/resources/example/hw/HelloWorld.fractal 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN" "classpath://org/objectweb/fractal/adl/xml/basic.dtd">
+
+<!--
+ * Julia
+ * Copyright (C) 2005-2007 INRIA, France Telecom, 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: Lionel.Seinturier@xxxxxxx
+ *
+ * Author: Lionel Seinturier
+ -->
+
+<definition name="example.hw.HelloWorld">
+
+ <interface name="r" role="server" signature="java.lang.Runnable" />
+
+ <component name="client">
+ <interface name="r" role="server" signature="java.lang.Runnable" />
+ <interface name="s" role="client" signature="example.hw.Service" />
+ <content class="example.hw.ClientImpl" />
+ </component>
+
+ <component name="server">
+ <interface name="s" role="server" signature="example.hw.Service" />
+ <content class="example.hw.ServerImpl" />
+ <attributes signature="example.hw.ServiceAttributes">
+ <attribute name="header" value="-> " />
+ <attribute name="count" value="1" />
+ </attributes>
+ <controller desc="parametricPrimitive" />
+ </component>
+
+ <binding client="this.r" server="client.r" />
+ <binding client="client.s" server="server.s" />
+
+ <controller desc="composite" />
+</definition>
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/src/test/java/example/hw/HelloWorldTestCase.java (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/assembly/src/test/java/example/hw/HelloWorldTestCase.java 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,130 @@
+/***
+ * Juliac
+ * 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: Lionel.Seinturier@xxxxxxxxxxxxxx
+ *
+ * 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.TestCase;
+
+import org.junit.Test;
+import org.objectweb.fractal.adl.juliac.runtime.Launcher;
+import org.objectweb.fractal.api.NoSuchInterfaceException;
+import org.objectweb.fractal.api.control.IllegalLifeCycleException;
+import org.objectweb.fractal.api.factory.InstantiationException;
+
+/**
+ * Automate the launching of the HelloWorld example and check that the example
+ * runs as expected.
+ *
+ * @author Lionel Seinturier <Lionel.Seinturier@xxxxxxxxxxxxxx>
+ * @since 1.3
+ */
+public class HelloWorldTestCase extends TestCase {
+
+ @Test
+ public void testHelloWorld()
+ throws
+ IOException, IllegalArgumentException, ClassNotFoundException,
+ InstantiationException, IllegalAccessException,
+ java.lang.InstantiationException, NoSuchInterfaceException,
+ IllegalLifeCycleException {
+
+ /*
+ * Use the Console class to direct the output of the example to a
+ * temporary file.
+ */
+ File tmp = File.createTempFile("helloworld-bin-",".txt");
+ PrintStream ps = new PrintStream(tmp);
+ Console.ps = ps;
+ Launcher.main(new String[]{"example.hw.HelloWorld","r"});
+ 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("helloworld-bin-",".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);
+ }
+ 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",
+ "SERVER created",
+ "Server: begin printing...",
+ "-> hello world",
+ "Server: print done.",
+ };
+}
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/.classpath (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/.classpath 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/fractal-api-2.0.2"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/.project (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/.project 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>juliac-examples-helloworld-bin-code</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/pom.xml (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/pom.xml 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,16 @@
+<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.objectweb.fractal.fractaladl.juliac.examples</groupId>
+ <artifactId>helloworld-bin</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.objectweb.fractal.fractaladl.juliac.examples</groupId>
+ <artifactId>helloworld-bin-code</artifactId>
+ <packaging>jar</packaging>
+ <name>Business code</name>
+
+</project>
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/ClientImpl.java (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/ClientImpl.java 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,54 @@
+package example.hw;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.objectweb.fractal.api.NoSuchInterfaceException;
+import org.objectweb.fractal.api.control.BindingController;
+import org.objectweb.fractal.api.control.IllegalBindingException;
+
+public class ClientImpl implements Runnable , BindingController {
+
+ public ClientImpl() {
+ Console.println("CLIENT created");
+ }
+
+ public void run() {
+ s.print("hello world");
+ }
+
+ private Service s;
+
+ public void bindFc(String clientItfName, Object serverItf) throws NoSuchInterfaceException, IllegalBindingException {
+ if (clientItfName.equals("s")) {
+ if (!(Service.class.isAssignableFrom(serverItf.getClass()))) {
+ throw new IllegalBindingException(((("server interfaces connected to " + clientItfName) + " must be instances of ") + (Service.class.getName())));
+ }
+ s = ((Service)(serverItf));
+ return ;
+ }
+ throw new NoSuchInterfaceException((("Client interface \'" + clientItfName) + "\' is undefined."));
+ }
+
+ public String[] listFc() {
+ List<String> __interfaces__ = new ArrayList<String>();
+ __interfaces__.add("s");
+ return ((String[])(__interfaces__.toArray(new String[]{ })));
+ }
+
+ public Object lookupFc(String clientItfName) throws NoSuchInterfaceException {
+ if (clientItfName.equals("s")) {
+ return s;
+ }
+ throw new NoSuchInterfaceException((("Client interface \'" + clientItfName) + "\' is undefined."));
+ }
+
+ public void unbindFc(String clientItfName) throws NoSuchInterfaceException {
+ if (clientItfName.equals("s")) {
+ s = null;
+ return ;
+ }
+ throw new NoSuchInterfaceException((("Client interface \'" + clientItfName) + "\' is undefined."));
+ }
+
+}
\ No newline at end of file
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/Console.java (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/Console.java 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,12 @@
+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);
+ }
+}
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/ServerImpl.java (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/ServerImpl.java 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,36 @@
+package example.hw;
+
+
+public class ServerImpl implements Service , ServiceAttributes {
+ 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;
+ }
+
+ public void setHeader(final String header) {
+ this.header = header;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setCount(final int count) {
+ this.count = count;
+ }
+}
\ No newline at end of file
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/Service.java (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/Service.java 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,6 @@
+package example.hw;
+
+
+public interface Service {
+ void print(String msg);
+}
\ No newline at end of file
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/ServiceAttributes.java (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/code/src/main/java/example/hw/ServiceAttributes.java 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,10 @@
+package example.hw;
+
+import org.objectweb.fractal.api.control.AttributeController;
+
+public interface ServiceAttributes extends AttributeController {
+ String getHeader();
+ void setHeader(String header);
+ int getCount();
+ void setCount(int count);
+}
\ No newline at end of file
--- trunk/fractaladl/juliac/examples/advanced/helloworld-bin/pom.xml (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/helloworld-bin/pom.xml 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,21 @@
+<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.objectweb.fractal.fractaladl.juliac</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.objectweb.fractal.fractaladl.juliac.examples</groupId>
+ <artifactId>helloworld-bin</artifactId>
+ <packaging>pom</packaging>
+ <name>Fractal HelloWorld example with binary assembling</name>
+
+ <modules>
+ <module>code</module>
+ <module>assembly</module>
+ </modules>
+
+</project>
--- trunk/fractaladl/juliac/examples/advanced/pom.xml (rev 0)
+++ trunk/fractaladl/juliac/examples/advanced/pom.xml 2008-04-29 19:41:00 UTC (rev 7555)
@@ -0,0 +1,21 @@
+<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.objectweb.fractal.fractaladl.juliac</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.3-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.objectweb.fractal.fractaladl.juliac.examples</groupId>
+ <artifactId>advanced</artifactId>
+ <packaging>pom</packaging>
+ <name>Juliac advanced examples</name>
+
+ <modules>
+ <module>helloworld-bin</module>
+ <module>ultra-merge-helloworld</module>
+ </modules>
+
+</project>
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 2006-2007, OW2 Consortium | contact | webmaster.