Search in sources :

Example 1 with HaleProject

use of eu.esdihumboldt.hale.io.project.jaxb.generated.HaleProject in project hale by halestudio.

the class ProjectParser method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin(Messages.ProjectParser_0, ProgressIndicator.UNKNOWN);
    try {
        File file;
        try {
            file = new File(getSource().getLocation());
        } catch (IllegalArgumentException e) {
            file = null;
        }
        String basePath = (file == null) ? (new File(".").getAbsolutePath()) : (FilenameUtils.getFullPath(file.getAbsolutePath()));
        // Unmarshal the project file
        JAXBContext jc;
        JAXBElement<HaleProject> root;
        try {
            jc = JAXBContext.newInstance(PROJECT_CONTEXT, ObjectFactory.class.getClassLoader());
            Unmarshaller u = jc.createUnmarshaller();
            u.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
            root = u.unmarshal(new StreamSource(getSource().getInput()), HaleProject.class);
        } catch (JAXBException e) {
            reporter.error(new IOMessageImpl("Unmarshalling the HaleProject from the given resource failed: {0}", e, -1, -1, getSource().getLocation()));
            reporter.setSuccess(false);
            return reporter;
        }
        project = new Project();
        projectFiles = new HashMap<String, ProjectFile>();
        report = reporter;
        HaleProject haleProject = root.getValue();
        // populate project and project files
        loadProject(haleProject);
        loadSchemas(haleProject, basePath);
        loadAlignment(haleProject, basePath);
        loadStyle(haleProject, basePath);
        loadInstances(haleProject, basePath);
        loadTasks(haleProject, basePath);
        loadConfig(haleProject);
        report = null;
        reporter.setSuccess(true);
        return reporter;
    } finally {
        progress.end();
    }
}
Also used : HaleProject(eu.esdihumboldt.hale.io.project.jaxb.generated.HaleProject) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) JAXBContext(javax.xml.bind.JAXBContext) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) HaleProject(eu.esdihumboldt.hale.io.project.jaxb.generated.HaleProject) Unmarshaller(javax.xml.bind.Unmarshaller) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) File(java.io.File)

Aggregations

Project (eu.esdihumboldt.hale.common.core.io.project.model.Project)1 ProjectFile (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 HaleProject (eu.esdihumboldt.hale.io.project.jaxb.generated.HaleProject)1 File (java.io.File)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1