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