1 | package dcworms.schedframe.scheduling.utils; |
---|
2 | |
---|
3 | import java.io.StringReader; |
---|
4 | import java.util.ArrayList; |
---|
5 | |
---|
6 | import org.exolab.castor.xml.MarshalException; |
---|
7 | import org.exolab.castor.xml.ResolverException; |
---|
8 | import org.exolab.castor.xml.Unmarshaller; |
---|
9 | import org.exolab.castor.xml.ValidationException; |
---|
10 | import org.exolab.castor.xml.XMLContext; |
---|
11 | |
---|
12 | import schedframe.DescriptionContainer; |
---|
13 | |
---|
14 | import org.qcg.broker.schemas.jobdesc.QcgJob; |
---|
15 | |
---|
16 | |
---|
17 | public class JobDescription extends ArrayList<TaskDescription> implements DescriptionContainer<QcgJob>{ |
---|
18 | |
---|
19 | private static final long serialVersionUID = 7853990656207447619L; |
---|
20 | protected static Unmarshaller unmarshaller; |
---|
21 | static { |
---|
22 | XMLContext context = new XMLContext(); |
---|
23 | try { |
---|
24 | context.addClass(org.qcg.broker.schemas.jobdesc.QcgJob.class); |
---|
25 | unmarshaller = context.createUnmarshaller(); |
---|
26 | } catch (ResolverException e) { |
---|
27 | e.printStackTrace(); |
---|
28 | unmarshaller = null; |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | protected String xml; |
---|
33 | protected QcgJob job; |
---|
34 | protected String jobId; |
---|
35 | |
---|
36 | public JobDescription(String xmlJobDesc) throws MarshalException, ValidationException{ |
---|
37 | xml = xmlJobDesc; |
---|
38 | } |
---|
39 | |
---|
40 | public String getJobId(){ |
---|
41 | return this.jobId; |
---|
42 | } |
---|
43 | |
---|
44 | public void setJobId(String id){ |
---|
45 | this.jobId = id; |
---|
46 | } |
---|
47 | |
---|
48 | public void discardUnused(){ |
---|
49 | job = null; |
---|
50 | xml = null; |
---|
51 | for(int i = 0; i < size(); i++){ |
---|
52 | get(i).discardUnused(); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | public QcgJob getDescription() { |
---|
57 | if(job == null){ |
---|
58 | try { |
---|
59 | job = (QcgJob) unmarshaller.unmarshal(new StringReader(xml)); |
---|
60 | } catch (MarshalException e) { |
---|
61 | e.printStackTrace(); |
---|
62 | } catch (ValidationException e) { |
---|
63 | e.printStackTrace(); |
---|
64 | } |
---|
65 | } |
---|
66 | return job; |
---|
67 | } |
---|
68 | |
---|
69 | public String getDocument() throws Exception { |
---|
70 | return xml; |
---|
71 | } |
---|
72 | |
---|
73 | } |
---|