1 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 36 public abstract class BaseModule implements ModuleLocal, CoefficientEventPublisher { 37 38 40 private static final String SESSION = "Session"; 41 42 44 private CoefficientContext ctx; 45 46 48 public abstract String getMainMethod(); 49 50 public abstract String getModuleDescription(); 51 52 public abstract String 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 66 public String getModuleName() { 67 String clazz = this.getClass() 68 .getName(); 69 String 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 82 public String canExecuteForRole(CoefficientContext ctx, String methodName, 83 Role usersHighestRole) { 84 return null; 85 } 86 87 95 public String displayUsersData(CoefficientUser user) { 96 return ""; 97 } 98 99 public CoefficientContext showHelp(CoefficientContext ctx) { 100 String 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 114 public void publishEvent(CoefficientEvent event) { 115 CoefficientEvents.publishEvent(event); 116 } 117 } 118 | Popular Tags |