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

The following examples show how to use org.apache.uima.resource.ExternalResourceDescription#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: ExtnlResBindSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Alter existing XRD.
 *
 * @param dialog the dialog
 * @param xrd the xrd
 * @param item the item
 */
private void alterExistingXRD(AddExternalResourceDialog dialog, ExternalResourceDescription xrd,
        TreeItem item) {
  valueChanged = false;
  xrd.setName(setValueChanged(dialog.xrName, xrd.getName()));
  xrd.setDescription(setValueChanged(dialog.xrDescription, xrd.getDescription()));
  xrd
          .setImplementationName(setValueChanged(dialog.xrImplementation, xrd
                  .getImplementationName()));

  ResourceSpecifier rs = xrd.getResourceSpecifier();
  if (null == dialog.xrUrlSuffix || "".equals(dialog.xrUrlSuffix)) {
    FileResourceSpecifier frs;
    if (null != rs && rs instanceof FileResourceSpecifier) {
      frs = (FileResourceSpecifier) rs;
    } else {
      frs = new FileResourceSpecifier_impl();
    }
    frs.setFileUrl(setValueChanged(dialog.xrUrl, frs.getFileUrl()));
    xrd.setResourceSpecifier(frs);
  } else {
    FileLanguageResourceSpecifier flrs;
    if (null != rs && rs instanceof FileLanguageResourceSpecifier) {
      flrs = (FileLanguageResourceSpecifier) rs;
    } else {
      flrs = new FileLanguageResourceSpecifier_impl();
    }
    flrs.setFileUrlPrefix(setValueChanged(dialog.xrUrl, flrs.getFileUrlPrefix()));
    flrs.setFileUrlSuffix(setValueChanged(dialog.xrUrlSuffix, flrs.getFileUrlSuffix()));
    xrd.setResourceSpecifier(flrs);
  }
  fillXrdItem(item, xrd);
  if (valueChanged)
    setFileDirty();
}
 
Example 2
Source File: ResourceManager_implTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * @see junit.framework.TestCase#setUp()
 */
protected void setUp() throws Exception {
  try {
    super.setUp();
    mManager = new ResourceManager_impl();
    mManager.setDataPath(TEST_DATAPATH_WITH_SPACES);

    // initialize sample resources
    ResourceManagerConfiguration cfg = new ResourceManagerConfiguration_impl();
    // simple data resource
    FileResourceSpecifier_impl spec = new FileResourceSpecifier_impl();
    spec.setFileUrl(TEST_DATA_FILE.toURL().toString());
    ExternalResourceDescription desc = new ExternalResourceDescription_impl();
    desc.setName("myData");
    desc.setResourceSpecifier(spec);

    // data resource with custom interface and implementation class
    ExternalResourceDescription desc2 = new ExternalResourceDescription_impl();
    desc2.setName("myCustomObject");
    desc2.setResourceSpecifier(spec);
    desc2.setImplementationName(TestResourceInterface_impl.class.getName());

    // parameterized (language-based) resource
    FileLanguageResourceSpecifier langSpec = new FileLanguageResourceSpecifier_impl();

    File baseDir = JUnitExtension.getFile("ResourceTest");
    langSpec.setFileUrlPrefix(new File(baseDir, "FileLanguageResource_implTest_data_").toURL()
            .toString());
    langSpec.setFileUrlSuffix(".dat");
    ExternalResourceDescription desc3 = new ExternalResourceDescription_impl();
    desc3.setName("myLanguageResource");
    desc3.setResourceSpecifier(langSpec);

    // parameterized resource with custom impl class
    ExternalResourceDescription desc4 = new ExternalResourceDescription_impl();
    desc4.setName("myLanguageResourceObject");
    desc4.setResourceSpecifier(langSpec);
    desc4.setImplementationName(TestResourceInterface_impl.class.getName());

    // resource path with space in it (tests proper URL encoding of spaces)
    FileResourceSpecifier_impl spec2 = new FileResourceSpecifier_impl();
    spec2.setFileUrl(TEST_FILE_IN_DATAPATH);
    ExternalResourceDescription desc5 = new ExternalResourceDescription_impl();
    desc5.setName("myResourceWithSpaceInPath");
    desc5.setResourceSpecifier(spec2);

    // resource path as filename instead of URL
    ExternalResourceDescription desc6 = new ExternalResourceDescription_impl();
    FileResourceSpecifier_impl fileSpec = new FileResourceSpecifier_impl();
    fileSpec.setFileUrl(TEST_DATA_FILE.getAbsolutePath());
    desc6.setResourceSpecifier(fileSpec);
    desc6.setName("myResourceWithFilePathNotUrl");

    cfg.setExternalResources(new ExternalResourceDescription[] { desc, desc2, desc3, desc4,
        desc5, desc6 });

    // define bindings
    ExternalResourceBinding binding1 = new ExternalResourceBinding_impl();
    binding1.setKey("myDataKey");
    binding1.setResourceName("myData");
    ExternalResourceBinding binding2 = new ExternalResourceBinding_impl();
    binding2.setKey("myCustomObjectKey");
    binding2.setResourceName("myCustomObject");
    ExternalResourceBinding binding3 = new ExternalResourceBinding_impl();
    binding3.setKey("myLanguageResourceKey");
    binding3.setResourceName("myLanguageResource");
    ExternalResourceBinding binding4 = new ExternalResourceBinding_impl();
    binding4.setKey("myLanguageResourceObjectKey");
    binding4.setResourceName("myLanguageResourceObject");
    ExternalResourceBinding binding5 = new ExternalResourceBinding_impl();
    binding5.setKey("myResourceWithSpaceInPathKey");
    binding5.setResourceName("myResourceWithSpaceInPath");
    ExternalResourceBinding binding6 = new ExternalResourceBinding_impl();
    binding6.setKey("myResourceWithFilePathNotUrl");
    binding6.setResourceName("myResourceWithFilePathNotUrl");
    cfg.setExternalResourceBindings(new ExternalResourceBinding[] { binding1, binding2, binding3,
        binding4, binding5, binding6 });

    mManager.initializeExternalResources(cfg, TEST_CONTEXT_NAME, null);

  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example 3
Source File: ExternalResourceFactory.java    From uima-uimafit with Apache License 2.0 3 votes vote down vote up
/**
 * Create an external resource description for a file addressable via an URL.
 * 
 * @param aName
 *          the name of the resource (the key).
 * @param aUrl
 *          a URL.
 * @return the description.
 * @see FileResourceSpecifier
 */
public static ExternalResourceDescription createNamedFileResourceDescription(
        final String aName, String aUrl) {
  ExternalResourceDescription extRes = new ExternalResourceDescription_impl();
  extRes.setName(aName);
  FileResourceSpecifier frs = new FileResourceSpecifier_impl();
  frs.setFileUrl(aUrl);
  extRes.setResourceSpecifier(frs);
  return extRes;
}