2003-02-27 00:16:22 +00:00
|
|
|
// Java All Types static client, cf all_types.idl for more details
|
2013-06-03 11:28:28 +00:00
|
|
|
// Copyright (C) 2006-2013, AdaCore
|
2003-02-26 23:41:03 +00:00
|
|
|
|
|
|
|
|
public class Client
|
|
|
|
|
{
|
|
|
|
|
public static void main( String [] args )
|
|
|
|
|
{
|
|
|
|
|
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init( args, null ) ;
|
|
|
|
|
|
|
|
|
|
org.omg.CORBA.Object obj = null ;
|
|
|
|
|
|
|
|
|
|
// Read the IOR from the `IOR` file.
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
java.io.FileInputStream file = new java.io.FileInputStream( "IOR" );
|
|
|
|
|
java.io.InputStreamReader input = new java.io.InputStreamReader( file );
|
|
|
|
|
java.io.BufferedReader reader = new java.io.BufferedReader( input );
|
|
|
|
|
String ref = reader.readLine();
|
|
|
|
|
obj = orb.string_to_object( ref ) ;
|
|
|
|
|
}
|
|
|
|
|
catch ( java.io.IOException ex )
|
|
|
|
|
{
|
|
|
|
|
ex.printStackTrace( ) ;
|
|
|
|
|
System.exit( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean pass;
|
|
|
|
|
|
|
|
|
|
// Narrow object reference.
|
2003-03-14 11:25:22 +00:00
|
|
|
idl.all_types ato = idl.all_typesHelper.narrow (obj);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// String type.
|
2003-02-26 23:41:03 +00:00
|
|
|
String my_string = "Hello distributed World in Java";
|
2003-03-14 11:25:22 +00:00
|
|
|
System.out.println ("echoString " + my_string.equals(ato.echoString (my_string)));
|
2003-02-26 23:41:03 +00:00
|
|
|
|
|
|
|
|
// Simple scalar types.
|
2003-03-14 11:25:22 +00:00
|
|
|
int res;
|
2013-06-03 11:28:28 +00:00
|
|
|
for (int i = 0; i < 10000; i++) {
|
2003-03-14 11:25:22 +00:00
|
|
|
res = ato.echoULong (456);
|
2013-06-03 11:28:28 +00:00
|
|
|
}
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
System.out.println ("echoBoolean " + ato.echoBoolean (true));
|
|
|
|
|
System.out.println ("echoShort " + ((short) 123 == ato.echoShort ((short) 123)));
|
|
|
|
|
System.out.println ("echoLong " + (456 == ato.echoLong (456)));
|
|
|
|
|
System.out.println ("echoULong " + (456 == ato.echoULong (456)));
|
|
|
|
|
System.out.println ("echoUShort " + ((short) 123 == ato.echoUShort ((short) 123)));
|
2013-06-03 11:28:28 +00:00
|
|
|
System.out.println ("echoFloat " + ((float) 2.7 == ato.echoFloat ((float) 2.7)));
|
|
|
|
|
|
|
|
|
|
// Value 34.4072222 is special: it becomes an invalid representation
|
|
|
|
|
// when byte swapped.
|
|
|
|
|
|
|
|
|
|
System.out.println ("echoFloat SW" + ((float) 34.4072222 == ato.echoFloat ((float) 34.4072222)));
|
2003-03-14 11:25:22 +00:00
|
|
|
System.out.println ("echoDouble " + (1.5 == ato.echoDouble (1.5)));
|
|
|
|
|
System.out.println ("echoChar " + ('A' == ato.echoChar ('A')));
|
|
|
|
|
System.out.println ("echoOctet " + ((byte) 5 == ato.echoOctet ((byte) 5)));
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Enum type.
|
|
|
|
|
idl.all_typesPackage.Color col = idl.all_typesPackage.Color.Blue;
|
|
|
|
|
System.out.println ("echoColor " + (idl.all_typesPackage.Color.Blue == ato.echoColor (col)));
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Unbounded sequence.
|
|
|
|
|
short u_seq[] = { 1, 2, 3, 4};
|
|
|
|
|
short res_u_seq[] = ato.echoUsequence (u_seq);
|
|
|
|
|
pass = true;
|
2013-06-03 11:28:28 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2003-03-14 11:25:22 +00:00
|
|
|
pass = pass & (res_u_seq[i] == u_seq[i]);
|
2013-06-03 11:28:28 +00:00
|
|
|
}
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
System.out.println ("echoUsequence " + pass);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Bounded sequence.
|
|
|
|
|
short b_seq[] = { 1, 2, 3, 4};
|
|
|
|
|
short res_b_seq[] = ato.echoUsequence (b_seq);
|
|
|
|
|
pass = true;
|
2013-06-03 11:28:28 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2003-03-14 11:25:22 +00:00
|
|
|
pass = pass & (res_b_seq[i] == b_seq[i]);
|
2013-06-03 11:28:28 +00:00
|
|
|
}
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
System.out.println ("echoBsequence " + pass);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Simple struct.
|
2013-06-03 11:28:28 +00:00
|
|
|
idl.all_typesPackage.simple_struct simple_s
|
2003-03-14 11:25:22 +00:00
|
|
|
= new idl.all_typesPackage.simple_struct (123, "Hello World!\n");
|
|
|
|
|
idl.all_typesPackage.simple_struct res_simple_s = ato.echoStruct (simple_s);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
pass = (simple_s.a == res_simple_s.a) && (simple_s.s.equals(res_simple_s.s));
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
System.out.println ("echoStruct " + pass);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Nested struct.
|
|
|
|
|
idl.all_typesPackage.nested_struct nested_s
|
|
|
|
|
= new idl.all_typesPackage.nested_struct (simple_s);
|
|
|
|
|
idl.all_typesPackage.nested_struct res_nested_s = ato.echoNestedStruct (nested_s);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
pass = (nested_s.ns.a == res_nested_s.ns.a) && (nested_s.ns.s.equals (res_nested_s.ns.s));
|
|
|
|
|
System.out.println ("echoNestedStruct " + pass);
|
|
|
|
|
|
|
|
|
|
// Object ref.
|
|
|
|
|
idl.all_types res_obj = ato.echoRef (ato);
|
|
|
|
|
// pass = org.omg.CORBA.portable.Delegate.is_equivalent(res_obj, ato);
|
|
|
|
|
// XXX how to test this ?
|
|
|
|
|
System.out.println ("echoRef " + true);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Union.
|
2013-06-03 11:28:28 +00:00
|
|
|
idl.all_typesPackage.myUnion union_t = new idl.all_typesPackage.myUnion();
|
2003-03-14 11:25:22 +00:00
|
|
|
union_t.Counter (4331);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// idl.all_typesPackage.myUnion res_union_t = ato.echoUnion (union_t);
|
|
|
|
|
// System.out.println ("echoUnion " + (res_union_t.Counter() == 4331));
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Union switch.
|
2013-06-03 11:28:28 +00:00
|
|
|
idl.all_typesPackage.myUnionEnumSwitch union_es_t
|
|
|
|
|
= new idl.all_typesPackage.myUnionEnumSwitch();
|
2003-03-14 11:25:22 +00:00
|
|
|
union_es_t.foo (4331);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2013-06-03 11:28:28 +00:00
|
|
|
// idl.all_typesPackage.myUnionEnumSwitch res_union_es_t
|
2003-03-14 11:25:22 +00:00
|
|
|
// = ato.echoUnionEnumSwitch (union_es_t);
|
|
|
|
|
//System.out.println ("echoUnionEnumSwitch " + (res_union_es_t.foo() == 4331));
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Simple array.
|
|
|
|
|
int simple_a[] = {1, 2, 3, 4, 5};
|
|
|
|
|
int res_simple_a[] = ato.echoArray(simple_a);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
pass = true;
|
2013-06-03 11:28:28 +00:00
|
|
|
for (int i = 0; i < 5 ; i++) {
|
2003-03-14 11:25:22 +00:00
|
|
|
pass = pass && (simple_a[i] == res_simple_a[i]);
|
2013-06-03 11:28:28 +00:00
|
|
|
}
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
System.out.println ("echoArray " + pass);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Multi-dimensionnal array.
|
|
|
|
|
int multi_a[][] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
|
|
|
|
|
int res_multi_a[][] = ato.echoMatrix (multi_a);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
pass = true;
|
2013-06-03 11:28:28 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2003-03-14 11:25:22 +00:00
|
|
|
pass = pass && (multi_a[i][j] == res_multi_a [i][j]);
|
2013-06-03 11:28:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2013-06-03 11:28:28 +00:00
|
|
|
System.out.println ("echoMatrix " + pass);
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Attributes.
|
|
|
|
|
ato.myColor (idl.all_typesPackage.Color.Blue);
|
|
|
|
|
System.out.println ("Attributes " + (idl.all_typesPackage.Color.Blue == ato.myColor()));
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// Read Only attributes.
|
|
|
|
|
int v1 = ato.Counter ();
|
|
|
|
|
int v2 = ato.Counter ();
|
|
|
|
|
System.out.println ("RO Attributes " + (v1 + 1 == v2));
|
2003-02-26 23:41:03 +00:00
|
|
|
|
2003-03-14 11:25:22 +00:00
|
|
|
// User exception.
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ato.testException (2845);
|
|
|
|
|
}
|
|
|
|
|
catch (idl.all_typesPackage.my_exception ex)
|
|
|
|
|
{
|
|
|
|
|
System.out.println ("User exception " + (ex.info == 2845));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// System exception.
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ato.testUnknownException (2485);
|
|
|
|
|
}
|
|
|
|
|
catch (org.omg.CORBA.UNKNOWN es)
|
|
|
|
|
{
|
|
|
|
|
System.out.println ("System exception " + true);
|
|
|
|
|
}
|
2003-02-26 23:41:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|