1 19 20 package za.org.coefficient.invokers.ejb; 21 22 import org.apache.commons.beanutils.MethodUtils; 23 import org.apache.commons.lang.StringUtils; 24 import org.apache.commons.collections.LRUMap; 25 26 import za.org.coefficient.invokers.base.BaseInvoker; 27 import za.org.coefficient.exception.ConfigurationException; 28 import za.org.coefficient.interfaces.ModuleLocal; 29 import za.org.coefficient.interfaces.ThemeLocalIf; 30 31 import java.util.Collections ; 32 import java.util.Map ; 33 34 54 public class EjbInvoker extends BaseInvoker { 55 57 private static final String CREATE = "create"; 59 private static final String LOCAL = "Local"; 60 61 public EjbInvoker() { 62 } 64 65 67 68 73 public Object getService(String serviceName) throws Exception { 74 Object serviceVal = null; 75 boolean serviceFound = true; 76 if (serviceName != null) { 77 serviceName = StringUtils.capitalise(serviceName); 81 try { 82 Object localHome = null; 83 if(localHome == null) { 85 javax.naming.InitialContext initialContext = 86 new javax.naming.InitialContext (); 87 try { 88 localHome =(javax.ejb.EJBLocalHome ) 89 initialContext.lookup(serviceName + LOCAL); 90 } catch (Exception e) { 92 e.printStackTrace(); 93 serviceFound = false; 94 } finally { 95 initialContext.close(); 96 } 97 } 98 99 if (serviceFound) { 100 serviceVal = MethodUtils 101 .invokeMethod(localHome, CREATE, null); 102 if (serviceVal == null) { 103 throw new ConfigurationException("Requested service, " 104 + serviceName + " is not available on the system!"); 105 } 106 } 107 } catch (NoSuchMethodException nsme) { 108 nsme.printStackTrace(); 109 } catch (IllegalAccessException iae) { 110 iae.printStackTrace(); 111 } 112 } 113 114 return serviceVal; 115 } 116 117 protected ThemeLocalIf getTheme(String theme) throws Exception { 118 ThemeLocalIf themeIf = null; 119 Object themeVal = getService(theme); 120 if (!(themeVal instanceof ThemeLocalIf)){ 121 throw new ConfigurationException("Requested theme, " 122 + theme + " is not a valid theme!"); 123 } else { 124 themeIf = (ThemeLocalIf) themeVal; 125 } 126 return themeIf; 127 } 128 129 protected ModuleLocal getModule(String module) throws Exception { 130 ModuleLocal mod = null; 131 Object modVal = getService(module); 132 if (!(modVal instanceof ModuleLocal)) { 133 throw new ConfigurationException("Requested module, " 134 + module + 135 " is not a system module!"); 136 } else { 137 mod = (ModuleLocal) modVal; 138 } 139 return mod; 140 } 141 142 } 143 144 | Popular Tags |