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