Hi,

On 23 August 2017 at 13:06, Julian Reschke <[email protected]> wrote:

> On 2017-08-23 13:39, Chetan Mehrotra wrote:
>
>> Below is one possible sketch of the proposed api. We introduce a new
>> AdaptableBinary which allows adapting a Binary to some other form.
>>
>> API
>> ===
>>
>> public interface AdaptableBinary {
>>
>>      /**
>>       * Adapts the binary to another type
>>       *
>>       * @param <AdapterType> The generic type to which this binary is
>> adapted
>>       *            to
>>       * @param type The Class object of the target type
>>       * @return The adapter target or <code>null</code> if the binary
>> cannot
>>       *         adapt to the requested type
>>       */
>>      <AdapterType> AdapterType adaptTo(Class<AdapterType> type);
>> }
>>
>
> Can we make that more generic, not relying on Binary?



adapting from something already Adaptable would work.
Sling Resource might be a good option, since a) its adaptable, and b) its
resolvable and already available to the code that would use this.




>
>
> Usage
>> =====
>>
>> Binary binProp = node.getProperty("jcr:data").getBinary();
>>
>> //Check if Binary is of type AdaptableBinary
>> if (binProp instanceof AdaptableBinary){
>>      AdaptableBinary adaptableBinary = (AdaptableBinary) binProp;
>>      SignedBinary url = adaptableBinary.adaptTo(SignedBinary.class);
>> }
>>
>>

This breaks the Adaptable pattern, which should not require intermediate
interfaces.
If the implementation needs instanceof we can drop the Adaptable pattern
and just use APIs.

if (binProp instanceof SignedBinary) {
     response.sendRedirect(((SingedBinary)binProp).getURL());
}

better would be

SingedBinary sb = resource.adaptTo(SignedBinary.class);
if ( sb != null ) { // oak might decide for this invocation a signed binary
is not appropriate, and so return null.
  response.sendRedirect(sb.getURL());
}

If the DS didn't have a AdapterFactory implemented, null will be returned.
Optionally implementing an interface on a call by call basis requires more
work, potentially, than adapting.




> Where SignedBinary is one of the supported adaptables.
>>
>> public interface SignedBinary {
>>
>>      URL getUrl(int ttl, TimeUnit unit)
>> }
>>
>
> Use URI, not URL.
>

Is there something so wrong with an immutable String in this case ?

Also, As a caller I could specify 20 years, or 30s. Oak should decide what
the ttl is, not leave it to the caller.

Best Regards
Ian


> ...
>>
>
> Best regards, Julian
>

Reply via email to