package schedframe.scheduling.plan.impl; import java.io.StringWriter; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.ValidationException; import schedframe.scheduling.plan.AllocationInterface; import schedframe.scheduling.plan.ScheduledTaskInterface; import schedframe.scheduling.plan.ScheduledTimeInterface; import org.qcg.broker.schemas.schedulingplan.types.AllocationStatus; public class ScheduledTask implements ScheduledTaskInterface { private static final long serialVersionUID = -9006532413203045991L; protected org.qcg.broker.schemas.schedulingplan.Task t; public ScheduledTask(){ t = new org.qcg.broker.schemas.schedulingplan.Task(); } public ScheduledTask(org.qcg.broker.schemas.schedulingplan.Task value){ t = value; } public org.qcg.broker.schemas.schedulingplan.Task getDescription() { return t; } public String getDocument() { StringWriter writer = new StringWriter(); try { t.marshal(writer); } catch (MarshalException e) { e.printStackTrace(); } catch (ValidationException e) { e.printStackTrace(); } return writer.toString(); } public void addAllocation( AllocationInterface allocation) throws IndexOutOfBoundsException { t.addAllocation((org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription()); } public void addAllocation(int index, AllocationInterface allocation) throws IndexOutOfBoundsException { t.addAllocation(index, (org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription()); } public void deleteTopology() { t.deleteTopology(); } @SuppressWarnings("unchecked") public AllocationInterface getAllocation(int index) throws IndexOutOfBoundsException { return new schedframe.scheduling.plan.impl.Allocation(t.getAllocation(index)); } @SuppressWarnings("unchecked") public AllocationInterface[] getAllocation() { org.qcg.broker.schemas.schedulingplan.Allocation tab[] = t.getAllocation(); if(tab == null) return null; schedframe.scheduling.plan.impl.Allocation ret[] = new schedframe.scheduling.plan.impl.Allocation[tab.length]; for(int i = 0; i < tab.length; i++){ ret[i] = new schedframe.scheduling.plan.impl.Allocation(tab[i]); } return ret; } public int getAllocationCount() { return t.getAllocationCount(); } public String getJobId() { return t.getJobId(); } public AllocationStatus getStatus() { return t.getStatus(); } public String getStatusDescription(){ return t.getStatusDescription(); } public String getTaskId() { return t.getTaskId(); } public int getTopology() { return t.getTopology(); } public boolean hasTopology() { return t.hasTopology(); } public void removeAllAllocation() { t.removeAllAllocation(); } public boolean removeAllocation( AllocationInterface allocation) { return t.removeAllocation((org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription()); } @SuppressWarnings("unchecked") public AllocationInterface removeAllocationAt(int index) { return new schedframe.scheduling.plan.impl.Allocation(t.removeAllocationAt(index)); } public void setAllocation(int index, AllocationInterface allocation) throws IndexOutOfBoundsException { t.setAllocation(index, (org.qcg.broker.schemas.schedulingplan.Allocation)allocation.getDescription()); } public void setAllocation( AllocationInterface[] allocationArray) { if(allocationArray == null) return; org.qcg.broker.schemas.schedulingplan.Allocation tab[] = new org.qcg.broker.schemas.schedulingplan.Allocation[allocationArray.length]; for(int i = 0; i < allocationArray.length; i++){ tab[i] = (org.qcg.broker.schemas.schedulingplan.Allocation)allocationArray[i].getDescription(); } t.setAllocation(tab); } public void setJobId(String jobId) { t.setJobId(jobId); } public void setStatus(AllocationStatus status) { t.setStatus(status); } public void setStatusDescription(String statusDescription){ t.setStatusDescription(statusDescription); } public void setTaskId(String taskId) { t.setTaskId(taskId); } public void setTopology(int topology) { t.setTopology(topology); } @SuppressWarnings("unchecked") public ScheduledTimeInterface getScheduledTime() { org.qcg.broker.schemas.schedulingplan.ScheduledTime time = t.getScheduledTime(); if(time == null) return null; ScheduledTime st = new ScheduledTime(time); return st; } public void setScheduledTime( ScheduledTimeInterface scheduledTime) { t.setScheduledTime((org.qcg.broker.schemas.schedulingplan.ScheduledTime) scheduledTime.getDescription()); } }