Java Code Examples for org.apache.uima.resource.metadata.NameValuePair#setName()

The following examples show how to use org.apache.uima.resource.metadata.NameValuePair#setName() . 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: ConfigurationManagerImplBase.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method that gets a NameValuePair array containing the specific parameter settings.
 * 
 * @param aGroupName
 *          name of group containing params, may be null
 * @param aParams
 *          array of parameters to look up
 * @param aContextName
 *          context containing parameters
 * 
 * @return array containing settings of the specific parameters
 */
private NameValuePair[] getParamSettings(String aGroupName, ConfigurationParameter[] aParams,
        String aContextName) {
  List<NameValuePair> result = new ArrayList<>();
  // iterate over config. param _declarations_
  if (aParams != null) {
    for (int i = 0; i < aParams.length; i++) {
      ConfigurationParameter param = aParams[i];
      NameValuePair nvp = UIMAFramework.getResourceSpecifierFactory().createNameValuePair();
      nvp.setName(param.getName());
      // look up value in context
      String qualifiedName = this.makeQualifiedName(aContextName, param.getName(), aGroupName);
      nvp.setValue(this.lookup(qualifiedName));
      result.add(nvp);
    }
  }
  NameValuePair[] resultArr = new NameValuePair[result.size()];
  result.toArray(resultArr);
  return resultArr;
}
 
Example 2
Source File: CPEFactory.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Replace a primitive value of a given parameter with a value defined in the CPE descriptor.
 *
 * @param aType -
 *          type of the primitive value ( String, Integer, Boolean, or Float)
 * @param aMandatoryParam the a mandatory param
 * @param aCps -
 *          parameter settings from the component's descriptor
 * @param aCPE_nvp -
 *          parameter containing array of values to replace values in the component's descriptor
 * @param aComponentName the a component name
 * @throws Exception -
 */
private void replacePrimitive(String aType, boolean aMandatoryParam,
        ConfigurationParameterSettings aCps,
        org.apache.uima.collection.metadata.NameValuePair aCPE_nvp,
        String aComponentName) throws Exception {
  boolean newParamSetting = false;

  // Get a new value for the primitive param
  Object aValueObject = aCPE_nvp.getValue();
  String param_name = aCPE_nvp.getName();

  // Find corresponding parameter in the in-memory component descriptor
  NameValuePair nvp = findMatchingNameValuePair(aCps, param_name.trim());
  if (nvp == null) {
    newParamSetting = true;
    nvp = new NameValuePair_impl();
    nvp.setName(param_name);
  }
  // Copy a new value based on type
  if (aType.equals("String") && aValueObject instanceof String) {
    nvp.setValue(aValueObject);
  } else if (aType.equals("Integer") && aValueObject instanceof Integer) {
    nvp.setValue(aValueObject);
  } else if (aType.equals("Float") && aValueObject instanceof Float) {
    nvp.setValue(aValueObject);

  } else if (aType.equals("Boolean") && aValueObject instanceof Boolean) {
    nvp.setValue(aValueObject);
  }

  if (newParamSetting) {
    aCps.setParameterValue(null, nvp.getName(), nvp.getValue());
  }
}
 
Example 3
Source File: CPEFactory.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Replace array values found in the component's descriptor with values found in the CPE
 * descriptor.
 *
 * @param aType -
 *          primitive type of the array (Sting, Integer, Float, or Boolean)
 * @param aMandatoryParam the a mandatory param
 * @param aCps -
 *          parameter settings from the component's descriptor
 * @param aCPE_nvp -
 *          parameter containing array of values to replace values in the component's descriptor
 * @param aComponentName the a component name
 * @throws Exception -
 *           any error
 */
private void replaceArray(String aType, boolean aMandatoryParam,
        ConfigurationParameterSettings aCps,
        org.apache.uima.collection.metadata.NameValuePair aCPE_nvp,
        String aComponentName) throws Exception {
  boolean newParamSetting = false;
  Object valueObject = aCPE_nvp.getValue();
  String param_name = aCPE_nvp.getName();
  // Find in the component in-memory descriptor a parameter with a given name
  NameValuePair nvp = findMatchingNameValuePair(aCps, param_name.trim());
  if (nvp == null) {
    // Parameter setting does not exist in the component's descriptor so create new
    newParamSetting = true;
    nvp = new NameValuePair_impl();
    nvp.setName(param_name);
  }
  // Override component's parameters based on type
  if (aType.equals("String") && valueObject instanceof String[]) {
    nvp.setValue(valueObject);
  } else if (aType.equals("Integer") && valueObject instanceof Integer[]) {
    nvp.setValue(valueObject);
  } else if (aType.equals("Float") && valueObject instanceof Float[]) {
    nvp.setValue(valueObject);
  } else if (aType.equals("Boolean") && valueObject instanceof Boolean[]) {
    nvp.setValue(valueObject);
  }
  if (newParamSetting) {
    aCps.setParameterValue(null, nvp.getName(), nvp.getValue());
  }

}
 
Example 4
Source File: FixedFlowController.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public static FlowControllerDescription getDescription() {
  FlowControllerDescription desc = getResourceSpecifierFactory().createFlowControllerDescription();
  
  desc.setImplementationName(FixedFlowController.class.getName());
  
  ProcessingResourceMetaData metaData = desc.getFlowControllerMetaData();
  metaData.setName("Fixed Flow Controller");
  metaData.setDescription("Simple FlowController that uses the FixedFlow element of the\n" + 
      "\t\taggregate descriptor to determine a linear flow.");
  metaData.setVendor("The Apache Software Foundation");
  metaData.setVersion("1.0");
  
  Capability capability = getResourceSpecifierFactory().createCapability();
  metaData.setCapabilities(new Capability[] { capability });
  
  ConfigurationParameter param = getResourceSpecifierFactory().createConfigurationParameter();
  param.setName("ActionAfterCasMultiplier");
  param.setType("String");
  param.setDescription("The action to be taken after a CAS has been input to a CAS Multiplier and the CAS Multiplier has finished processing it.\n" + 
      "\t\t Valid values are:\n" + 
      "\t\t\tcontinue - the CAS continues on to the next element in the flow\n" + 
      "\t\t\tstop - the CAS will no longer continue in the flow, and will be returned from the aggregate if possible.\n" + 
      "\t\t\tdrop - the CAS will no longer continue in the flow, and will be dropped (not returned from the aggregate) if possible.\t \n" + 
      "\t\t\tdropIfNewCasProduced (the default) - if the CAS multiplier produced a new CAS as a result of processing this CAS, then this\n" + 
      "\t\t\t\tCAS will be dropped.  If not, then this CAS will continue.");
  ConfigurationParameterDeclarations parameterDeclarations = getResourceSpecifierFactory().createConfigurationParameterDeclarations();
  parameterDeclarations.setConfigurationParameters(new ConfigurationParameter[] { param });
  metaData.setConfigurationParameterDeclarations(parameterDeclarations);
  
  NameValuePair paramSetting = getResourceSpecifierFactory().createNameValuePair();
  paramSetting.setName("ActionAfterCasMultiplier");
  paramSetting.setValue("dropIfNewCasProduced");
  ConfigurationParameterSettings parameterSettings = getResourceSpecifierFactory().createConfigurationParameterSettings();
  parameterSettings.setParameterSettings(new NameValuePair[] { paramSetting });
  metaData.setConfigurationParameterSettings(parameterSettings);
  
  return desc;
}
 
Example 5
Source File: FixedFlowController.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public static FlowControllerDescription makeDefaultDescription() {
  FlowControllerDescription desc = getResourceSpecifierFactory().createFlowControllerDescription();
  
  desc.setImplementationName(FixedFlowController.class.getName());
  
  ProcessingResourceMetaData metaData = desc.getFlowControllerMetaData();
  metaData.setName("Fixed Flow Controller");
  metaData.setDescription("Simple FlowController that uses the FixedFlow element of the\n" + 
      "\t\taggregate descriptor to determine a linear flow.");
  metaData.setVendor("The Apache Software Foundation");
  metaData.setVersion("1.0");
  
  Capability capability = getResourceSpecifierFactory().createCapability();
  metaData.setCapabilities(new Capability[] { capability });
 
  ConfigurationParameter param = getResourceSpecifierFactory().createConfigurationParameter();
  param.setName("ActionAfterCasMultiplier");
  param.setType("String");
  param.setDescription("The action to be taken after a CAS has been input to a CAS Multiplier and the CAS Multiplier has finished processing it.\n" + 
      "\t\t Valid values are:\n" + 
      "\t\t\tcontinue - the CAS continues on to the next element in the flow\n" + 
      "\t\t\tstop - the CAS will no longer continue in the flow, and will be returned from the aggregate if possible.\n" + 
      "\t\t\tdrop - the CAS will no longer continue in the flow, and will be dropped (not returned from the aggregate) if possible.\t \n" + 
      "\t\t\tdropIfNewCasProduced (the default) - if the CAS multiplier produced a new CAS as a result of processing this CAS, then this\n" + 
      "\t\t\t\tCAS will be dropped.  If not, then this CAS will continue.");
  ConfigurationParameterDeclarations parameterDeclarations = getResourceSpecifierFactory().createConfigurationParameterDeclarations();
  parameterDeclarations.setConfigurationParameters(new ConfigurationParameter[] { param });
  metaData.setConfigurationParameterDeclarations(parameterDeclarations);
  
  NameValuePair paramSetting = getResourceSpecifierFactory().createNameValuePair();
  paramSetting.setName("ActionAfterCasMultiplier");
  paramSetting.setValue("dropIfNewCasProduced");
  ConfigurationParameterSettings parameterSettings = getResourceSpecifierFactory().createConfigurationParameterSettings();
  parameterSettings.setParameterSettings(new NameValuePair[] { paramSetting });
  metaData.setConfigurationParameterSettings(parameterSettings);

  return desc;
}
 
Example 6
Source File: ConfigurableDataResourceSpecifier_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testXmlization() throws Exception {
  try {
    // create a ConfigurableDataResourceSpecifier
    ConfigurableDataResourceSpecifier_impl cspec = new ConfigurableDataResourceSpecifier_impl();
    cspec.setUrl("jdbc:db2:MyDatabase");
    ResourceMetaData md = new ResourceMetaData_impl();
    cspec.setMetaData(md);
    md.setName("foo");
    ConfigurationParameterDeclarations decls = new ConfigurationParameterDeclarations_impl();
    ConfigurationParameter param = new ConfigurationParameter_impl();
    param.setName("param");
    param.setType("String");
    decls.addConfigurationParameter(param);
    md.setConfigurationParameterDeclarations(decls);
    ConfigurationParameterSettings settings = new ConfigurationParameterSettings_impl();
    NameValuePair nvp = new NameValuePair_impl();
    nvp.setName("param");
    nvp.setValue("bar");
    settings.setParameterSettings(new NameValuePair[] { nvp });
    md.setConfigurationParameterSettings(settings);

    // wrtie to XML
    StringWriter sw = new StringWriter();
    cspec.toXML(sw);
    String xmlStr = sw.getBuffer().toString();

    // parse back
    ByteArrayInputStream inStream = new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8));
    XMLInputSource in = new XMLInputSource(inStream, null);
    ConfigurableDataResourceSpecifier_impl parsedSpec = (ConfigurableDataResourceSpecifier_impl) UIMAFramework
            .getXMLParser().parse(in);

    assertEquals(cspec, parsedSpec);

  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}