private InteractionStream parseDataSource(File file) throws IOException { PsiJami.initialiseAllMIDataSources(); MIDataSourceFactory dataSourceFactory = MIDataSourceFactory.getInstance(); MIDataSourceOptionFactory optionsFactory = MIDataSourceOptionFactory.getInstance(); // by default we always have interaction evidences InteractionStream interactionSource = dataSourceFactory.getInteractionSourceWith(optionsFactory.getDefaultOptions(file)); if (interactionSource == null){ throw new IOException("Cannot parse the file "+file.getName()); } return interactionSource; } }
/** * * @param requiredOptions : options needed and to initialise dataSource * @return a new MIDatasource instance if the factory could find a registered MIDataSource matching the options. * Null if the factory cannot provide any MIDataSource implementation matching the requested options */ public MIDataSource getMIDataSourceWith(Map<String,Object> requiredOptions) { for (Map.Entry<Class<? extends MIDataSource>, Map<String, Object>> entry : registeredDataSources.entrySet()){ // we check for a DataSource that can be used with the given options if (areSupportedOptions(entry.getValue(), requiredOptions)){ try { return instantiateNewDataSource(entry.getKey(), requiredOptions); } catch (IllegalAccessException e) { logger.log(Level.SEVERE,"We cannot instantiate data source of type " + entry.getKey() + " with the given options.", e); } catch (InstantiationException e) { logger.log(Level.SEVERE,"We cannot instantiate data source of type " + entry.getKey() + " with the given options.", e); } catch (Exception e){ logger.log(Level.WARNING,"We cannot instantiate data source of type " + entry.getKey() + " with the given options.", e); } } } return null; }
protected void initialiseInputDataStream() { InputStream inputStreamToAnalyse = null; try { inputStreamToAnalyse = resource.getInputStream(); MIDataSourceFactory dataSourceFactory = MIDataSourceFactory.getInstance(); MIDataSourceOptionFactory optionFactory = MIDataSourceOptionFactory.getInstance(); this.interactionDataSource = dataSourceFactory.getInteractionSourceWith(createDatasourceOptions(inputStreamToAnalyse, optionFactory)); } catch (IOException e) { logger.warn("Input resource cannot be opened " + resource.getDescription()); throw new ItemStreamException("Input resource must be readable: " + resource, e); } }
/** * * @param requiredOptions : options needed and to initialise dataSource * @param <I> : type of interaction * @return a new InteractionStream instance if the factory could find a registered InteractionStream matching the options. * Null if the factory cannot provide any InteractionStream implementation matching the requested options */ public <I extends Interaction> InteractionStream<I> getInteractionSourceWith(Map<String,Object> requiredOptions) { for (Map.Entry<Class<? extends MIDataSource>, Map<String, Object>> entry : registeredDataSources.entrySet()){ // we check for a DataSource that can be used with the given options if (interactionSourceClass.isAssignableFrom(entry.getKey()) && areSupportedOptions(entry.getValue(), requiredOptions)){ try { return (InteractionStream) instantiateNewDataSource(entry.getKey(), requiredOptions); } catch (IllegalAccessException e) { logger.log(Level.SEVERE,"We cannot instantiate interaction data source of type " + entry.getKey() + " with the given options.", e); } catch (InstantiationException e) { logger.log(Level.SEVERE,"We cannot instantiate interaction data source of type " + entry.getKey() + " with the given options.", e); } catch (Exception e){ logger.log(Level.WARNING,"We cannot instantiate interaction data source of type " + entry.getKey() + " with the given options.", e); } } } return null; }