Main page / Java Connectivity page

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: 
	MinCor\DemoJava\InnerClasses

Mapping: 
	Java inner class   <--->   standalone .Net class



Example 

The Java server:

    Interface     : InnerClasses\Greetings.java
    Implementation: InnerClasses\GreetingsImpl.java

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

        // ...
    }	
    




The .Net client:

    Implementation: ClientImpl.cs
    IDL-File      : InnerClasses.idl
    Generated     : InnerClasses.cs
          

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

    a_oFrmClt.writeLog("\nInfo returned:\n");
    a_oFrmClt.writeLog(oRetInfo.name);
    a_oFrmClt.writeLog(oRetInfo.message);
    a_oFrmClt.writeLog(oRetInfo.businessNote);
    a_oFrmClt.writeLog(oRetInfo.privateNote);
    // ...
          

    
    Note, that we have to add several items to the list of assemblies to be searched for 
    by the .Net Reflection. This list is set using the "-AddAssembly" parameter during ORB 
    initialization:
    
    private static string[] m_strORBInit = {"-ORBEndpoint iiop://localhost:8545/portspan=100", 
                                            "-ORBInitRef NameService=corbaloc:iiop:1.2@localhost:1050/NameService",
                                            "-ORBDebug",
                                            "-AddAssembly DotNetClient.exe,JavaBuiltinTypesCF.dll,MinCorCF.dll" };