Coverage Report - org.kuali.student.core.dictionary.service.impl.DictionaryServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DictionaryServiceImpl
59%
13/22
100%
2/2
1.125
 
 1  
 package org.kuali.student.core.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.kuali.student.core.dictionary.dto.ObjectStructureDefinition;
 9  
 import org.kuali.student.core.dictionary.service.DictionaryService;
 10  
 import org.springframework.context.ApplicationContext;
 11  
 import org.springframework.context.ConfigurableApplicationContext;
 12  
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 13  
 import org.springframework.util.StringUtils;
 14  
 
 15  
 public class DictionaryServiceImpl implements DictionaryService{
 16  
         private String[] dictionaryContext;
 17  
         private Map<String, ObjectStructureDefinition> objectStructures;
 18  
 
 19  
         public DictionaryServiceImpl() {
 20  0
                 super();
 21  0
         }
 22  
 
 23  
         public DictionaryServiceImpl(String dictionaryContext) {
 24  12
                 super();
 25  12
                 String[] locations = StringUtils.tokenizeToStringArray(dictionaryContext, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
 26  12
                 this.dictionaryContext = locations;
 27  12
                 init();
 28  12
         }
 29  
         
 30  
         public DictionaryServiceImpl(String[] dictionaryContext) {
 31  0
                 super();
 32  0
                 this.dictionaryContext = dictionaryContext;
 33  0
                 init();
 34  0
         }
 35  
 
 36  
         @SuppressWarnings("unchecked")
 37  
         public void init() {
 38  12
                 ApplicationContext ac = new ClassPathXmlApplicationContext(dictionaryContext);
 39  
 
 40  12
                 Map<String, ObjectStructureDefinition> beansOfType = (Map<String, ObjectStructureDefinition>) ac.getBeansOfType(ObjectStructureDefinition.class);
 41  12
                 objectStructures = new HashMap<String, ObjectStructureDefinition>();
 42  12
                 for (ObjectStructureDefinition objStr : beansOfType.values()){
 43  36
                         objectStructures.put(objStr.getName(), objStr);
 44  
                 }
 45  12
         }
 46  
 
 47  
         @Override
 48  
         public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
 49  23
                 return objectStructures.get(objectTypeKey);
 50  
         }
 51  
 
 52  
         @Override
 53  
         public List<String> getObjectTypes() {
 54  4
                 return new ArrayList<String>(objectStructures.keySet());
 55  
         }
 56  
 
 57  
         public String[] getDictionaryContext() {
 58  0
                 return dictionaryContext;
 59  
         }
 60  
 
 61  
         public void setDictionaryContext(String[] dictionaryContext) {
 62  0
                 this.dictionaryContext = dictionaryContext;
 63  0
         }
 64  
 }