In Java, a class can contain inner classes. According to the OMG Java-to-IDL mapping, such an inner class is mapped into a separate IDL interface with a composite name formed by concatenating the name of the outer class, two underscores, and the name of the inner class, f.e.:
inner class 'TheInner' within class 'TheOuter' --> interface 'TheOuter__TheInner'
|
This example defines a serializable Java class with a serializable inner class
as a member.
The Java class is passed by value by a sample method exhibited in a separate
interface.
Java inner class <---> standalone .NET class
public class GreetingsImpl extends PortableRemoteObject implements Greetings
{
public Info hello( Info oInfo) throws RemoteException
{
...
Info oRet = new Info();
...
return oRet;
}
}
|
public class Info implements Serializable
{
...
private Notes m_oNotes;
public Info()
{
m_oNotes = new Notes();
}
public class Notes implements Serializable
{
public String m_strPrivateNote;
public String m_strBusinessNote;
}
...
}
|
In .NET the Java Serializable is mapped in two separate classes: Info and
Info__Notes.
Like for every serializable an implementation has to be provided (see also the
Objects by value example for the mapping of Java Serializables).
Implementations of Serializables: InfoImpl.cs, Info__NotesImpl.cs
Usage:
...
InnerClasses.InfoImpl oInfo = new InnerClasses.InfoImpl();
oInfo.name = "Ted";
oInfo.message = "just a sample";
oInfo.businessNote = "Inner class demo";
oInfo.privateNote = "this value is from an inner class";
InnerClasses.Info oRetInfo = oGreetings.hello( oInfo);
System.Console.WriteLine("\nInfo returned:\n");
System.Console.WriteLine(" Name :{0}", oRetInfo.name);
System.Console.WriteLine(" Message :{0}", oRetInfo.message);
System.Console.WriteLine(" Business note:{0} (Inner class)", oRetInfo.businessNote);
System.Console.WriteLine(" Private note :{0} (Inner class)", oRetInfo.privateNote);
...
|
> start orbd -ORBInitialPort 10050
|
(could also use startNameService.bat located in the DemoJava directory to quick start the name service)
b.) Start the java server by using JNDI CosNaming and work with a name service running on 'localhost' at port '10050':
> start java -cp .;Server.jar -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:10050 Server
|
(could also use buildServer.bat and startServer.bat located in the JavaServer directory to quick build and run the Java Server)
c.) Start the .NET Client.