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

The following examples show how to use org.apache.uima.resource.metadata.ResourceMetaData#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: Pipeline.java    From bluima with Apache License 2.0 6 votes vote down vote up
private PipelineBuilder build(PipelineBuilder builder)
        throws InvalidXMLException, IOException, SAXException,
        CpeDescriptorException {

    Set<String> cpeNames = newHashSet();

    for (AnalysisEngineDescription aed : this.aeds) {

        // workaround to use multiple cpe with the same name
        String name = aed.getMetaData().getName();
        if (cpeNames.contains(name)) {
            ResourceMetaData metaData = aed.getMetaData();
            String newName = name + System.currentTimeMillis();
            metaData.setName(newName);
            aed.setMetaData(metaData);
            cpeNames.add(newName);
        } else {
            cpeNames.add(name);
        }
        builder.add(aed);
    }
    return builder;
}
 
Example 2
Source File: ResourceMetaDataFactory.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Adds meta data from a {@link org.apache.uima.fit.descriptor.ResourceMetaData} annotation to the
 * given meta data object if such an annotation is present on the component class. If no
 * annotation is present, default values are be added.
 * 
 * @param aMetaData
 *          the meta data object to configure.
 * @param aComponentClass
 *          the class that may carry the {@link org.apache.uima.fit.descriptor.ResourceMetaData}
 *          annotation
 */
public static void configureResourceMetaData(ResourceMetaData aMetaData, Class<?> aComponentClass) {
  org.apache.uima.fit.descriptor.ResourceMetaData componentAnno = ReflectionUtil
          .getInheritableAnnotation(org.apache.uima.fit.descriptor.ResourceMetaData.class,
                  aComponentClass);

  if (componentAnno == null) {
    // Default handling if no annotation is present.
    aMetaData.setCopyright(getDefaultCopyright(aComponentClass));
    aMetaData.setDescription(getDefaultDescription(aComponentClass));
    aMetaData.setName(getDefaultName(aComponentClass));
    aMetaData.setVendor(getDefaultVendor(aComponentClass));
    aMetaData.setVersion(getDefaultVersion(aComponentClass));
  } else {
    // If annotation is present, use it
    // Annotation values cannot be null, but we want to avoid empty strings in the meta data,
    // thus we set to null when the value is empty.
    aMetaData.setCopyright(emptyAsNull(componentAnno.copyright()));
    aMetaData.setDescription(emptyAsNull(componentAnno.description()));
    aMetaData.setName(emptyAsNull(componentAnno.name()));
    aMetaData.setVendor(emptyAsNull(componentAnno.vendor()));
    aMetaData.setVersion(emptyAsNull(componentAnno.version()));
  }
}
 
Example 3
Source File: ResourceServiceAdapter_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testGetMetaData() throws Exception {
  try {
    ResourceMetaData md = new ResourceMetaData_impl();
    md.setName("Test");
    md.setDescription("This is a test");
    ConfigurationParameter p1 = new ConfigurationParameter_impl();
    p1.setName("IntegerArrayParam");
    p1.setDescription("multi-valued parameter with Integer data type");
    p1.setType(ConfigurationParameter.TYPE_INTEGER);
    p1.setMultiValued(true);
    md.getConfigurationParameterDeclarations().setConfigurationParameters(
            new ConfigurationParameter[] { p1 });

    mServiceStub.getMetaDataReturnValue = md;
    ResourceMetaData result = mAdapter.getMetaData();
    Assert.assertEquals("callGetMetaData", mServiceStub.lastMethodName);
    Assert.assertEquals(md, result);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example 4
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);
  }
}
 
Example 5
Source File: ConfigurableDataResource_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testInitialize() 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);

    // initialize a DataResource
    ConfigurableDataResource_impl cdr = new ConfigurableDataResource_impl();
    cdr.initialize(cspec, Collections.EMPTY_MAP);
    assertEquals(new URI("jdbc:db2:MyDatabase"), cdr.getUri());
    assertEquals("foo", cdr.getMetaData().getName());
    ConfigurationParameter param0 = cdr.getMetaData().getConfigurationParameterDeclarations()
            .getConfigurationParameters()[0];
    assertEquals("param", param0.getName());
    assertEquals("String", param0.getType());

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