On 6/23/08, Felix Meschberger <[EMAIL PROTECTED]> wrote:
> Hi all,
>
>  As of SLING-395 JCR Node-based resources may be adapted to a
>  java.util.Map. Each entry in the map is automatically typed from the
>  underlying JCR Property as per the
> JcrResourceUtil.toObject(Property)
>  method.
>
>  In some use cases, it would be helpful to have helper methods to get a
>  default value, if no actual value is stored in the map (i.e. the named
>  JCR property does not exist) or to specify what exact Java type we want
>  the value to be converted to.
>
>  The latter functionality would be esp. helpful when content is written
>  to nt:unstructured nodes by means of the SlingPostServlet. Because in
>  this case the value would always be written as a string regardless of
>  the intended data type.
>
>  So, I propose that in Sling we define an interface ValueMap as follows:
>
>     package org.apache.sling.api.resource;
>     public interface ValueMap extends Map<String, Object> {
>
>         // returns the named value or null if not existing
>         @Overwrite
>         Object get(String name);
>
>         // return named value converted to type T or
>         // null if not existing
>         <T> T get(String name, Class<T> type);
>
>         // return named value converted to the type T of
>         // the default value or the default value if the
>         // named value does not exist
>         <T> T get(String name, T defaultValue);
>
>     }
>
>  This interface will primarily be used to implement the [Value]Map adapter
> for JCR Node based resources but may also be used for other adapters to be
> done in the future - e.g. an adapter for Bundle-based Properties files which
> provide the properties data.
>
>  The interface would live in the org.apache.sling.api.resource and therefore
> be an enhancement of the Sling API.

+1 great!

Reply via email to