1 | package dcworms.schedframe.scheduling.utils; |
---|
2 | |
---|
3 | import java.io.StringReader; |
---|
4 | |
---|
5 | import org.exolab.castor.xml.MarshalException; |
---|
6 | import org.exolab.castor.xml.ResolverException; |
---|
7 | import org.exolab.castor.xml.Unmarshaller; |
---|
8 | import org.exolab.castor.xml.ValidationException; |
---|
9 | import org.exolab.castor.xml.XMLContext; |
---|
10 | |
---|
11 | import org.qcg.broker.schemas.jobdesc.Task; |
---|
12 | |
---|
13 | import schedframe.DescriptionContainer; |
---|
14 | |
---|
15 | public class TaskDescription implements DescriptionContainer<Task> { |
---|
16 | |
---|
17 | |
---|
18 | protected static Unmarshaller unmarshaller; |
---|
19 | static { |
---|
20 | XMLContext context = new XMLContext(); |
---|
21 | try { |
---|
22 | context.addClass(org.qcg.broker.schemas.jobdesc.Task.class); |
---|
23 | unmarshaller = context.createUnmarshaller(); |
---|
24 | } catch (ResolverException e) { |
---|
25 | e.printStackTrace(); |
---|
26 | unmarshaller = null; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | protected String xml; |
---|
31 | protected Task task; |
---|
32 | protected String taskId; |
---|
33 | protected String userDn; |
---|
34 | protected long submissionTime; |
---|
35 | protected long taskLength; |
---|
36 | protected long waitTime; |
---|
37 | |
---|
38 | |
---|
39 | public TaskDescription(String xmlTask){ |
---|
40 | xml = xmlTask; |
---|
41 | } |
---|
42 | |
---|
43 | public String getTaskId(){ |
---|
44 | return taskId; |
---|
45 | } |
---|
46 | |
---|
47 | public void setTaskId(String id){ |
---|
48 | this.taskId = id; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | public void discardUnused(){ |
---|
54 | xml = null; |
---|
55 | task = null; |
---|
56 | } |
---|
57 | |
---|
58 | public Task getDescription() { |
---|
59 | if(task == null){ |
---|
60 | try { |
---|
61 | task = (Task) unmarshaller.unmarshal(new StringReader(xml)); |
---|
62 | } catch (MarshalException e) { |
---|
63 | e.printStackTrace(); |
---|
64 | } catch (ValidationException e) { |
---|
65 | e.printStackTrace(); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | return task; |
---|
70 | } |
---|
71 | |
---|
72 | public String getDocument() throws Exception { |
---|
73 | return xml; |
---|
74 | } |
---|
75 | |
---|
76 | public String getUserDn() { |
---|
77 | return userDn; |
---|
78 | } |
---|
79 | |
---|
80 | public void setUserDn(String userDn) { |
---|
81 | this.userDn = userDn; |
---|
82 | } |
---|
83 | |
---|
84 | public long getSubmissionTime() { |
---|
85 | return submissionTime; |
---|
86 | } |
---|
87 | |
---|
88 | public void setSubmissionTime(long submissionTime) { |
---|
89 | this.submissionTime = submissionTime; |
---|
90 | } |
---|
91 | |
---|
92 | public long getTaskLength() { |
---|
93 | return taskLength; |
---|
94 | } |
---|
95 | |
---|
96 | public void setTaskLength(long taskLength) { |
---|
97 | this.taskLength = taskLength; |
---|
98 | } |
---|
99 | |
---|
100 | public long getWorkloadLogWaitTime() { |
---|
101 | return waitTime; |
---|
102 | } |
---|
103 | |
---|
104 | public void setWorkloadLogWaitTime(long waitTime) { |
---|
105 | this.waitTime = waitTime; |
---|
106 | } |
---|
107 | |
---|
108 | } |
---|