KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > BaseModule


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.modules;
21
22 import za.org.coefficient.authentication.CoefficientUser;
23 import za.org.coefficient.authentication.Role;
24 import za.org.coefficient.events.*;
25 import za.org.coefficient.events.CoefficientEvent;
26 import za.org.coefficient.events.CoefficientEventPublisher;
27 import za.org.coefficient.interfaces.CoefficientContext;
28 import za.org.coefficient.interfaces.ModuleLocal;
29
30 /**
31  * DOCUMENT ME!
32  *
33  * @author $author$
34  * @version $Revision: 1.9 $
35  */

36 public abstract class BaseModule implements ModuleLocal, CoefficientEventPublisher {
37     
38     //~ Static fields/initializers =============================================
39

40     private static final String JavaDoc SESSION = "Session";
41
42     //~ Instance fields ========================================================
43

44     private CoefficientContext ctx;
45
46     //~ Methods ================================================================
47

48     public abstract String JavaDoc getMainMethod();
49
50     public abstract String JavaDoc getModuleDescription();
51
52     public abstract String JavaDoc getModuleDisplayName();
53
54     public void setCoefficientContext(CoefficientContext ctx) {
55         this.ctx = ctx;
56     }
57
58     public CoefficientContext getCoefficientContext() {
59         return this.ctx;
60     }
61
62     /**
63      * This is a base implementation so all modules will have the right
64      * format of their names
65      */

66     public String JavaDoc getModuleName() {
67         String JavaDoc clazz = this.getClass()
68                            .getName();
69         String JavaDoc temp =
70             clazz.substring(clazz.lastIndexOf(".") + 1, clazz.length());
71         int idx = temp.indexOf(SESSION);
72         if(idx > 0) {
73             temp = temp.substring(0, idx);
74         }
75         return temp;
76     }
77
78     /**
79      * This is a base implementation that will allow all methods to be
80      * invoked without regard to roles
81      */

82     public String JavaDoc canExecuteForRole(CoefficientContext ctx, String JavaDoc methodName,
83         Role usersHighestRole) {
84         return null;
85     }
86
87     /**
88      * This is a base implementation that will return an empty string for
89      * a modules user related data. This should be implmented to show what
90      * data the module contains that relates to the currently logged in
91      * user.
92      *
93      * @return String containing the html to display for the modules summary.
94      */

95     public String JavaDoc displayUsersData(CoefficientUser user) {
96         return "";
97     }
98
99     public CoefficientContext showHelp(CoefficientContext ctx) {
100         String JavaDoc mod = getModuleDisplayName();
101         ctx.setModuleContent("There is currently no help for module: " + mod
102                              + " and operation: " + ctx.getLastNonHelpOp()
103                              + ".", "Help");
104         return ctx;
105     }
106
107     public final boolean isProjectRequired() {
108         return this instanceof BaseProjectModule;
109     }
110
111     /**
112      * @see za.org.coefficient.events.CoefficientEventPublisher#publishEvent(za.org.coefficient.events.CoefficientEvent)
113      */

114     public void publishEvent(CoefficientEvent event) {
115         CoefficientEvents.publishEvent(event);
116     }
117 }
118
Popular Tags