1
2
3
4
5
6 package org.weda.common.impl;
7
8 import java.util.List;
9 import java.util.Map;
10 import org.weda.common.NamesListRegistry;
11 import org.weda.common.NamesListRegistryException;
12 import org.weda.common.impl.NamesList.State;
13
14 /**
15 *
16 * @author Mikhail Titov
17 */
18 public class NamesListRegistryImpl implements NamesListRegistry{
19 private Map<String, NamesList> namesLists;
20
21 public void init() throws NamesListRegistryException {
22 try{
23 for (String listName: namesLists.keySet())
24 initAndGetNamesList(listName);
25 }catch(Exception e){
26 throw new NamesListRegistryException(
27 "Error while initializing names list registry", e);
28 }
29 }
30
31 public List<String> getNamesList(String listName)
32 throws NamesListRegistryException
33 {
34 NamesList list = namesLists.get(listName);
35 if (list == null)
36 throw new NamesListRegistryException(
37 String.format(
38 "Names list (%s) not found in registry", listName));
39 else
40 return list.getNames();
41 }
42
43 List<String> initAndGetNamesList(String listName)
44 throws NamesListRegistryException, NamesListException
45 {
46 NamesList namesList = namesLists.get(listName);
47 if (namesList==null)
48 throw new NamesListRegistryException(
49 String.format(
50 "Names list (%s) not found in registry", listName));
51 else{
52 if (namesList.getState() == State.INITIALIZING)
53 throw new NamesListRegistryException(
54 String.format(
55 "Detected lists initializing cycle " +
56 "at list name (%s)"
57 , listName));
58 else {
59 if (namesList.getState() == State.NOT_INITIALIZED){
60 namesList.setNamesListReg(this);
61 namesList.init();
62 }
63 return namesList.getNames();
64 }
65 }
66 }
67
68 public void setNamesLists(Map<String, NamesList> namesLists){
69 this.namesLists = namesLists;
70 }
71
72 }