1 | package schedframe.scheduling; |
---|
2 | |
---|
3 | import java.io.StringWriter; |
---|
4 | import java.io.Writer; |
---|
5 | |
---|
6 | import org.exolab.castor.xml.Marshaller; |
---|
7 | import org.exolab.castor.xml.ResolverException; |
---|
8 | import org.exolab.castor.xml.XMLContext; |
---|
9 | |
---|
10 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
11 | import org.qcg.broker.schemas.resreqs.Task; |
---|
12 | |
---|
13 | /** |
---|
14 | * |
---|
15 | * @author Marcin Krystek |
---|
16 | * |
---|
17 | */ |
---|
18 | public class ResourceRequirements extends AbstractResourceRequirements<Task>{ |
---|
19 | |
---|
20 | protected static Marshaller marshaller; |
---|
21 | static { |
---|
22 | XMLContext context = new XMLContext(); |
---|
23 | try { |
---|
24 | context.addClass(org.qcg.broker.schemas.resreqs.Task.class); |
---|
25 | marshaller = context.createMarshaller(); |
---|
26 | } catch (ResolverException e) { |
---|
27 | e.printStackTrace(); |
---|
28 | marshaller = null; |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | protected TaskInterface<?> task; |
---|
33 | |
---|
34 | public ResourceRequirements(Task task){ |
---|
35 | this.task = new schedframe.scheduling.Task(task); |
---|
36 | this.resourceRequirements = task; |
---|
37 | } |
---|
38 | |
---|
39 | public ResourceRequirements(TaskInterface<?> task){ |
---|
40 | this.task = task; |
---|
41 | this.resourceRequirements = (Task) task.getDescription(); |
---|
42 | } |
---|
43 | |
---|
44 | public double getParameterDoubleValue(ResourceParameterName parameterName) |
---|
45 | throws NoSuchFieldException, IllegalArgumentException { |
---|
46 | return task.getParameterDoubleValue(parameterName); |
---|
47 | } |
---|
48 | |
---|
49 | public String getParameterStringValue(ResourceParameterName parameterName) |
---|
50 | throws NoSuchFieldException, IllegalArgumentException { |
---|
51 | return task.getParameterStringValue(parameterName); |
---|
52 | } |
---|
53 | |
---|
54 | public Task getDescription() { |
---|
55 | return this.resourceRequirements; |
---|
56 | } |
---|
57 | |
---|
58 | public String getDocument() throws Exception { |
---|
59 | Writer w = new StringWriter(); |
---|
60 | |
---|
61 | marshaller.marshal(this.resourceRequirements, w); |
---|
62 | |
---|
63 | return w.toString(); |
---|
64 | } |
---|
65 | |
---|
66 | } |
---|