1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.academics.dao;
16
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.kuali.mobility.academics.entity.Career;
20 import org.kuali.mobility.academics.entity.Subject;
21 import org.kuali.mobility.academics.entity.Term;
22 import org.kuali.mobility.shared.InitBean;
23
24 import javax.annotation.Resource;
25 import javax.xml.bind.JAXBContext;
26 import javax.xml.bind.JAXBException;
27 import javax.xml.bind.Unmarshaller;
28 import java.io.InputStream;
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35 public class AcademicsInitBeanDemo implements InitBean {
36 private static Logger LOG = LoggerFactory.getLogger(AcademicsInitBeanDemo.class);
37
38 @Resource(name="academicsDao")
39 private AcademicsDao dao;
40
41 public void loadData() {
42 List<Term> terms = new ArrayList<Term>();
43 try {
44 Term term = null;
45 JAXBContext jc = JAXBContext.newInstance(Term.class);
46 Unmarshaller um = jc.createUnmarshaller();
47 InputStream in = this.getClass().getResourceAsStream("/ScheduleOfClasses.xml");
48 term = (Term) um.unmarshal(in);
49 terms.add(term);
50 } catch (JAXBException jbe) {
51 LOG.error(jbe.getLocalizedMessage(), jbe);
52 }
53 getDao().setTerms(terms);
54 List<Career> careers = new ArrayList<Career>();
55 List<Subject> subjects = new ArrayList<Subject>();
56 careers.addAll(terms.get(0).getCareers());
57 for( Career c : careers ) {
58 subjects.addAll(c.getSubjects());
59 }
60 getDao().setCareers(careers);
61 getDao().setSubjects(subjects);
62 }
63
64 public AcademicsDao getDao() {
65 return dao;
66 }
67
68 public void setDao(AcademicsDao dao) {
69 this.dao = dao;
70 }
71 }