Class ClientContext

java.lang.Object
net.sf.basedb.util.extensions.ClientContext
Direct Known Subclasses:
AuthenticationContext, JspContext

public class ClientContext extends Object
Keeps information about the current context in the client application that extensions can use to decide what actions to generate. It is, for example, possible to check the permissions of logged in user and enable/disable certain actions if a condition is not met. Or, the extension may inspect the current item and decide if the extension can be used on that item or not.

The current context is passed to an ActionFactory twice, first to check if an extension should be enabled or not with the ActionFactory.prepareContext(InvokationContext) method. This method also allows an extension to write back information to the context. This may, for example, include information about which Javascript scripts to import or which stylesheets to load. The prepareContext method is only called once for each use of an extension.

The second time is when calling the ActionFactory.getActions(InvokationContext) method. This method can be called multiple times. For example, if an extension point is in a list context, the getActions method may be called one time for each item in the list. If so, the getCurrentItem() returns the currently active item.

Client applications may subclass this object to provide more information about the client environment. See, for example, the JspContext object.

Version:
2.7
Author:
nicklas
Last modified
$Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
  • Field Details

  • Constructor Details

    • ClientContext

      public ClientContext()
      Create a new context with no session or current item.
      Since:
      3.0
    • ClientContext

      public ClientContext(SessionControl sc)
      Create a new context with a session and no DbControl. The session is final and can't be replaced.
      Parameters:
      sc - The current session
    • ClientContext

      public ClientContext(SessionControl sc, Object item)
      Create a new context with a session and item but no DbControl. The session is final and can't be replaced. Use setCurrentItem(Object) to change the item.
      Parameters:
      sc - The current session
      item - The current item
    • ClientContext

      public ClientContext(DbControl dc)
      Create a new context with a DbControl. The DbControl is final and can't be replaced.
      Parameters:
      dc - An open DbControl
    • ClientContext

      public ClientContext(DbControl dc, Object item)
      Create a new context with a DbControl and item. The DbControl is final and can't be replaced. Use setCurrentItem(Object) to change the item.
      Parameters:
      dc - An open DbControl
      item - The current item
    • ClientContext

      protected ClientContext(SessionControl sc, DbControl dc, Object item)
  • Method Details

    • getSessionControl

      public SessionControl getSessionControl()
      Get the current session control.
    • getDbControl

      public DbControl getDbControl()
      Get the current DbControl. This can be null if the extension point doesn't provide an open DbControl. An extension MUST NEVER call DbControl.close() or DbControl.commit().
    • getCurrentItem

      public <T> T getCurrentItem()
      Get the currently active item. It can be any type of object, but the extension point may declare (in it's documentation) that the current item is always of a certain class.
      Returns:
      The current item, or null
    • setCurrentItem

      public void setCurrentItem(Object item)
      Set the currently active item.
      Parameters:
      item - The item that is the current item
    • getCurrentExtensionPoint

      public ExtensionPoint<?> getCurrentExtensionPoint()
      Get the currently active extension point.
      Since:
      3.19.3
    • setCurrentExtensionPoint

      protected void setCurrentExtensionPoint(ExtensionPoint<?> xtPoint)
    • getCurrentExtension

      public Extension<?> getCurrentExtension()
      Get the currently active extension point.
      Since:
      3.19.3
    • setCurrentExtension

      protected void setCurrentExtension(Extension<?> xt)
    • getAttribute

      public <T> T getAttribute(String name)
      Get an attribute of the context.
      Parameters:
      name - The name of the attribute
      Returns:
      The value, or null
    • setAttribute

      public void setAttribute(String name, Object value)
      Set an attribute of the context.
      Parameters:
      name - The name of the attribute
      value - The value, if null the attribute is removed
    • linkAttributes

      public void linkAttributes(ClientContext other)
      Link this context to the other context with respect to attributes. Existing attributes in this context will be copied to the other context. After this method call they will share the same internal storage so that updates to one context is reflected in the other.
      Since:
      3.19.4
    • storeAttributes

      public void storeAttributes(ItemContext cc, String key)
      Store all attributes that has been set on this context to the given ItemContext instance. Since the ItemContext is persistant for session it is possible to load the same attributes into another context later with loadAttributes(ItemContext, String)
      Since:
      3.19.4
    • loadAttributes

      public void loadAttributes(ItemContext cc, String key)
      Load attributes to this context from the given ItemContext instance.
      Since:
      3.19.4