Previous Next Contents Index


IContext interface

In NAS applications, some public methods require an IContext object as a parameter. The IContext interface itself has no public methods. You do not create or destroy IContext objects, but you can obtain them in several ways.

Package
com.kivasoft

Examples
The following examples describe different ways to obtain a context.

Example 1
From an AppLogic, an instance of this context is available as a member variable context within the superclass com.kivasoft.applogic.Applogic. The following code is used from within an AppLogic method:

     com.kivasoft.IContext kivaContext; 

kivaContext = this.context;
Example 2
From a servlet, the standard servlet context can be cast to IServerContext, and from there, a com.kivasoft.IContext instance can be obtained. The servlet code would look like this:

     ServletContext ctx = getServletContext(); 

com.netscape.server.IServerContext sc;

// legal cast within NAS
sc = (com.netscape.server.IServerContext) ctx;
com.kivasoft.IContext kivaContext = sc.getContext();
Example 3
As an alternative to Example 2, a caller can access the underlying AppLogic instance from a servlet and obtain the context there, as described in Example 1 for AppLogics. The servlet code would look like this:

     HttpServletRequest req; 

HttpServletRequest2 req2;
req2 = (HttpServletRequest2) req; // legal cast within NAS
AppLogic al = req2.getAppLogic();
com.kivasoft.IContext kivaContext;
kivaContext = al.context;
Example 4
From a bean, the standard javax.ejb.SessionContext or javax.ejb.EntityContext can be cast to an IServerContext, and from there, a com.kivasoft.IContext instance can be obtained. In a bean, the code would look like this:

     javax.ejb.SessionContext m_ctx; 

.
.
.
com.netscape.server.IServerContext sc;
// legal cast within NAS
sc = (com.netscape.server.IServerContext) m_ctx;
com.kivasoft.IContext kivaContext;
kivaContext = sc.getContext();
Example 5
From a Java extension, an instance of the context is supplied to the init( ) method of your extension, as shown by the following code:

   public int init(IObject obj) { 

com.kivasoft.IContext kivaContext = (com.kivasoft.IContext) obj;
.
.
.
Related Topics
com.kivasoft.applogic.AppLogic class (deprecated),
com.kivasoft.dlm.GXContext class,
com.netscape.server.ICallerContext interface,
com.netscape.server.IServerContext interface

Taking Advantage of NAS Features

 

© Copyright 1999 Netscape Communications Corp.