Presentation is loading. Please wait.

Presentation is loading. Please wait.

CORBA Any’s and TypeCodes Martin Senger

Similar presentations


Presentation on theme: "CORBA Any’s and TypeCodes Martin Senger"— Presentation transcript:

1 CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk

2 We want something, but we do not know what... Type-safety vs. flexibility –type-safe are objects with type known at the compile time - but it limits developers –most often the type-safe problems end by crashing programs - but not breaking security –inheritance is (probably) also sort of type- unsafe Methods to find the “real” type: –type-casting, narrowing, testing a variable,...

3 In CORBA, there are: org.omg.CORBA.Object –a super-class to all CORBA Objects –represents (only) interfaces –narrowing to the “real” type can be costly Any –and we are going to talk about it in details... DynAny –that’s a new story… - an extension of Any’s

4 A place of Any’s in CORBA Entity Object reference Value Type Abstract Interface Basic Value Constructed Values Struct Sequence Union Array Short Long LongLong UShort ULong ULongLong Float Double LongDouble Fixed Char WChar String WString Boolean Octet Enum Any

5 Some features... The any type permits the specification of values that can express any OMG IDL type An any contains a TypeCode and a value that is described by the TypeCode Each IDL language mapping provides operations that allow to insert and access the TypeCode and value contained in an any

6 Remember: The golden rule You can pass in Any only “things” whose types are known to the receiving program already in time of compilation Therefore the “things” in Any can be only –basic IDL types (boolean, float,…) –sequences of (most) basic IDL types String and WString are exceptions –types defined in IDL files known to both sites of communication

7 Creating Any’s (in Java) create an empty Any: Any any = orb.create_any(); insert the value into the Any –for basic IDL types: String str = “Hello World”; any.insert_string (str); –for compiled IDL types use their Helper classes: MyClass myClass = new MyClass (…); MyClassHelper.insert (any, myClass); –for sequences of basic IDL types use their Helper classes that are provided by ORB: int[] myNumbers = new int[] { 1, 2, 3, 4, 6 }; ShortSeqHelper.insert (any, myNumbers);

8 Extracting from Any’s (in Java) extract the value from an Any –for basic IDL types: int number = any.extract_short(); –for compiled IDL types use their Helper classes: MyClass myClass = MyClassHelper.extract (any); –for sequences of basic IDL types use their Helper classes that are provided by ORB: int[] myNumbers = ShortSeqHelper.extract (any); of course, first you have to know what type you have got in the Any...

9 CORBA TypeCodes TypeCodes are values that represent data types TypeCode is described as a CORBA interface –with methods to enquire what type it represents, –to ask if two TypeCodes are equal or equivalent, –and with some exceptions (BadParam, Bounds) TypeCodes are used in Any’s, by Interface Repository, by DII, etc...

10 The contents of a TypeCode a “kind” field enum TCKind { tk_null, tk_void, tk_short, tk_long, tk_ushort, tk_ulong, tk_float, tk_double, tk_boolean, tk_char, tk_octet, tk_any, tk_TypeCode, tk_Principal, tk_objref, tk_struct, tk_union, tk_enum, tk_string, tk_sequence, tk_array, tk_alias, tk_except, tk_longlong, tk_ulonglong, tk_longdouble, tk_wchar, tk_wstring, tk_fixed, tk_value, tk_value_box, tk_native, tk_abstract_interface }; a set of parameters appropriate for that “kind”

11 TypeCode parameters From the book: “Advanced CORBA Programming with C++” by Michi Henning and Steve Vinoski Each TypeCode has a “kind” field... …and for each “kind” field it has different parameters

12 Some TypeCode’s special kinds tk_null –this TC does not describe anything (“not-there” condition) tk_TypeCode –to insert TypeCodes into an Any tk_alias –describes typedef definitions tk_any –because an Any can contain another Any tk_void –used in the Interface Repository (never in Any’s)

13 Where TypeCodes come from don’t bother, usually they are created for you Helper classes have method returning TC: TypeCode tc = MyClassHelper.type(); ORB has methods for creating TC’s (examples): TypeCode create_struct_tc ( in RepositoryId id, in Identifier name, in StructMemberSeq members); TypeCode get_primitive_tc (in TCKind tcKind);

14 Notes on hands-on [skipping Any’s => will be done in Property Service hands-on] TypeCodes –go to directory “ TypeCodes ” –compile “ ExerciseTypeCodes.idl ” –implement conversion methods “ stringToEnum ”, “ enumToString ”, and “ printAll ” in the example “ ReadingColors.java ” –hint: look what parameters are available for “kind” enum


Download ppt "CORBA Any’s and TypeCodes Martin Senger"

Similar presentations


Ads by Google