corba any’s and typecodes martin senger [email protected]
TRANSCRIPT
![Page 2: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/2.jpg)
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,...
![Page 3: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/3.jpg)
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
![Page 4: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/4.jpg)
A place of Any’s in CORBA
EntityEntity
Object referenceObject reference
Value TypeValue Type
Abstract InterfaceAbstract Interface
Basic ValueBasic Value
Constructed ValuesConstructed Values
StructSequenceUnionArray
StructSequenceUnionArray
ShortLongLongLongUShortULongULongLongFloatDoubleLongDoubleFixedCharWCharStringWStringBooleanOctetEnumAny
ShortLongLongLongUShortULongULongLongFloatDoubleLongDoubleFixedCharWCharStringWStringBooleanOctetEnumAny
![Page 5: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/5.jpg)
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
![Page 6: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/6.jpg)
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
![Page 7: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/7.jpg)
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);
![Page 8: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/8.jpg)
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...
![Page 9: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/9.jpg)
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...
![Page 10: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/10.jpg)
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”
![Page 11: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/11.jpg)
TypeCode parameters
TCKind Parameters tk_fixed Digits, scale tk_objref Repository ID, interface name tk_struct Structure name,
{ member name, member type code }… tk_union Union name, discriminator type code,
{ label value, member name, member type code }…, repository ID
tk_enum Enum name, { enumerator name }…, repository ID tk_string Bound tk_wstring Bound tk_sequence Element type code, bound tk_array Element type code, dimension tk_alias Alias name, aliased type code, repository ID tk_except Exception name, { member name, member type code }
repository ID
From the book: “Advanced CORBA Programming with C++” by Michi Henning and Steve Vinoski
Each TypeCodehas a “kind”
field...
…and for each“kind” field ithas differentparameters
![Page 12: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/12.jpg)
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)
![Page 13: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/13.jpg)
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);
![Page 14: CORBA Any’s and TypeCodes Martin Senger senger@ebi.ac.uk](https://reader035.vdocuments.mx/reader035/viewer/2022071709/56649ce55503460f949b2500/html5/thumbnails/14.jpg)
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