Generating java from IDL (avoiding default package)
Asked Answered
T

1

8

I'm working with a LARGE legacy C++ code base with numerous IDL files that have all the types and constants declared outside of any module.

For C++, this results in code being generated to the global namespace -- ugly, but acceptable.

Now I'm trying to add Java clients to connect via CORBA. For Java, however, the types that are generated from the IDL (using the Sun/Oracle IDL compiler for java: idlj) are in the java default package because they are not within an IDL module. This results in Java compilation errors, as it is illegal to import from the default package.

I'm looking for the easiest way to correct the problem.

I've considered the following:

  1. Place a module declaration around all types. I'm currently working this solution, but it's VERY painful, based on the number of types affected and the impact to the large legacy C++ codebase.
  2. Use the -pkgPrefix or -pkgTranslate options. So far, I can't figure out how to accomplish this generically, since you must specify a module to translate from or specify a type to add a prefix to. -pkgPrefix can be used for a specific type, but we have hundreds of types and I'd rather not list a -pkgPrefix option specifically for each compiled file...
  3. Use a pragma directive? I'm not aware of one to use, but hoping a guru can point the way?
  4. ????

I find it difficult to believe that there's no easy way to force the IDL to be in a Java package if there's not an existing module that contains all the types. I'm hoping that I'm just missing the obvious!

Edit:

  • IDL-to-Java compiler is idlj.
  • Added example below.
  • Updated Item #2 (above) to clarify that using -pkgPrefix for each type is not feasible (unless it can be reasonably scripted?)

Example:


Foo.idl

struct Foo
{
  .
  .
  .
}

Foo.java: (note that no package is specified, meaning the default package):

public final class Foo implements org.omg.CORBA.portable.IDLEntity
{
  .
  .
  .
}

ClassUsesFoo.java:

package com.sigh;

import Foo;  // <-- this is an error
public class ClassUsesFoo
{
     private Foo f;
};
Tabshey answered 25/6, 2012 at 21:19 Comment(1)
Q: What tool are you using to generate Java from IDL? The standard Sun "idlj"? Could you give a specific example of 1) your command-line (with "-pkgPrefix") and 2) the resulting Java (that's not working)?Admeasure
T
3

you can play with options pkgPrefix and pkgTranslate as indicated in a french site I guess you had that part right but I detail just in case.

example:

interface T1
{
};
interface T2
{
};

You out pkgPrefix configuration in file idl.config

PkgPrefix.T1=aaa
PkgPrefix.T2=bbb

Following command

idlj -td dir T.idl

creates the files in (existing) directory dir:

dir/
├── aaa
│   ├── T1Helper.java
│   ├── T1Holder.java
│   ├── T1.java
│   ├── T1Operations.java
│   └── _T1Stub.java
└── bbb
    ├── T2Helper.java
    ├── T2Holder.java
    ├── T2.java
    ├── T2Operations.java
    └── _T2Stub.java

To create the configuration file, you can use a combination of grep / awk / sed / cut.

Tessi answered 14/9, 2012 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.