Any
implements the IDL basic type any
, which allows the specification of values that can express an arbitrary IDL type. This allows a program to handle values whose types are not known at compile time. The IDL type any
is most often used in code that uses the Interface Repository or the Dynamic Invocation Interface (DII).Consider the following interface:
// IDL interface Example { void op(in any value); };A client can construct an
any
to contain an arbitrary type of value and then pass this in a call to operation op()
. A process receiving an any
must determine what type of value it stores and then extract the value.
any
is mapped to a Java class which conceptually contains a TypeCode
and a value:
// Java package IE.Iona.Orbix2.CORBA; public class Any extends MarshalBuffer implements IDLCloneable, Marshalable { // Constructors public Any(); public Any(int kind); public Any(Any a); public Any(Any a, int kind); public Any(TypeCode tc, byte[] value, int length, boolean do_copy) throws SystemException; public Any(TypeCode tc, byte[] value, int length, boolean do_copy, int kind) throws SystemException; // Methods public void copy(Any a); public java.lang.Object clone(); public boolean equals(java.lang.Object _obj); public String toString(); public void reset(); public void resetPosition(); public void setTypeCode(TypeCode tc); // Insert Methods public void insertShort(short s) throws SystemException; public void insertLong(int l) throws SystemException; public void insertUShort(short s) throws SystemException; public void insertULong(int l) throws SystemException; public void insertFloat(float f) throws SystemException; public void insertDouble(double d) throws SystemException; public void insertChar(char c) throws SystemException; public void insertOctet(byte b) throws SystemException; public void insertString(String s) throws SystemException; public void insertString(String s, int length) throws SystemException; public void insertBoolean(boolean b) throws SystemException; public void insertAny(Any a) throws SystemException; public void insertTypeCode(TypeCode tc) throws SystemException; public void insertObject( IE.Iona.Orbix2.CORBA._ObjectRef oref) throws SystemException; public void insertPrincipal(String p) throws SystemException; public void insert(Marshalable m) throws SystemException; // Array Insert Methods public void insertShortArray(short s[], int length) throws SystemException; public void insertLongArray(int l[], int length) throws SystemException; public void insertUShortArray(short s[], int length) throws SystemException; public void insertULongArray(int l[], int length) throws SystemException; public void insertFloatArray(float f[], int length) throws SystemException; public void insertDoubleArray(double d[], int length) throws SystemException; public void insertCharArray(char c[], int length) throws SystemException; public void insertOctetArray(byte b[], int length) throws SystemException; public void insertStringArray(String s[], int length) throws SystemException; public void insertBooleanArray(boolean b[], int length) throws SystemException; public void insertAnyArray(Any a[], int length) throws SystemException; public void insertTypeCodeArray(TypeCode tc[], int length) throws SystemException; public void insertObjectArray( IE.Iona.Orbix2.CORBA._ObjectRef oref[], int length) throws SystemException; public void insertArray(Marshalable m[], int length) throws SystemException; // Extract Methods public short extractShort() throws SystemException; public int extractLong() throws SystemException; public short extractUShort() throws SystemException; public int extractULong() throws SystemException; public float extractFloat() throws SystemException; public double extractDouble() throws SystemException; public char extractChar() throws SystemException; public byte extractOctet() throws SystemException; public String extractString() throws SystemException; public boolean extractBoolean() throws SystemException; public Any extractAny() throws SystemException; public TypeCode extractTypeCode() throws SystemException; public IE.Iona.Orbix2.CORBA._ObjectRef extractObject() throws SystemException; public void extract(Marshalable m) throws SystemException; // Array Extract Methods public int extractShortArray(short s[],int length) throws SystemException; public int extractLongArray(int l[],int length) throws SystemException; public int extractUShortArray(short s[],int length) throws SystemException; public int extractULongArray(int l[],int length) throws SystemException; public int extractFloatArray(float f[],int length) throws SystemException; public int extractDoubleArray(double d[],int length) throws SystemException; public int extractCharArray(char c[],int length) throws SystemException; public int extractOctetArray(byte b[],int length) throws SystemException; public int extractStringArray(String s[], int length) throws SystemException; public int extractBooleanArray(boolean b[],int length) throws SystemException; public int extractAnyArray(Any a[], int length) throws SystemException; public int extractTypeCodeArray(TypeCode tc[], int length) throws SystemException; public int extractObjectArray( IE.Iona.Orbix2.CORBA._ObjectRef oref[], int length) throws SystemException; public int extractArray(Marshalable m[], int length) throws SystemException; // Data Accessor Methods public TypeCode type(); public byte[] value(); public boolean containsType(TypeCode t); }
CORBA.TypeCode
public Any();
Any
with a TypeCode
of type tk_null
and with a zero value. The easiest and the type-safe way to construct an Any
is to use the default constructor and then use the appropriate insertion method to insert a value into the Any
. For example,
// Java short s = 10; IE.Iona.Orbix2.CORBA.Any a = new IE.Iona.Orbix2.CORBA.Any (); a.insertShort (s);
Any
constructors.
public Any(int kind);
Any
with a TypeCode
of type tk_null
and with a zero value. The parameter
kind
indicates the marshalling protocol associated with the Any
object. This parameter can take the value _CORBA.IT_ORBIX_OR_KIND
, to indicate native Orbix marshalling, or _CORBA.IT_INTEROPERABLE_OR_KIND
, to indicate IIOP marshalling (see Chapter 9, "ORB Interoperability" of the OrbixWeb Programming Guide).
Notes:
CORBA defined. See Also:
Other Any
constructors.
public Any(Any a);
TypeCode
and value of a
.
Any
constructors.
public Any(Any a, int kind);
TypeCode
and value of a
. The parameter
kind
indicates the marshalling protocol associated with the Any
object. This parameter can take the value _CORBA.IT_ORBIX_OR_KIND
, to indicate native Orbix marshalling, or _CORBA.IT_INTEROPERABLE_OR_KIND
, to indicate IIOP marshalling (see Chapter 9, "ORB Interoperability" of the OrbixWeb Programming Guide).
Notes:
CORBA defined. See Also:
Other Any
constructors.
public Any(TypeCode tc, byte[] value, int length, boolean do_copy) throws SystemException;
Any
with a specific TypeCode
and value. This constructor is needed for cases where it is not possible to use the default constructor and Any
insertion methods.Note that this constructor is not type-safe; the programmer is responsible for ensuring consistency between the
TypeCode
and the actual type of the argument stored in the value
buffer.
OtherAny
constructors.
public Any(TypeCode tc, byte[] value, int length, boolean do_copy, int kind) throws SystemException;
Any
with a specific TypeCode
and value. This constructor is needed for cases where it is not possible to use the default constructor and Any
insertion methods.Note that this constructor is not type-safe; the programmer is responsible for ensuring consistency between the
TypeCode
and the actual type of the argument stored in the value
buffer.The parameter
kind
indicates the marshalling protocol associated with the Any
object. This parameter can take the value _CORBA.IT_ORBIX_OR_KIND
, to indicate native Orbix marshalling, or _CORBA.IT_INTEROPERABLE_OR_KIND
, to indicate IIOP marshalling (see Chapter 9, "ORB Interoperability" of the OrbixWeb Programming Guide).
Parameters:
Notes:
OrbixWeb specific. See Also:
OtherAny
constructors.
public boolean containsType(TypeCode t);
TypeCode
associated with the Any
matches a specified type.
true
if TypeCode
parameter matches Any.type()
, otherwise returns false
.
CORBA.Any.type()
CORBA.Any.setTypeCode()
CORBA.TypeCode
public java.lang.Object clone();
Any
object, copies the existing Any
to the new object and returns the new object.
CORBA.Any.copy()Copy constructor.
public void copy(Any a);
Any
type and value into an existing Any
object.
CORBA.Any.clone()
Copy constructor.
public boolean equals(java.lang.Object _obj);
type
and value
of the Any
to those of an Any
referenced by parameter _obj
.
true
if the Any
matches the parameter object, otherwise returns false
.
public short extractShort() throws SystemException; public int extractLong() throws SystemException; public short extractUShort() throws SystemException; public int extractULong() throws SystemException; public float extractFloat() throws SystemException; public double extractDouble() throws SystemException; public char extractChar() throws SystemException; public byte extractOctet() throws SystemException; public String extractString() throws SystemException; public boolean extractBoolean() throws SystemException; public Any extractAny() throws SystemException; public TypeCode extractTypeCode() throws SystemException; public IE.Iona.Orbix2.CORBA._ObjectRef extractObject() throws SystemException; public void extract(Marshalable m) throws SystemException;
Any
. The type of an Any
can be determined via the accessor method CORBA.Any.type()
, and the value can then be extracted using the appropriate extraction method. To extract a user-defined type from an
Any
, the IDL source file must be compiled with the -A
switch. The generic extraction method extract()
should then be used to extract values of this type. For example, take the definition:
// IDL struct Details { string name; };Compilation with the
-A
switch allows struct Details
to be extracted as follows:
// Java Details d = new Details (); IE.Iona.Orbix2.CORBA.Any a; // Somehow initialise a. if ((a.type ()).equals (Details._tc_Details)) { try { a.extract (d); } catch (IE.Iona.Orbix2.CORBA.SystemException se) { ... } }If the extraction is successful, the value of the
Any
will be copied to the target object.Note that IDL enumerated types should be extracted from an
Any
using the method extractLong()
.
CORBA.Any.insert()
public int extractShortArray(short s[],int length) throws SystemException; public int extractLongArray(int l[],int length) throws SystemException; public int extractUShortArray(short s[],int length) throws SystemException; public int extractULongArray(int l[],int length) throws SystemException; public int extractFloatArray(float f[],int length) throws SystemException; public int extractDoubleArray(double d[],int length) throws SystemException; public int extractCharArray(char c[],int length) throws SystemException; public int extractOctetArray(byte b[],int length) throws SystemException; public int extractStringArray(String s[], int length) throws SystemException; public int extractBooleanArray(boolean b[],int length) throws SystemException; public int extractAnyArray(Any a[], int length) throws SystemException; public int extractTypeCodeArray(TypeCode tc[], int length) throws SystemException; public int extractObjectArray( IE.Iona.Orbix2.CORBA._ObjectRef oref[], int length) throws SystemException; public int extractArray(Marshalable m[], int length) throws SystemException;
Any
. The type of an Any
can be determined via the accessor method CORBA.Any.type()
, and the value can then be extracted using the appropriate extraction method. To extract an array of a user-defined type from an
Any
, the IDL source file must be compiled with the -A
switch. The generic extraction method extractArray()
should then be used to extract arrays of this type. For example, take an IDL
long
array containing ten elements: such an array can be extracted as follows:
// Java int la[] = new long[10]; IE.Iona.Orbix2.CORBA.Any a; // Somehow initialise a. if ((a.type ()).equals (IE.Iona.Orbix._CORBA._tc_long)) { try { a.extract (la, 10); } catch (IE.Iona.Orbix2.CORBA.SystemException se) { ... } }If the extraction is successful, the value of the
Any
will be copied to the target array.
CORBA.Any.insertArray()
public void insertShort(short s) throws SystemException; public void insertLong(int l) throws SystemException; public void insertUShort(short s) throws SystemException; public void insertULong(int l) throws SystemException; public void insertFloat(float f) throws SystemException; public void insertDouble(double d) throws SystemException; public void insertChar(char c) throws SystemException; public void insertOctet(byte b) throws SystemException; public void insertString(String s) throws SystemException; public void insertString(String s, int length) throws SystemException; public void insertBoolean(boolean b) throws SystemException; public void insertAny(Any a) throws SystemException; public void insertTypeCode(TypeCode tc) throws SystemException; public void insertObject( IE.Iona.Orbix2.CORBA._ObjectRef oref) throws SystemException; public void insertPrincipal(String p) throws SystemException; public void insert(Marshalable m) throws SystemException;
Any
. Any previous value held by the
Any
will be discarded. Each insertion method takes a copy of the value being inserted.To insert a user-defined type into an
Any
, the IDL source file must be compiled with the -A
switch. The generic insertion method insert()
can then be used to insert the type into an Any
. For example, for the definition:
// IDL struct AStruct { string str; float number; };the
insert()
method can be used as follows:
// Java IE.Iona.Orbix2.CORBA.Any a = new IE.Iona.Orbix2.CORBA.Any (); AStruct s; // Somehow initialise s. try { a.insert (s); } catch (IE.Iona.Orbix2.CORBA.SystemException se) { ... }Note that enumerated IDL types represent a special case for insertion into an
Any
. The IDL compiler maps an IDL enum to a Java int
. Therefore, enum
values should not be inserted into an Any
using the generic insert()
method. Instead, an
int
value should be inserted into the Any
using the insertLong()
method and the type of the Any
should be set explicitly to the TypeCode
value for the required enum
. The TypeCode
can be set using the method setTypeCode()
, while the TypeCode
value for the enumerated type is generated by the IDL compiler (with the -A
switch).
CORBA.Any.extract()
CORBA.Any.setTypeCode()
public void insertShortArray(short s[], int length) throws SystemException; public void insertLongArray(int l[], int length) throws SystemException; public void insertUShortArray(short s[], int length) throws SystemException; public void insertULongArray(int l[], int length) throws SystemException; public void insertFloatArray(float f[], int length) throws SystemException; public void insertDoubleArray(double d[], int length) throws SystemException; public void insertCharArray(char c[], int length) throws SystemException; public void insertOctetArray(byte b[], int length) throws SystemException; public void insertStringArray(String s[], int length) throws SystemException; public void insertBooleanArray(boolean b[], int length) throws SystemException; public void insertAnyArray(Any a[], int length) throws SystemException; public void insertTypeCodeArray(TypeCode tc[], int length) throws SystemException; public void insertObjectArray( IE.Iona.Orbix2.CORBA._ObjectRef oref[], int length) throws SystemException; public void insertArray(Marshalable m[], int length) throws SystemException;
Any
. Each insertion method takes two parameters: the array value to be inserted and the length of the array.Any previous value held by the
Any
will be discarded. Each insertion method takes a copy of the array being inserted.To insert an array of a user-defined type into an
Any
, the IDL source file for that type must be compiled with the -A
switch.The generic insertion method insertArray()
can then be used to insert the type into an Any
. For example, consider the definition:
// IDL struct AStruct { string str; float number; };The
insertArray()
method can be used to insert an array of this type as follows:
// Java IE.Iona.Orbix2.CORBA.Any a = new IE.Iona.Orbix2.CORBA.Any (); AStruct sa[] = new AStruct[10]; // Somehow complete initialisation of sa. try { a.insertArray (sa, 10); } catch (IE.Iona.Orbix2.CORBA.SystemException se) { ... }As for single element insertion, arrays of IDL enumerated types (which map to Java
int
) should be inserted using insertLongArray()
. The type of the Any
should then be set to the TypeCode
value for the enumerated type using the method setTypeCode()
.
CORBA.Any.extractArray()
CORBA.Any.insert()
CORBA.Any.setTypeCode()
public void reset();
tk_null
to the type of the Any
and null
to the value.
public void resetPosition();
Any
to the beginning of the value
buffer. This is required when extracting a value from an Any
more than once.
CORBA.Any.extract()
CORBA.Any.extractArray()
public void setTypeCode(TypeCode tc);
Any
. Required when inserting IDL enumerated types; these are inserted as type long
and the type is then set explicitly.
CORBA.Any.insert()
CORBA.Any.insertArray()
public String toString();
Any
in a string of the following format:
Any with typecode "<type>"
public TypeCode type();
TypeCode
associated with the Any
.
CORBA.Any.value()
CORBA.Any.setTypeCode()
CORBA.TypeCode
public byte[] value();
Any
.
CORBA.Any.type()