|
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
- References
- Constants
- Typedef and java Mapping
- Names and Scope
- Pseudo Objects
- Object
- Contexts
- Reserved Names
- Any
- Constructing an Any
- Extracting an Any value
- Server For Any Example
- Any as out, inout Parameters
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
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
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.java | testHelper.java |
Time.java | _testSkeleton.java | testHolder.java |
TimeHelper.java | _testStub.java | testPackage/ |
TimeHolder.java | _tie_test.java |
_testImplBase.java | test.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() ;
}
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
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
Context | NVList |
ContextList | Object |
Current | ORB |
DynamicImplemenation | Principal |
Environment | Request |
ExceptionList | ServerRequest |
NamedValue | TypeCode |
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
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 ();
};
};
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
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
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
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 }
}
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 ); }
}
}
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:
short | char | Any |
long | wchar | Object |
longlong | string | Streamable |
ushort | wstring | Principle |
ulong | octet | TypeCode |
ulonglong | boolean | |
float | double | |
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 )
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 );
}
}
}
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_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_unused_29 | |
tk_unused_30 | tk_unused_31 | tk_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() ) )
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);
};
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);
}
}
}
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() ;
}
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