com.webmethods.portal.bizPolicy
Interface IContext

All Superinterfaces:
Cloneable, ILocaleInfo, IPrincipalData, IURI, Serializable

public interface IContext
extends IPrincipalData, IURI, ILocaleInfo

IContext is the java bean that represents the current user's portal session. It provides a protocol independent way of accessing request and session information. It is guaranteed to always be available for any business logic or presentation logic. If an IContext is accessed from outside of the scope of a current session then it will act as the system user.

IContext can be accessed from anywhere with the following code examples:

 IContext context = com.webmethods.portal.bizPolicy.impl.ContextFactory.acquireContext(true);
 
Or if you have access to the HttpServletRequest,
 //request = HttpServletRequest
 IContext context = com.webmethods.portal.bizPolicy.impl.ContextFactory.acquireContext(request);
 

IContext holds the following types of information:

See Also:
com.webmethods.portal.framework.presentation.PresentationData

Field Summary
static String DEFAULT_CLASS
          The default implementation of this interface: com.webmethods.portal.bizPolicy.impl.Context
static String ID
           
static int SCOPE_APPLICATION
          Deprecated.  
static int SCOPE_REQUEST
          All attributes are stored with a scope.
static int SCOPE_SESSION
          All attributes are stored with a scope.
static String SERVICE_NAME
           
 
Method Summary
 boolean canImpersonate(IThingID userID)
          Checks if the current user can impersonate other users
 void clearAttributes(int scope)
          Clears all the attributes on the IContext that stored stateful user information for a given scope.
 void clearMessage()
          Clears any information message
 Object getAttribute(Object key, int scope)
          Gets an attribute on the IContext that was used to store stateful user information.
 Map getAttributes(int scope)
          Retrieves all the attributes on the IContext that store stateful user information for the given scope.
 Object getCommandResult()
          Retrieves the result of the last command.
 IContextProvider getContextProvider()
          Returns instance of ContextProvider which created this context instance
 IURI getCurrentResource()
          Retrieves the current resource.
 String getCurrentResourceType()
          (Probably) Only valid in the webApplication context The type might be for instance: folder, content, wm_xt_rssfeed, etc...
 IPrincipalData getInternalPrincipalData()
          Get the internal storage for the IPrincipalData.
 IInformationalMessage getMessage()
          Retrieves a message if available
 IContextState getTrackedState()
          Deprecated. for use only with the PostRenderCache
 ITraits getTraits()
          Get the ITraits object for the current context.
 boolean hasMessage()
          Whether the current context has a message
 boolean hasRenderedPageStart()
          This is a clue to the presentation system that this context's request has already rendered the start of a page In case of error, don't rerender all the header info
 void impersonate(IThingID userID, boolean isAdmin)
          Have this context impersonate a user.
 void initialize(IPrincipalData info)
          Initialize this context using the given principal data object.
 boolean isSystemContext()
          Returns true if this is a system context.
 boolean isValid()
          Describes whether this is context is in a valid state.
 void removeAttribute(Object key, int scope)
          Removes an attribute on the IContext that stored stateful user information.
 void setAttribute(Object key, Object value, int scope)
          Sets an attribute on the IContext in order to store stateful user information.
 void setAttributes(Map properties, int scope)
          Sets attributes on the IContext in order to store stateful user information.
 void setCommandResult(Object obj)
          Sets the command result on the context with SCOPE_REQUEST scope.
 void setCurrentResource(IURI uri)
          Set the current resource.
 void setCurrentResourceType(String type)
           
 void setInformationalMessage(int severity, String message)
          This sets a message that can later be retrieved (stored on the session)
 void setRenderedPageStart()
           
 void setSystemContext(boolean isSystemContext)
          Set whether this is a system context.
 void setTraits(ITraits traits)
          Set the ITraits object for the current context.
 void startTracking()
          Deprecated. for use only with the PostRenderCache
 void stopTracking()
          Deprecated. for use only with the PostRenderCache
 
Methods inherited from interface com.webmethods.portal.bizPolicy.IPrincipalData
getDN, getDomain, getPassword, getUri, getUserDirectoryURI, getUserID, getUserName, isAdminSession, isAnonymous, isAuthenticated, isLoginSession, isPrivilegedInfo, setAuthentication, setDN, setDomain, setInfo, setIsAdminSession, setIsAnonymous, setIsLoginSession, setIsPrivilegedInfo, setUri, setUserID, setUserName
 
Methods inherited from interface com.webmethods.portal.system.IURI
clone, getSegment, getSegments, getSegments, getServiceName, getSize, initialize, toString
 
Methods inherited from interface com.webmethods.portal.bizPolicy.ILocaleInfo
evaluateLocale, getiContext, getLocale, setLocale, setLocale
 

Field Detail

SERVICE_NAME

static final String SERVICE_NAME
See Also:
Constant Field Values

ID

static final String ID

DEFAULT_CLASS

static final String DEFAULT_CLASS
The default implementation of this interface: com.webmethods.portal.bizPolicy.impl.Context

See Also:
Constant Field Values

SCOPE_REQUEST

static final int SCOPE_REQUEST
All attributes are stored with a scope. This scope represents attributes that last for a single request. To associate an attribute with the current request, you can do the following:

 context.setAttribute("myAttrKey", myObjectVal, IContext.SCOPE_REQEUST);
 
Then to retrieve the attribute later during the same request use the follwoing:

 Object myObjectVal = context.getAttribute("myAttrKey", IContext.SCOPE_REQEUST);
 

See Also:
IContext.setAttribute(java.lang.Object, java.lang.Object, int), IContext.getAttribute(java.lang.Object, int), Constant Field Values

SCOPE_SESSION

static final int SCOPE_SESSION
All attributes are stored with a scope. This scope represents attributes that last for a user's session. To associate an attribute with the current user's session, you can do the following:

 context.setAttribute("myAttrKey", myObjectVal, IContext.SCOPE_SESSION);
 
Then to retrieve the attribute later during the same request use the follwoing:

 Object myObjectVal = context.getAttribute("myAttrKey", IContext.SCOPE_SESSION);
 

See Also:
IContext.setAttribute(java.lang.Object, java.lang.Object, int), IContext.getAttribute(java.lang.Object, int), Constant Field Values

SCOPE_APPLICATION

static final int SCOPE_APPLICATION
Deprecated. 
All attributes are stored with a scope. This scope represents attributes that last for the length of the application.

See Also:
Constant Field Values
Method Detail

isValid

boolean isValid()
Describes whether this is context is in a valid state. This is only used internally, and should not be necessary to ever check.

Returns:
true if valid, false otherwise

getContextProvider

IContextProvider getContextProvider()
Returns instance of ContextProvider which created this context instance

Returns:

initialize

void initialize(IPrincipalData info)
Initialize this context using the given principal data object. This is only used internally, and should not be necessary to ever invoke.

Parameters:
info - IPrincipalData object

getTraits

ITraits getTraits()
Get the ITraits object for the current context. This allows you to inspect the current registered traits that control the runtime execution of user's interaction with Portal Verbs.

Returns:
the ITraits object

setTraits

void setTraits(ITraits traits)
Set the ITraits object for the current context. This allows you to set the registered traits that control the runtime execution of user's interaction with Portal Verbs.

Parameters:
traits - the ITraits object.
See Also:
IContext.getTraits()

setAttribute

void setAttribute(Object key,
                  Object value,
                  int scope)
Sets an attribute on the IContext in order to store stateful user information.

Parameters:
key - the identifier of the data
value - the data
scope - the scope of the data
See Also:
IContext.SCOPE_REQUEST, IContext.SCOPE_SESSION

setAttributes

void setAttributes(Map properties,
                   int scope)
Sets attributes on the IContext in order to store stateful user information.

Parameters:
properties - A Map of attributes to store
scope - the scope of the data
See Also:
IContext.SCOPE_REQUEST, IContext.SCOPE_SESSION

getAttribute

Object getAttribute(Object key,
                    int scope)
Gets an attribute on the IContext that was used to store stateful user information.

Parameters:
key - the identifier of the data
scope - the scope of the data
Returns:
the data if found, NULL otherwise
See Also:
IContext.SCOPE_REQUEST, IContext.SCOPE_SESSION

removeAttribute

void removeAttribute(Object key,
                     int scope)
Removes an attribute on the IContext that stored stateful user information.

Parameters:
key - the identifier of the data
scope - the scope of the data
See Also:
IContext.SCOPE_REQUEST, IContext.SCOPE_SESSION

clearAttributes

void clearAttributes(int scope)
Clears all the attributes on the IContext that stored stateful user information for a given scope.

Parameters:
scope - the scope of the data
See Also:
IContext.SCOPE_REQUEST, IContext.SCOPE_SESSION

getAttributes

Map getAttributes(int scope)
Retrieves all the attributes on the IContext that store stateful user information for the given scope.

Parameters:
scope - the scope of the data
Returns:
Map of attributes
See Also:
IContext.SCOPE_REQUEST, IContext.SCOPE_SESSION

getCommandResult

Object getCommandResult()
Retrieves the result of the last command. If this request invoked a Portal Verb, then the result (if any) will be placed on the context in the Request Scope.

Returns:
the command result value.
See Also:
IContext.setCommandResult(java.lang.Object)

setCommandResult

void setCommandResult(Object obj)
Sets the command result on the context with SCOPE_REQUEST scope.

Parameters:
obj - the command result value to set.
See Also:
IContext.getCommandResult()

getCurrentResource

IURI getCurrentResource()
Retrieves the current resource. (Probably) Only valid in the webApplication context.

Returns:
the IURI of the current resource

setCurrentResource

void setCurrentResource(IURI uri)
Set the current resource.

Parameters:
uri - the IURI of the current resource
See Also:
IContext.getCurrentResource()

getCurrentResourceType

String getCurrentResourceType()
(Probably) Only valid in the webApplication context The type might be for instance: folder, content, wm_xt_rssfeed, etc...

Returns:
the type of the current reosurce

setCurrentResourceType

void setCurrentResourceType(String type)
See Also:
IContext.getCurrentResourceType()

startTracking

void startTracking()
Deprecated. for use only with the PostRenderCache

Start tracking session parameters.


stopTracking

void stopTracking()
Deprecated. for use only with the PostRenderCache

Stop tracking session parameters.


getTrackedState

IContextState getTrackedState()
Deprecated. for use only with the PostRenderCache

Return session tracking state.

Returns:
the IContextState of the current context.

isSystemContext

boolean isSystemContext()
Returns true if this is a system context. This allows the Session Monitor portlet distinguish between system sessions (non-user) and normal user sessions.

Returns:
True if this is a system context, False otherwise.
See Also:
IContext.setSystemContext(boolean)

setSystemContext

void setSystemContext(boolean isSystemContext)
Set whether this is a system context.

Parameters:
isSystemContext - True if this is a system context, False otherwise.
See Also:
IContext.isSystemContext()

canImpersonate

boolean canImpersonate(IThingID userID)
Checks if the current user can impersonate other users

Parameters:
userID - the user to impersonate
Returns:
true or false

impersonate

void impersonate(IThingID userID,
                 boolean isAdmin)
                 throws PortalException
Have this context impersonate a user.

Parameters:
userID - The IThingID of the user to impersonate.
isAdmin - True if this is an administrator.
Throws:
PortalException - if userID is invalid

getInternalPrincipalData

IPrincipalData getInternalPrincipalData()
Get the internal storage for the IPrincipalData.

Returns:
the IPrincipalData object for the current context.

hasRenderedPageStart

boolean hasRenderedPageStart()
This is a clue to the presentation system that this context's request has already rendered the start of a page In case of error, don't rerender all the header info


setRenderedPageStart

void setRenderedPageStart()
See Also:
IContext.hasRenderedPageStart()

setInformationalMessage

void setInformationalMessage(int severity,
                             String message)
This sets a message that can later be retrieved (stored on the session)

Parameters:
severity -
message - already localized message
See Also:
IInformationalMessage

getMessage

IInformationalMessage getMessage()
Retrieves a message if available

See Also:
IInformationalMessage

clearMessage

void clearMessage()
Clears any information message

See Also:
IInformationalMessage

hasMessage

boolean hasMessage()
Whether the current context has a message

See Also:
IInformationalMessage