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.apache.log4j.Logger;
18 import org.kuali.mobility.academics.entity.Career;
19 import org.kuali.mobility.academics.entity.Subject;
20 import org.kuali.mobility.academics.entity.Term;
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
31
32
33
34 public class AcademicsInitBeanDemo implements InitBean {
35 private static Logger LOG = Logger.getLogger(AcademicsInitBeanDemo.class);
36
37 @Resource(name="academicsDao")
38 private AcademicsDao dao;
39
40 public void loadData() {
41 List<Term> terms = new ArrayList<Term>();
42 try {
43 Term term = null;
44 JAXBContext jc = JAXBContext.newInstance(Term.class);
45 Unmarshaller um = jc.createUnmarshaller();
46 InputStream in = this.getClass().getResourceAsStream("/ScheduleOfClasses.xml");
47 term = (Term) um.unmarshal(in);
48 terms.add(term);
49 } catch (JAXBException jbe) {
50 LOG.error(jbe.getLocalizedMessage(), jbe);
51 }
52 getDao().setTerms(terms);
53 List<Career> careers = new ArrayList<Career>();
54 List<Subject> subjects = new ArrayList<Subject>();
55 careers.addAll(terms.get(0).getCareers());
56 for( Career c : careers ) {
57 subjects.addAll(c.getSubjects());
58 }
59 getDao().setCareers(careers);
60 getDao().setSubjects(subjects);
61 }
62
63 public AcademicsDao getDao() {
64 return dao;
65 }
66
67 public void setDao(AcademicsDao dao) {
68 this.dao = dao;
69 }
70 }