1 19 20 package za.org.coefficient.invokers.webapp; 21 22 import org.apache.commons.lang.StringUtils; 23 24 import za.org.coefficient.invokers.base.BaseInvoker; 25 import za.org.coefficient.exception.ConfigurationException; 26 import za.org.coefficient.interfaces.ModuleLocal; 27 import za.org.coefficient.interfaces.ThemeLocalIf; 28 29 38 public class WebAppInvoker extends BaseInvoker { 39 40 42 47 public Object getService(String serviceName) throws Exception { 48 Object service = null; 49 if (serviceName != null) { 50 serviceName = StringUtils.capitalise(serviceName); 54 javax.naming.Context initCtx = new javax.naming.InitialContext (); 55 javax.naming.Context envCtx = 56 (javax.naming.Context ) initCtx.lookup("java:comp/env"); 57 javax.naming.InitialContext initialContext = 58 new javax.naming.InitialContext (); 59 try { 60 service = envCtx.lookup(serviceName); 61 } catch (Exception e) { 62 e.printStackTrace(); 63 throw new ConfigurationException("Requested service, " 64 + serviceName + " is not available on the system!"); 65 } finally { 66 initCtx.close(); 67 envCtx.close(); 68 } 69 } 70 71 return service; 72 } 73 74 protected ThemeLocalIf getTheme(String themeName) throws Exception { 75 Object theme = getService(themeName); 76 if(theme instanceof ThemeLocalIf) { 77 return (ThemeLocalIf)theme; 78 } else { 79 throw new ConfigurationException("Requested theme, " 80 + themeName 81 + " is not a valid theme!"); 82 } 83 } 84 85 protected ModuleLocal getModule(String moduleName) throws Exception { 86 Object module = getService(moduleName); 87 if(module instanceof ModuleLocal) { 88 return (ModuleLocal)module; 89 } else { 90 throw new ConfigurationException("Requested module, " 91 + moduleName 92 + " is not a system module!"); 93 } 94 } 95 96 } 97 | Popular Tags |