Uploaded image for project: 'Tamaya'
  1. Tamaya
  2. TAMAYA-378

Clarify Property Key Resolution on Injection

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.3-incubating
    • 0.4-incubating
    • Extensions
    • None

    Description

      Current Situation

      Currently key resolution is very complex and leads to many different keys potentially being looked up. Given the following class:

       

      package a.b.c;
      public class Injected{
        @Config("myProp", "myFallbackProp")
        private String property;
      }
      

       

      Would evaluate to the following key lookup chain:

       

      a.b.c.Injected.myProp
      a.b.c.Injected.myFallbackProp
      Injected.myProp
      Injected.myFallbackProp
      myProp
      myFallbackProp

       

       Proposal

      This is weird to the user, so the proposal is to

      1. Separate the main from the fallback keys
      2. Allow to define how to combine the (field)property key, with the class key.

      Therefore the @Config annotation should be adapted as follows:

       

      public @interface Config {
      
       String UNCONFIGURED_VALUE = ...;
      
       String key() default "";
       KeyResolution keyResolution() default KeyResolution.AUTO;
       String[] alternateKeys() default {};
      
       String defaultValue() default UNCONFIGURED_VALUE;
       boolean required() default true;
      }
      

       

      Herebythe enum type KeyResolution defines how the property key(s) are evaluated:

      • AUTO: This is the default key resolution strateg. The targeting key is evaluated as follows:
        • The containing class does not have a @ConfigSection annotation and the field/method does not have a @Config annotation:
          the main key equals to
              Owning.class.getSimpleName() + '.' + propertyKey.
          {{This equals to }}RELATIVE_SIMPLE.
        • The containing class does not have a @ConfigArea annotation:
          the main key equals to
              propertyKey.
          This equals to ABSOLUTE
        • The containing class does have a @ConfigArea annotation:
          the main key equals to 
              _sectionAnnotation.getValue() + '.' + propertyKe_y. 
      • RELATIVE_SIMPLE: The targeting key is evaluated to
        Owner.class.getSimpleName() + '.' + * propertyKey
      • RELATIVE_FQN:  ** The targeting key is evaluated to 
        Owner.class.getName() + '.' + * propertyKey
      • ABSOLUTE: The targeting key is evaluated to propertyKey.

      Hereby this resolution policy only applies to the main property key, modelled by key(), whereas fallback keys always are considered as ABSOLUTE keys.

      Example

      Given the following class:

      package a.b.c;
      public class Injected{
        @Config(key="myProp", fallbackKeys={"myFallbackProp"})
        private String property;
      }
      

       Would evaluate to the following key lookup chain:

      Injected.myProp
      myFallbackProp

       Using KeyResolution.ABSOLUTE the keys would be:

      myProp
      myFallbackProp

        Using KeyResolution.RELATIVE_FQN the keys would be:

      a.b.c.Injected.myProp
      myFallbackProp

      This drastically reduces the keyset and makes the resolution more explicit and less magic IMO.

       

      Attachments

        Activity

          People

            anatole Anatole Tresch
            anatole Anatole Tresch
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 4h
                4h
                Remaining:
                Time Spent - 1h 10m Remaining Estimate - 2h 50m
                2h 50m
                Logged:
                Time Spent - 1h 10m Remaining Estimate - 2h 50m
                1h 10m