Search in sources :

Example 1 with ProjectType

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();
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) ObjectFactory(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ObjectFactory) ProjectType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType) JAXBContext(javax.xml.bind.JAXBContext)

Example 2 with ProjectType

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;
}
Also used : IOConfigurationType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.IOConfigurationType) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) ExportConfigurationType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ExportConfigurationType) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) Value(eu.esdihumboldt.hale.common.core.io.Value) PropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.PropertyType) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType)

Example 3 with ProjectType

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);
}
Also used : ProjectType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

ProjectType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ProjectType)3 JAXBContext (javax.xml.bind.JAXBContext)2 Value (eu.esdihumboldt.hale.common.core.io.Value)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)1 ComplexPropertyType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType)1 ExportConfigurationType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ExportConfigurationType)1 IOConfigurationType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.IOConfigurationType)1 ObjectFactory (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ObjectFactory)1 PropertyType (eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.PropertyType)1 IOException (java.io.IOException)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1