/*
* File: LoadManagers.java
* Author: Daniel Rogers
* Created on Jan 11, 2010
*
*/
import gri.tasks.managers.JobManagerSet;
import gri.tasks.managers.xml.BasicJobManagerSerializer;
import gri.tasks.managers.xml.JobManagerEntrySerializer;
import gri.tasks.managers.xml.TypedSerializerSet;
import gri.tasks.java.xml.FunctionTaskManagerSerializer;
import gri.gridp.tasks.managers.xml.GridpTaskManagerSerializer;
import gri.gridp.tasks.ssh.xml.ProxyTaskManagerSerializer;
import gri.data.serializers.jdom.IO;
import gri.data.serializers.jdom.JDOMSerializer;
import gri.data.serializers.jdom.ListSerializer;
import org.jdom.Element;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class Loader {
public static JobManagerSet load(File file) throws Exception {
return (JobManagerSet)IO.read(
file,
new JobManagerSetSerializer()
);
}
static class JobManagerSetSerializer implements JDOMSerializer {
JDOMSerializer jobEntrySerializer;
// --------------------------------------------- Constructors
public JobManagerSetSerializer() {
//task providers (for basic JobManager):
TypedSerializerSet taskManagerSerializers = new TypedSerializerSet();
taskManagerSerializers.addSerializer(new FunctionTaskManagerSerializer());
taskManagerSerializers.addSerializer(new GridpTaskManagerSerializer());
taskManagerSerializers.addSerializer(new ProxyTaskManagerSerializer());
//job managers:
TypedSerializerSet jobManagerSerializer = new TypedSerializerSet();
jobManagerSerializer.addSerializer(
new BasicJobManagerSerializer(taskManagerSerializers));
//jobManagerSerializer.addSerializer(
// new PBSJobManagerSerializer());
//jobManagerSerializer.addSerializer(
// new ProxyJobManagerSerializer());
//job manager entries:
this.jobEntrySerializer = new JobManagerEntrySerializer(jobManagerSerializer);
}
// -------------------------------------------- Implementation
public void write(Object o, Element elem) {
writeSet((JobManagerSet)o, elem);
}
public Object read(Element elem) throws IOException {
return readSet(elem);
}
public void writeSet(JobManagerSet managers, Element elem) {
throw new RuntimeException("Not implemented");
}
public JobManagerSet readSet(Element elem) throws IOException {
ListSerializer listSerializer = new ListSerializer(jobEntrySerializer, "jobManagerEntry");
List entries = listSerializer.readList(elem);
return new JobManagerSet(entries);
}
}
}