You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "J.W. Janssen (JIRA)" <ji...@apache.org> on 2016/02/04 17:01:39 UTC

[jira] [Updated] (FELIX-5177) Support injecting configuration proxies

     [ https://issues.apache.org/jira/browse/FELIX-5177?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J.W. Janssen updated FELIX-5177:
--------------------------------
    Attachment: FELIX-5177.patch

I've attached my patch.

Some documentation: 

The approach is to take a map or dictionary along with a class, the configuration-type, and return a proxy that converts method calls from the configuration-type to lookups in the map or dictionary. The results of these lookups are then converted to the expected return type of the invoked configuration method. As proxies are returned, no implementations of the desired configuration-type are necessary!

To make this work, a new interface method on {{ConfigurationDependency}} is defined that has the following signature: {{setCallback(Object instance, String callback, Class<?> configType)}}. This will make sure that the proper method is called with the correct configuration type. If this method is not used, the current/old behaviour is used.

The lookups performed are based on the name of the method called on the configuration type. The method names are "mangled" to the following form: {{(lower case letter) (any valid character)*}}. Method names starting with get or is (JavaBean convention) are stripped from these prefixes. For example: given a dictionary with the key "foo" can be accessed from a configuration-type using the following method names: {{foo()}}, {{getFoo()}} and {{isFoo()}}.

The return values supported are: primitive types (or their object wrappers), strings, enums, arrays of primitives/strings, Collection types, Map types, Classes and interfaces. When an interface is returned, it is treated equally to a configuration type, that is, it is returned as a proxy where lookups are performed against the original map or dictionary.

Arrays can be represented either as comma-separated values, optionally enclosed in square brackets. For example: {{[ a, b, c ]}} and {{a,b,c}} are both considered an array of length 3 with the values "a", "b" and "c". Alternatively, you can append the array index to the key in the dictionary to obtain the same: a dictionary with {{"arr.0" => "a", "arr.1" => "b", "arr.2" => "c"}} would result in the same array as the earlier examples.

Maps can be represented as single string values similarly as arrays, each value consisting of both the key and value separated by a dot. Optionally, the value can be enclosed in curly brackets. Similar to array, you can use the same dot notation using the keys. For example, a dictionary with {{"map" => "key1.value1, key2.value2"}} and a dictionary with {{"map.key1" => "value1", "map2.key2" => "value2"}} result in the same map being returned. Instead of a map, you could also define an interface with the methods {{getKey1()}} and {{getKey2()}} and use that interface as return type instead of a Map.

In case a lookup does not yield a value from the underlying map or dictionary, the following rules are applied:

# primitive types yield their default value, as defined by the Java Specification;
# string, Classes and enum values yield {{null}};
# for arrays, collections and maps, an empty array/collection/map is returned;
# for other interface types that are treated as configuration type a null-object is returned.


> Support injecting configuration proxies
> ---------------------------------------
>
>                 Key: FELIX-5177
>                 URL: https://issues.apache.org/jira/browse/FELIX-5177
>             Project: Felix
>          Issue Type: Improvement
>          Components: Dependency Manager Runtime
>            Reporter: J.W. Janssen
>         Attachments: FELIX-5177.patch
>
>
> DM supports mandatory configurations, but does not allow anything other than a dictionary to be passed to the callback. In other DI frameworks (like DS) it is possible to use type-safe configurations and let those be injected instead of plain dictionaries.
> It would be great if DM also would support this, as it would remove lots of configuration boiler plate code from our projects.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)