hello jordan.

you're right - the interface contract is defined here:
https://github.com/apache/sling/blob/trunk/bundles/extensions/models/api/src/main/java/org/apache/sling/models/spi/ImplementationPicker.java

returning null always means "i cannot pick an implementation", but not "pick no 
other implementation and return null for the adaption". so the default first 
implementation picker always steps in as last resort.

if you really need this behavior and cannot find another solution for your 
usecase please create an improvement ticket. we cannot change the existing 
behavior, but we could make it configurable (e.g. a switch to disable the first 
implementation picker by configuration), or provide other means to further 
control the implementation picking behavior.

stefan


>-----Original Message-----
>From: Shurmer, Jordan [mailto:[email protected]]
>Sent: Thursday, August 18, 2016 10:07 PM
>To: [email protected]
>Subject: Sling Model default Implementation Picker
>
>Hello Sling Devs,
>
>I've got a question about the sling models [FirstImplementationPicker][1].
>This appears to essentially be a "default" implementation picker. It will
>be used in two situation: (1) my app doesn't provide any other
>ImplementationPickers; (2) all my app's ImplementationPickers returned
>null, declaring that they couldn't find an implementation.
>
>The Second situation has caused me a bit of pain today, and I'm wondering
>FirstImplementationPicker was intended to act in that situation. Here's my
>thinking:
>
>I have an interface which has multiple implementations. The correct
>implementation will be chosen based on a property of the Resource being
>adapted. If there is no Implementation found for one of the possible values
>of that property, I would like the resource to *not* be adapted (i.e. the
>adaptTo() returning null). So, I wrote a custom ImplementationPicker and
>returned null when there is no matching implementation, but then saw that
>one of my Impl's was chosen seemingly arbitrarily.
>
>I wonder if a "better" default implementation picker would return null if
>it is given multiple implementationTypes since it can't determine how one
>would want to choose one over the other, and only return the
>implementationType if there is only one to choose from.
>
>WDYT? Do I just have bad expectations of this Interface?
>
>[1]:
>https://github.com/apache/sling/blob/trunk/bundles/extensions/models/impl/s
>rc/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java
>
>
>Jordan Shurmer | Software Engineer | Scripps Lifestyle Studios
>
>9721 Sherrill Blvd, Knoxville TN 37932
>Office: 865-560-4887
>[email protected]
>
>SCRIPPS NETWORKS INTERACTIVE | the Leader in Lifestyle Media |
>scrippsnetworksinteractive.com
>HGTV | Food Network | Travel Channel | DIY Network | Cooking Channel |
>Great American Country | TVN | Fine Living | Asian Food Channel

Reply via email to