You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Richard Eckart de Castilho <re...@apache.org> on 2017/05/02 00:11:31 UTC

Re: @ConfParam initialization of values from symbol name of static instance?

Hi,

> On 26.04.2017, at 22:29, José Tomás Atria <jt...@gmail.com> wrote:
> 
> Hello all!
> 
> I know that UIMA-FIT is capable of initializing enum-typed configuration parameters from a string equal to the name of one of the values in an enum class. i.e. this works as documented:
> 
> public static enum SomeEnum {
>     A_VALUE;
> }
> 
> @ConfigurationParameter( name = "example", mandatory = false, defaultValue="A_VALUE" )
> private SomeEnum enumValue;
> 
> However, I recently had to refactor one my enums into a normal class with static members, and I found that UIMA-FIT is equally capable of initializing these parameters from a string equal to the symbol of a class instance set up as a static member i.e. this also works:
> 
> public static class SomeClass {
>     public static final SomeClass A_VALUE = new SomeClass()
> }
> 
> @ConfigurationParameter( name = "example", mandatory = false, defaultValue="A_VALUE" )
> private SomeClass classValue;
> 
> Is this known behaviour? I tried stepping through the conf param initialization logic, but I got lost in the depths of Spring, and I get the feeling that this is basically a side-effect of spring's implementation of enum initialization details, which seems a little unreliable...

I wasn't aware that this is possible. But it sounds rather like a nice feature than like something that is unreliable. 

> Then again, enum types are basically immutable collections of class instances as static members, no?

I don't know how exactly enums are translated into byte-code, but what you say makes sense.

> Is it reasonable to use this "feature"? if so, should it be mentioned in the documentation?

Puh... why not. I am sometimes considering to drop the dependency on Spring to avoid/reduce potential dependency version conflicts - but then I never have the time and since Spring does a great job of maintaining compatibility, issues have never turned out really problematic...

Regarding mentioning it in the documentation - not sure. Do we have to document all the behaviors of Spring in detail? If it were documented, we should also have unit tests for it. Would you like to turn your code into a unit test and to contribute it + the related documentation?

Cheers,

-- Richard

P.S.: I am aware that you have contributed a patch to uimaFIT which has so far not been integrated (https://issues.apache.org/jira/browse/UIMA-4212). The main reason is that the patch does not include
unit tests (cf. my comment from Dec 2015). Contributions are really welcome, but without tests, it is
somewhat tedious to integrate them.

Re: @ConfParam initialization of values from symbol name of static instance?

Posted by José Tomás Atria <jt...@gmail.com>.
>
> Regarding mentioning it in the documentation - not sure. Do we have to
> document all the behaviors of Spring in detail? If it were documented, we
> should also have unit tests for it. Would you like to turn your code into a
> unit test and to contribute it + the related documentation?
>

I'd be happy to! I'd like to explore how far this capability goes in any
case, as I was actually initializing values from a String[] when I
discovered that it worked. I'll try to put together some tests.


> P.S.: I am aware that you have contributed a patch to uimaFIT which has so
> far not been integrated (https://issues.apache.org/jira/browse/UIMA-4212).
> The main reason is that the patch does not include
> unit tests (cf. my comment from Dec 2015). Contributions are really
> welcome, but without tests, it is
> somewhat tedious to integrate them.


Ah yes, I remember that. Sorry for not finishing up the patch properly;
since I came to programming from the academy I was not very familiar with
unit-testing when I started playing around with UIMA etc. but I'm still
very interested in contributing. Let me find some time and I'll take a look
at both the indexing methods and this param initialization thingy.

cheers!
jta
-- 

sent from a phone. please excuse terseness and tpyos.

enviado desde un teléfono. por favor disculpe la parquedad y los erroers.