Java Code Examples for org.apache.uima.resource.metadata.ResourceMetaData#getConfigurationParameterSettings()

The following examples show how to use org.apache.uima.resource.metadata.ResourceMetaData#getConfigurationParameterSettings() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregateCollectionReader.java    From bluima with Apache License 2.0 6 votes vote down vote up
public AggregateCollectionReader(List<CollectionReader> readers,
    TypeSystemDescription tsd) {
try {
    CollectionReaderDescription crd = CollectionReaderFactory
	    .createReaderDescription(AggregateCollectionReader.class, tsd);
    ResourceMetaData metaData = crd.getMetaData();
    ConfigurationParameterSettings paramSettings = metaData
	    .getConfigurationParameterSettings();
    Map<String, Object> additionalParameters = new HashMap<String, Object>();
    additionalParameters
	    .put(CollectionReader.PARAM_CONFIG_PARAM_SETTINGS,
		    paramSettings);
    initialize(crd, additionalParameters);

    this.readers = readers;
    this.readerIterator = this.readers.iterator();
    currentReader = this.readerIterator.next();
} catch (ResourceInitializationException rie) {
    throw new RuntimeException(rie);
}
   }
 
Example 2
Source File: ResourceCreationSpecifierFactory.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * This method sets the configuration parameters of a resource. The length of
 * configurationParameters and configurationValues should be equal
 * 
 * @param metaData
 *          The ResourceMetaData whose parameters are to be set.
 * @param configurationParameters
 *          an array of configuration parameters
 * @param configurationValues
 *          an array of configuration parameter values
 */
public static void setConfigurationParameters(ResourceMetaData metaData,
        ConfigurationParameter[] configurationParameters, Object[] configurationValues) {
  ConfigurationParameterDeclarations paramDecls = metaData
          .getConfigurationParameterDeclarations();
  ConfigurationParameterSettings paramSettings = metaData.getConfigurationParameterSettings();
  for (int i = 0; i < configurationParameters.length; i++) {
    ConfigurationParameter decl = paramDecls.getConfigurationParameter(null,
            configurationParameters[i].getName());
    if (paramDecls != null && decl == null) {
      paramDecls.addConfigurationParameter(configurationParameters[i]);
      decl = configurationParameters[i];
    }

    // Upgrade single-value to multi-value if necessary
    Object value = configurationValues[i];
    if ((value != null) && decl.isMultiValued() && !isMultiValue(value)) {
      value = Array.newInstance(value.getClass(), 1);
      Array.set(value, 0, configurationValues[i]);
    }

    paramSettings.setParameterValue(configurationParameters[i].getName(), value);
  }
}
 
Example 3
Source File: ConfigurationManagerImplBase.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public synchronized void createContext(String aContextName, ResourceMetaData aResourceMetaData, Settings externalOverrides)
        throws ResourceConfigurationException {
  if (mContextNameToParamDeclsMap.containsKey(aContextName)) {
    return;
  }
  // first internally validate settings in the ResourceMetaData (catches data type problems,
  // settings for undefined parameters, etc.)
  aResourceMetaData.validateConfigurationParameterSettings();

  // Iterate through all declared parameters, calling abstract method to allow
  // concrete ConfigurationManager implementations to set up data structures to
  // provide access to the parameter values
  ConfigurationParameterDeclarations paramDecls = aResourceMetaData
          .getConfigurationParameterDeclarations();
  ConfigurationParameterSettings settings = aResourceMetaData.getConfigurationParameterSettings();

  // parameters in no group
  ConfigurationParameter[] paramsInNoGroup = paramDecls.getConfigurationParameters();
  if (paramsInNoGroup.length > 0) // group-less parameters
  {
    declareParameters(null, paramsInNoGroup, settings, aContextName, externalOverrides);
  }

  // parameter groups
  ConfigurationGroup[] groups = paramDecls.getConfigurationGroups();
  if (groups != null) {
    for (int i = 0; i < groups.length; i++) {
      String[] names = groups[i].getNames();
      {
        for (int j = 0; j < names.length; j++) {
          // common params
          ConfigurationParameter[] commonParams = paramDecls.getCommonParameters();
          if (commonParams != null) {
            declareParameters(names[j], commonParams, settings, aContextName, externalOverrides);
          }
          // params in group
          ConfigurationParameter[] params = groups[i].getConfigurationParameters();
          if (params != null) {
            declareParameters(names[j], params, settings, aContextName, externalOverrides);
          }
        }
      }
    }
  }

  // store parameter declarations in map for later access
  mContextNameToParamDeclsMap.put(aContextName, paramDecls);

  // validate
  validateConfigurationParameterSettings(aContextName);
}
 
Example 4
Source File: ConfigurationParameterInitializer.java    From uima-uimafit with Apache License 2.0 3 votes vote down vote up
/**
 * Initialize a component from a {@link ResourceMetaData}.
 *
 * @param component
 *          the component to initialize.
 * @param dataResource
 *          a data resource with configuration meta data.
 * @see #initialize(Object, UimaContext)
 * @throws ResourceInitializationException
 *           if a failure occurs during initialization.
 */
public static void initialize(Object component, DataResource dataResource)
        throws ResourceInitializationException {
  ResourceMetaData metaData = dataResource.getMetaData();
  ConfigurationParameterSettings settings = metaData.getConfigurationParameterSettings();
  initialize(component, settings.getParameterSettings());
}