SDSU CS 696 Emerging Technologies: Distributed Objects
Spring Semester, 1998
CORBA IDL part 3

To Lecture Notes Index
© 1998, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 21-Apr-98

Contents of Doc 22, CORBA IDL part 3

  1. References
    1. Constants
    2. Typedef and java Mapping
    3. Names and Scope
    4. Pseudo Objects
    5. Object
    6. Contexts
    7. Reserved Names
    8. Any
      1. Constructing an Any
      2. Extracting an Any value
      3. Server For Any Example
      4. Any as out, inout Parameters

References


CORBA Specification V2.1 Chapter 3 OMG IDL Syntax and Semantics, August 1997

CORBA Specification V2.2 Chapter 24, Mapping of OMG IDL to Java, February 1998

OrbixWeb Programmer's Guide, IONA Technologies PLC, November 1997, chapter 5 Introduction to CORBA IDL, chapter 6 IDL to Java Mapping pp 79 - 140, chapter 17 Type Any pp 331-336

Iona's IDL compiler


Doc 22, CORBA IDL part 3 Slide # 2

Constants

const long SecondsPerMinute = 60;
interface ConstantExample
   {
   const short MinutesPerHour = 60;
   const long SecondsPerDay = SecondsPerMinute  * 
                                 MinutesPerHour * 24;
   };

Constants can be
integer types, char types, boolean,
string types, floating point types
named constants of one of the above types
Mapping Constants
// Java generated by the OrbixWeb IDL compiler

public interface ConstantExample
    extends org.omg.CORBA.Object
{
    public static final short MinutesPerHour = 60;
    public static final int SecondsPerDay = 86400;
    public java.lang.Object _deref() ;
}

// Java generated by the OrbixWeb IDL compiler

public interface SecondsPerMinute {
    public static final int value = 60;
}

Note what happens when const is outside of an interface

Doc 22, CORBA IDL part 3 Slide # 3

Typedef and java Mapping

struct Time {
   short hour;
   short minute;
   short second;
};
   
typedef Time CORBA_Time;

interface test {
   void saveTime( inout CORBA_Time when );
};

Files Created

CORBA_TimeHelper.java_testOperations.javatestHelper.java
Time.java_testSkeleton.javatestHolder.java
TimeHelper.java_testStub.javatestPackage/
TimeHolder.java_tie_test.java
_testImplBase.javatest.java

// Java generated by the OrbixWeb IDL compiler

import Time;
import TimeHelper;
import TimeHolder;
import CORBA_TimeHelper;

public interface test
    extends org.omg.CORBA.Object
{
    public void saveTime(TimeHolder how) ;
    public java.lang.Object _deref() ;
}

Doc 22, CORBA IDL part 3 Slide # 4

Names and Scope


An entire OMG IDL file forms a naming scope

The following kinds of definitions form nested scopes:
module
interface
structure
union
operation
exception

OMG IDL is NOT case sensitive,

However, all references to a definition must use the same case as the defining occurrence


Doc 22, CORBA IDL part 3 Slide # 5

Pseudo Objects


Pseudo objects are constructs whose definition is usually specified in IDL, but whose mapping is language specific

These are CORBA "system" objects
CORBA Pseudo Objects
ContextNVList
ContextListObject
CurrentORB
DynamicImplemenationPrincipal
EnvironmentRequest
ExceptionListServerRequest
NamedValueTypeCode


You can only use the following pseudo objects as attribute or operation parameter types in an IDL specification (according to OrbixWeb documentation)
NamedValue
Principle
TypeCode


Doc 22, CORBA IDL part 3 Slide # 6

Object


All IDL defined object inherit from CORBA.Object

module CORBA {

interface Object {                                      // PIDL
        ImplementationDef    get_implementation ();
        InterfaceDef    get_interface ();
        boolean   is_nil();
        Object   duplicate ();
        void     release ();
        boolean   is_a ( in string logical_type_id);
        boolean   non_existent();
        boolean   is_equivalent ( in Object other_object );
        unsigned long    hash( in unsigned long maximum );

        Status create_request (
                in Context      ctx,
                in Identifier   operation,
                in NVList       arg_list,
                inout NamedValueresult,
                out Request     request,
                in Flags                req_flags
        );
        Policy   get_policy ( in PolicyType   policy_type );
        DomainManagersList   get_domain_managers ();
        };
};

Doc 22, CORBA IDL part 3 Slide # 7
get_implementation ()
Deprecated

get_interface ()
Returns an object in the Interface Repository
More on this when we cover the Interface Repository

is_nil();
Determines if the object reference is nil

duplicate ();
Duplicates the object reference

release ();
Releases the object reference
Does not affect the object implementation

is_a ( in string logical_type_id);
Check to see if object is of a given type

non_existent();
Test to see if an object has been destroyed

is_equivalent ( in Object other_object );
Checks to see if object references are equivalent

hash( in unsigned long maximum );
hash value for the object reference

Status create_request ();
get_policy ( in PolicyType policy_type );
get_domain_managers ();
Covered Later


Doc 22, CORBA IDL part 3 Slide # 8

Contexts


A context expression specifies which elements of the client's context may affect the performance of a request by the object

Will see more of this when we cover Dynamic Interface Invocation and Naming Service

Reserved Names


Naming convention

If any IDL construct will map to a Java name that is reserved, the IDL construct name will have an underscore character prepended to it when mapped to Java


Doc 22, CORBA IDL part 3 Slide # 9

Any


Holds any type
IDL For Any Example
struct SampleStruct
   {
   string bar;
   };

interface SimpleAny
   {
   void  anyTest( in any test );
   };

interface InOutAny
   {
   void  holdAny( inout any trouble );
   };

Some Java Code Generated by the IDL compiler
public final class SampleStruct 
    implements java.lang.Cloneable 
{
    public String bar;

    public SampleStruct () {}

    public SampleStruct (String bar) {
        this.bar = bar;
    }

    public java.lang.Object clone()  { code removed    }
}

Doc 22, CORBA IDL part 3 Slide # 10

Constructing an Any

import IE.Iona.OrbixWeb._CORBA;
import org.omg.CORBA.*;

public class AnyClient {
   public static void main(String args[]) {
      ORB myOrb = ORB.init();
   
      SimpleAny remoteObject;
      
      Any parameter = myOrb.create_any();
      
      short toPass = 42;
      
      SampleStruct passMeToo = new SampleStruct();
      passMeToo.bar = "Hi Mom";
      
      String hostname = "eli.sdsu.edu";
      String serverLabel = ":Any";

      try {
         remoteObject = 
            SimpleAnyHelper.bind(serverLabel, hostname );
         
         parameter.insert_short( toPass );
         remoteObject.anyTest( parameter );

         SampleStructHelper.insert( parameter, passMeToo );
         remoteObject.anyTest( parameter );
         
         }
      catch ( SystemException error )
         { System.out.println( error ); }
      }
   }

Doc 22, CORBA IDL part 3 Slide # 11
insert Methods - Basic Types

For each basic type there is an insert method in the class org.omg.CORBA.Any of the form:
insert_<type>( <type> );

Sample usage:
parameter.insert_short( aShort );
parameter.insert_ushort( anUnsignedShort );

The types are:

shortcharAny
longwcharObject
longlongstringStreamable
ushortwstringPrinciple
ulongoctetTypeCode
ulonglongboolean
floatdouble
insert Methods - User Defined Types

For each user defined type there is an insert method in the class <type>Helper:
public static void insert (org.omg.CORBA.Any   any, 
                           <type> value)

Sample usage
SampleStructHelper.insert( parameter, passMeToo )

Doc 22, CORBA IDL part 3 Slide # 12

Extracting an Any value

import org.omg.CORBA.*;

class SimpleAnyImplementation extends _SimpleAnyImplBase
   {
   public void anyTest(org.omg.CORBA.Any test)
      {
      short myShort;
      SampleStruct myStruct;
      
      TypeCode theType = test.type();
      if ( theType.kind() == TCKind.tk_short )
         {
         System.out.println( "It was a short" );
         myShort = test.extract_short();
         }
      
      else if ( theType.equal( SampleStructHelper.type() ) )
         {
         System.out.println( "It was user defiend type" );
         myStruct = SampleStructHelper.extract( test );
         }
      }
   }

Doc 22, CORBA IDL part 3 Slide # 13
Testing for the Basic Types

Extract the TypeCode from the Any
Then compare the type to one in TCKind
      TypeCode theType = test.type();
      if ( theType.kind() == TCKind.tk_short )


The class org.omg.CORBA.TCKind contains the following basic types:
tk_nulltk_voidtk_shorttk_long
tk_ushorttk_ulongtk_float
tk_doubletk_booleantk_chartk_octet
tk_anytk_TypeCodetk_Principaltk_objref
tk_structtk_uniontk_enumtk_string
tk_sequencetk_arraytk_aliastk_except
tk_longlongtk_ulonglongtk_longdoubletk_wchar
tk_wstringtk_fixedtk_unused_29
tk_unused_30tk_unused_31tk_estruct

Testing for User-Defined Types

Extract the TypeCode from the Any
Then compare the type to the one returned from the type's helper class
      else if ( theType.equal( SampleStructHelper.type() ) )


Doc 22, CORBA IDL part 3 Slide # 14
TypeCode Methods
interface TypeCode { // PIDL
   exception Bounds {};
   exception BadKind {};

   // for all TypeCode kinds
   boolean equal (in TypeCode tc);
   TCKind kind ();

   // for tk_objref, tk_struct, tk_union, tk_enum, tk_alias, and tk_except
   RepositoryId id () raises (BadKind);

   // for tk_objref, tk_struct, tk_union, tk_enum, tk_alias, and tk_except
   Identifier name () raises (BadKind);

   // for tk_struct, tk_union, tk_enum, and tk_except
   unsigned long member_count () raises (BadKind);
   Identifier member_name (in unsigned long index) 
      raises (BadKind, Bounds);

   // for tk_struct, tk_union, and tk_except
   TypeCode member_type (in unsigned long index) 
      raises (BadKind, Bounds);

   // for tk_union
   any member_label (in unsigned long index) 
      raises (BadKind, Bounds);
   TypeCode discriminator_type () raises (BadKind);
   long default_index () raises (BadKind); 

   // for tk_string, tk_sequence, and tk_array
   unsigned long length () raises (BadKind);

   // for tk_sequence, tk_array, and tk_alias
   TypeCode content_type () raises (BadKind);

   // for tk_fixed
   unsigned short fixed_digits() raises (BadKind);
   short fixed_scale() raises (BadKind);

   // deprecated interface
   long param_count (); 
   any parameter (in long index) raises (Bounds); 
};

Doc 22, CORBA IDL part 3 Slide # 15

Server For Any Example

import IE.Iona.OrbixWeb._CORBA;
import IE.Iona.OrbixWeb.CORBA.ORB;

public class AnyServer
   {
   public static void main (String args[])
      {
      org.omg.CORBA.ORB orb =
         org.omg.CORBA.ORB.init();
      
      SimpleAny serverObject = null;
         
      try
         {
         serverObject = new SimpleAnyImplementation();
         _CORBA.Orbix.impl_is_ready( "Any" );
         System.out.println("Server going Down");
         }
      catch ( org.omg.CORBA.SystemException corbaError)
         {
         System.out.println("Exception " + corbaError);
         }
      }
   }

Doc 22, CORBA IDL part 3 Slide # 16

Any as out, inout Parameters

The IDL
interface InOutAny
   {
   void  holdAny( inout any trouble );
   };


Now the any itself must be wrapped in a Holder!
// Java generated by the OrbixWeb IDL compiler 

public interface InOutAny
    extends org.omg.CORBA.Object
{
    public void holdAny(org.omg.CORBA.AnyHolder trouble) ;

    public java.lang.Object _deref() ;
}


Doc 22, CORBA IDL part 3 Slide # 17
A sample Client
import IE.Iona.OrbixWeb._CORBA;
import org.omg.CORBA.*;

public class AnyHolderClient
   {
   public static void main(String args[])
      {
      ORB myOrb = ORB.init();
   
      InOutAny remoteObject;
      
      Any parameter = myOrb.create_any();
      short theData = 42;
      AnyHolder inOut = new AnyHolder();
      
      String hostname = "eli.sdsu.edu";
      String serverLabel = ":Any";

      try
         {
         remoteObject = 
            InOutHelper.bind(serverLabel, hostname );
         
         parameter.insert_short( theData );
         inOut.value = parameter;
         remoteObject.holdAny( inOut );

         parameter = inOut.value;
         // Now extract the data you want
         }
      catch ( SystemException error )
         {
         System.out.println( error );
      }
   }



visitors since 24-Mar-98