src/core/net/sf/basedb/util/extensions/ActionFactory.java

Code
Comments
Other
Rev Date Author Line
4158 22 Feb 08 nicklas 1 /**
4198 28 Mar 08 nicklas 2   $Id:ActionFactory.java 4187 2008-03-20 11:15:25Z nicklas $
4158 22 Feb 08 nicklas 3
4158 22 Feb 08 nicklas 4   Copyright (C) Authors contributing to this file.
4158 22 Feb 08 nicklas 5
4158 22 Feb 08 nicklas 6   This file is part of BASE - BioArray Software Environment.
4158 22 Feb 08 nicklas 7   Available at http://base.thep.lu.se/
4158 22 Feb 08 nicklas 8
4158 22 Feb 08 nicklas 9   BASE is free software; you can redistribute it and/or
4158 22 Feb 08 nicklas 10   modify it under the terms of the GNU General Public License
4479 05 Sep 08 jari 11   as published by the Free Software Foundation; either version 3
4158 22 Feb 08 nicklas 12   of the License, or (at your option) any later version.
4158 22 Feb 08 nicklas 13
4158 22 Feb 08 nicklas 14   BASE is distributed in the hope that it will be useful,
4158 22 Feb 08 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4158 22 Feb 08 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4158 22 Feb 08 nicklas 17   GNU General Public License for more details.
4158 22 Feb 08 nicklas 18
4158 22 Feb 08 nicklas 19   You should have received a copy of the GNU General Public License
4515 11 Sep 08 jari 20   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 27   An action factory is an object which knows how to create 
4170 07 Mar 08 nicklas 28   {@link Action}:s. Action factories are part of an extension
4170 07 Mar 08 nicklas 29   (see {@link Extension#getActionFactory()}).
4170 07 Mar 08 nicklas 30   
4170 07 Mar 08 nicklas 31   <p>
4170 07 Mar 08 nicklas 32   Action factory implementations must be thread-safe, since a 
4170 07 Mar 08 nicklas 33   single instance of the factory may have to serve multiple requests
4170 07 Mar 08 nicklas 34   at the same time.
4170 07 Mar 08 nicklas 35   
4170 07 Mar 08 nicklas 36   <p>
4170 07 Mar 08 nicklas 37   Note 1! A single factory instance may be used by more than one 
4170 07 Mar 08 nicklas 38   extension. This is at the control of the client application.
4170 07 Mar 08 nicklas 39   
4170 07 Mar 08 nicklas 40   <p>
4170 07 Mar 08 nicklas 41   Note 2! The BASE web-client uses the {@link XmlLoader} to 
4170 07 Mar 08 nicklas 42   define extensions. The <code>XmlLoader</code> always create a
4170 07 Mar 08 nicklas 43   separate factory instance for each extension. The <code>XmlLoader</code>
4170 07 Mar 08 nicklas 44   also requires that the factories has a public no-argument constructor.
4158 22 Feb 08 nicklas 45
4158 22 Feb 08 nicklas 46   @author nicklas
4158 22 Feb 08 nicklas 47   @version 2.7
4198 28 Mar 08 nicklas 48   @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 54     This method is called once for each request/use of an
4170 07 Mar 08 nicklas 55     extension and have two purposes:
4158 22 Feb 08 nicklas 56     
4170 07 Mar 08 nicklas 57     <ul>
4170 07 Mar 08 nicklas 58     <li>The factory should decide if the extension should be enabled or
4170 07 Mar 08 nicklas 59       not. For example, the factory may check the permissions of the
4170 07 Mar 08 nicklas 60       logged in user and determine that they are inadequate. The boolean
4170 07 Mar 08 nicklas 61       return value determines if the extension is enabled or disabled.
4170 07 Mar 08 nicklas 62       
4170 07 Mar 08 nicklas 63     <li>Initialise the context with resources that the actions may need.
4170 07 Mar 08 nicklas 64       With the BASE web-client this means that it is possible to
4170 07 Mar 08 nicklas 65       add scripts or stylesheets that is needed by the extension.
4198 28 Mar 08 nicklas 66       See {@link net.sf.basedb.clients.web.extensions.JspContext}.
4170 07 Mar 08 nicklas 67     </ul>
4170 07 Mar 08 nicklas 68     
4207 04 Apr 08 nicklas 69     @param context The current invokation context
4170 07 Mar 08 nicklas 70     @return TRUE if the extension should be enabled, 
4170 07 Mar 08 nicklas 71       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 76     This method may be called one or several times for each request. 
4158 22 Feb 08 nicklas 77     This is decided by the extension point. If, for example, the extension
4158 22 Feb 08 nicklas 78     point is a pure single-item extension point then this method is probably
4158 22 Feb 08 nicklas 79     only called once. If the extension point is a per-item extension point in
4158 22 Feb 08 nicklas 80     a list context, then this method may be called once for every item in the list.
4158 22 Feb 08 nicklas 81     The context parameter contains all information about the context of
4158 22 Feb 08 nicklas 82     the extension point, including the current item, if any.
4158 22 Feb 08 nicklas 83     
4207 04 Apr 08 nicklas 84     @param context The current invokation context
4158 22 Feb 08 nicklas 85     @return An array of actions that should be added to the extension point.
4158 22 Feb 08 nicklas 86       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 }