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