2.17.2: 2011-06-17

net.sf.basedb.util.extensions
Class ClientContext

java.lang.Object
  extended by net.sf.basedb.util.extensions.ClientContext
Direct Known Subclasses:
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 Summary
private  Map<String,Object> attributes
           
private  DbControl dc
           
private  Object item
           
private  SessionControl sc
           
 
Constructor Summary
  ClientContext(DbControl dc)
          Create a new context with a DbControl.
  ClientContext(DbControl dc, Object item)
          Create a new context with a DbControl and item.
  ClientContext(SessionControl sc)
          Create a new context with a session and no DbControl.
protected ClientContext(SessionControl sc, DbControl dc, Object item)
           
  ClientContext(SessionControl sc, Object item)
          Create a new context with a session and item but no DbControl.
 
Method Summary
 Object getAttribute(String name)
          Get an attribute of the context.
 Object getCurrentItem()
          Get the currently active item.
 DbControl getDbControl()
          Get the current DbControl.
 SessionControl getSessionControl()
          Get the current session control.
 void setAttribute(String name, Object value)
          Set an attribute of the context.
 void setCurrentItem(Object item)
          Set the currently active item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sc

private final SessionControl sc

dc

private final DbControl dc

item

private Object item

attributes

private Map<String,Object> attributes
Constructor Detail

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 Detail

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 Object 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

getAttribute

public Object 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

2.17.2: 2011-06-17