Commits

camlspotter committed fae319e Draft

point example with main in java

  • Participants
  • Parent commits e83a3d9
  • Branches android

Comments (0)

Files changed (10)

ojacare/examples/point_from_java/.depend

Empty file added.

ojacare/examples/point_from_java/Makefile

+#	$Id: Makefile,v 1.6 2004/03/28 02:45:09 henry Exp $
+
+include ../Makefile.config
+
+# Nom de l'éxécutable
+EXEC = point
+
+# Liste des fichiers IDL
+IDL       = p
+
+# Liste des répertoires contenant les modules et bibliotčques Caml utilisées
+MLINCDIRS = 
+
+# Liste des modules Caml 
+MODULES   = 
+
+# Liste des bibliothčques Caml ŕ inclure ŕ l'édition de lien
+LIBRARIES = 
+
+# Liste des bibliothčques C ŕ inclure ŕ l'édition de lien
+CLIBS     = 
+
+# Liste des classes Java ŕ compiler
+CLASS     = mypack/Point mypack/Colored mypack/ColoredPoint mypack/Cloud mypack/Main
+
+# Liste des classes Java ayant l'attribut callback 
+CBCLASS   = mypack/ColoredPoint
+
+cmo.o: p.cmo main-point.cmo
+	ocamlfind ocamlc -verbose -output-obj -o cmo.o -package camljava,ojacare  -linkpkg     p.cmo  main-point.cmo
+
+libOCaml.so: cmo.o
+	ld -shared cmo.o -L`ocamlc -where` -L`ocamlfind printconf destdir`/camljava -lcamljni_shared -lcamlrun_shared -ldl -lm -lncurses -o $@ 
+
+run: $(addsuffix .class, $(CLASS)) $(addsuffix .class, $(addprefix callback/, $(CBCLASS))) libOCaml.so
+	LD_LIBRARY_PATH=.:`ocamlfind printconf destdir`/camljava:`ocamlc -where` CLASSPATH=.:mypack:callback/mypack:`ocamlfind printconf destdir`/camljava/camljava.jar java Main
+
+clean::
+	rm *.so
+
+include $(OJACAREDIR)/Makefile.include

ojacare/examples/point_from_java/main-point.ml

+ (*	$Id: main-point.ml,v 1.4 2004/03/28 21:04:37 henry Exp $	*)
+
+open P
+
+let display s = print_string s; flush stdout ;;
+
+display "Creation d'un point p  : ";;
+let p = new default_point ();;
+display "OK\n";;
+
+display "Creation d'un point p2 = (1,1) : ";;
+let p2 = new point 1 1;;
+display "OK\n";;
+
+display "Envoi p#display : ";;
+p#display ();;
+display "Envoi p2#display : ";;
+p2#display ();;
+
+display "Envoi p#moveto 4 3 : ";;
+p#moveto 4 3;;
+p#display ();;
+
+display "Envoi p#rmoveto 2 -2 : ";;
+p#rmoveto 2 ~-2;;
+p#display ();;
+  
+display "Envoi p2#toString : ";;
+let s = p2#toString () in print_string s; print_newline ();;
+
+display "Envoi p2#distance : ";;
+let d = p2#distance () in print_float d; print_newline ();;
+
+display "Envoi p2#set_x 4 : ";;
+p2#set_x 4;;
+p2#display ();;
+
+display "Creation d'un point colore pc = (1,3) cyan : ";;
+let pc = new colored_point 1 3 "cyan";;
+display "OK\n";;
+
+display "Creation d'un point colore pc2 = (2,3) blue : ";;
+let pc2 = new colored_point 1 3 "blue";;
+display "OK\n";;
+
+display "Envoi pc#display : ";;
+pc#display ();;
+
+display "Envoi pc2#display : ";;
+pc2#display ();;
+
+display "Envoi pc2#getColor : ";;
+let s = pc2#getColor () in print_string s; print_newline ();;
+
+display "Creation d'un nuage de point : ";;
+let n = new empty_cloud ();;
+display "OK\n";;
+
+display "Ajout des points p2 pc1 pc2 p1 au nuage n: ";;
+n#addPoint p2;;
+n#addPoint (pc :> jPoint);;
+n#addPoint (pc2 :> jPoint);;
+n#addPoint p;;
+display "OK\n";;
+
+display "Envoi n#toString : ";;
+let s = n#toString () in print_string s; print_newline ();;
+
+class ml_colored_point x y c  =
+  object
+    inherit _stub_colored_point x y c as super
+    method getColor () = "Caml"^(super#getColor ())
+  end;;
+
+display "Creation d'un point callback cb1 = (5,6) blue ";;
+let cb1 = new ml_colored_point 5 6 "blue";;
+display "OK\n";;
+
+display "Envoi cb1#getColor : ";;
+let s = cb1#getColor () in print_string s; print_newline ();;
+
+display "Envoi cb1#toString : ";;
+let s = cb1#toString () in print_string s; print_newline ();;
+
+display "Ajout du point cb au nuage n: ";;
+n#addPoint (cb1 :> jPoint);;
+display "OK\n";;
+
+display "Envoi n#toString : ";;
+let s = n#toString () in print_string s; print_newline ();;

ojacare/examples/point_from_java/mypack/Cloud.java

+// 	$Id: Cloud.java,v 1.1 2004/03/20 00:03:19 henry Exp $	
+
+package mypack;
+import java.util.Vector;
+
+public class Cloud {
+
+    Vector data;
+
+    public Cloud() {
+	data = new Vector();
+    }
+
+    void addPoint(Point p) {
+	data.add(p);
+    }
+
+    public String toString() {
+	return data.toString();
+    }
+
+   public static void main(String [] args) {
+
+	Point p1 = new Point();
+	Point p2 = new Point(1,3);
+	Point pc1 = new ColoredPoint(-4,2,"Cyan");
+
+	Cloud n = new Cloud();
+
+	n.addPoint(p1);
+	n.addPoint(p2);
+	n.addPoint(pc1);
+
+	System.out.println(n);
+
+   }
+    
+
+}

ojacare/examples/point_from_java/mypack/Colored.java

+package mypack;
+
+public interface Colored {
+
+  String getColor();
+  void setColor(String c);
+
+}

ojacare/examples/point_from_java/mypack/ColoredPoint.java

+//	$Id: ColoredPoint.java,v 1.1 2004/03/20 00:03:19 henry Exp $
+
+package mypack;
+import mypack.Point;
+
+public class ColoredPoint extends Point implements Colored {
+
+    String c;
+
+    public ColoredPoint() {
+	super();
+	this.c = "";
+    }
+
+    public ColoredPoint(int x,int y, String c) {
+	super(x,y);
+	this.c = c;
+    }
+
+    public String getColor() {
+	return this.c;
+    }
+
+    public void setColor(String c) {
+	this.c = c;
+    }
+
+    public String toString() {
+	return super.toString()+":"+this.getColor();
+    }
+
+    public boolean eq(ColoredPoint p) {
+	return super.eq(p) && this.c.equals(p.c);
+    }
+    public static void main(String args []) {
+	ColoredPoint p1 =new ColoredPoint(2,3,"Rouge");
+	ColoredPoint p2 =new ColoredPoint(4,4,"Bleu");
+	p1.rmoveto(3,2);
+	p1.display();
+	p2.display();
+    }
+
+}

ojacare/examples/point_from_java/mypack/Main.java

+import fr.inria.caml.camljava.OCaml;
+
+public class Main {
+    public static void main (String[] args) {
+	System.loadLibrary("OCaml");
+	OCaml.startup(args);
+
+	System.out.println("Hello world from Java!!");
+    }
+}

ojacare/examples/point_from_java/mypack/Point.java

+//	$Id: Point.java,v 1.1.1.1 2003/10/19 22:57:41 henry Exp $
+
+package mypack;
+
+public class Point {
+  
+    int x;
+    int y;
+    
+    public Point() { 
+	this.x = 0;
+	this.y = 0;
+    };
+    
+    public Point(int x,int y) {
+	this.x = x;
+	this.y = y;
+    };
+
+    public void moveto(int x, int y) {
+	this.x = x;
+	this.y = y;
+    };
+
+    public void rmoveto(int rx,int ry) {
+	this.x += rx;
+	this.y += ry;
+    };
+
+    public String toString() {
+	return "("+x+","+y+")";
+    };
+    
+    public void display() {
+	System.out.println(this.toString());
+    };
+
+    public double distance() {
+	return Math.sqrt(this.x*this.x + this.y*this.y);
+    };
+    
+    public boolean eq(Point p) {
+	return this.x == p.x && this.y == p.y;
+    };
+
+    public static void main(String args []) {
+	Point p1 =new Point(2,3);
+	Point p2 =new Point(4,4);
+	p1.rmoveto(3,2);
+	p1.display();
+	p2.display();
+    }
+
+}

ojacare/examples/point_from_java/p.idl

+package mypack;
+
+class Point {
+ 
+  int x;
+  int y; 
+  
+  [name default_point] <init> ();
+  [name point] <init> (int,int);
+  
+  void moveto(int,int);
+  void rmoveto(int,int);
+  string toString();
+  void display();
+  double distance();
+  boolean eq(Point);
+
+  static void main(string [] arg);
+
+}
+
+interface Colored {
+
+  string getColor();
+  void setColor(string);
+
+}
+
+[callback] class ColoredPoint extends Point implements Colored {
+
+  [name default_colored_point] <init> ();
+  [name colored_point] <init> (int,int,string);
+
+  [name eq_colored_point] boolean eq(ColoredPoint);
+
+  static void main(string [] arg);
+
+}
+
+class Cloud {
+  
+  [name empty_cloud] <init> ();
+
+  void addPoint(Point);
+  string toString();
+
+  static void main(string [] arg);
+
+}

ojacare/examples/point_from_java/p.mli-seatle.txt

+type _jni_jCloud type _jni_jColoredPoint type _jni_jColored type _jni_jPoint
+class type jCloud =
+  object
+    inherit JniHierarchy.top
+    method _get_jni_jCloud : _jni_jCloud
+    method addPoint : jPoint -> unit
+    method toString : unit -> string
+  end
+and jColoredPoint =
+  object
+    inherit jPoint
+    inherit jColored
+    method _get_jni_jColoredPoint : _jni_jColoredPoint
+    method eq_colored_point : jColoredPoint -> bool
+  end
+and jColored =
+  object
+    inherit JniHierarchy.top
+    method _get_jni_jColored : _jni_jColored
+    method getColor : unit -> string
+    method setColor : string -> unit
+  end
+and jPoint =
+  object
+    inherit JniHierarchy.top
+    method _get_jni_jPoint : _jni_jPoint
+    method set_x : int -> unit
+    method get_x : unit -> int
+    method set_y : int -> unit
+    method get_y : unit -> int
+    method moveto : int -> int -> unit
+    method rmoveto : int -> int -> unit
+    method toString : unit -> string
+    method display : unit -> unit
+    method distance : unit -> float
+    method eq : jPoint -> bool
+  end
+class type virtual _stub_jColoredPoint =
+  object
+    inherit JniHierarchy.top
+    method _get_jni_jColored : _jni_jColored
+    method _get_jni_jPoint : _jni_jPoint
+    method _get_jni_jColoredPoint : _jni_jColoredPoint
+    method _stub_moveto : int -> int -> unit
+    method _stub_rmoveto : int -> int -> unit
+    method _stub_toString : Jni.obj
+    method _stub_display : unit
+    method _stub_distance : float
+    method _stub_eq : Jni.obj -> bool
+    method _stub_getColor : Jni.obj
+    method _stub_setColor : Jni.obj -> unit
+    method _stub_eq_colored_point : Jni.obj -> bool
+    method get_x : unit -> int
+    method set_x : int -> unit
+    method get_y : unit -> int
+    method set_y : int -> unit
+    method moveto : int -> int -> unit
+    method rmoveto : int -> int -> unit
+    method toString : unit -> string
+    method display : unit -> unit
+    method distance : unit -> float
+    method eq : jPoint -> bool
+    method getColor : unit -> string
+    method setColor : string -> unit
+    method eq_colored_point : jColoredPoint -> bool
+  end
+val jCloud_of_top : JniHierarchy.top -> jCloud
+val jColoredPoint_of_top : JniHierarchy.top -> jColoredPoint
+val jColored_of_top : JniHierarchy.top -> jColored
+val jPoint_of_top : JniHierarchy.top -> jPoint
+val _instance_of_jCloud : JniHierarchy.top -> bool
+val _instance_of_jColoredPoint : JniHierarchy.top -> bool
+val _instance_of_jColored : JniHierarchy.top -> bool
+val _instance_of_jPoint : JniHierarchy.top -> bool
+val jArray_init_jCloud : int -> (int -> jCloud) -> jCloud JniArray.jArray
+val jArray_init_jColoredPoint :
+  int -> (int -> jColoredPoint) -> jColoredPoint JniArray.jArray
+val jArray_init_jColored :
+  int -> (int -> jColored) -> jColored JniArray.jArray
+val jArray_init_jPoint : int -> (int -> jPoint) -> jPoint JniArray.jArray
+class empty_cloud : unit -> jCloud
+class colored_point : int -> int -> string -> jColoredPoint
+class default_colored_point : unit -> jColoredPoint
+class point : int -> int -> jPoint
+class default_point : unit -> jPoint
+class virtual _stub_colored_point :
+  int -> int -> string -> _stub_jColoredPoint
+class virtual _stub_default_colored_point : unit -> _stub_jColoredPoint
+val mypack_jCloud__main : string JniArray.jArray -> unit
+val mypack_jColoredPoint__main : string JniArray.jArray -> unit
+val mypack_jPoint__main : string JniArray.jArray -> unit