2014-12-18 0:05 GMT+01:00 Anatole Tresch <[email protected]>:
> Hi all
> I would like to present another use case: injection of configuration in SE
> (EE should be almost similar):
>
>                  Automatic Configuration (Configuration Injection)
>
> Tamaya must provide a feature for automatic configuration, where properties
> of a class or methods can be annotated:
>
>    -
>
>    Hereby the lifecycle of the instances configured should not be managed
>    by Tamaya.
>     -
>
>    String as well as other types should be supported.
>     -
>

We should limit to types we can handle to start I think (until we
finished other IoC integration to keep it aligned to start)

So file, string, primitive wrappers, uri, inetaddress...

>    It must be possible to define default values to be used, if no valid
>    value is present.
>     -
>
>    It must be possible to define dynamic expressions, at least for default
>    values.
>     -
>
>    The values configured can be reinjected, if the underlying configuration
>    changes. This should also be the case fir final classes, such as Strings.
>     -
>

-1, I would introduce DynamicValue<String> (or any generic) for it

>    Reinjection should be controllable by an loading policy.
>     -
>
>    It should be possible to evaluate multiple keys, e.g. current keys, and
>    as a backup deprecated keys from former application releases.
>     -
>
>    It should be possible to evaluate multiple configurations.
>     -
>
>    The type conversion of the properties injected should be configurable.
>     -
>
>    The value evaluated for a property (before type conversion) may be
>    adaptable as well.
>     -
>
>    It should be possible to observe configuration changes.
>
>   To illustrate the points above imagine the following POJO:
>   Configured POJO Example
>
> *public* *class* *MyPojo* {
>   @ConfigProperty("myCurrency")
>   @DefaultValue("CHF")                       // use as default
>   @WithLoadingPolicy(LoadingPolicy.INITIAL)  // load the value only
> once (no reinjection)
>   *private* *String* currency;
>
>   @ConfigProperty("myCurrencyRate")
>   *private* *Long* currencyRate;
>
>   @ConfigProperty                            // evaluates to
> key=<fieldName>="fullRate"
>   @ConfigProperty("fallback.property")
>   @WithConfig("default")
>   @WithConfig("moduleConfig");
>   *private* *BigDecimal* fullRate;
>
>   // Configuration method
>   *void* setStartup(@ConfigProperty *boolean* startup,
> @ConfigProperty("componentName") @WithConfig("module1")
> @DefaultValue("N/A") *String* compName){
>      ...
>   }
>

I would put default value in @ConfigProperty to avoid
TooMuchAnnotationsException
@WithConfig({}) for the same reason or even in @ConfigProperty(configs = {})?


>   // Configuration method
>   @ConfigProperty("componentName")
>   @WithConfig("module1")
>   @DefaultValue("N/A")
>   *private* *void* setComponentName(*String* compName){
>      ...
>   }
>
>   // Configuration listener method, defining which properties to listen for
>   @ConfigChanges
>   @ConfigProperty("componentName")
>   *private* *void* setComponentName(ConfigChange change){
>      ...
>   }
>
> }
>
>   The instance then can be passed for being configured:
>   Configuring a POJO
>
> MyPojo instance = *new* MyPojo();*Configuration*.configure(instance);
>

I'd use "bind" keyword since you don't configure the instance, just
you map the config on it no?

>   This will configure all values according to the load policies (by default
> LoadPolicy.INITIAL). Depending on the listeners present and the properties
> injected Tamaya will keep weak references to the bean and the current
> environment, so it can be determined, when configuration changes must be
> published into the bean.

Would hide it behind DynamicValue cause in some case you'll not be
able to do it very well, would also allow to add some useful methods
like hasChanged().

>   Feel free to comment or ask questions ;)
>
> Best,
> Anatole
>
> --
> *Anatole Tresch*
> Java Engineer & Architect, JSR Spec Lead
> Glärnischweg 10
> CH - 8620 Wetzikon
>
> *Switzerland, Europe Zurich, GMT+1*
> *Twitter:  @atsticks*
> *Blogs: **http://javaremarkables.blogspot.ch/
> <http://javaremarkables.blogspot.ch/>*
>
> *Google: atsticksMobile  +41-76 344 62 79*

Reply via email to