OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | fractal-commits List | August 2008 Index

<--  Date Index  --> <--  Thread Index  -->

[fractal-commits] [8427] trunk/juliac/examples/advanced/foobar-cases/absolutepath:Enhance example by having Juliac generate code in addition to compiling.


Title: [8427] trunk/juliac/examples/advanced/foobar-cases/absolutepath: Enhance example by having Juliac generate code in addition to compiling.
Revision
8427
Author
seintur
Date
2008-08-31 20:05:06 +0200 (Sun, 31 Aug 2008)

Log Message

Enhance example by having Juliac generate code in addition to compiling.

Modified Paths

Added Paths

Diff

Modified: trunk/juliac/examples/advanced/foobar-cases/absolutepath/pom.xml (8426 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/pom.xml	2008-08-31 18:04:23 UTC (rev 8426)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/pom.xml	2008-08-31 18:05:06 UTC (rev 8427)
@@ -20,15 +20,10 @@
 			<version>${fractalapi.version}</version>
 		</dependency>
 		<dependency>
-			<groupId>org.objectweb.fractal.julia</groupId>
-			<artifactId>julia-runtime</artifactId>
-			<version>${julia.version}</version>
+			<groupId>org.objectweb.fractal.fraclet.java</groupId>
+			<artifactId>fraclet-annotations</artifactId>
+			<version>3.0</version>
 		</dependency>
-		<dependency>
-			<groupId>org.objectweb.fractal.julia</groupId>
-			<artifactId>julia-mixins</artifactId>
-			<version>${julia.version}</version>
-		</dependency>
 
 		<dependency>
 			<groupId>org.objectweb.fractal.juliac</groupId>
@@ -42,9 +37,14 @@
 		</dependency>
 		<dependency>
 			<groupId>org.objectweb.fractal.juliac</groupId>
-			<artifactId>juliac-oo</artifactId>
+			<artifactId>juliac-fractaladl</artifactId>
 			<version>${project.version}</version>
 		</dependency>
+		<dependency>
+			<groupId>org.objectweb.fractal.juliac</groupId>
+			<artifactId>juliac-ultra-merge</artifactId>
+			<version>${project.version}</version>
+		</dependency>
 
 		<dependency>
 			<groupId>junit</groupId>

Modified: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/java/example/absolutepath/AbsolutePathTestCase.java (8426 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/java/example/absolutepath/AbsolutePathTestCase.java	2008-08-31 18:04:23 UTC (rev 8426)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/java/example/absolutepath/AbsolutePathTestCase.java	2008-08-31 18:05:06 UTC (rev 8427)
@@ -27,10 +27,14 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashMap;
 
 import org.junit.Test;
-import org.objectweb.fractal.api.factory.InstantiationException;
 import org.objectweb.fractal.juliac.Juliac;
+import org.objectweb.fractal.juliac.JuliacParams;
+import org.objectweb.fractal.juliac.Utils;
 
 /**
  * Test whether Juliac works correctly when invoked with absolute paths.
@@ -44,8 +48,7 @@
     public void test()
     throws
         IllegalArgumentException, IOException, InstantiationException,
-        java.lang.InstantiationException, IllegalAccessException,
-        ClassNotFoundException {
+        IllegalAccessException, ClassNotFoundException {
         
         /*
          * Create a temporary directory.
@@ -75,34 +78,48 @@
         /*
          * Copy source files to the created temporary directory.
          */
-        ClassLoader loader = getClass().getClassLoader();
-        String root = "example/absolutepath/";
-        copy(loader,root,"ClientImpl.java",fsrcs);
-        copy(loader,root,"ServerImpl.java",fsrcs);
-        copy(loader,root,"Service.java",fsrcs);
-        copy(loader,root,"ServiceAttributes.java",fsrcs);
+        ClassLoader mainloader = getClass().getClassLoader();
+        String root = "example/absolutepath";
+        copy(mainloader,root,"ClientImpl.java",fsrcs);
+        copy(mainloader,root,"Console.java",fsrcs);
+        copy(mainloader,root,"ServerImpl.java",fsrcs);
+        copy(mainloader,root,"Service.java",fsrcs);
+        copy(mainloader,root,"ServiceAttributes.java",fsrcs);
+        copy(mainloader,root+"/clt","AbstractClient.java",fsrcs);
+        copy(mainloader,root+"/srv","Printer.java",fsrcs);
+        copy(mainloader,root+"/srv","ServerImpl2.java",fsrcs);
+        copy(mainloader,root+"/srv","ServerImpl3.java",fsrcs);
         
         /*
-         * Define command line arguments for invoking Juliac.
+         * Define parameters sfor invoking Juliac.
          */
         String srcs = fsrcs.getAbsolutePath();
         String gensrc = fgensrc.getAbsolutePath();
         String genclass = fgenclass.getAbsolutePath();
+
+        String adl = "example.absolutepath.HelloWorld";
+        URL url = ""
+        ClassLoader loader = new URLClassLoader(new URL[]{url},mainloader);
         
-        StringBuffer argline = new StringBuffer();
-        argline.append("--opt OO --compileInput --compileGenerated");
-        argline.append(" --srcs ");
-        argline.append(srcs);
-        argline.append(" --gensrc ");
-        argline.append(gensrc);
-        argline.append(" --genclass ");
-        argline.append(genclass);
+        // use ULTRA_MERGE since no mixin is required
+        // else it would be a bit trickier to retrieve the path to the mixin artifact
+        JuliacParams jps =
+            new JuliacParams(
+                new File("."),  // don't care since absolute paths are given below
+                new String[]{srcs}, new String[0],
+                gensrc, genclass, genclass, "ULTRA_MERGE", (String) null
+            );
         
         /*
          * Invoke Juliac.
          */
-        String[] args = argline.toString().split(" ");
-        Juliac.main(args);
+        Juliac jc = new Juliac();
+        jc.setClassLoader(loader);
+        jc.init(jps);
+        jc.compileAndReport(false);
+        jc.loadGenerators();
+        jc.generate(adl,adl,new HashMap<Object,Object>());
+        jc.compileAndReport(false);
     }
     
     /**

Modified: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ClientImpl.java (8426 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ClientImpl.java	2008-08-31 18:04:23 UTC (rev 8426)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ClientImpl.java	2008-08-31 18:05:06 UTC (rev 8427)
@@ -1,54 +1,18 @@
 package example.absolutepath;
 
-import java.util.ArrayList;
-import java.util.List;
+import org.objectweb.fractal.fraclet.annotations.Component;
+import org.objectweb.fractal.fraclet.annotations.Interface;
 
-import org.objectweb.fractal.api.NoSuchInterfaceException;
-import org.objectweb.fractal.api.control.BindingController;
-import org.objectweb.fractal.api.control.IllegalBindingException;
+import example.absolutepath.clt.AbstractClient;
 
-public class ClientImpl implements Runnable , BindingController {
+@Component(provides=@Interface(name="r",signature=Runnable.class))
+public class ClientImpl extends AbstractClient {
 
     public ClientImpl() {
-        System.err.println("CLIENT created");
-    }
-    
+        Console.println("CLIENT created: "+header2);
+    }    
+
     public void run() {
-        s.print("hello world");
+        super.run();
     }
-    
-    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 interfaces.toArray(new String[interfaces.size()]);
-    }
-    
-    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

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/Console.java (0 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/Console.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/Console.java	2008-08-31 18:05:06 UTC (rev 8427)
@@ -0,0 +1,12 @@
+package example.absolutepath;
+
+import java.io.PrintStream;
+
+public class Console {
+
+    public static PrintStream ps = System.err;
+    
+    public static void println( String msg ) {
+        ps.println(msg);
+    }
+}

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/HelloWorld.fractal (0 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/HelloWorld.fractal	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/HelloWorld.fractal	2008-08-31 18:05:06 UTC (rev 8427)
@@ -0,0 +1,76 @@
+<?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) 2007-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
+ -->
+
+<definition name="example.absolutepath.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" cardinality="collection" signature="example.absolutepath.Service" />
+    	<content class="example.absolutepath.ClientImpl" />
+	</component>
+
+	<component name="server">
+	    <interface name="s" role="server" signature="example.absolutepath.Service" />
+	    <interface name="s2" role="client" signature="example.absolutepath.Service" />
+	    <content class="example.absolutepath.ServerImpl" />
+	    <attributes signature="example.absolutepath.ServiceAttributes">
+			<attribute name="header" value="-> " />
+			<attribute name="count" value="1" />
+	    </attributes>
+    	<controller desc="parametricPrimitive" />
+	</component>
+	
+	<component name="server2">
+	    <interface name="s" role="server" signature="example.absolutepath.Service" />
+	    <content class="example.absolutepath.srv.ServerImpl2" />
+	    <attributes signature="example.absolutepath.ServiceAttributes">
+			<attribute name="header" value="=> " />
+			<attribute name="count" value="2" />
+	    </attributes>
+    	<controller desc="parametricPrimitive" />
+	</component>
+	
+	<component name="server3">
+	    <interface name="s" role="server" signature="example.absolutepath.Service" />
+	    <content class="example.absolutepath.srv.ServerImpl3" />
+	    <attributes signature="example.absolutepath.ServiceAttributes">
+			<attribute name="header" value="== " />
+			<attribute name="count" value="3" />
+	    </attributes>
+    	<controller desc="parametricPrimitive" />
+	</component>
+	
+	<binding client="this.r" server="client.r" />
+	
+	<binding client="client.s1" server="server.s" />
+	<binding client="client.s3" server="server3.s" />
+
+	<binding client="server.s2" server="server2.s" />
+
+    <controller desc="composite" />
+</definition>

Modified: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServerImpl.java (8426 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServerImpl.java	2008-08-31 18:04:23 UTC (rev 8426)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServerImpl.java	2008-08-31 18:05:06 UTC (rev 8427)
@@ -1,29 +1,30 @@
 package example.absolutepath;
 
+import org.objectweb.fractal.fraclet.annotations.Component;
+import org.objectweb.fractal.fraclet.annotations.Interface;
+import org.objectweb.fractal.fraclet.annotations.Requires;
 
+@Component(provides=@Interface(name="s",signature=ServiceAttributes.class))
 public class ServerImpl implements Service , ServiceAttributes {
+    
+    @Requires
+    private Service s2;
+    
     private String header;
-    
     private int count;
     
     public ServerImpl() {
-        System.err.println("SERVER created");
+        Console.println("SERVER created");
     }
     
     public void print(final String msg) {
-        new Exception() {
-            private static final long serialVersionUID = 2182742162070453637L;
-            
-            public String toString() {
-                return "Server: print method called";
-            }
-            
-        }.printStackTrace();
-        System.err.println("Server: begin printing...");
+        String header = getHeader();
+        Console.println("Server: begin printing...");
         for (int i = 0 ; i < (count) ; ++i) {
-            System.err.println(((header) + msg));
+            Console.println(header + msg);
         }
-        System.err.println("Server: print done.");
+        Console.println("Server: print done.");
+        s2.print(msg);
     }
     
     public String getHeader() {

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/clt/AbstractClient.java (0 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/clt/AbstractClient.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/clt/AbstractClient.java	2008-08-31 18:05:06 UTC (rev 8427)
@@ -0,0 +1,24 @@
+package example.absolutepath.clt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.objectweb.fractal.fraclet.annotations.Requires;
+import org.objectweb.fractal.fraclet.types.Cardinality;
+
+import example.absolutepath.Service;
+
+public class AbstractClient implements Runnable {
+
+    protected String header2 = "foobar";
+
+    public void run() {
+        for (Map.Entry<String,Service> entry : m.entrySet()) {
+            Service s = entry.getValue();
+            s.print("hello world");
+        }
+    }
+    
+    @Requires(name="s",cardinality=Cardinality.COLLECTION)
+    private Map<String,Service> m = new HashMap<String, Service>();
+}

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/Printer.java (0 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/Printer.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/Printer.java	2008-08-31 18:05:06 UTC (rev 8427)
@@ -0,0 +1,11 @@
+package example.absolutepath.srv;
+
+import example.absolutepath.Console;
+
+class Printer {
+    
+    void print( String msg ) {
+        Console.println(msg);
+    }
+
+}

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/ServerImpl2.java (0 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/ServerImpl2.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/ServerImpl2.java	2008-08-31 18:05:06 UTC (rev 8427)
@@ -0,0 +1,48 @@
+package example.absolutepath.srv;
+
+import org.objectweb.fractal.fraclet.annotations.Component;
+import org.objectweb.fractal.fraclet.annotations.Interface;
+
+import example.absolutepath.Service;
+import example.absolutepath.ServiceAttributes;
+
+@Component(provides=@Interface(name="s",signature=ServiceAttributes.class))
+public class ServerImpl2 implements Service , ServiceAttributes {
+    
+    private String header;
+    private int count;
+    
+    public ServerImpl2() {
+        Printer printer = new Printer();
+        printer.print("SERVER2 created");
+    }
+    
+    /**
+     * Print method.
+     */
+    public void print(final String msg) {
+        Printer printer = new Printer();
+        String header = getHeader();
+        printer.print("Server2: begin printing...");
+        for (int i = 0 ; i < (count) ; ++i) {
+            printer.print(header + msg);
+        }
+        printer.print("Server2: 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

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/ServerImpl3.java (0 => 8427)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/ServerImpl3.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/srv/ServerImpl3.java	2008-08-31 18:05:06 UTC (rev 8427)
@@ -0,0 +1,48 @@
+package example.absolutepath.srv;
+
+import org.objectweb.fractal.fraclet.annotations.Component;
+import org.objectweb.fractal.fraclet.annotations.Interface;
+
+import example.absolutepath.Service;
+import example.absolutepath.ServiceAttributes;
+
+@Component(provides=@Interface(name="s",signature=ServiceAttributes.class))
+public class ServerImpl3 implements Service , ServiceAttributes {
+    
+    private String header;
+    private int count;
+    
+    public ServerImpl3() {
+        Printer printer3 = new Printer();
+        printer3.print("SERVER3 created");
+    }
+    
+    /**
+     * Print method.
+     */
+    public void print(final String msg) {
+        Printer printer = new Printer();
+        String header = getHeader();
+        printer.print("Server3: begin printing...");
+        for (int i = 0 ; i < (count) ; ++i) {
+            printer.print(header + msg);
+        }
+        printer.print("Server3: 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


<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.