1    /*
2     * Copyright 2005 :torweg free software group
3     * 
4     * This program is free software: you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation, either version 3 of the License, or
7     * (at your option) any later version.
8     * 
9     * This program is distributed in the hope that it will be useful,
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    * GNU General Public License for more details.
13    * 
14    * You should have received a copy of the GNU General Public License
15    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16    *
17    */
18   package org.torweg.pulse.bundle;
19   
20   /**
21    * is the base class for all {@code Controller}s of <em>pulse</em>.
22    * 
23    * <p>
24    * <strong>Attention:</strong> {@code Controller}s are singletons and
25    * therefore not thread-safe. Both static and instance fields are shared among
26    * different requests.
27    * </p>
28    * <p>
29    * The execution of the {@code Controller}'s methods are controlled by
30    * annotations.
31    * </p>
32    * 
33    * @see org.torweg.pulse.annotations.Action
34    * @see org.torweg.pulse.annotations.AnyAction
35    * @see org.torweg.pulse.annotations.Permission
36    * @see org.torweg.pulse.annotations.Groups
37    * 
38    * @author Thomas Weber
39    * @version $Revision: 1383 $
40    */
41   public class Controller {
42   
43       /**
44        * flag indicating whether the {@code Controller} is always running.
45        */
46       private AlwaysRun alwaysRun;
47   
48       /**
49        * is used during {@code Bundle} initialisation, to configure the
50        * always run behaviour of the {@code Controller}.
51        * 
52        * @param ar
53        *            the always run setting
54        */
55       public final void setAlwaysRun(final AlwaysRun ar) {
56           this.alwaysRun = ar;
57       }
58   
59       /**
60        * returns whether the {@code Controller} is run for every request, or
61        * if it is run only during request for its {@code Bundle}.
62        * 
63        * @return whether the {@code Controller} is run for every request, or
64        *         if it is run only during request for its {@code Bundle}.
65        */
66       public final boolean isAlwaysRun() {
67           return (this.alwaysRun != AlwaysRun.FALSE);
68       }
69   
70       /**
71        * returns the AlwaysRun setting of the {@code Controller}.
72        * 
73        * @return the AlwaysRun setting
74        */
75       public final AlwaysRun getAlwaysRun() {
76           return this.alwaysRun;
77       }
78   
79       /**
80        * enumerates the different settings for AlwaysRun.
81        * 
82        * @author Thomas Weber
83        */
84       public enum AlwaysRun {
85   
86           /**
87            * is not always run.
88            */
89           FALSE,
90   
91           /**
92            * always run before the controller with the action.
93            */
94           PRE,
95   
96           /**
97            * always run, but after the controller with the action.
98            */
99           POST;
100      }
101  
102  }
103