- Retrieve the name of the active work area to determine whether
the calling thread is associated with a work area.
Applications
use the getName method on the UserWorkArea interface to retrieve the name
of the current work area. If the thread is not associated with a work area,
the getName method returns null. In the following code example, the name of
the work area corresponds to the name of the class in which the work area
was begun.
public class SimpleSampleBeanImpl implements SessionBean {
...
public String [] test() {
// Get the work-area reference from JNDI.
...
// Retrieve the name of the work area. In this example,
// the name is used to identify the class in which the
// work area was begun.
String invoker = userWorkArea.getName();
...
}
}
- Overriding
work area properties. Server objects can override client
work area properties by creating their own, nested work area.
- Retrieve properties from a work area by using the get method.
The get method is intentionally lightweight; there are no declared
exceptions to handle. If there is no active work area, or if there is no such
property set in the current work area, the get method returns null.
Note: The
get method can raise a NotSerializableError in the relatively rare scenario
in which CORBA clients set composed data types and invoke enterprise-bean
interfaces.
The following example shows the retrieval of the
site-identifier and priority properties by the SimpleSampleBean. Notice that
one property was set into an outer work area by the client and the other property
was set into the nested work area by the server-side bean; the nesting is
transparent to the retrieval of the properties.
public class SimpleSampleBeanImpl implements SessionBean {
public String [] test() {
...
// Begin a nested work area.
userWorkArea.begin("SimpleSampleBean");
try {
userWorkArea.set("company",
SimpleSampleCompany.London_Development);
}
catch (NotOriginator e) {
}
SimpleSampleCompany company =
(SimpleSampleCompany) userWorkArea.get("company");
SimpleSamplePriority priority =
(SimpleSamplePriority) userWorkArea.get("priority");
...
}
}
- Optional: Retrieve a list of all the keys visible from
a work area.
The UserWorkArea interface provides the retrieveAllKeys
method for retrieving a list of all the keys visible from a work area. This
method takes no arguments and returns an array of strings. The retrieveAllKeys
method returns null if there is no work area associated with the thread. If
there is an associated work area that does not contain any properties, the
method returns an array of size 0.
- Query the mode of a work area property using the getMode method.
The UserWorkArea interface provides the getMode method determine
the mode of a specific property. This method takes the property's key as an
argument and returns the mode as a PropertyModeType object. If the specified
key does not exist in the work area, the method returns PropertyModeType.normal,
indicating that the property can be set and removed without error.
- Optional: Delete a work area property.
The
UserWorkArea interface provides the remove method to delete a property from
the current scope of a work area. If the property was initially set in the
current scope, removing it deletes the property. If the property was initially
set in an enclosing work area, removing it deletes the property until the
current scope is completed. When the current work area is completed, the deleted
property is restored.
The remove method takes the property's key as
an argument. Only properties with the modes normal and read-only can be removed.
Attempting to remove a fixed property creates the PropertyFixed exception.
Attempting to remove properties in work areas that originated in other processes
creates the NotOriginator exception.
Example
The server side of the SimpleSample application example, which
is included in the topic,Developing applications that use work areas, accepts remote invocations from clients. With each remote
call, the server also gets a work area from the client if the client has created
one. The work area is propagated transparently. None of the remote methods
includes the work area on its argument list.
In the example application,
the server objects use the work area interface for demonstration purposes
only. For example, the SimpleSampleBean intentionally attempts to write directly
to an imported work area, which creates the NotOriginator exception. Likewise,
the bean intentionally attempts to mask the read only SimpleSampleCompany,
which triggers the PropertyReadOnly exception. The SimpleSampleBean also nests
a work area and successfully overrides the priority property before invoking
the SimpleSampleBackendBean. A true business application would extract the
work area properties and use them to guide the local work. The SimpleSampleBean
mimics this by writing a message that function is denied when a request emanates
from a sales environment.