Coverage Report - org.kuali.student.common.dictionary.service.impl.DictionaryServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DictionaryServiceImpl
60%
15/25
75%
3/4
1.25
 
 1  
 package org.kuali.student.common.dictionary.service.impl;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.HashMap;
 5  
 import java.util.List;
 6  
 import java.util.Map;
 7  
 
 8  
 import org.apache.log4j.Logger;
 9  
 import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
 10  
 import org.kuali.student.common.dictionary.service.DictionaryService;
 11  
 import org.kuali.student.common.validator.DefaultValidatorImpl;
 12  
 import org.springframework.context.ApplicationContext;
 13  
 import org.springframework.context.ConfigurableApplicationContext;
 14  
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 15  
 import org.springframework.util.StringUtils;
 16  
 
 17  
 public class DictionaryServiceImpl implements DictionaryService{
 18  
         private String[] dictionaryContext;
 19  
         private Map<String, ObjectStructureDefinition> objectStructures;
 20  1
     final static Logger LOG = Logger.getLogger(DictionaryServiceImpl.class);
 21  
     
 22  
         public DictionaryServiceImpl() {
 23  0
                 super();
 24  0
         }
 25  
 
 26  
         public DictionaryServiceImpl(String dictionaryContext) {
 27  12
                 super();
 28  12
                 String[] locations = StringUtils.tokenizeToStringArray(dictionaryContext, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
 29  12
                 this.dictionaryContext = locations;
 30  12
                 init();
 31  12
         }
 32  
         
 33  
         public DictionaryServiceImpl(String[] dictionaryContext) {
 34  0
                 super();
 35  0
                 this.dictionaryContext = dictionaryContext;
 36  0
                 init();
 37  0
         }
 38  
 
 39  
         @SuppressWarnings("unchecked")
 40  
         public void init() {
 41  12
                 ApplicationContext ac = new ClassPathXmlApplicationContext(dictionaryContext);
 42  
 
 43  12
                 Map<String, ObjectStructureDefinition> beansOfType = (Map<String, ObjectStructureDefinition>) ac.getBeansOfType(ObjectStructureDefinition.class);
 44  12
                 objectStructures = new HashMap<String, ObjectStructureDefinition>();
 45  12
                 for (ObjectStructureDefinition objStr : beansOfType.values()){
 46  36
                         if(objectStructures.containsKey(objStr.getName())){
 47  0
                                 LOG.warn("There is already a dictionary structure with the name '"+objStr+"'.");
 48  
                         }
 49  36
                         objectStructures.put(objStr.getName(), objStr);
 50  
                 }
 51  12
         }
 52  
 
 53  
         @Override
 54  
         public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
 55  23
                 return objectStructures.get(objectTypeKey);
 56  
         }
 57  
 
 58  
         @Override
 59  
         public List<String> getObjectTypes() {
 60  4
                 return new ArrayList<String>(objectStructures.keySet());
 61  
         }
 62  
 
 63  
         public String[] getDictionaryContext() {
 64  0
                 return dictionaryContext;
 65  
         }
 66  
 
 67  
         public void setDictionaryContext(String[] dictionaryContext) {
 68  0
                 this.dictionaryContext = dictionaryContext;
 69  0
         }
 70  
 }