[477] | 1 | package schedframe.scheduling.plan.impl; |
---|
| 2 | |
---|
| 3 | import java.io.StringWriter; |
---|
| 4 | import java.util.ArrayList; |
---|
| 5 | |
---|
| 6 | import org.exolab.castor.xml.MarshalException; |
---|
| 7 | import org.exolab.castor.xml.ValidationException; |
---|
| 8 | |
---|
| 9 | import schedframe.scheduling.plan.ScheduledTaskInterface; |
---|
| 10 | import schedframe.scheduling.plan.SchedulingPlanInterface; |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | public class SchedulingPlan implements SchedulingPlanInterface<org.qcg.broker.schemas.schedulingplan.SchedulingPlan> { |
---|
| 14 | |
---|
| 15 | private static final long serialVersionUID = 2557774150841711876L; |
---|
| 16 | protected org.qcg.broker.schemas.schedulingplan.SchedulingPlan sp; |
---|
| 17 | |
---|
| 18 | public SchedulingPlan(){ |
---|
| 19 | sp = new org.qcg.broker.schemas.schedulingplan.SchedulingPlan(); |
---|
[481] | 20 | taskList = new ArrayList<ScheduledTaskInterface<?>>(); |
---|
[477] | 21 | } |
---|
| 22 | |
---|
| 23 | public SchedulingPlan(org.qcg.broker.schemas.schedulingplan.SchedulingPlan value){ |
---|
| 24 | sp = value; |
---|
[481] | 25 | taskList = new ArrayList<ScheduledTaskInterface<?>>(); |
---|
[477] | 26 | } |
---|
| 27 | |
---|
| 28 | public org.qcg.broker.schemas.schedulingplan.SchedulingPlan getDescription() { |
---|
| 29 | return sp; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | public String getDocument() { |
---|
| 33 | StringWriter writer = new StringWriter(); |
---|
| 34 | try { |
---|
| 35 | sp.marshal(writer); |
---|
| 36 | } catch (MarshalException e) { |
---|
| 37 | e.printStackTrace(); |
---|
| 38 | } catch (ValidationException e) { |
---|
| 39 | e.printStackTrace(); |
---|
| 40 | } |
---|
| 41 | return writer.toString(); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | public <Task_> void addTask(ScheduledTaskInterface<Task_> task) |
---|
| 45 | throws IndexOutOfBoundsException { |
---|
| 46 | sp.addTask((org.qcg.broker.schemas.schedulingplan.Task) task.getDescription()); |
---|
| 47 | taskList.add(task); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | public <Task_> void addTask(int index, ScheduledTaskInterface<Task_> task) |
---|
| 51 | throws IndexOutOfBoundsException { |
---|
| 52 | sp.addTask(index, (org.qcg.broker.schemas.schedulingplan.Task) task.getDescription()); |
---|
| 53 | taskList.add(index, task); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | @SuppressWarnings("unchecked") |
---|
| 57 | public ScheduledTaskInterface<org.qcg.broker.schemas.schedulingplan.Task> getTask(int index) |
---|
| 58 | throws IndexOutOfBoundsException { |
---|
| 59 | return new ScheduledTask(sp.getTask(index)); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | @SuppressWarnings("unchecked") |
---|
| 63 | public ScheduledTaskInterface<org.qcg.broker.schemas.schedulingplan.Task>[] getTask() { |
---|
| 64 | org.qcg.broker.schemas.schedulingplan.Task tab[] = sp.getTask(); |
---|
| 65 | if(tab == null) return null; |
---|
| 66 | |
---|
| 67 | ScheduledTask ret[] = new ScheduledTask[tab.length]; |
---|
| 68 | for(int i = 0; i < tab.length; i++){ |
---|
| 69 | ret[i] = new ScheduledTask(tab[i]); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | return ret; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | public int getTaskCount() { |
---|
| 76 | return sp.getTaskCount(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | public void removeAllTask() { |
---|
| 80 | sp.removeAllTask(); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | public <Task_> boolean removeTask(ScheduledTaskInterface<Task_> task) { |
---|
| 84 | return sp.removeTask((org.qcg.broker.schemas.schedulingplan.Task) task.getDescription()); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | @SuppressWarnings("unchecked") |
---|
| 88 | public ScheduledTaskInterface<org.qcg.broker.schemas.schedulingplan.Task> removeTaskAt(int index) { |
---|
| 89 | return new ScheduledTask(sp.removeTaskAt(index)); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | public <Task_> void setTask(int index, ScheduledTaskInterface<Task_> task) |
---|
| 93 | throws IndexOutOfBoundsException { |
---|
| 94 | sp.setTask(index, (org.qcg.broker.schemas.schedulingplan.Task) task.getDescription()); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | public <Task_> void setTask(ScheduledTaskInterface<Task_>[] taskArray) { |
---|
| 98 | if(taskArray == null) return; |
---|
| 99 | |
---|
| 100 | org.qcg.broker.schemas.schedulingplan.Task tab[] = new org.qcg.broker.schemas.schedulingplan.Task[taskArray.length]; |
---|
| 101 | for(int i = 0; i < taskArray.length; i++){ |
---|
| 102 | tab[i] = (org.qcg.broker.schemas.schedulingplan.Task)taskArray[i].getDescription(); |
---|
| 103 | } |
---|
| 104 | sp.setTask(tab); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
[481] | 108 | protected ArrayList<ScheduledTaskInterface<?>> taskList; |
---|
[477] | 109 | |
---|
[481] | 110 | public ArrayList<ScheduledTaskInterface<?>> getTasks() { |
---|
[477] | 111 | |
---|
| 112 | return this.taskList; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | } |
---|