You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by Johannes Darms <jo...@scai.fraunhofer.de> on 2014/11/06 14:14:42 UTC

UIMAFit Configuration Parameter injection

Hey there,

I'm trying to inject an Object into an UIMA Component with a @ConfigurationParameter Annotation. The Documentation says that I can inject any Object with a single String Argument Constructor. Which does not work! I can only inject Types that are defined in PropertyEditorRegistrySupport and PropertyEditorUtil. And of course there is no custom PropertyEditor defined for my Class which leads to an exception. Sadly the API for solving my problem (configure custom PropertyEditors) is encapsulated. Are there any restrictions and/or design decision to hide this functionality from a developer? 


Regards,

Johannes

Re: UIMAFit Configuration Parameter injection

Posted by Richard Eckart de Castilho <re...@apache.org>.
Hi,

it is true that it is currently not possible to register custom property editors.
i think there is no reason speaking against it, but there was no need to do it so
far. 

However, I did a test and I cannot reproduce your problem that a class with a
string constructor could not be used. Consider the following code that works for me:

---

  public static class CustomValue {
    public String value;

    public CustomValue(String aValue) {
      super();
      value = aValue;
    }
  }

  public static class CustomValueAE1 extends JCasAnnotator_ImplBase {
    public static final String PARAM_VALUE = "value";
    @ConfigurationParameter(name = PARAM_VALUE, defaultValue = "default value", mandatory = false)
    public CustomValue param;

    @Override
    public void initialize(UimaContext aContext) throws ResourceInitializationException {
      super.initialize(aContext);
    }

    @Override
    public void process(JCas aJCas) throws AnalysisEngineProcessException {
      /* do nothing */
    }
  }

  @Test
  public void testCustomValueParams() throws Exception {
    AnalysisEngine aed = AnalysisEngineFactory.createEngine(CustomValueAE1.class,
            CustomValueAE1.PARAM_VALUE, "my value");
    CustomValueAE1 ae = new CustomValueAE1();
    ae.initialize(aed.getUimaContext());
    assertEquals("my value", ae.param.value);

    aed = AnalysisEngineFactory.createEngine(CustomValueAE1.class);
    ae = new CustomValueAE1();
    ae.initialize(aed.getUimaContext());
    assertEquals("default value", ae.param.value);
  }
  
---

I suppose what you are trying to do is something like this? 

---

    aed = AnalysisEngineFactory.createEngine(CustomValueAE1.class,
            CustomValueAE1.PARAM_VALUE, new CustomValue("other value"));
    ae = new CustomValueAE1();
    ae.initialize(aed.getUimaContext());
    assertEquals("other value", ae.param.value);
---

True, this currently does not work, but I think that uimaFIT should probably be
changed to fall back to toString() in such a case so that adding an appropriate
toString() method to CustomValue should fix the problem.

Would you mind opening Jira issues for those cases that do not work for you?

Cheers,

-- Richard


On 06.11.2014, at 14:14, Johannes Darms <jo...@scai.fraunhofer.de> wrote:

> Hey there,
> 
> I'm trying to inject an Object into an UIMA Component with a @ConfigurationParameter Annotation. The Documentation says that I can inject any Object with a single String Argument Constructor. Which does not work! I can only inject Types that are defined in PropertyEditorRegistrySupport and PropertyEditorUtil. And of course there is no custom PropertyEditor defined for my Class which leads to an exception. Sadly the API for solving my problem (configure custom PropertyEditors) is encapsulated. Are there any restrictions and/or design decision to hide this functionality from a developer? 
> 
> 
> Regards,
> 
> Johannes