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.
    -

   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.
    -

   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){
     ...
  }

  // 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);

  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.
  ​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