## Name

idlj - The IDL-to-Java Compiler

f3idlj generates Java bindings from a given IDL file.

## Synopsis

    f3
    idlj [ f3optionsf3 ] f4idl-filef3

where f2idl-file is the name of a file containing Interface Definition Language (IDL) definitions. f2Options may appear in any order, but must precede the f2idl-file.

## Description

The IDL-to-Java Compiler generates the Java bindings for a given IDL file. For binding details, see the

f2OMG IDL to Java Language Language Mapping Specification @

http://docs.oracle.com/javase/7/docs/technotes/guides/idl/mapping/jidlMapping.html. Some previous releases of the IDL-to-Java compiler were named f2idltojava.

##

Emitting Client and Server Bindings

To generate Java bindings for an IDL file named My.idl:

    f3
    idlj My.idl

This generates the client-side bindings and is equivalent to:

    f3
    idlj f3-fclient My.idl

The client-side bindings do not include the server-side skeleton. If you want to generate the server-side bindings for the interfaces:

    f3
    idlj f3-fserver My.idl

Server-side bindings include the client-side bindings plus the skeleton, all of which are f2POA (that is, Inheritance Model) classes. If you want to generate both client and server-side bindings, use one of the following (equivalent) commands:

    f3
    idlj f3-fclient -fserver My.idl
    idlj f3-fall My.idl

There are two possible server-side models: the Inheritance Model and the Tie Delegation Model.

The default server-side model is the f2Portable Servant Inheritance Model. Given an interface f2My defined in f2My.idl, the file f2MyPOA.java is generated. You must provide the implementation for f2My and it must inherit from f2MyPOA.

f2MyPOA.java is a stream-based skeleton that extends

f2org.omg.PortableServer.Servant @

http://docs.oracle.com/javase/7/docs/api/org/omg/PortableServer/Servant.html and implements the f2InvokeHandler interface and the operations interface associated with the IDL interface the skeleton implements.

The f2PortableServer module for the

f2Portable Object Adapter (POA) @

http://docs.oracle.com/javase/7/docs/technotes/guides/idl/POA.html defines the native f2Servant type. In the Java programming language, the f2Servant type is mapped to the Java f2org.omg.PortableServer.Servant class. It serves as the base class for all POA servant implementations and provides a number of methods that may be invoked by the application programmer, as well as methods which are invoked by the POA itself and may be overridden by the user to control aspects of servant behavior.

Another option for the Inheritance Model is to use the f2-oldImplBase flag in order to generate server-side bindings that are compatible with versions of the Java programming language prior to J2SE 1.4. Note that using the f2-oldImplBase flag is non-standard: these APIs are being deprecated. You would use this flag ONLY for compatibility with existing servers written in J2SE 1.3. In that case, you would need to modify an existing MAKEFILE to add the f2-oldImplBase flag to the f2idlj compiler, otherwise POA-based server-side mappings will be generated. To generate server-side bindings that are backwards compatible:

    f3
    idlj f3-fclient -fserver f3-oldImplBase My.idl
    idlj f3-fall f3-oldImplBase My.idl

Given an interface f2My defined in f2My.idl, the file f2_MyImplBase.java is generated. You must provide the implementation for f2My and it must inherit from f2_MyImplBase.

The other server-side model is called the Tie Model. This is a delegation model. Because it is not possible to generate ties and skeletons at the same time, they must be generated separately. The following commands generate the bindings for the Tie Model:

    f3
    idlj f3-fall My.idl
    idlj f3-fallTIE My.idl

For the interface f2My, the second command generates f2MyPOATie.java. The constructor to f2MyPOATie takes a f2delegate. In this example, using the default POA model, the constructor also needs a f2poa. You must provide the implementation for f2delegate, but it does not have to inherit from any other class, only the interface f2MyOperations. But to use it with the ORB, you must wrap your implementation within f2MyPOATie. For instance:

    f3
        ORB orb = ORB.init(args, System.getProperties());

        // Get reference to rootpoa & activate the POAManager
        POA rootpoa = (POA)orb.resolve_initial_references("RootPOA");
        rootpoa.the_POAManager().activate();

        // create servant and register it with the ORB
        MyServant myDelegate = new MyServant();
        myDelegate.setORB(orb);

        // create a tie, with servant being the delegate.
        MyPOATie tie = new MyPOATie(myDelegate, rootpoa);

        // obtain the objectRef for the tie
        My ref = tie._this(orb);

You might want to use the Tie model instead of the typical Inheritance model if your implementation must inherit from some other implementation. Java allows any number of interface inheritance, but there is only one slot for class inheritance. If you use the inheritance model, that slot is used up . By using the Tie Model, that slot is freed up for your own use. The drawback is that it introduces a level of indirection: one extra method call occurs when invoking a method.

To generate server-side, Tie model bindings that are compatible with versions of the IDL to Java language mapping in versions prior to J2SE 1.4.

    f3
    idlj f3-oldImplBase f3-fall My.idl
    idlj f3-oldImplBase f3-fallTIE My.idl

For the interface f2My, this will generate f2My_Tie.java. The constructor to f2My_Tie takes a f2impl. You must provide the implementation for f2impl, but it does not have to inherit from any other class, only the interface f2HelloOperations. But to use it with the ORB, you must wrap your implementation within f2My_Tie. For instance:

    f3
        ORB orb = ORB.init(args, System.getProperties());

        // create servant and register it with the ORB
        MyServant myDelegate = new MyServant();
        myDelegate.setORB(orb);

        // create a tie, with servant being the delegate.
        MyPOATie tie = new MyPOATie(myDelegate);

        // obtain the objectRef for the tie
        My ref = tie._this(orb);

##

Specifying Alternate Locations for Emitted Files

If you want to direct the emitted files to a directory other than the current directory, invoke the compiler as:

    f3
    idlj f3-td /altdir My.idl

For the interface f2My, the bindings will be emitted to f2/altdir/My.java, etc., instead of f2./My.java.

##

Specifying Alternate Locations for Include Files

If f2My.idl included another idl file, f2MyOther.idl, the compiler assumes that f2MyOther.idl resides in the local directory. If it resides in f2/includes, for example, then you would invoke the compiler with the following command:

    f3
    idlj f3-i /includes My.idl

If f2My.idl also included f2Another.idl that resided in f2/moreIncludes, for example, then you would invoke the compiler with the following command:

    f3
    idlj f3-i /includes -i /moreIncludes My.idl

Since this form of include can become irritatingly long, another means of indicating to the compiler where to search for included files is provided. This technique is similar to the idea of an environment variable. Create a file named f2idl.config in a directory that is listed in your CLASSPATH. Inside of f2idl.config, provide a line with the following form:

    f3
    includes=/includes;/moreIncludes

The compiler will find this file and read in the includes list. Note that in this example the separator character between the two directories is a semicolon (;). This separator character is platform dependent. On the Windows platform, use a semicolon, on the Unix platform, use a colon, etc. For more information on f2includes, see the

f2Setting the Classpath @

http://docs.oracle.com/javase/7/docs/technotes/tools/index.html#general.

##

Emitting Bindings for Include Files

By default, only those interfaces, structs, etc, that are defined in the idl file on the command line have Java bindings generated for them. The types defined in included files are not generated. For example, assume the following two idl files:

f4My.idl

    f3
    #include <MyOther.idl>
    interface My
    {
    };

f4MyOther.idl

    f3
    interface MyOther
    {
    };

The following command will only generate the java bindings for f2My:

    f3
    idlj My.idl

To generate all of the types in f2My.idl and all of the types in the files that f2My.idl includes (in this example, f2MyOther.idl), use the following command:

    f3
    idlj f3-emitAll My.idl

There is a caveat to the default rule. f2#include statements which appear at global scope are treated as described. These f2#include statements can be thought of as import statements. f2#include statements which appear within some enclosing scope are treated as true f2#include statements, meaning that the code within the included file is treated as if it appeared in the original file and, therefore, Java bindings are emitted for it. Here is an example:

f4My.idl

    f3
    #include <MyOther.idl>
    interface My
    {
      #include <Embedded.idl>
    };

f4MyOther.idl

    f3
    interface MyOther
    {
    };

f4Embedded.idl

    f3
    enum E {one, two, three};

Running the following command:

    f3
    idlj My.idl

will generate the following list of Java files:

    f3

Notice that f2MyOther.java was not generated because it is defined in an import-like f2#include. But f2E.java f2was generated because it was defined in a true f2#include. Also notice that since f2Embedded.idl was included within the scope of the interface f2My, it appears within the scope of f2My (that is,in f2MyPackage).

If the f2-emitAll flag had been used in the previous example, then all types in all included files would be emitted.

##

Inserting Package Prefixes

Suppose that you work for a company named ABC that has constructed the following IDL file:

f4Widgets.idl

    f3
    module Widgets
    {
      interface W1 {...};
      interface W2 {...};
    };

Running this file through the IDL-to-Java compiler will place the Java bindings for f2W1 and f2W2 within the package f2Widgets. But there is an industry convention that states that a company's packages should reside within a package named f2com.<company name>. The f2Widgets package is not good enough. To follow convention, it should be f2com.abc.Widgets. To place this package prefix onto the f2Widgets module, execute the following:

    f3
    idlj f3-pkgPrefix Widgets com.abc Widgets.idl

If you have an IDL file which includes f2Widgets.idl, the f2-pkgPrefix flag must appear in that command also. If it does not, then your IDL file will be looking for a f2Widgets package rather than a f2com.abc.Widgets package.

If you have a number of these packages that require prefixes, it might be easier to place them into the f2idl.config file described above. Each package prefix line should be of the form:

    f3
    PkgPrefix.<type>=<prefix>

So the line for the above example would be:

    f3
    PkgPrefix.Widgets=com.abc

The use of this option does not affect the Repository ID.

##

Defining Symbols Before Compilation

You may need to define a symbol for compilation that is not defined within the IDL file, perhaps to include debugging code in the bindings. The command

    f3
    idlj f3-d MYDEF My.idl

is the equivalent of putting the line f2#define MYDEF inside f2My.idl.

##

Preserving Pre-Existing Bindings

If the Java binding files already exist, the f2-keep flag will keep the compiler from overwriting them. The default is to generate all files without considering if they already exist. If you've customized those files (which you should not do unless you are very comfortable with their contents), then the f2-keep option is very useful. The command

    f3
    idlj f3-keep My.idl

emits all client-side bindings that do not already exist.

##

Viewing Progress of Compilation

The IDL-to-Java compiler will generate status messages as it progresses through its phases of execution. Use the f2-v option to activate this "verbose" mode:

    f3
    idlj f3-v My.idl

By default the compiler does not operate in verbose mode.

##

Displaying Version Information

To display the build version of the IDL-to-Java compiler, specify the f2-version option on the command-line:

    f3
    idlj -version

Version information also appears within the bindings generated by the compiler. Any additional options appearing on the command-line are ignored.

## Options

-d symbol This is equivalent to the following line in an IDL file:

    f3
    #define f4symbolf3

-emitAll Emit all types, including those found in f2#include files.

-fside Defines what bindings to emit. f2side is one of f2client, f2server, f2serverTIE, f2all, or f2allTIE. The f2-fserverTIE and f2-fallTIE options cause delegate model skeletons to be emitted. Assumes f2-fclient if the flag is not specified.

-i include-path By default, the current directory is scanned for included files. This option adds another directory.

-keep If a file to be generated already exists, do not overwrite it. By default it is overwritten.

-noWarn Suppresses warning messages.

-oldImplBase Generates skeletons compatible with pre-1.4 JDK ORBs. By default, the POA Inheritance Model server-side bindings are generated. This option provides backward-compatibility with older versions of the Java programming language by generating server-side bindings that are f2ImplBase Inheritance Model classes.

-pkgPrefix type prefix Wherever f2type is encountered at file scope, prefix the generated Java package name with f2prefix for all files generated for that type. The f2type is the simple name of either a top-level module, or an IDL type defined outside of any module.

-pkgTranslate type package Whenever the module name f2type is encountered in an identifier, replace it in the identifier with f2package for all files in the generated Java package. Note that f2pkgPrefix changes are made first. f2type is the simple name of either a top-level module, or an IDL type defined outside of any module, and must match the full package name exactly.
If more than one translation matches an identifier, the longest match is chosen. For example, if the arguments include:

    f3
      -pkgTranslate foo bar -pkgTranslate foo.baz buzz.fizz

The following translations would occur:

    f3
    foo          => bar
    foo.boo      => bar.boo
    foo.baz      => buzz.fizz
    foo.baz.bar  => buzz.fizz.bar

The following package names cannot be translated:

o f2org

o f2org.omg or any subpackages of f2org.omg

Any attempt to translate these packages will result in uncompilable code, and the use of these packages as the first argument after f2-pkgTranslate will be treated as an error.

-skeletonName xxx%yyy Use f2xxx%yyy as the pattern for naming the skeleton. The defaults are:

o %POA for the f2POA base class (f2-fserver or f2-fall)

o _%ImplBase for the f2oldImplBase class (f2-oldImplBase and (f2-fserver or f2-fall))

-td dir Use f2dir for the output directory instead of the current directory.

-tieName xxx%yyy Name the tie according to the pattern. The defaults are:

o %POATie for the f2POA tie base class (f2-fserverTie or f2-fallTie)

o %_Tie for the f2oldImplBase tie class (f2-oldImplBase and (f2-fserverTie or f2-fallTie))

-nowarn, -verbose Verbose mode.

-version Display version information and terminate.

See the Description section for more option information.

## Restrictions:

o Escaped identifiers in the global scope may not have the same spelling as IDL primitive types, f2Object, or f2ValueBase. This is because the symbol table is pre-loaded with these identifiers; allowing them to be redefined would overwrite their original definitions. (Possible permanent restriction).

o The f2fixed IDL type is not supported.

## Known Problems:

o No import generated for global identifiers. If you invoke on an unexported local impl, you do get an exception, but it seems to be due to a f2NullPointerException in the f2ServerDelegate DSI code.