The valuetype IDL type is used to pass state data over the wire. A
valuetype is best thought of as a struct with inheritance and methods. Valuetypes differ from normal interfaces in that they contain properties to describe the valuetype's state, and contain implementation details beyond that of an interface.
Valuetype instances can be shared by other valuetypes across or within other instances. Other IDL data types such as struct,
union, or
sequence cannot be shared. Valuetypes that are shared are
isomorphic between the sending context and the receiving context.
Null valuetypes can be passed over the wire, unlike IDL data types such as structs, unions, and sequences. For instance, by boxing a struct as a boxed valuetype, you can pass a null value struct. For more information, see
“Boxed valuetypes”.
Factories are methods that can be declared in valuetypes to create valuetypes in a portable way. For more information on Factories, see
“Implementing factories”.
Abstract valuetypes contain only methods and do not have state. They may not be instantiated. Abstract valuetypes are a bundle of operation signatures with a purely local implementation.
These two valuetypes contain a variable balance, and they inherit the
get_name method from the abstract valuetype
Account.
In the IDL sample (for more information, see “Valuetype IDL code sample”), you define a valuetype named
Point that defines a point on a graph. It contains two public variables, the
x and
y coordinates, one private variable that is the
label of the point, the valuetype's
factory, and a
print method to print the point.
When you have defined your IDL, compile it using idl2java to create source files. You then modify the source files to implement your valuetypes.
In the obv\PointImpl.java, the
PointImpl class extends the
Point class, which is generated from the IDL.
In the following example, the generated Point_init class contains the
create method declared in your IDL. This class extends
org.omg.CORBA.portable.ValueFactory . The
PointDefaultFactory class implements
PointValueFactory as shown in the following example.
PointImpl() is called to create a new valuetype, which is read in from the
InputStream by
read_value.
You must call read_value or your Factory will not work, and you may not call any other method.
To register your Factory with the VisiBroker ORB, call ORB.register_value_factory. This is required only if you do not name your factory
valuetypenameDefaultFactory. For more information on registering Factories, see
“Registering valuetypes”.
public class PointDefaultFactory implements PointValueFactory {
public java.io.Serializable read_value (
org.omg.CORBA_2_3.portable.InputStream is) {
java.io.Serializable val = new PointImpl();
// create and initialize value
// It is very important that this call is made.
val = ((org.omg.CORBA_2_3.portable.InputStream)is).read_value(val);
return val;
}
public Point create (int x, int y, java.lang.String z) {
// IMPLEMENT:
return NO_IMPLEMENT;
}
}
When the VisiBroker ORB receives a valuetype, it will look for that type's factory. It will look for a factory named <valuetype>DefaultFactory. For instance, the Point valuetype's factory is called
PointDefaultFactory. If the correct factory doesn't conform to this naming schema (
<valuetype>DefaultFactory), you must register the correct factory so the VisiBroker ORB can create an instance of the valuetype.
Each language mapping specifies how and when registration occurs. If you created a factory with the <valuetype>DefaultFactory naming convention, this is considered implicitly registering that factory, and you do not need to explicitly register your factory with the VisiBroker ORB.
To register a factory that does not conform to the <valuetype>DefaultFactory naming convention, call
register_value_factory. To unregister a factory, call
unregister_value_factory on the VisiBroker ORB. You can also lookup a registered valuetype factory by calling
lookup_value_factory on the VisiBroker ORB.
Boxed valuetypes allow you to wrap non-value IDL data types as valuetypes. For example, the following IDL boxed valuetype declaration,
When you declare a custom valuetype, the valuetype extends org.omg.CORBA.portable. CustomValue, as opposed to
org.omg.CORBA.portable.StreamableValue, as in a regular valuetype. The compiler does not generate read or write methods for your valuetype.
You must implement your own read and write methods by using org.omg.CORBA. portable.DataInputStream and
org.omg.CORBA.portable.DataOutputStream to read and write the values, respectively.
Truncatable valuetypes allow you to treat an inherited valuetype as its parent.
The following IDL defines a valuetype checkingAccount that is inherited from the base type
Account and can be truncated in the receiving object.