use of eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType in project hale by halestudio.
the class JaxbProjectIO method save.
/**
* Save a project to an output stream.
*
* @param project the project to save
* @param out the output stream
* @throws Exception if converting or writing the alignment fails
*/
public static void save(Project project, OutputStream out) throws Exception {
ProjectType projType = ProjectToJaxb.convert(project);
JAXBContext jc = JAXBContext.newInstance(PROJECT_CONTEXT, ObjectFactory.class.getClassLoader());
Marshaller m = jc.createMarshaller();
// Indent output
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
// set encoding
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
// Specify the schema location
// m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
// "http://knowledgeweb.semanticweb.org/heterogeneity/alignment align.xsd");
ObjectFactory of = new ObjectFactory();
try {
m.marshal(of.createHaleProject(projType), out);
} finally {
out.flush();
out.close();
}
}
use of eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType in project hale by halestudio.
the class ProjectToJaxb method convert.
/**
* Convert the given project to the corresponding JAXB type.
*
* @param project the project to convert
* @return the converted project
*/
public static ProjectType convert(Project project) {
ProjectType result = new ProjectType();
result.setAuthor(project.getAuthor());
result.setCreated(toXMLCalendar(project.getCreated()));
result.setDescription(project.getDescription());
result.setModified(toXMLCalendar(project.getModified()));
result.setName(project.getName());
result.setSaveConfig(toIOConfigurationType(project.getSaveConfiguration()));
if (project.getHaleVersion() != null) {
result.setVersion(project.getHaleVersion().toString());
}
// resources
for (IOConfiguration resource : project.getResources()) {
result.getResource().add(toIOConfigurationType(resource));
}
// export configs
for (Entry<String, IOConfiguration> confEntry : project.getExportConfigurations().entrySet()) {
IOConfigurationType conf = toIOConfigurationType(confEntry.getValue());
ExportConfigurationType exportConf = new ExportConfigurationType();
exportConf.setConfiguration(conf);
exportConf.setName(confEntry.getKey());
result.getExportConfig().add(exportConf);
}
// project files
for (ProjectFileInfo file : project.getProjectFiles()) {
result.getFile().add(toProjectFileType(file));
}
// properties
for (Entry<String, Value> property : project.getProperties().entrySet()) {
Object p = createProperty(property.getKey(), property.getValue());
if (p instanceof PropertyType) {
result.getAbstractProperty().add(of.createProperty((PropertyType) p));
} else if (p instanceof ComplexPropertyType) {
result.getAbstractProperty().add(of.createComplexProperty((ComplexPropertyType) p));
}
}
return result;
}
use of eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType in project hale by halestudio.
the class JaxbProjectIO method load.
/**
* Load a project from an input stream.
*
* @param in the input stream
* @return the alignment
* @throws JAXBException if reading the alignment failed
*/
public static Project load(InputStream in) throws JAXBException {
JAXBContext jc;
JAXBElement<ProjectType> root = null;
jc = JAXBContext.newInstance(PROJECT_CONTEXT, ProjectType.class.getClassLoader());
Unmarshaller u = jc.createUnmarshaller();
try {
root = u.unmarshal(new StreamSource(in), ProjectType.class);
} finally {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
ProjectType genProject = root.getValue();
// convert to project
return JaxbToProject.convert(genProject);
}
Aggregations