/*
* Coefficient - facilitates project based collaboration
* Copyright (C) 2003, Dylan Etkin, CSIR icomtek
* PO Box 395
* Pretoria 0001, RSA
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package za.org.coefficient.modules;
import za.org.coefficient.authentication.CoefficientUser;
import za.org.coefficient.authentication.Role;
import za.org.coefficient.events.*;
import za.org.coefficient.events.CoefficientEvent;
import za.org.coefficient.events.CoefficientEventPublisher;
import za.org.coefficient.interfaces.CoefficientContext;
import za.org.coefficient.interfaces.ModuleLocal;
/**
* DOCUMENT ME!
*
* @author $author$
* @version $Revision: 1.9 $
*/
public abstract class BaseModule implements ModuleLocal, CoefficientEventPublisher {
//~ Static fields/initializers =============================================
private static final String SESSION = "Session";
//~ Instance fields ========================================================
private CoefficientContext ctx;
//~ Methods ================================================================
public abstract String getMainMethod();
public abstract String getModuleDescription();
public abstract String getModuleDisplayName();
public void setCoefficientContext(CoefficientContext ctx) {
this.ctx = ctx;
}
public CoefficientContext getCoefficientContext() {
return this.ctx;
}
/**
* This is a base implementation so all modules will have the right
* format of their names
*/
public String getModuleName() {
String clazz = this.getClass()
.getName();
String temp =
clazz.substring(clazz.lastIndexOf(".") + 1, clazz.length());
int idx = temp.indexOf(SESSION);
if(idx > 0) {
temp = temp.substring(0, idx);
}
return temp;
}
/**
* This is a base implementation that will allow all methods to be
* invoked without regard to roles
*/
public String canExecuteForRole(CoefficientContext ctx, String methodName,
Role usersHighestRole) {
return null;
}
/**
* This is a base implementation that will return an empty string for
* a modules user related data. This should be implmented to show what
* data the module contains that relates to the currently logged in
* user.
*
* @return String containing the html to display for the modules summary.
*/
public String displayUsersData(CoefficientUser user) {
return "";
}
public CoefficientContext showHelp(CoefficientContext ctx) {
String mod = getModuleDisplayName();
ctx.setModuleContent("There is currently no help for module: " + mod
+ " and operation: " + ctx.getLastNonHelpOp()
+ ".", "Help");
return ctx;
}
public final boolean isProjectRequired() {
return this instanceof BaseProjectModule;
}
/**
* @see za.org.coefficient.events.CoefficientEventPublisher#publishEvent(za.org.coefficient.events.CoefficientEvent)
*/
public void publishEvent(CoefficientEvent event) {
CoefficientEvents.publishEvent(event);
}
}
|