Coverage Report - org.kuali.rice.krms.impl.repository.SimpleRuleRepositoryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleRuleRepositoryImpl
0%
0/19
0%
0/14
5.5
 
 1  
 package org.kuali.rice.krms.impl.repository;
 2  
 
 3  
 import java.util.HashSet;
 4  
 import java.util.Map;
 5  
 import java.util.Set;
 6  
 import java.util.Map.Entry;
 7  
 import java.util.concurrent.ConcurrentHashMap;
 8  
 import java.util.concurrent.ConcurrentMap;
 9  
 
 10  
 import org.kuali.rice.krms.framework.repository.ContextDefinition;
 11  
 import org.kuali.rice.krms.framework.repository.RuleRepository;
 12  
 
 13  
 /**
 14  
  * This impl has some concurrency issues to consider 
 15  
  * @author gilesp
 16  
  *
 17  
  */
 18  0
 public class SimpleRuleRepositoryImpl implements RuleRepository {
 19  
         
 20  0
         ConcurrentMap<String, Set<ContextDefinition>> contextDefinitions = new ConcurrentHashMap<String, Set<ContextDefinition>>();
 21  
         
 22  
         @Override
 23  
         public ContextDefinition selectContext(Map<String, String> contextQualifiers) {
 24  0
                 Set<ContextDefinition> results = null;
 25  0
                 if (contextQualifiers != null) for (Entry<String,String> entry : contextQualifiers.entrySet()) {
 26  0
                         Set<ContextDefinition> qualifierMatches = contextDefinitions.get(entry.getKey()+"="+entry.getValue());
 27  0
                         if (null == results) {
 28  0
                                 results = new HashSet<ContextDefinition>(qualifierMatches);
 29  
                         } else {
 30  0
                                 results.retainAll(qualifierMatches);
 31  
                         }
 32  0
                 }
 33  0
                 if (results != null) {
 34  0
                         if (results.size() == 1) return results.iterator().next();
 35  0
                         else throw new IllegalArgumentException("ambiguous qualifiers");
 36  
                 }
 37  0
                 return null;
 38  
         }
 39  
         
 40  
         public void addContextDefinitionMapping(Map<String, String> contextQualifiers, ContextDefinition contextDefinition) {
 41  0
                 if (contextQualifiers != null) for (Entry<String,String> entry : contextQualifiers.entrySet()) {
 42  0
                         String key = entry.getKey()+"="+entry.getValue();
 43  
                         // TODO: synchronize here
 44  0
                         contextDefinitions.putIfAbsent(key, new HashSet<ContextDefinition>());
 45  0
                         contextDefinitions.get(key).add(contextDefinition);
 46  0
                 }
 47  0
         }
 48  
 
 49  
 }