Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 5004

Show
Ignore:
Timestamp:
07/21/08 17:23:46 (4 months ago)
Author:
tmdugan
Message:

-- dss

* made changes to extend loadRule and RuleClassLoader in LogicService
* updated openmrs jar

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/dss/.classpath

    r4960 r5004  
    6262        <classpathentry kind="lib" path="lib-common/junit/hsqldb.jar"/> 
    6363        <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"/> 
    6565        <classpathentry kind="output" path="build"/> 
    6666</classpath> 
  • openmrs-modules/dss/metadata/config.xml

    r4960 r5004  
    77        <id>dss</id> 
    88        <name>Dss</name> 
    9         <version>2.19</version> 
     9        <version>2.20</version> 
    1010        <package>org.openmrs.module.@MODULE_ID@</package> 
    1111        <author>Vibha Anand and Tammy Dugan</author> 
  • openmrs-modules/dss/src/org/openmrs/module/dss/CompilingClassLoader.java

    r4774 r5004  
    2020import org.openmrs.api.AdministrationService; 
    2121import org.openmrs.api.context.Context; 
     22import org.openmrs.logic.RuleClassLoader; 
    2223import org.openmrs.module.ModuleClassLoader; 
    2324import org.openmrs.module.ModuleFactory; 
     
    3334 @Author - Vibha Anand - Adapted from ibm.com/developerWorks 
    3435 */ 
    35 public class CompilingClassLoader extends ClassLoader 
     36public class CompilingClassLoader extends RuleClassLoader 
    3637{ 
    3738        private static Log log = LogFactory.getLog( CompilingClassLoader.class ); 
     
    210211                 
    211212                // 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); 
    265214 
    266215                //if the class is not found, look in rule directory 
  • openmrs-modules/dss/src/org/openmrs/module/dss/impl/DssServiceImpl.java

    r4871 r5004  
    133133                                        continue; 
    134134                                } 
    135                                 ruleName = ruleName.toUpperCase(); 
    136135 
    137136                                Result result; 
     
    169168                        String rulePackagePrefix) throws Exception 
    170169        { 
     170                LogicService logicService = Context.getLogicService(); 
     171                 
    171172                // Create a CompilingClassLoader 
    172173                CompilingClassLoader ccl = new CompilingClassLoader(); 
    173                  
    174                 AdministrationService adminService =  
    175                         Context.getAdministrationService(); 
     174 
     175                AdministrationService adminService = Context.getAdministrationService(); 
    176176                if (rulePackagePrefix == null) 
    177177                { 
     
    181181 
    182182                Class clas = null; 
    183                  
    184                 //try to load the class dynamically 
    185                 if(!rule.contains(rulePackagePrefix)) 
    186                 { 
    187                         clas = ccl.loadClass(rulePackagePrefix+rule); 
    188                 }else 
     183 
     184                // try to load the class dynamically 
     185                if (!rule.contains(rulePackagePrefix)) 
     186                { 
     187                        clas = ccl.loadClass(rulePackagePrefix + rule); 
     188                } else 
    189189                { 
    190190                        clas = ccl.loadClass(rule); 
    191                 }               
    192  
    193                 //try to load the class from the class library 
    194                 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)) 
    197197                        { 
    198                                 clas = ccl.loadClass(defaultPackagePrefix+rule); 
    199                         }else 
     198                                clas = ccl.loadClass(defaultPackagePrefix + rule); 
     199                        } else 
    200200                        { 
    201201                                clas = ccl.loadClass(rule); 
    202                         }       
    203                 } 
    204                  
    205                 //try to load the class as it is 
    206                 if(clas == null) 
     202                        } 
     203                } 
     204 
     205                // try to load the class as it is 
     206                if (clas == null) 
    207207                { 
    208208                        clas = ccl.loadClass(rule); 
    209209                } 
    210                  
     210 
    211211                if (clas == null) 
    212212                { 
     
    214214                } 
    215215 
     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 
    216224                try 
    217225                { 
    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); 
    235227                } catch (Exception e) 
    236228                { 
    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                } 
    241231        } 
    242232