This section presents guidelines that you should follow when deriving your own classes from Context or ContextCache.
If you are creating a direct Context subclass, you should define the following String constants, since their values will be required when obtaining a context: CONTEXT_CLASS_NAME, CONTEXT_CACHE_CLASS_NAME, and CONTEXT_TYPE. The first two constants should contain the fully-qualified class names for your Context and ContextCache subclasses. The last constant declares the name of the context type appropriate to this new Context subclass.
If you are creating a direct Context subclass, you should define a unique value for CONTEXT_TYPE that is descriptive of the type of service provided by the new context. If you are simply extending an existing major Context subclass (for example, MailContext, CalContext, or ABContext), you should just inherit the value for CONTEXT_TYPE that is defined in those subclasses.
If you are creating a direct Context subclass, you should define a getContext method for obtaining its instances. The body of the method can simply call Context.getContext, casting the result to the current class:
public static <YOUR_SUBCLASS_NAME> getContext(PageContext
pageContext)throws Exception
{
return (<YOUR_SUBCLASS_NAME>) Context.getContext(pageContext,
CONTEXT_CLASS_NAME,CONTEXT_CACHE_CLASS_NAME,CONTEXT_TYPE);
}
If you are extending an existing Context subclass, such as ABContext, the result can be cast to that class instead:
return (ABContext) Context.getContext(pageContext,
CONTEXT_CLASS_NAME,CONTEXT_CACHE_CLASS_NAME,CONTEXT_TYPE);
When overriding either version of init, make sure that your subclass invokes super as its first line:
// Inside a Context subclass public void init(HttpServletRequest request, SSOToken session, SSOAdapter ssoAdapter) throws Exception{ super.init(request,session,<your_custom_service_name>,ssoAdapter); ... // your app-specific code from here on |
Failure to do so will prevent the context from being initialized correctly.
The base Context class registers itself as a listener for changes fired from user sessions, and your subclass will inherit this base behavior. You might want to override this method to perform additional tasks beyond what is defined in the parent implementation. Typically this will involve code for cleaning up the context when the session becomes invalid.
If you have created a direct Context subclass, you should also create a direct ContextCache subclass that corresponds to the direct Context subclass. For example, IMContext and IMContextCache. Using this example, the new cache class need only contain the following:
package com.whatever.im; import com.sun.portal.wireless.taglibs.base.*; public class IMContextCache extends ContextCache { } |
If you are extending an existing major Context subclass, you should not create a new ContextCache subclass. Instead, you should use the same ContextCache subclass that is already defined.