My favorites | Sign in
Project Logo
                
Search
for
Updated Feb 02, 2009 by Schmeeky
Labels: Featured, Phase-Deploy, Phase-Implementation
GettingStarted  
How to get Javada working with a simple example

Compiling Javada

To compile Javada, the following libraries are required:

  1. Eclipse 3.0 or later
  2. EMF Runtime 2.2 or later
  3. Eclipse CORBA Plugin IDL parser

From these projects, the following .jar files are required:

  1. org.eclipse.emf.common
  2. org.eclipse.emf.ecore
  3. org.eclipse.text
  4. org.eclipse.equinox.common
  5. org.eclipse.core.runtime
  6. net.sf.eclipsecorba.idl

The easiest way to build the javada.jar library is to use the fat-jar plugin for eclipse:

http://fjep.sourceforge.net/

In the Javada project, right click on 'settings.fatjar' and choose Fat-Jar -> Fast Build. The jar archive will be created.

Once this is created, run package.sh to build a zip file containing all the necessary files.

To install Javada, just unzip the javada.zip file.

Defining a simple IDL interface

In the examples/pizza directory is a simple example of an interface that you can compile using Javada. Here is the contents of pizza.idl:

/*
 * Example IDL file for Javada
 * Copyright (c) 2007 Rapita Systems
 */
#include "javada_types.idl"

module x {
	interface Topping {
		string getName();
	};
	
	interface Toppings {
		Natural size();
		Topping get(in Natural index);
	};

	interface Pizza {
		Toppings getToppings();
	};
};

The javada_types.idl file contains some default Ada types to make writing interfaces easier. Since Java doesn't have the same strong typing of primitive types that Ada has, these types will become int types in the Java version of the interface.

Supported Features of IDL

Sequences are implmented as arrays - the only semantic difference between arrays and sequences in IDL is to do with transferring them across the network.

out and inout parameters on methods are not supported (Java does not have out parameters, so a new container class will need to be constructed)

Interface arguments are not supported.

Unsupported Features of IDL

Generating code using Javada

Javada has very few command line options. A usage summary can be displayed by simply typing javada.

$ javada
*******************************************
* Javada - Java to Ada Binings Generator  *
* Copyright (c) 2007 Rapita Systems Ltd.  *
* http://www.rapitasystems.com            *
*                                         *
* Licenced under GPL 2.0:                 *
* http://www.gnu.org/copyleft/gpl.html    *
*******************************************
Input file not specified
Usage: javada [<options>] <inputFile>
Options:        -I dir  Include dir when searching for IDL files
                -O dir  Use dir for output directory
                -L name Set the name of the JNI library to compile
                -J name Use name as the prefix for Java packages

Running javada on an IDL interface will generate a number of files:

There is currently no support for classes, where fields and operations are mixed. In order to ensure that field values were visible to the other side of the interface, getters and setters would be needed, which makes the implementation equivalent to an interface.

The pizza example uses the following command line for Javada:

$javada -O generated -L pizza -I ../../include -I . -J javada pizza.idl
*******************************************
Parsing pizza.idl
Parsing ..\..\include\javada_types.idl
Writing generated\x.ads
Writing generated\x.adb
Writing generated\x-util.ads
Writing generated\x-util.adb
Writing generated\javada\x\Topping.java
Writing generated\javada\x\prx\ToppingPrx.java
Writing generated\javada\x\Toppings.java
Writing generated\javada\x\prx\ToppingsPrx.java
Writing generated\javada\x\Pizza.java
Writing generated\javada\x\prx\PizzaPrx.java

The x.ad? files contain the public Ada declarations for the interfaces in the x module. The contents of x.ads begins like this:

-- DO NOT EDIT THIS FILE - it is machine generated
with Ada.Containers; use Ada.Containers;
package X is

   -- Types for Topping

   type Topping is abstract tagged null record;
     
   -- Interface Methods for Topping
   function Hash_Code(Obj: Topping) return Hash_Type is abstract;
   function GetName
     (Obj: Topping) return String is abstract;
   ...

This is the interface definition for Topping, and could be used to produce an Ada implementation, or to access a Java object through a proxy.

The Topping.java file is the equivalent for the Java side of the binding.

The x-util.ad?, and ...Prx.java files contain the implementation of marshalling code and proxy objects. Usually you won't need to use these modules, except for bootstrapping (see below).

Implementing a Javada-generated interface

Implementation Tips

Ada type constraints

In order to define special ada types (eg, Positive, mod types, etc), specify them in a separate IDL file and include it using the directive:

#include "<idl file>"

This will allow the Ada generator to place the symbols in the source code, while the Java generator will use the underlying type of the declaration. For example, in the jnilib folder there is a file called JavadaTypes.idl. By including this file you can use the common Ada types Positive and Natural. The file contains:

typedef long Positive;
typedef long Natural;

If you want to define complex constraints yourself, place the declarations in a package:

module mytypes {
 typedef long specialModType;
};

Then implement the Ada package:

package mytypes is
 type specialModType is mod 2**15;
end mytypes;

This will allow you to use the type in your definitions, but Javada will not generate a package for the included file. Java will use the base type specified in the IDL file.


Sign in to add a comment
Hosted by Google Code