/** * Load the {@link IParameters} from the give {@link InputStream} * @param stream - stream of the parameter file. */ public void loadParametersFromStream(InputStream stream) { // stream parameters always overrides any other source parametersLocation = null; this.parameters.fromString(StreamUtil.streamUtf8AsString(stream)); } }
private void instantiateConnector (int index) { try { if (infoList.get(index).classLoader == null) { currentConnector = (IQuery)Class.forName(infoList.get(index).connectorClass).newInstance(); } else { currentConnector = (IQuery)Class.forName(infoList.get(index).connectorClass, true, infoList.get(index).classLoader).newInstance(); } currentParams = currentConnector.getParameters(); if ( !Util.isEmpty(paramsList.get(index)) ) { // Set the current parameters if they exist currentParams.fromString(paramsList.get(index)); } // Otherwise use the defaults } catch ( InstantiationException e ) { throw new OkapiException("Error creating the connector. " + e.getMessage(), e); } catch ( IllegalAccessException e ) { throw new OkapiException("Error creating the connector. " + e.getMessage(), e); } catch ( ClassNotFoundException e ) { throw new OkapiException("Error creating the connector. " + e.getMessage(), e); } }
/** * Gets the parameters for a given custom filter configuration. This * default implementation gets the custom data from a file located * in the current directory at the time the method is called. */ @Override public IParameters getCustomParameters (FilterConfiguration config, IFilter existingFilter) { // Instantiate a filter (or re-use one) IFilter filter = instantiateFilter(config, existingFilter); // Get the default parameters object IParameters params = filter.getParameters(); if ( params == null ) { return null; // This filter does not have parameters } // Load the provided parameter file // In this implementation the file is stored in a given directory if (config.parametersLocation != null) { File file = new File(customParmsDir + config.parametersLocation); params.load(Util.URItoURL(file.toURI()), false); } else if (config.parameters != null) { params.fromString(config.parameters.toString()); } return params; }
@Override public IParameters getParameters (FilterConfiguration config, IFilter existingFilter) { IFilter filter = instantiateFilter(config, existingFilter); IParameters params = filter.getParameters(); // No parameters for this filter if ( params == null ) { return null; } // Default parameters if ( config.parametersLocation == null && config.parameters == null ) { return params; } if ( config.custom ) { params = getCustomParameters(config, filter); } else if (config.parametersLocation != null) { // Note that we cannot assume the parameters are the same // if we re-used an existing filter, as we cannot compare the // configuration identifiers URL url = filter.getClass().getResource(config.parametersLocation); params.load(url, false); } else if (config.parameters != null) { params.fromString(config.parameters.toString()); } return params; }
params.fromString(fc.parameters.toString()); } else { params.reset();
newParams.fromString(baseParams.toString());
tmParams.fromString(connectorParams);
tmParams.fromString(connectorParams);
@Override protected Event handleStartBatch(Event event) { tuEventCount = 0; try { connector = (ITMQuery) Class.forName(params.getResourceClassName()).newInstance(); } catch (InstantiationException e) { throw new OkapiException("Error creating connector.", e); } catch (IllegalAccessException e) { throw new OkapiException("Error creating connector.", e); } catch (ClassNotFoundException e) { throw new OkapiException("Error creating connector.", e); } IParameters connectorParams = connector.getParameters(); if (connectorParams != null) { // Set the parameters only if the connector takes them connectorParams.fromString(params.getResourceParameters()); } connector.setRootDirectory(rootDir); // Before open() connector.setParameters(connectorParams); connector.open(); if ((sourceLocale != null) && (targetLocale != null)) { connector.setLanguages(sourceLocale, targetLocale); } connector.setThreshold(params.getThreshold()); connector.setMaximumHits(5); return event; }
fprm.fromString(info.getFilterParameters());