Changeset 5004
- Timestamp:
- 07/21/08 17:23:46 (4 months ago)
- Files:
-
- openmrs-modules/dss/.classpath (modified) (1 diff)
- openmrs-modules/dss/lib-common/openmrs-api-1.3.0.00.4870.jar (deleted)
- openmrs-modules/dss/lib-common/openmrs-api-1.3.0.13.4957.jar (added)
- openmrs-modules/dss/metadata/config.xml (modified) (1 diff)
- openmrs-modules/dss/src/org/openmrs/module/dss/CompilingClassLoader.java (modified) (3 diffs)
- openmrs-modules/dss/src/org/openmrs/module/dss/impl/DssServiceImpl.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs-modules/dss/.classpath
r4960 r5004 62 62 <classpathentry kind="lib" path="lib-common/junit/hsqldb.jar"/> 63 63 <classpathentry kind="lib" path="lib-common/junit/junit-3.8.1.jar"/> 64 <classpathentry kind="lib" path="lib-common/openmrs-api-1.3.0. 00.4870.jar"/>64 <classpathentry kind="lib" path="lib-common/openmrs-api-1.3.0.13.4957.jar"/> 65 65 <classpathentry kind="output" path="build"/> 66 66 </classpath> openmrs-modules/dss/metadata/config.xml
r4960 r5004 7 7 <id>dss</id> 8 8 <name>Dss</name> 9 <version>2. 19</version>9 <version>2.20</version> 10 10 <package>org.openmrs.module.@MODULE_ID@</package> 11 11 <author>Vibha Anand and Tammy Dugan</author> openmrs-modules/dss/src/org/openmrs/module/dss/CompilingClassLoader.java
r4774 r5004 20 20 import org.openmrs.api.AdministrationService; 21 21 import org.openmrs.api.context.Context; 22 import org.openmrs.logic.RuleClassLoader; 22 23 import org.openmrs.module.ModuleClassLoader; 23 24 import org.openmrs.module.ModuleFactory; … … 33 34 @Author - Vibha Anand - Adapted from ibm.com/developerWorks 34 35 */ 35 public class CompilingClassLoader extends ClassLoader36 public class CompilingClassLoader extends RuleClassLoader 36 37 { 37 38 private static Log log = LogFactory.getLog( CompilingClassLoader.class ); … … 210 211 211 212 // Our goal is to get a Class object 212 Class clas = null; 213 214 //look for loaded classes 215 try 216 { 217 clas = super.findLoadedClass(name); 218 } catch (Exception e) 219 { 220 } 221 222 //look for system classes 223 if (clas == null) 224 { 225 try 226 { 227 clas = super.findSystemClass(name); 228 } catch (Exception e) 229 { 230 } 231 } 232 233 //check context class loader 234 if (clas == null) 235 { 236 try 237 { 238 ClassLoader parent = Thread.currentThread(). 239 getContextClassLoader(); 240 clas = parent.loadClass(name); 241 } catch (Exception e) 242 { 243 } 244 } 245 246 //check module class loaders 247 if(clas == null) 248 { 249 Collection<ModuleClassLoader> moduleClassLoaders = 250 ModuleFactory.getModuleClassLoaders(); 251 252 Iterator<ModuleClassLoader> iter = moduleClassLoaders.iterator(); 253 254 while(iter.hasNext()&&clas == null) 255 { 256 ModuleClassLoader currClassLoader = iter.next(); 257 try 258 { 259 clas = currClassLoader.loadClass(name); 260 } catch (Exception e) 261 { 262 } 263 } 264 } 213 Class clas = super.findClass(name); 265 214 266 215 //if the class is not found, look in rule directory openmrs-modules/dss/src/org/openmrs/module/dss/impl/DssServiceImpl.java
r4871 r5004 133 133 continue; 134 134 } 135 ruleName = ruleName.toUpperCase();136 135 137 136 Result result; … … 169 168 String rulePackagePrefix) throws Exception 170 169 { 170 LogicService logicService = Context.getLogicService(); 171 171 172 // Create a CompilingClassLoader 172 173 CompilingClassLoader ccl = new CompilingClassLoader(); 173 174 AdministrationService adminService = 175 Context.getAdministrationService(); 174 175 AdministrationService adminService = Context.getAdministrationService(); 176 176 if (rulePackagePrefix == null) 177 177 { … … 181 181 182 182 Class clas = null; 183 184 // try to load the class dynamically185 if (!rule.contains(rulePackagePrefix))186 { 187 clas = ccl.loadClass(rulePackagePrefix +rule);188 } else183 184 // try to load the class dynamically 185 if (!rule.contains(rulePackagePrefix)) 186 { 187 clas = ccl.loadClass(rulePackagePrefix + rule); 188 } else 189 189 { 190 190 clas = ccl.loadClass(rule); 191 } 192 193 // try to load the class from the class library194 if (clas == null &&defaultPackagePrefix!=null)195 { 196 if (!rule.contains(defaultPackagePrefix))191 } 192 193 // try to load the class from the class library 194 if (clas == null && defaultPackagePrefix != null) 195 { 196 if (!rule.contains(defaultPackagePrefix)) 197 197 { 198 clas = ccl.loadClass(defaultPackagePrefix +rule);199 } else198 clas = ccl.loadClass(defaultPackagePrefix + rule); 199 } else 200 200 { 201 201 clas = ccl.loadClass(rule); 202 } 203 } 204 205 // try to load the class as it is206 if (clas == null)202 } 203 } 204 205 // try to load the class as it is 206 if (clas == null) 207 207 { 208 208 clas = ccl.loadClass(rule); 209 209 } 210 210 211 211 if (clas == null) 212 212 { … … 214 214 } 215 215 216 Object obj = clas.newInstance(); 217 218 if (!(obj instanceof org.openmrs.logic.Rule)) 219 { 220 throw new Exception("Could not load class for rule: " + rule 221 + ". The rule must implement the Rule interface."); 222 } 223 216 224 try 217 225 { 218 // Use reflection to call its main() method, and to 219 // pass the arguments in. 220 // Get a class representing the type of the activate method's 221 // argument 222 Class activateArgType[] = 223 { String.class }; 224 // Find the standard main method in the class 225 226 Method activate = clas.getMethod("activate", activateArgType); 227 228 // Create a list containing the arguments -- in this case, 229 // an array of strings 230 Object argsArray[] = 231 { rule.toUpperCase() }; 232 // Call the method 233 234 activate.invoke(clas.newInstance(), argsArray); 226 logicService.addRule(rule, (org.openmrs.logic.Rule) obj); 235 227 } catch (Exception e) 236 228 { 237 log.error(e); 238 throw new Exception("Could not call activate method of rule."); 239 } 240 229 logicService.updateRule(rule, (org.openmrs.logic.Rule) obj); 230 } 241 231 } 242 232