/* * Copyright (c) 2012 Data Harmonisation Panel * * All rights reserved. This program and the accompanying materials are made * available under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution. If not, see <http://www.gnu.org/licenses/>. * * Contributors: * HUMBOLDT EU Integrated Project #030962 * Data Harmonisation Panel <http://www.dhpanel.eu> */ package eu.esdihumboldt.hale.common.align.io.impl; import java.io.IOException; import java.io.InputStream; import eu.esdihumboldt.hale.common.align.io.EntityResolver; import eu.esdihumboldt.hale.common.align.model.MutableAlignment; import eu.esdihumboldt.hale.common.core.io.IOProvider; import eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException; import eu.esdihumboldt.hale.common.core.io.ProgressIndicator; import eu.esdihumboldt.hale.common.core.io.impl.AbstractIOProvider; import eu.esdihumboldt.hale.common.core.io.report.IOReporter; import eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl; /** * HALE alignment reader * * @author Simon Templer */ public class JaxbAlignmentReader extends AbstractAlignmentReader { /** * @see IOProvider#isCancelable() */ @Override public boolean isCancelable() { return false; } /** * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter) */ @Override protected MutableAlignment loadAlignment(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException { progress.begin("Load HALE alignment", ProgressIndicator.UNKNOWN); InputStream in = getSource().getInput(); MutableAlignment alignment = null; try { EntityResolver entityResolver = null; if (getServiceProvider() != null) { entityResolver = getServiceProvider().getService(EntityResolver.class); } alignment = JaxbAlignmentIO.load(in, reporter, getSourceSchema(), getTargetSchema(), getPathUpdater(), entityResolver); } catch (Exception e) { reporter.error(new IOMessageImpl(e.getMessage(), e)); reporter.setSuccess(false); return alignment; } finally { in.close(); } progress.end(); reporter.setSuccess(true); return alignment; } }