# idlj - The IDL-to-Java Compiler

> idlj generates Java bindings from a given IDL file.

## Synopsis

>     idlj [ options ] idl-file

> Options may appear in any order, but must precede the idl-file.

## Description

> The IDL-to-Java Compiler generates the Java bindings for a given IDL file. For binding details, see the IDL to Java document at the OMG website.

> ### Emitting Client and Server Bindings

> To generate Java bindings for an IDL file named My.idl:
> `idlj My.idl`
> This generates the client-side bindings and is equivalent to:
> `idlj -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:
> `idlj -fserver My.idl`
> Server-side bindings include the client-side bindings plus the skeleton, all of which are `ImplBase` (that is, Inheritance model) classes. If you want to generate both client side and server side bindings, use one of the following (equivalent) commands:
> `idlj -fclient -fserver My.idl`
> `idlj -fall My.idl`
> The default server-side model is the inheritance model. Given an interface `My` defined in `My.idl`, the file `_MyImplBase.java` is generated. You must provide the implementation for `My` and it must inherit from `_MyImplBase`.

> There is another server-side model called the Tie Model. This is a delegation model. The following commands generate the bindings for the Tie Model:

> `idlj -fserverTIE My.idl`
> `idlj -fallTIE My.idl`
> For the interface `My`, this will generate `My_Tie.java`. The constructor to `My_Tie` takes a `My`. You must provide the implementation for `My`, but it does not have to inherit from any other class, only the interface `My`. But to use it with the ORB, you must wrap your implementation within `My_Tie`. For instance:
> `MyImpl myImpl = new MyImpl ();`
> `My_Tie tie = new My_Tie (myImpl);`
> `orb.connect (tie);`
> 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.

> ### 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:

> > `idlj -td /altdir My.idl`

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

> ### Specifying Alternate Locations for Include Files

> If `My.idl` included another idl file, `MyOther.idl`, the compiler assumes that `MyOther.idl` resides in the local directory. If it resides in `/includes`, for example, then you would invoke the compiler with the following command:
> `idlj -i /includes My.idl`
> If `My.idl` also included `Another.idl` that resided in `/moreIncludes`, for example, then you would invoke the compiler with the following command:
> `idlj -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 `idl.config` in a directory that is listed in your CLASSPATH. Inside of `idl.config`, provide a line with the following form:
> `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 NT it is a semicolon, on AIX it is a colon, etc.

> ### 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:

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

> MyOther.idl

> `interface MyOther`
> `{`
> `};`

> The following command will only generate the java bindings for `My`:
> `idlj My.idl`
> To generate all of the types in `My.idl` and all of the types in the files that `My.idl` includes (in this example, `MyOther.idl`), use the following command:
> `idlj -emitAll My.idl`
> There is a caveat to the default rule. `#include` statements which appear at global scope are treated as described. These `#include` statements can be thought of as import statements. `#include` statements which appear within some enclosing scope are treated as true `#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:

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

> ` MyOther.idl
> `interface MyOther`
> `{`
> `};

> ` Embedded.idl
> `enum E {one, two, three};`

> Running the following command:
> `idlj My.idl`
> will generate the following list of Java files:
> `./MyHolder.java`
> `./MyHelper.java`
> `./_MyStub.java`
> `./MyPackage`
> `./MyPackage/EHolder.java`
> `./MyPackage/EHelper.java`
> `./MyPackage/E.java`
> `./My.java`
> Notice that `MyOther.java` was not generated because it is defined in an import-like `#include`. But `E.java` was generated because it was defined in a true `#include`. Also notice that since `Embedded.idl` was included within the scope of the interface `My`, it appears within the scope of `My` (that is,in `MyPackage`).

> If the -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:

> Widgets.idl

> `module Widgets`
> `{`
> `interface W1 {...};`
> `interface W2 {...};`
> `};`

> Running this file through the IDL-to-Java compiler will place the Java bindings for `W1` and `W2` within the package `Widgets`. But there is an industry convention that states that a company's packages should reside within a package named `com.<company name>`. The `Widgets` package is not good enough. To follow convention, it should be `com.abc.Widgets`. To place this package prefix onto the `Widgets` module, execute the following:
> `idlj -pkgPrefix Widgets com.abc Widgets.idl`
> If you have an IDL file which includes `Widgets.idl`, the -pkgPrefix flag must appear in that command also. If it does not, then your IDL file will be looking for a `Widgets` package rather than a `com.abc.Widgets` package.

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

> `PkgPrefix.<type>=<prefix>`
> So the line for the above example would be:
> `PkgPrefix.Widgets=com.abc`

> ### 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
> `idlj -d MYDEF My.idl`
> is the equivalent of putting the line `#define MYDEF` inside `My.idl`.

> ### Preserving Pre-Existing Bindings

> If the Java binding files already exist, the -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 -keep option is very useful. The command
> `idlj -keep My.idl`
> emit all client-side bindings that do not already exist.

> ### Viewing Progres of Compilation

> The Idl-to-Java compiler will generate status messages as it progresses through its phases of execution. Use the `-v` option to activate this "verbose" mode:
> `idlj -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 -version option on the command-line:

> `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:

> >     #define symbol

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

> -fside
>   Defines what bindings to emit. side is one of client, server, serverTIE, all, or allTIE. Assumes -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.

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

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

> -nowarn, -verbose
>   Verbose mode.

> -version
>   Display version information and terminate.

> -J option
>   Pass option to the Java virtual machine, where option is one of the options described on the reference page for the java application launcher. For example, -J-Xms48m sets the startup memory to 48 megabytes.
> See the Description section for more option information.

## Restrictions:

- Escaped identifiers in the global scope may not have the same spelling as IDL primitive types, `Object`, or `ValueBase`. 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).
- No local stubs, and no copy semantics when passing values locally (awaiting POA implementation).
- The `fixed` IDL type is not supported.
- The generated stubs do not support Serialization, due to IDL/Java mapping specification 1998-08-22 section 25.3.1.3 failing to specify what's required.
- Constants of type `octet` cannot be declared.

## Known Problems:

- The Java bindings for IDL valuetypes produced by the IDL compiler are not fully compliant with the latest OMG revision of the Objects By Value specification. Fully compliant bindings will be supported in a future release of the compiler.
- In some cases, the Java class generated by the compiler from an IDL valuetype definition may not contain a no-argument constructor. If this occurs, edit the generated code to add an empty public or protected no-argument constructor.
- The compiler may complete the compilation process without errors but fail to generate output. If this happens, specify the -emitAll option.
- The compiler does not recognize the deprecated CORBA::Principal type.
- Declaration of a constant and method or attribute having the same name in the same scope does not cause an error. The following IDL should cause an error but doesn't:

          interface t {
            const long foo = 1;
            attribute long foo;
          };

- The following IDL results in an error for "S is an undeclared type" in interface B. It shouldn't.

          interface A { struct S { short s; }; };
          interface B:A { typedef S new_S;
                          exception ex {S f1;}; // Error for "S" here
          };

- If a `union` defines another `union` in its default clause, the resulting Java class gets compilation errors. The work-around is to define the `nested union` outside of the containing `union`.