4158 |
22 Feb 08 |
nicklas |
1 |
/** |
4198 |
28 Mar 08 |
nicklas |
$Id:ActionFactory.java 4187 2008-03-20 11:15:25Z nicklas $ |
4158 |
22 Feb 08 |
nicklas |
3 |
|
4158 |
22 Feb 08 |
nicklas |
Copyright (C) Authors contributing to this file. |
4158 |
22 Feb 08 |
nicklas |
5 |
|
4158 |
22 Feb 08 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4158 |
22 Feb 08 |
nicklas |
Available at http://base.thep.lu.se/ |
4158 |
22 Feb 08 |
nicklas |
8 |
|
4158 |
22 Feb 08 |
nicklas |
BASE is free software; you can redistribute it and/or |
4158 |
22 Feb 08 |
nicklas |
modify it under the terms of the GNU General Public License |
4479 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
4158 |
22 Feb 08 |
nicklas |
of the License, or (at your option) any later version. |
4158 |
22 Feb 08 |
nicklas |
13 |
|
4158 |
22 Feb 08 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4158 |
22 Feb 08 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4158 |
22 Feb 08 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4158 |
22 Feb 08 |
nicklas |
GNU General Public License for more details. |
4158 |
22 Feb 08 |
nicklas |
18 |
|
4158 |
22 Feb 08 |
nicklas |
You should have received a copy of the GNU General Public License |
4515 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4158 |
22 Feb 08 |
nicklas |
21 |
*/ |
4158 |
22 Feb 08 |
nicklas |
22 |
package net.sf.basedb.util.extensions; |
4158 |
22 Feb 08 |
nicklas |
23 |
|
4170 |
07 Mar 08 |
nicklas |
24 |
import net.sf.basedb.util.extensions.xml.XmlLoader; |
4170 |
07 Mar 08 |
nicklas |
25 |
|
4158 |
22 Feb 08 |
nicklas |
26 |
/** |
4170 |
07 Mar 08 |
nicklas |
An action factory is an object which knows how to create |
4170 |
07 Mar 08 |
nicklas |
{@link Action}:s. Action factories are part of an extension |
4170 |
07 Mar 08 |
nicklas |
(see {@link Extension#getActionFactory()}). |
4170 |
07 Mar 08 |
nicklas |
30 |
|
4170 |
07 Mar 08 |
nicklas |
<p> |
4170 |
07 Mar 08 |
nicklas |
Action factory implementations must be thread-safe, since a |
4170 |
07 Mar 08 |
nicklas |
single instance of the factory may have to serve multiple requests |
4170 |
07 Mar 08 |
nicklas |
at the same time. |
4170 |
07 Mar 08 |
nicklas |
35 |
|
4170 |
07 Mar 08 |
nicklas |
<p> |
4170 |
07 Mar 08 |
nicklas |
Note 1! A single factory instance may be used by more than one |
4170 |
07 Mar 08 |
nicklas |
extension. This is at the control of the client application. |
4170 |
07 Mar 08 |
nicklas |
39 |
|
4170 |
07 Mar 08 |
nicklas |
<p> |
4170 |
07 Mar 08 |
nicklas |
Note 2! The BASE web-client uses the {@link XmlLoader} to |
4170 |
07 Mar 08 |
nicklas |
define extensions. The <code>XmlLoader</code> always create a |
4170 |
07 Mar 08 |
nicklas |
separate factory instance for each extension. The <code>XmlLoader</code> |
4170 |
07 Mar 08 |
nicklas |
also requires that the factories has a public no-argument constructor. |
4158 |
22 Feb 08 |
nicklas |
45 |
|
4158 |
22 Feb 08 |
nicklas |
@author nicklas |
4158 |
22 Feb 08 |
nicklas |
@version 2.7 |
4198 |
28 Mar 08 |
nicklas |
@base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $ |
4158 |
22 Feb 08 |
nicklas |
49 |
*/ |
4158 |
22 Feb 08 |
nicklas |
50 |
public interface ActionFactory<A extends Action> |
4158 |
22 Feb 08 |
nicklas |
51 |
{ |
4158 |
22 Feb 08 |
nicklas |
52 |
|
4158 |
22 Feb 08 |
nicklas |
53 |
/** |
4170 |
07 Mar 08 |
nicklas |
This method is called once for each request/use of an |
4170 |
07 Mar 08 |
nicklas |
extension and have two purposes: |
4158 |
22 Feb 08 |
nicklas |
56 |
|
4170 |
07 Mar 08 |
nicklas |
<ul> |
4170 |
07 Mar 08 |
nicklas |
<li>The factory should decide if the extension should be enabled or |
4170 |
07 Mar 08 |
nicklas |
not. For example, the factory may check the permissions of the |
4170 |
07 Mar 08 |
nicklas |
logged in user and determine that they are inadequate. The boolean |
4170 |
07 Mar 08 |
nicklas |
return value determines if the extension is enabled or disabled. |
4170 |
07 Mar 08 |
nicklas |
62 |
|
4170 |
07 Mar 08 |
nicklas |
<li>Initialise the context with resources that the actions may need. |
4170 |
07 Mar 08 |
nicklas |
With the BASE web-client this means that it is possible to |
4170 |
07 Mar 08 |
nicklas |
add scripts or stylesheets that is needed by the extension. |
4198 |
28 Mar 08 |
nicklas |
See {@link net.sf.basedb.clients.web.extensions.JspContext}. |
4170 |
07 Mar 08 |
nicklas |
</ul> |
4170 |
07 Mar 08 |
nicklas |
68 |
|
4207 |
04 Apr 08 |
nicklas |
@param context The current invokation context |
4170 |
07 Mar 08 |
nicklas |
@return TRUE if the extension should be enabled, |
4170 |
07 Mar 08 |
nicklas |
FALSE if the extension should be disabled |
4158 |
22 Feb 08 |
nicklas |
72 |
*/ |
4207 |
04 Apr 08 |
nicklas |
73 |
public boolean prepareContext(InvokationContext<? super A> context); |
4158 |
22 Feb 08 |
nicklas |
74 |
|
4158 |
22 Feb 08 |
nicklas |
75 |
/** |
4158 |
22 Feb 08 |
nicklas |
This method may be called one or several times for each request. |
4158 |
22 Feb 08 |
nicklas |
This is decided by the extension point. If, for example, the extension |
4158 |
22 Feb 08 |
nicklas |
point is a pure single-item extension point then this method is probably |
4158 |
22 Feb 08 |
nicklas |
only called once. If the extension point is a per-item extension point in |
4158 |
22 Feb 08 |
nicklas |
a list context, then this method may be called once for every item in the list. |
4158 |
22 Feb 08 |
nicklas |
The context parameter contains all information about the context of |
4158 |
22 Feb 08 |
nicklas |
the extension point, including the current item, if any. |
4158 |
22 Feb 08 |
nicklas |
83 |
|
4207 |
04 Apr 08 |
nicklas |
@param context The current invokation context |
4158 |
22 Feb 08 |
nicklas |
@return An array of actions that should be added to the extension point. |
4158 |
22 Feb 08 |
nicklas |
Returns null or an empty array if there are no actions in the current context. |
4158 |
22 Feb 08 |
nicklas |
87 |
*/ |
4207 |
04 Apr 08 |
nicklas |
88 |
public A[] getActions(InvokationContext<? super A> context); |
4158 |
22 Feb 08 |
nicklas |
89 |
|
4158 |
22 Feb 08 |
nicklas |
90 |
} |