Java Reference
In-Depth Information
the value of the attribute. There also must be a setter method. The Java signature
of the setter method for this CORBA attribute is a
void
method named
huh(int
value)
where the parameter is the type matching the type of the attribute. The
purpose of the setter method is to allow the client to pass in a value to assign to
fHuh
, therefore we use
public void huh (int huh) {
fHuh = huh;
}
We also need to implement
method1()
and
add()
, similarly to the way they
were implemented in the RMI example in Chapter 18. One difference is that
here we demonstrate accessing the
COR19
-
CONSTANT
and
SERVER
-
CONSTANT
values as follows:
public void method1 (String s)
{
String cor19
-
con
=
COR19
-
CONSTANT.value;
String server
-
con
=
SERVER
-
CONSTANT.value;
System.out.println (s + "/" + cor19
-
con + "/" +
server
-
con);
}
The
add()
method is straightforward as well. The complete code for this example
is available on the Web Course.
The
demo()
operation was created to demonstrate the use of an
inout
param-
eter and the corresponding Holder object. To access the base object contained
in a Holder object, we use the public instance variable named
value
. Since
demo()
was declared in the IDL as receiving an
inout CustomData
struc-
ture, the Java implementation receives a
CustomDataHolder
object, and we
obtain the contained
CustomData
object as follows:
CustomData cd = custom
-
data
-
holder.value;
where
custom
-
data
-
holder
is the input parameter. Then we can manipulate
the fields within
cd
at will. Recall that
CustomData
was declared to have two
fields - a
float
and an
int
(well, an IDL
long
,which becomes an
int
in the
Java implementation). For demonstration purposes, we multiply the
float
field
by two and the
int
field by three:
public void demo (CustomDataHolder custom
-
data
-
holder)
throws Cor19UserException
{
CustomData cd
=
custom
-
data
-
holder.value;
cd.someFloatValue *
=
2;
cd.someIntegerValue *
=
3;
}
Search WWH ::
Custom Search