1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.dining.dao;
16
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.kuali.mobility.dining.entity.DiningHall;
20 import org.kuali.mobility.dining.entity.DiningHallGroup;
21 import org.kuali.mobility.shared.InitBean;
22
23 import javax.annotation.Resource;
24 import javax.xml.bind.JAXBContext;
25 import javax.xml.bind.JAXBException;
26 import javax.xml.bind.Unmarshaller;
27 import java.io.InputStream;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35 public class DiningInitBean implements InitBean {
36
37 private static final Logger LOG = LoggerFactory.getLogger(DiningInitBean.class);
38
39 @Resource(name="diningDao")
40 private DiningDao dao;
41
42 private Map<String, List<String>> diningUrls;
43 private boolean loadFromFile;
44
45 public void loadData() {
46 List<DiningHallGroup> diningHallGroups = new ArrayList<DiningHallGroup>();
47 DiningHall diningHall = null;
48 DiningHallGroup diningHallGroup = new DiningHallGroup();
49 if( isLoadFromFile() ) {
50 for( String key : getDiningUrls().keySet() ) {
51
52 try {
53 JAXBContext jc = JAXBContext.newInstance(DiningHallGroup.class);
54 Unmarshaller um = jc.createUnmarshaller();
55 InputStream in = this.getClass().getResourceAsStream( getDiningUrls().get(key).get(0));
56 diningHallGroup = (DiningHallGroup) um.unmarshal(in);
57
58 } catch (JAXBException jbe) {
59 LOG.error(jbe.getLocalizedMessage(), jbe);
60 }
61 diningHallGroups.add(diningHallGroup);
62 }
63 }
64 getDao().setDiningHallGroups(diningHallGroups);
65 }
66
67 public DiningDao getDao() {
68 return dao;
69 }
70
71 public void setDao(DiningDao dao) {
72 this.dao = dao;
73 }
74
75 public Map<String, List<String>> getDiningUrls() {
76 return diningUrls;
77 }
78
79 public void setDiningUrls(Map<String, List<String>> diningUrls) {
80 this.diningUrls = diningUrls;
81 }
82
83 public boolean isLoadFromFile() {
84 return loadFromFile;
85 }
86
87 public void setLoadFromFile(boolean loadFromFile) {
88 this.loadFromFile = loadFromFile;
89 }
90 }