context clause is mapped to a Java method which takes an extra parameter, of type Context. For example:
// IDL
interface A {
void op(in unsigned long s)
context ("accuracy", "base");
};
is mapped to:
// Java
// In file _ARef.java.
public interface _ARef
extends IE.Iona.Orbix2.CORBA._ObjectRef {
public void op(int s,
IE.Iona.Orbix2.CORBA.Context _c)
throws IE.Iona.Orbix2.CORBA.SystemException;
}
The full definition of class Context is given in the OrbixWeb Reference Guide.
Context are pseudo-objects. A client can create a Context as follows:
// Java import IE.Iona.Orbix2.CORBA.Context; ... Context ctxt = Context.IT_create ();This creates an initially empty
Context object, to which identifier:value mappings can be added, and which can be passed to a function that takes a Context parameter.The default context for a process can be obtained by calling
get_default_context():
// Java // In package IE.Iona.Orbix2.CORBA, // in class ORB. static private Context default_context; public Context get_default_context();on the
_CORBA.Orbix object. For example:
// Java import IE.Iona.Orbix2.CORBA.Context; import IE.Iona.Orbix2._CORBA; ... Context defC = _CORBA.Orbix.get_default_context();This context provides a useful mechanism for sharing context changes between different parts of a program. Currently, it is initially empty.
Note that
Context objects can be nested, by specifying the parent parameter when creating a (child) Context, or by using the create_child() method.Figure 15.1 illustrates a context hierarchy. A hierarchy may be set up by specifying the parent context in the constructor; a name can also be given to a context:
// Java
Context c1 = Context.IT_create("high");
Context c2 = Context.IT_create(c1, "middle");
Context c3 = Context.IT_create(c2, "low");
|
Context provides a method get_values() to retrieve the property values in a Context; it is defined as:
// Java // In package IE.Iona.Orbix2.CORBA, // in class Context. public int get_values (String start_scope, Flags op_flags, String prop_name, IE.Iona.Orbix2.CORBA.NVListHolder hvalues);The
start_scope parameter to get_values() can be used to specify that the search for the values requested is to be made in a (direct or indirect) parent context of the context on which the call is made. The call searches backwards for a context with the specified name, and if this is found then it will search for the specified Identifiers in that context. For example, the following code specifies that the search for identifiers beginning with "sys_" should begin in the context named middle:
// Java
NVList list = NVList.IT_create();
NVListHolder listHolder (list);
int rv = 0;
try {
rv = c3.get_values ("middle", 0, "sys_*",
listHolder)))
}
catch (SystemException se) {
// Handle the error.
}
if (rv) {
// Iterate through the NVList
// returned in listHolder.value.
}
If zero is passed as the first parameter to get_values(), the search begins in the context which is the target of the call.
get_values() has a parameter of type Flags. When the null flag is passed to get_values(), searching of identifier(s) will propagate upwards to parent contexts. If the Flags parameter passed to get_values() is _CORBA.CTX_RESTRICT_SCOPE, then searching is restricted to the specified scope or Context object.