Class ClientContext
- Direct Known Subclasses:
AuthenticationContext
,JspContext
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
Modifier and TypeFieldDescriptionprivate Extension<?>
private ExtensionPoint<?>
private final DbControl
private Object
private final SessionControl
-
Constructor Summary
ModifierConstructorDescriptionCreate a new context with no session or current item.Create a new context with a DbControl.ClientContext
(DbControl dc, Object item) Create a new context with a DbControl and item.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
Modifier and TypeMethodDescription<T> T
getAttribute
(String name) Get an attribute of the context.Extension<?>
Get the currently active extension point.Get the currently active extension point.<T> T
Get the currently active item.Get the current DbControl.Get the current session control.void
linkAttributes
(ClientContext other) Link this context to the other context with respect to attributes.void
loadAttributes
(ItemContext cc, String key) Load attributes to this context from the given ItemContext instance.void
setAttribute
(String name, Object value) Set an attribute of the context.protected void
setCurrentExtension
(Extension<?> xt) protected void
setCurrentExtensionPoint
(ExtensionPoint<?> xtPoint) void
setCurrentItem
(Object item) Set the currently active item.void
storeAttributes
(ItemContext cc, String key) Store all attributes that has been set on this context to the given ItemContext instance.
-
Field Details
-
sc
-
dc
-
currentXtPoint
-
currentXt
-
item
-
attributes
-
-
Constructor Details
-
ClientContext
public ClientContext()Create a new context with no session or current item.- Since:
- 3.0
-
ClientContext
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
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
Create a new context with a DbControl. The DbControl is final and can't be replaced.- Parameters:
dc
- An open DbControl
-
ClientContext
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
-
-
Method Details
-
getSessionControl
Get the current session control. -
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 <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
Set the currently active item.- Parameters:
item
- The item that is the current item
-
getCurrentExtensionPoint
Get the currently active extension point.- Since:
- 3.19.3
-
setCurrentExtensionPoint
-
getCurrentExtension
Get the currently active extension point.- Since:
- 3.19.3
-
setCurrentExtension
-
getAttribute
Get an attribute of the context.- Parameters:
name
- The name of the attribute- Returns:
- The value, or null
-
setAttribute
Set an attribute of the context.- Parameters:
name
- The name of the attributevalue
- The value, if null the attribute is removed
-
linkAttributes
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
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 withloadAttributes(ItemContext, String)
- Since:
- 3.19.4
-
loadAttributes
Load attributes to this context from the given ItemContext instance.- Since:
- 3.19.4
-