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:

  • Information about the current user: username, domain, thingID.
  • Information about the current request: currentResourceURI, and current Requested Type. (see PresentationData for more information.
  • Attributes: Session or request based attributes that you can use like a Map.
  • Traits: An advanced topic that controls the runtime execution of Portal Verbs.

See Also:
  • Field Details

    • SERVICE_NAME

      static final String SERVICE_NAME
      See Also:
    • 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:
    • 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:
    • 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:
    • SCOPE_APPLICATION

      @Deprecated 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:
  • Method Details

    • 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:
    • 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:
    • setAttributes

      void setAttributes(Map<? extends Object,? extends Object> 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:
    • 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:
    • 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:
    • 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:
    • getAttributes

      Map<Object,Object> 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • startTracking

      @Deprecated void startTracking()
      Deprecated.
      for use only with the PostRenderCache
      Start tracking session parameters.
    • stopTracking

      @Deprecated void stopTracking()
      Deprecated.
      for use only with the PostRenderCache
      Stop tracking session parameters.
    • getTrackedState

      @Deprecated 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:
    • 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:
    • 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:
    • 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:
    • getMessage

      IInformationalMessage getMessage()
      Retrieves a message if available
      See Also:
    • clearMessage

      void clearMessage()
      Clears any information message
      See Also:
    • hasMessage

      boolean hasMessage()
      Whether the current context has a message
      See Also: