@ConfParam initialization of values from name of static instance?

4 views
Skip to first unread message

José Tomás Atria

unread,
Apr 25, 2017, 6:09:59 PM4/25/17
to uimafi...@googlegroups.com
Hello all!

I am aware 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 of the enums I was using into a normal class with static members, and I found that UIMA-FIT is equally capable of initializing these parameter values from a string equal to the name given in the class definition to a static instance... 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 enumValue;

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 seem a little unreliable. then again, enum types are basically fixed-valued classes with static instances, no?

I have attached a working example of what I mean if my explanation above doesn't make sense.

Any comments would be welcome, I'm very curious to know why this works and whether it is reliable enough to be used in production...

Thanks!
jta



--

sent from a phone. please excuse terseness and tpyos.

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

José Tomás Atria

unread,
Apr 25, 2017, 6:11:32 PM4/25/17
to uimafi...@googlegroups.com
forgot the attachment, of course...
demo.java

Richard Eckart de Castilho

unread,
Apr 26, 2017, 3:45:25 AM4/26/17
to uimafi...@googlegroups.com
Hi,

this list isn't really used anymore since uimaFIT became a sub-project of Apache UIMA. Posts should now go to "us...@uima.apache.org".

On 26.04.2017, at 00:11, José Tomás Atria <jta...@gmail.com> wrote:
>
> However, I recently had to refactor one of the enums I was using into a normal class with static members, and I found that UIMA-FIT is equally capable of initializing these parameter values from a string equal to the name given in the class definition to a static instance... 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 enumValue;
>
> 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 seem 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 fixed-valued classes with static instances, no?

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

Cheers,

-- Richard
Reply all
Reply to author
Forward
0 new messages