Saving Context Data

Sometimes it is useful to save context data centrally inside a session context and to use these data like a session-global variable. You should be very restrictive with this option - otherwise you may end up in a scenario in which any kind of data exchange is done by the context.

This document covers the following topics:


Different Levels of Context

The session management allows you to hold context information at two levels:

  • Session Context
    Within the session context, save data that you want to access from everywhere inside your adapters.

  • Subsession Context
    Within the subsession context, save data which you want to access from everywhere inside a subsession.

    Two different subsessions have also two different subsession contexts, i.e. the saved data are kept independent per subsession.

Accessing the Context

You obtain the context(s) by calling methods which are inherited from the Adapter class:

  • findSessionContext()
    Returns a context which is held for each session.

  • findSubSessionContext()
    Returns a context which is held for each subsession.

Both methods return a com.softwareag.cis.context.ILookupContext interface. This interface offers the possibility to bind and look up any objects.

public interface ILookupContext
{
    public Object lookup(String s, boolean reactWithErrorIfNotExist);
    public void bind(String s, Object o);
    public void releaseAllReferences();
}

When binding objects to a context, use a naming convention that is similar to the naming of your Java classes to avoid naming conflicts. Example:

...
findSessionContext.bind("com/yourcompany/application/parameter");
...

The context can be cleaned up by the releaseAllReferences() method. It is integrated into Application Designer's session management.

Typical Usage Scenarios

Examples of typical data that you save at the session context level:

  • Name of the user who is currently logged on.

  • Name of the system to which the user is currently logged on.

  • Language in which the user is logged on.

Examples of typical data that you save at the subsession context level:

  • ID of the object you are processing.

  • Temporary data you want to pass from one page to another.