InnerClasses - A Java Serializable with an Inner Class

Description:

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.

Source:

\DemoJava\InnerClasses

Mapping:

Java inner class <---> standalone .NET class


Example

Step 1. Write the Java server:

  public class GreetingsImpl extends PortableRemoteObject implements Greetings  
  {
    public Info hello( Info oInfo) throws RemoteException 
    {
      ...
      Info oRet = new Info();
      ...
      return oRet;
    }
  }

Serializable with inner class: InnerClasses\Info.java

 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;
   }
   
   ...
 }

Step 2. Write the .NET client:

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);
  ...

Step 3. Run the example

a.) Start the sun name service on port 10050:

    > 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.