| Summary | The method signature in generated Java or C code from the IDL compiler only has the method name as opposed to the fully qualified name. |
|---|---|
| Article Number | 24785 |
| Environment | Orbacus-Orbix-Orbix for Java Developme-Windows-n/a Orbix 3.3.10 |
| Question/Problem Description | Take the following two IDL files: =======================
// one.idl
#include "two.idl"
module X
{
interface Y
{
A::FileDetails get_file_details(in octet inode);
};
};
======================= and =======================
// two.idl…
module A
{
struct FileDetails
{
long m_id;
string m_filename;
};
};
=======================Where one.idl includes two.idl. The following IDL compiler commands are used to compile those to IDL files. > idlj -jP p.q.r one.idl > idlj -jP p.q.r two.idl Where "-jP" flag specifies the package prefix. Since one.idl contains interface Y in module X there will be a generated Y.java file in directory p\\q\\r\\X. And the package name will be p.q.r.X (where p.q.r is picked up from the -jP option to the idlj command and the "X" is picked up from the module name in the one.idl file.) Similarly there will be a FileDetails.java file generated in directory p\\q\\r\\A (where A is the module name in two.idl.) Snippet of Y.java: ===================
//
// Java generated by the OrbixWeb IDL compiler
//
package p.q.r.X;
public interface Y extends org.omg.CORBA.Object
{
public A.FileDetails get_file_details(byte inode) ;
...
===================
Snippet of FileDetails.java: =============
//
// Java generated by the OrbixWeb IDL compiler
//
package p.q.r.A;
public final class FileDetails
implements java.lang.Cloneable
{
public int m_id;
public String m_filename;
=============... Now if I compile Y.java using the following Java command: > javac -cp p\\q\\r p\\q\\r\\X\\Y.java I get the following error: ==================
p\\q\\r\\X\\Y.java:11: cannot access A.FileDetails
bad class file: p\\q\\r\\A\\FileDetails.java
file does not contain class A.FileDetails
Please remove or make sure it appears in the correct subdirectory of the classpath.
public A.FileDetails get_file_details(byte inode) ;
^
1 error
==================The generated code Y.java is making reference to "A.FileDetails" and not fully qualified "p.q.r.A.FileDetails" name. |
| Clarifying Information | |
| Error Message | p\\q\\r\\X\\Y.java:11: cannot access A.FileDetails bad class file: p\\q\\r\\A\\FileDetails.java file does not contain class A.FileDetails Please remove or make sure it appears in the correct subdirectory of the classpath. public A.FileDetails get_file_details(byte inode) ; ^ 1 error |
| Defect/Enhancement Number | |
| Cause |
This is because the "-jP" flag specifying the package name only changes the "pakage" statement in the java generated file. It does not affect the internal references inside the code (e.g. function call to other packages). The "-jP" flag will also place the generated file in the right package directory. Internal references (like method names in another package) is determined by the module name(s) in the IDL file.
module X
{ module Y
{
interface Z
{
A::FileDetails get_file_details(in octet inode);
};
};
};
============the resulting generated file will contain the package X.Y as follows: =================
//
// Java generated by the OrbixWeb IDL compiler
//
package X.Y;
public interface Z
extends org.omg.CORBA.Object
{
public A.FileDetails get_file_details(byte inode) ;
public java.lang.Object _deref() ;
}
================= But reference to FileDetails, which is in the included IDL file (two.idl), will be pointing at A.FileDetails because in two.idl there is a module called "A". If one.idl is compiled using: > idlj -jP Q one.idl the generated Java code containing interface Z will be placed in Q\\X\\Y and will contain package Q.X.Y. If two.idl is compiled using: > idlj -jP P two.idl the generated Java code containing FileDetails will be placed in P\\A and will contain package P.A When compiling Z.java the compiler will complain that A.FileDetails is in the non-existant package A. |
| Resolution | To solve this problem instead of using the "-jP" flag to determine package name and placement, use module statements as appropriate in the IDL files. So in the above example, if FileDetails needs to be in package P.A then change two.idl to have an all inclusive module called P. Here's an example: ==========
module P
{
module A
{
struc FileDetails
{
long m_id;
string m_filename;
};
}; ============ |
| Workaround | |
| Notes | |
| Attachment |
| Created date: | 20 September 2011 |
|---|---|
| Last Modified: | 13 February 2013 |
| Last Published: | 12 May 2012 |
| First Published date: | 26 October 2011 |
#Orbix
#KnowledgeDocs