use of eu.esdihumboldt.hale.common.core.io.IOProvider in project hale by halestudio.
the class CharsetConfigurationPage method enable.
@Override
public void enable() {
// select I/O provider default charset
IOProvider pro = getWizard().getProvider();
if (pro != null) {
Charset cs = pro.getCharset();
if (cs != null) {
setCharset(cs.name());
update();
}
if (detectButton != null) {
detectButton.setEnabled(pro instanceof ImportProvider);
}
}
}
use of eu.esdihumboldt.hale.common.core.io.IOProvider in project hale by halestudio.
the class HeadlessIO method executeConfiguration.
/**
* Execute a single I/O configuration. If no matching advisor is given for
* the configuration, first the extension point is queried for an advisor,
* if not found it is ignored.
*
* @param conf the I/O configuration
* @param advisors map of advisors, action ID mapped to responsible advisor
* @param reportHandler the report handler, may be <code>null</code>
* @param serviceProvider the service provider
* @throws IOException if an error occurs executing a configuration
*/
public static void executeConfiguration(IOConfiguration conf, Map<String, IOAdvisor<?>> advisors, ReportHandler reportHandler, ServiceProvider serviceProvider) throws IOException {
// get advisor ...
final String actionId = conf.getActionId();
IOAdvisor<?> advisor = advisors.get(actionId);
if (advisor == null) {
// try to find registered advisor for action (e.g. lookup)
List<IOAdvisorFactory> regAdvisors = IOAdvisorExtension.getInstance().getFactories(new FactoryFilter<IOAdvisor<?>, IOAdvisorFactory>() {
@Override
public boolean acceptFactory(IOAdvisorFactory factory) {
return factory.getActionID().equals(actionId);
}
@Override
public boolean acceptCollection(ExtensionObjectFactoryCollection<IOAdvisor<?>, IOAdvisorFactory> collection) {
return true;
}
});
if (regAdvisors != null && !regAdvisors.isEmpty()) {
try {
advisor = regAdvisors.get(0).createAdvisor(actionId, serviceProvider);
log.info(MessageFormat.format("No advisor for action {0} given, using advisor registered through extension point.", actionId));
} catch (Exception e) {
log.error(MessageFormat.format("Failed to load registered advisor for action {0}.", actionId));
if (advisor != null) {
// shouldn't happen, but seems to happen anyway
log.error("Advisor is set in spite of error", e);
}
}
}
}
if (advisor == null) {
log.info(MessageFormat.format("No advisor for action {0} given, I/O configuration is ignored.", actionId));
// ignore this configuration
return;
}
// ... and provider
IOProvider provider = loadProvider(conf);
if (provider != null) {
if (serviceProvider != null) {
// set service provider, just in case the advisor does not do it
provider.setServiceProvider(serviceProvider);
}
// execute provider
executeProvider(provider, advisor, null, reportHandler);
// XXX progress?!!
} else {
throw new IOException(MessageFormat.format("Could not execute I/O configuration, provider with ID {0} not found.", conf.getProviderId()));
}
}
use of eu.esdihumboldt.hale.common.core.io.IOProvider in project hale by halestudio.
the class HeadlessIO method loadProvider.
/**
* Load and configure the I/O provider specified by the given I/O
* configuration.
*
* @param conf the I/O configuration
* @return the provider or <code>null</code> if it was not found or could
* not be created
*/
public static IOProvider loadProvider(IOConfiguration conf) {
IOProvider provider = null;
IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (descriptor != null) {
try {
provider = descriptor.createExtensionObject();
// configure settings
provider.loadConfiguration(conf.getProviderConfiguration());
if (provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setCache(conf.getCache());
}
} catch (Exception e) {
log.error("Could not instantiate I/O provider.", e);
}
}
return provider;
}
use of eu.esdihumboldt.hale.common.core.io.IOProvider in project hale by halestudio.
the class AppSchemaFileWriterTest method loadTestProject.
@BeforeClass
public static void loadTestProject() {
try {
URL archiveLocation = AppSchemaFileWriterTest.class.getResource(PROJECT_LOCATION);
ArchiveProjectReader projectReader = new ArchiveProjectReader();
projectReader.setSource(new DefaultInputSupplier(archiveLocation.toURI()));
IOReport report = projectReader.execute(new LogProgressIndicator());
if (!report.isSuccess()) {
throw new RuntimeException("project reader execution failed");
}
tempDir = projectReader.getTemporaryFiles().iterator().next();
project = projectReader.getProject();
assertNotNull(project);
sourceSchemaSpace = new DefaultSchemaSpace();
targetSchemaSpace = new DefaultSchemaSpace();
// load schemas
List<IOConfiguration> resources = project.getResources();
for (IOConfiguration resource : resources) {
String actionId = resource.getActionId();
String providerId = resource.getProviderId();
// get provider
IOProvider provider = null;
IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(providerId);
if (descriptor == null) {
throw new RuntimeException("Could not load I/O provider with ID: " + resource.getProviderId());
}
provider = descriptor.createExtensionObject();
provider.loadConfiguration(resource.getProviderConfiguration());
prepareProvider(provider, project, tempDir.toURI());
IOReport providerReport = provider.execute(new LogProgressIndicator());
if (!providerReport.isSuccess()) {
throw new RuntimeException("I/O provider execution failed");
}
// TODO: could (should?) be done by an advisor
if (provider instanceof SchemaReader) {
Schema schema = ((SchemaReader) provider).getSchema();
if (actionId.equals(SchemaIO.ACTION_LOAD_SOURCE_SCHEMA)) {
sourceSchemaSpace.addSchema(schema);
} else if (actionId.equals(SchemaIO.ACTION_LOAD_TARGET_SCHEMA)) {
targetSchemaSpace.addSchema(schema);
}
}
}
// load alignment
List<ProjectFileInfo> projectFiles = project.getProjectFiles();
for (ProjectFileInfo projectFile : projectFiles) {
if (projectFile.getName().equals(AlignmentIO.PROJECT_FILE_ALIGNMENT)) {
AlignmentReader alignReader = new JaxbAlignmentReader();
alignReader.setSource(new DefaultInputSupplier(projectFile.getLocation()));
alignReader.setSourceSchema(sourceSchemaSpace);
alignReader.setTargetSchema(targetSchemaSpace);
alignReader.setPathUpdater(new PathUpdate(null, null));
IOReport alignReport = alignReader.execute(new LogProgressIndicator());
if (!alignReport.isSuccess()) {
throw new RuntimeException("alignment reader execution failed");
}
alignment = alignReader.getAlignment();
assertNotNull(alignment);
break;
}
}
} catch (Exception e) {
log.error("Exception occurred", e);
fail("Test project could not be loaded: " + e.getMessage());
}
}
use of eu.esdihumboldt.hale.common.core.io.IOProvider in project hale by halestudio.
the class IOReferenceContent method getInputStream.
@Override
public InputStream getInputStream(String pluginID, String href, Locale locale) {
// it is an I/O provider reference
if (href.startsWith(IO_PROVIDERS_TOPIC_PATH)) {
String providerId = href.substring(IO_PROVIDERS_TOPIC_PATH.length());
// strip everything after a ?
int ind = providerId.indexOf('?');
if (ind >= 0) {
providerId = providerId.substring(0, ind);
}
// strip the .*htm? ending
if (providerId.endsWith("html") || providerId.endsWith("htm")) {
providerId = providerId.substring(0, providerId.lastIndexOf('.'));
}
try {
return getIOProviderContent(providerId);
} catch (Exception e) {
log.error("Error creating instance io info page.", e);
return null;
}
} else // should be an I/O provider overview by type
if (href.startsWith(OVERVIEW_TOPIC_PATH)) {
// extract provider type name
String providerType = href.substring(OVERVIEW_TOPIC_PATH.length());
// strip everything after a ?
int ind = providerType.indexOf('?');
if (ind >= 0) {
providerType = providerType.substring(0, ind);
}
// strip the .*htm? ending
if (providerType.endsWith("html") || providerType.endsWith("htm")) {
providerType = providerType.substring(0, providerType.lastIndexOf('.'));
}
Class<? extends IOProvider> providerClass = null;
switch(providerType) {
case "InstanceReader":
providerClass = InstanceReader.class;
break;
case "InstanceWriter":
providerClass = InstanceWriter.class;
break;
case "InstanceValidator":
providerClass = InstanceValidator.class;
break;
}
if (providerClass != null) {
final Class<? extends IOProvider> provider = providerClass;
try {
return getContentFromTemplate("overview." + providerType, TEMPLATE_OVERVIEW, new Callable<VelocityContext>() {
@Override
public VelocityContext call() throws Exception {
VelocityContext context = new VelocityContext();
// getProviderFactorries returns
// Collection<IOProviderDescriptor>
Collection<IOProviderDescriptor> writer = HaleIO.getProviderFactories(provider);
context.put("providers", writer);
context.put("providerType", provider.getSimpleName());
return context;
}
});
} catch (Exception e) {
log.error("Error creating provider overview", e);
return null;
}
}
return null;
}
return null;
}
Aggregations