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 theActionFactory.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. TheprepareContext
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, thegetActions
method may be called one time for each item in the list. If so, thegetCurrentItem()
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
Fields Modifier and Type Field Description private Map<String,Object>
attributes
private DbControl
dc
private Object
item
private SessionControl
sc
-
Constructor Summary
Constructors Modifier Constructor Description ClientContext()
Create a new context with no session or current item.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.ClientContext(SessionControl sc, Object item)
Create a new context with a session and item but no DbControl.protected
ClientContext(SessionControl sc, DbControl dc, Object item)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
Constructor Detail
-
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. UsesetCurrentItem(Object)
to change the item.- Parameters:
sc
- The current sessionitem
- 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. UsesetCurrentItem(Object)
to change the item.- Parameters:
dc
- An open DbControlitem
- 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 callDbControl.close()
orDbControl.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
-
-