You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Carsten Ziegeler <cz...@apache.org> on 2014/03/14 09:19:58 UTC
[RT] Support for deep reads from a value map
When writing rendering code, a commonly used shortcut is to do deep reads
to get properties from a child resource, like:
ValueMap vm = ResourceUtil.getValueMap(resource);
vm.get("jcr:content/jcr:title", "No title found");
While this works with jcr backed resources, this doesn't work in the
general case and the contract of a value map returned by a resource is to
just return the properties of the resource. In addition, the implementation
in the jcr resource bundle is wrong as it bypasses all resource mechanisms,
e.g. in the above case resource.getChild("jcr:content") might return a
resource from a different resource provider etc.
Adding the same code over and over again in each ValueMap implementation
doesn't look like a good solution either.
The simplest solution would be to enhance ResourceUtil.getValueMap() to
return a wrapper of the value map which allows deep reads.
Introducing a new concept, like a DeepValueMap (maybe with a better name)
are not very helpful as this would require to change all existing code.
However, it is safe to assume that existing code is using
ResourceUtil.getValueMap().
WDYT?
Regards
Carsten
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Fri, Mar 14, 2014 at 11:19 AM, Bertrand Delacretaz
<bd...@apache.org> wrote:
> ...I'm not opposed to changing just ResourceUtil.getValueMap() to provide
> "deep" value maps, just trying to understand the reasoning behind it....
Thinking about it...if we require people to use a utility method, we
might as well create a new ResourceUtil.getDeepValueMap() method to
make it more explicit.
-Bertrand
Re: [RT] Support for deep reads from a value map
Posted by Julian Sedding <js...@gmail.com>.
I believe it would be possible to implement
AbstractResource#adaptTo(ValueMap.class) in a generic way supporting
relative paths.
A rarely used feature (at least of the JcrResourceProvider) is to
request a property as a Resource (e.g.
resource.getResource("jcr:title").adaptTo(String.class)). If the
contract of ResourceResolver#getResource(Resource base, String path)
was clarified to provide each property as a Resource, this method
could be used
to implement a deep ValueMap.
public DeepValueMap implements ValueMap {
public T get(String relPath, T type) {
Resource descendant = resource.getChild(relPath);
if (descendant == null) {
return null;
} else {
return descendant.adaptTo(type);
}
}
// other methods and constructors ommitted for brevity
}
In addition, it may be useful for ResourceProvider implementation if a
reusable ValueResource class was available to cast to the different
property types (e.g. the Java equivalents of JCR property types).
Regards
Julian
On Fri, Mar 14, 2014 at 11:58 AM, Carsten Ziegeler <cz...@apache.org> wrote:
> Well, in practice, bundles implementing a previous version will not resolve
> anyway
>
>
> 2014-03-14 11:56 GMT+01:00 Bertrand Delacretaz <bd...@apache.org>:
>
>> On Fri, Mar 14, 2014 at 11:53 AM, Carsten Ziegeler <cz...@apache.org>
>> wrote:
>> > All implementations should inherit from AbstractResource for exactly
>> those
>> > reasons :)
>>
>> *in theory*, yes.
>>
>> -Bertrand
>>
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
Well, in practice, bundles implementing a previous version will not resolve
anyway
2014-03-14 11:56 GMT+01:00 Bertrand Delacretaz <bd...@apache.org>:
> On Fri, Mar 14, 2014 at 11:53 AM, Carsten Ziegeler <cz...@apache.org>
> wrote:
> > All implementations should inherit from AbstractResource for exactly
> those
> > reasons :)
>
> *in theory*, yes.
>
> -Bertrand
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Fri, Mar 14, 2014 at 11:53 AM, Carsten Ziegeler <cz...@apache.org> wrote:
> All implementations should inherit from AbstractResource for exactly those
> reasons :)
*in theory*, yes.
-Bertrand
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
All implementations should inherit from AbstractResource for exactly those
reasons :)
Carsten
2014-03-14 11:48 GMT+01:00 Bertrand Delacretaz <bd...@apache.org>:
> Hi,
>
> On Fri, Mar 14, 2014 at 11:42 AM, Carsten Ziegeler <cz...@apache.org>
> wrote:
> > ...The only other option I see is to make ValueMap a first class citizen
> and:
> > a) add a getValueMap() method to Resource - default implementation in
> > AbstractResource does the same as ResourceUtil does today
> > b) clearly state that deep gets are allowed for reading from those maps
>
> I like that, it makes sense for every Resource to have a ValueMap.
>
> a) will break some code, but with c) that will be easy to fix.
>
> > c) provide utility code in AbstractResource (or maybe somewhere else) so
> > implementations do not need to copy the same code over and over again...
>
> I'd put that somewhere else (ValueMapUtil or ResourceUtil) and use it
> in AbstractResource, to make it easier to reuse in Resource
> implementations that might not inherit from AbstractResource.
>
> AbstractResource should also then provide an adaptTo method that calls
> getValueMap.
>
> -Bertrand
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,
On Fri, Mar 14, 2014 at 11:42 AM, Carsten Ziegeler <cz...@apache.org> wrote:
> ...The only other option I see is to make ValueMap a first class citizen and:
> a) add a getValueMap() method to Resource - default implementation in
> AbstractResource does the same as ResourceUtil does today
> b) clearly state that deep gets are allowed for reading from those maps
I like that, it makes sense for every Resource to have a ValueMap.
a) will break some code, but with c) that will be easy to fix.
> c) provide utility code in AbstractResource (or maybe somewhere else) so
> implementations do not need to copy the same code over and over again...
I'd put that somewhere else (ValueMapUtil or ResourceUtil) and use it
in AbstractResource, to make it easier to reuse in Resource
implementations that might not inherit from AbstractResource.
AbstractResource should also then provide an adaptTo method that calls
getValueMap.
-Bertrand
Re: [RT] Support for deep reads from a value map
Posted by Justin Edelson <ju...@justinedelson.com>.
OK. Thanks for explaining. Just wanted to make sure I wasn't missing something.
Justin
On Sun, Mar 16, 2014 at 5:46 AM, Carsten Ziegeler <cz...@apache.org> wrote:
> Hi Justin
>
> it's right we can get the same result without adding this method, however
> with adding this method we really make clear that there is a contract
> change.
> We don't need a refactoring of the Resource api, just an extension - which
> imho we should have done from the beginning.
>
> Carsten
>
>
> 2014-03-15 14:37 GMT+01:00 Justin Edelson <ju...@justinedelson.com>:
>
>> Hi Carsten,
>> I don't understand the coupling between the addition of
>> Resource.getValueMap() and having the Mongo, Merged, and JMX
>> ResourceProviders start using DeepReadValueMapDecorator.
>>
>> IIOW, couldn't we get the same effect *without* changing the Resource
>> API? That has an impact on downstream users and I'd suggest putting it
>> in the category of "things to address the next time we do a
>> refactoring of the Resource API".
>>
>> Regards,
>> Justin
>>
>> On Sat, Mar 15, 2014 at 8:57 AM, Carsten Ziegeler <cz...@apache.org>
>> wrote:
>> > Exactly, if you have a look at the implementation or read my description,
>> > you see that the jcr implementation did not change at all. So, for all
>> jcr
>> > backed resources nothing has changed and the deep read is done there.
>> > Implementations are free to implement the deep read themselves or can use
>> > the provided support.
>> >
>> > Although, as mentioned in the beginning, the jcr implementation is wrong
>> as
>> > it does not use the resource tree, so a
>> getValueMap().get("content/title")
>> > might return something different than a
>> > getChild("content").getValueMap().get("title"). But this has always been
>> > the case, and as the jcr implementation is very complicated with all the
>> > encoding stuff it contains, I think we shouldn't touch this.
>> >
>> > Carsten
>> >
>> >
>> > 2014-03-14 20:28 GMT+01:00 Alexander Klimetschek <ak...@adobe.com>:
>> >
>> >> IIUC, a deep read is now done generically by fetching sub resources
>> first
>> >> and each value map will from now on only read their "local" values.
>> >>
>> >> I think this introduces overhead for a lot of common operations. For
>> every
>> >> descendant node you now have to read and instantiate a resource and
>> value
>> >> map. So far with the JCR property map this was left to the JCR repo.
>> >>
>> >> IMO we should not change much here and simply support deep reads
>> whereever
>> >> possible in the resource implemention (and the missing part here is in
>> the
>> >> /mnt/overlay resource merger AFAIU).
>> >>
>> >> Cheers,
>> >> Alex
>> >>
>> >> On 14.03.2014, at 08:45, Carsten Ziegeler <cz...@apache.org> wrote:
>> >>
>> >> > I just found out that we have to change our idea a little bit, we
>> can't
>> >> > demand that Resource#adaptTo(ValueMap.class) always returns a value
>> map.
>> >> > The nice exception is the JcrPropertyResource...
>> >> >
>> >> > Regards
>> >> > Carsten
>> >> >
>> >> >
>> >> > 2014-03-14 15:08 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
>> >> >
>> >> >> Hi Felix,
>> >> >>
>> >> >> yes, the changes I just committed in fact deprecate
>> >> >> ResourceUtil.getValueMap() and let that method call
>> >> resource.getValueMap()
>> >> >> (if resource is not null of course).
>> >> >>
>> >> >> The utility code is an implementation of the value map which supports
>> >> the
>> >> >> deep read methods. See the new DeepReadValueMapDecorator class.
>> >> >>
>> >> >> Existing implementations which currently return a value map simply
>> need
>> >> to
>> >> >> wrap their value map with this new decorator. Of course they are
>> free to
>> >> >> implement the deep reads by themselves.
>> >> >>
>> >> >> I wanted to change the jcr resource provider, but that would
>> introduce
>> >> >> incompatibilities to a lot of wired path encoding stuff in the
>> >> >> implementation. So it's safer to leave it as is.
>> >> >>
>> >> >> Carsten
>> >> >>
>> >> >>
>> >> >> 2014-03-14 14:58 GMT+01:00 Felix Meschberger <fm...@adobe.com>:
>> >> >>
>> >> >> Hi
>> >> >>>
>> >> >>> Am 14.03.2014 um 11:42 schrieb Carsten Ziegeler <
>> cziegeler@apache.org
>> >> >:
>> >> >>>
>> >> >>>> The only other option I see is to make ValueMap a first class
>> citizen
>> >> >>> and:
>> >> >>>
>> >> >>> I think this makes sense independently of deep reads or not -- and
>> >> maybe
>> >> >>> we should have done this right when we introduced the ValueMap...
>> >> >>>
>> >> >>>> a) add a getValueMap() method to Resource - default implementation
>> in
>> >> >>>> AbstractResource does the same as ResourceUtil does today
>> >> >>>
>> >> >>> In essence ?
>> >> >>>
>> >> >>>> ValueMap AbstractResource.getValueMap() {
>> >> >>>> return ResourceUtil.getValueMap(this);
>> >> >>>> }
>> >> >>>
>> >> >>> or rather copy the ResourceUtil.getValueMap(Resource) method to
>> >> >>> AbstractResource.getValueMap(), implement the deep-read logic there
>> >> and do
>> >> >>>
>> >> >>>> ValueMap ResourceUtil.getValueMap(Resource r) {
>> >> >>>> return r.getValueMap();
>> >> >>>> }
>> >> >>>
>> >> >>> while at the same time deprecating
>> ResourceUtil.getValueMap(Resource) ?
>> >> >>>
>> >> >>>
>> >> >>>> b) clearly state that deep gets are allowed for reading from those
>> >> maps
>> >> >>>
>> >> >>> That would go to the JavaDoc of Resource.getValueMap() along with
>> the
>> >> >>> requirement to never return null.
>> >> >>>
>> >> >>>> c) provide utility code in AbstractResource (or maybe somewhere
>> else)
>> >> so
>> >> >>>> implementations do not need to copy the same code over and over
>> again
>> >> >>>
>> >> >>> What kind of utility code ?
>> >> >>>
>> >> >>> What would existing implementations do ?
>> >> >>>
>> >> >>> I would assume the JCR-based one would have to be touched to not
>> >> support
>> >> >>> deep reads itself, others will benefit. Right ?
>> >> >>>
>> >> >>> Regards
>> >> >>> Felix
>> >> >>>
>> >> >>>>
>> >> >>>> This would mean:
>> >> >>>> a) current code does not need to change, regardless whether
>> >> >>> ResourceUtil or
>> >> >>>> adaptTo is used
>> >> >>>> b) a value map is always provided
>> >> >>>> c) all value maps support deep reads
>> >> >>>> d) no code duplication necessary
>> >> >>>>
>> >> >>>> Carsten
>> >> >>>>
>> >> >>>>
>> >> >>>> 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cziegeler@apache.org
>> >:
>> >> >>>>
>> >> >>>>> The idea behind ResourceUtil.getValueMap is that it never returns
>> >> null
>> >> >>>>> while resource.adaptTo(ValueMap) can.
>> >> >>>>> That's the whole point of this utility method.
>> >> >>>>>
>> >> >>>>> I assume people who do resource.adaptTo(ValueMap) never check for
>> >> null
>> >> >>>>> which is bound to fail
>> >> >>>>>
>> >> >>>>> Carsten
>> >> >>>>>
>> >> >>>>>
>> >> >>>>> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
>> >> >>>>>
>> >> >>>>>> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in
>> >> >>> rendering
>> >> >>>>>> code.
>> >> >>>>>> +1
>> >> >>>>>>
>> >> >>>>>>
>> >> >>>>>
>> >> >>>>>
>> >> >>>>> --
>> >> >>>>> Carsten Ziegeler
>> >> >>>>> cziegeler@apache.org
>> >> >>>>>
>> >> >>>>
>> >> >>>>
>> >> >>>>
>> >> >>>> --
>> >> >>>> Carsten Ziegeler
>> >> >>>> cziegeler@apache.org
>> >> >>>
>> >> >>>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Carsten Ziegeler
>> >> >> cziegeler@apache.org
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Carsten Ziegeler
>> >> > cziegeler@apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > Carsten Ziegeler
>> > cziegeler@apache.org
>>
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
Hi Justin
it's right we can get the same result without adding this method, however
with adding this method we really make clear that there is a contract
change.
We don't need a refactoring of the Resource api, just an extension - which
imho we should have done from the beginning.
Carsten
2014-03-15 14:37 GMT+01:00 Justin Edelson <ju...@justinedelson.com>:
> Hi Carsten,
> I don't understand the coupling between the addition of
> Resource.getValueMap() and having the Mongo, Merged, and JMX
> ResourceProviders start using DeepReadValueMapDecorator.
>
> IIOW, couldn't we get the same effect *without* changing the Resource
> API? That has an impact on downstream users and I'd suggest putting it
> in the category of "things to address the next time we do a
> refactoring of the Resource API".
>
> Regards,
> Justin
>
> On Sat, Mar 15, 2014 at 8:57 AM, Carsten Ziegeler <cz...@apache.org>
> wrote:
> > Exactly, if you have a look at the implementation or read my description,
> > you see that the jcr implementation did not change at all. So, for all
> jcr
> > backed resources nothing has changed and the deep read is done there.
> > Implementations are free to implement the deep read themselves or can use
> > the provided support.
> >
> > Although, as mentioned in the beginning, the jcr implementation is wrong
> as
> > it does not use the resource tree, so a
> getValueMap().get("content/title")
> > might return something different than a
> > getChild("content").getValueMap().get("title"). But this has always been
> > the case, and as the jcr implementation is very complicated with all the
> > encoding stuff it contains, I think we shouldn't touch this.
> >
> > Carsten
> >
> >
> > 2014-03-14 20:28 GMT+01:00 Alexander Klimetschek <ak...@adobe.com>:
> >
> >> IIUC, a deep read is now done generically by fetching sub resources
> first
> >> and each value map will from now on only read their "local" values.
> >>
> >> I think this introduces overhead for a lot of common operations. For
> every
> >> descendant node you now have to read and instantiate a resource and
> value
> >> map. So far with the JCR property map this was left to the JCR repo.
> >>
> >> IMO we should not change much here and simply support deep reads
> whereever
> >> possible in the resource implemention (and the missing part here is in
> the
> >> /mnt/overlay resource merger AFAIU).
> >>
> >> Cheers,
> >> Alex
> >>
> >> On 14.03.2014, at 08:45, Carsten Ziegeler <cz...@apache.org> wrote:
> >>
> >> > I just found out that we have to change our idea a little bit, we
> can't
> >> > demand that Resource#adaptTo(ValueMap.class) always returns a value
> map.
> >> > The nice exception is the JcrPropertyResource...
> >> >
> >> > Regards
> >> > Carsten
> >> >
> >> >
> >> > 2014-03-14 15:08 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
> >> >
> >> >> Hi Felix,
> >> >>
> >> >> yes, the changes I just committed in fact deprecate
> >> >> ResourceUtil.getValueMap() and let that method call
> >> resource.getValueMap()
> >> >> (if resource is not null of course).
> >> >>
> >> >> The utility code is an implementation of the value map which supports
> >> the
> >> >> deep read methods. See the new DeepReadValueMapDecorator class.
> >> >>
> >> >> Existing implementations which currently return a value map simply
> need
> >> to
> >> >> wrap their value map with this new decorator. Of course they are
> free to
> >> >> implement the deep reads by themselves.
> >> >>
> >> >> I wanted to change the jcr resource provider, but that would
> introduce
> >> >> incompatibilities to a lot of wired path encoding stuff in the
> >> >> implementation. So it's safer to leave it as is.
> >> >>
> >> >> Carsten
> >> >>
> >> >>
> >> >> 2014-03-14 14:58 GMT+01:00 Felix Meschberger <fm...@adobe.com>:
> >> >>
> >> >> Hi
> >> >>>
> >> >>> Am 14.03.2014 um 11:42 schrieb Carsten Ziegeler <
> cziegeler@apache.org
> >> >:
> >> >>>
> >> >>>> The only other option I see is to make ValueMap a first class
> citizen
> >> >>> and:
> >> >>>
> >> >>> I think this makes sense independently of deep reads or not -- and
> >> maybe
> >> >>> we should have done this right when we introduced the ValueMap...
> >> >>>
> >> >>>> a) add a getValueMap() method to Resource - default implementation
> in
> >> >>>> AbstractResource does the same as ResourceUtil does today
> >> >>>
> >> >>> In essence ?
> >> >>>
> >> >>>> ValueMap AbstractResource.getValueMap() {
> >> >>>> return ResourceUtil.getValueMap(this);
> >> >>>> }
> >> >>>
> >> >>> or rather copy the ResourceUtil.getValueMap(Resource) method to
> >> >>> AbstractResource.getValueMap(), implement the deep-read logic there
> >> and do
> >> >>>
> >> >>>> ValueMap ResourceUtil.getValueMap(Resource r) {
> >> >>>> return r.getValueMap();
> >> >>>> }
> >> >>>
> >> >>> while at the same time deprecating
> ResourceUtil.getValueMap(Resource) ?
> >> >>>
> >> >>>
> >> >>>> b) clearly state that deep gets are allowed for reading from those
> >> maps
> >> >>>
> >> >>> That would go to the JavaDoc of Resource.getValueMap() along with
> the
> >> >>> requirement to never return null.
> >> >>>
> >> >>>> c) provide utility code in AbstractResource (or maybe somewhere
> else)
> >> so
> >> >>>> implementations do not need to copy the same code over and over
> again
> >> >>>
> >> >>> What kind of utility code ?
> >> >>>
> >> >>> What would existing implementations do ?
> >> >>>
> >> >>> I would assume the JCR-based one would have to be touched to not
> >> support
> >> >>> deep reads itself, others will benefit. Right ?
> >> >>>
> >> >>> Regards
> >> >>> Felix
> >> >>>
> >> >>>>
> >> >>>> This would mean:
> >> >>>> a) current code does not need to change, regardless whether
> >> >>> ResourceUtil or
> >> >>>> adaptTo is used
> >> >>>> b) a value map is always provided
> >> >>>> c) all value maps support deep reads
> >> >>>> d) no code duplication necessary
> >> >>>>
> >> >>>> Carsten
> >> >>>>
> >> >>>>
> >> >>>> 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cziegeler@apache.org
> >:
> >> >>>>
> >> >>>>> The idea behind ResourceUtil.getValueMap is that it never returns
> >> null
> >> >>>>> while resource.adaptTo(ValueMap) can.
> >> >>>>> That's the whole point of this utility method.
> >> >>>>>
> >> >>>>> I assume people who do resource.adaptTo(ValueMap) never check for
> >> null
> >> >>>>> which is bound to fail
> >> >>>>>
> >> >>>>> Carsten
> >> >>>>>
> >> >>>>>
> >> >>>>> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
> >> >>>>>
> >> >>>>>> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in
> >> >>> rendering
> >> >>>>>> code.
> >> >>>>>> +1
> >> >>>>>>
> >> >>>>>>
> >> >>>>>
> >> >>>>>
> >> >>>>> --
> >> >>>>> Carsten Ziegeler
> >> >>>>> cziegeler@apache.org
> >> >>>>>
> >> >>>>
> >> >>>>
> >> >>>>
> >> >>>> --
> >> >>>> Carsten Ziegeler
> >> >>>> cziegeler@apache.org
> >> >>>
> >> >>>
> >> >>
> >> >>
> >> >> --
> >> >> Carsten Ziegeler
> >> >> cziegeler@apache.org
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Carsten Ziegeler
> >> > cziegeler@apache.org
> >>
> >>
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Justin Edelson <ju...@justinedelson.com>.
Hi Carsten,
I don't understand the coupling between the addition of
Resource.getValueMap() and having the Mongo, Merged, and JMX
ResourceProviders start using DeepReadValueMapDecorator.
IIOW, couldn't we get the same effect *without* changing the Resource
API? That has an impact on downstream users and I'd suggest putting it
in the category of "things to address the next time we do a
refactoring of the Resource API".
Regards,
Justin
On Sat, Mar 15, 2014 at 8:57 AM, Carsten Ziegeler <cz...@apache.org> wrote:
> Exactly, if you have a look at the implementation or read my description,
> you see that the jcr implementation did not change at all. So, for all jcr
> backed resources nothing has changed and the deep read is done there.
> Implementations are free to implement the deep read themselves or can use
> the provided support.
>
> Although, as mentioned in the beginning, the jcr implementation is wrong as
> it does not use the resource tree, so a getValueMap().get("content/title")
> might return something different than a
> getChild("content").getValueMap().get("title"). But this has always been
> the case, and as the jcr implementation is very complicated with all the
> encoding stuff it contains, I think we shouldn't touch this.
>
> Carsten
>
>
> 2014-03-14 20:28 GMT+01:00 Alexander Klimetschek <ak...@adobe.com>:
>
>> IIUC, a deep read is now done generically by fetching sub resources first
>> and each value map will from now on only read their "local" values.
>>
>> I think this introduces overhead for a lot of common operations. For every
>> descendant node you now have to read and instantiate a resource and value
>> map. So far with the JCR property map this was left to the JCR repo.
>>
>> IMO we should not change much here and simply support deep reads whereever
>> possible in the resource implemention (and the missing part here is in the
>> /mnt/overlay resource merger AFAIU).
>>
>> Cheers,
>> Alex
>>
>> On 14.03.2014, at 08:45, Carsten Ziegeler <cz...@apache.org> wrote:
>>
>> > I just found out that we have to change our idea a little bit, we can't
>> > demand that Resource#adaptTo(ValueMap.class) always returns a value map.
>> > The nice exception is the JcrPropertyResource...
>> >
>> > Regards
>> > Carsten
>> >
>> >
>> > 2014-03-14 15:08 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
>> >
>> >> Hi Felix,
>> >>
>> >> yes, the changes I just committed in fact deprecate
>> >> ResourceUtil.getValueMap() and let that method call
>> resource.getValueMap()
>> >> (if resource is not null of course).
>> >>
>> >> The utility code is an implementation of the value map which supports
>> the
>> >> deep read methods. See the new DeepReadValueMapDecorator class.
>> >>
>> >> Existing implementations which currently return a value map simply need
>> to
>> >> wrap their value map with this new decorator. Of course they are free to
>> >> implement the deep reads by themselves.
>> >>
>> >> I wanted to change the jcr resource provider, but that would introduce
>> >> incompatibilities to a lot of wired path encoding stuff in the
>> >> implementation. So it's safer to leave it as is.
>> >>
>> >> Carsten
>> >>
>> >>
>> >> 2014-03-14 14:58 GMT+01:00 Felix Meschberger <fm...@adobe.com>:
>> >>
>> >> Hi
>> >>>
>> >>> Am 14.03.2014 um 11:42 schrieb Carsten Ziegeler <cziegeler@apache.org
>> >:
>> >>>
>> >>>> The only other option I see is to make ValueMap a first class citizen
>> >>> and:
>> >>>
>> >>> I think this makes sense independently of deep reads or not -- and
>> maybe
>> >>> we should have done this right when we introduced the ValueMap...
>> >>>
>> >>>> a) add a getValueMap() method to Resource - default implementation in
>> >>>> AbstractResource does the same as ResourceUtil does today
>> >>>
>> >>> In essence ?
>> >>>
>> >>>> ValueMap AbstractResource.getValueMap() {
>> >>>> return ResourceUtil.getValueMap(this);
>> >>>> }
>> >>>
>> >>> or rather copy the ResourceUtil.getValueMap(Resource) method to
>> >>> AbstractResource.getValueMap(), implement the deep-read logic there
>> and do
>> >>>
>> >>>> ValueMap ResourceUtil.getValueMap(Resource r) {
>> >>>> return r.getValueMap();
>> >>>> }
>> >>>
>> >>> while at the same time deprecating ResourceUtil.getValueMap(Resource) ?
>> >>>
>> >>>
>> >>>> b) clearly state that deep gets are allowed for reading from those
>> maps
>> >>>
>> >>> That would go to the JavaDoc of Resource.getValueMap() along with the
>> >>> requirement to never return null.
>> >>>
>> >>>> c) provide utility code in AbstractResource (or maybe somewhere else)
>> so
>> >>>> implementations do not need to copy the same code over and over again
>> >>>
>> >>> What kind of utility code ?
>> >>>
>> >>> What would existing implementations do ?
>> >>>
>> >>> I would assume the JCR-based one would have to be touched to not
>> support
>> >>> deep reads itself, others will benefit. Right ?
>> >>>
>> >>> Regards
>> >>> Felix
>> >>>
>> >>>>
>> >>>> This would mean:
>> >>>> a) current code does not need to change, regardless whether
>> >>> ResourceUtil or
>> >>>> adaptTo is used
>> >>>> b) a value map is always provided
>> >>>> c) all value maps support deep reads
>> >>>> d) no code duplication necessary
>> >>>>
>> >>>> Carsten
>> >>>>
>> >>>>
>> >>>> 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
>> >>>>
>> >>>>> The idea behind ResourceUtil.getValueMap is that it never returns
>> null
>> >>>>> while resource.adaptTo(ValueMap) can.
>> >>>>> That's the whole point of this utility method.
>> >>>>>
>> >>>>> I assume people who do resource.adaptTo(ValueMap) never check for
>> null
>> >>>>> which is bound to fail
>> >>>>>
>> >>>>> Carsten
>> >>>>>
>> >>>>>
>> >>>>> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
>> >>>>>
>> >>>>>> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in
>> >>> rendering
>> >>>>>> code.
>> >>>>>> +1
>> >>>>>>
>> >>>>>>
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> Carsten Ziegeler
>> >>>>> cziegeler@apache.org
>> >>>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> Carsten Ziegeler
>> >>>> cziegeler@apache.org
>> >>>
>> >>>
>> >>
>> >>
>> >> --
>> >> Carsten Ziegeler
>> >> cziegeler@apache.org
>> >>
>> >
>> >
>> >
>> > --
>> > Carsten Ziegeler
>> > cziegeler@apache.org
>>
>>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
Exactly, if you have a look at the implementation or read my description,
you see that the jcr implementation did not change at all. So, for all jcr
backed resources nothing has changed and the deep read is done there.
Implementations are free to implement the deep read themselves or can use
the provided support.
Although, as mentioned in the beginning, the jcr implementation is wrong as
it does not use the resource tree, so a getValueMap().get("content/title")
might return something different than a
getChild("content").getValueMap().get("title"). But this has always been
the case, and as the jcr implementation is very complicated with all the
encoding stuff it contains, I think we shouldn't touch this.
Carsten
2014-03-14 20:28 GMT+01:00 Alexander Klimetschek <ak...@adobe.com>:
> IIUC, a deep read is now done generically by fetching sub resources first
> and each value map will from now on only read their "local" values.
>
> I think this introduces overhead for a lot of common operations. For every
> descendant node you now have to read and instantiate a resource and value
> map. So far with the JCR property map this was left to the JCR repo.
>
> IMO we should not change much here and simply support deep reads whereever
> possible in the resource implemention (and the missing part here is in the
> /mnt/overlay resource merger AFAIU).
>
> Cheers,
> Alex
>
> On 14.03.2014, at 08:45, Carsten Ziegeler <cz...@apache.org> wrote:
>
> > I just found out that we have to change our idea a little bit, we can't
> > demand that Resource#adaptTo(ValueMap.class) always returns a value map.
> > The nice exception is the JcrPropertyResource...
> >
> > Regards
> > Carsten
> >
> >
> > 2014-03-14 15:08 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
> >
> >> Hi Felix,
> >>
> >> yes, the changes I just committed in fact deprecate
> >> ResourceUtil.getValueMap() and let that method call
> resource.getValueMap()
> >> (if resource is not null of course).
> >>
> >> The utility code is an implementation of the value map which supports
> the
> >> deep read methods. See the new DeepReadValueMapDecorator class.
> >>
> >> Existing implementations which currently return a value map simply need
> to
> >> wrap their value map with this new decorator. Of course they are free to
> >> implement the deep reads by themselves.
> >>
> >> I wanted to change the jcr resource provider, but that would introduce
> >> incompatibilities to a lot of wired path encoding stuff in the
> >> implementation. So it's safer to leave it as is.
> >>
> >> Carsten
> >>
> >>
> >> 2014-03-14 14:58 GMT+01:00 Felix Meschberger <fm...@adobe.com>:
> >>
> >> Hi
> >>>
> >>> Am 14.03.2014 um 11:42 schrieb Carsten Ziegeler <cziegeler@apache.org
> >:
> >>>
> >>>> The only other option I see is to make ValueMap a first class citizen
> >>> and:
> >>>
> >>> I think this makes sense independently of deep reads or not -- and
> maybe
> >>> we should have done this right when we introduced the ValueMap...
> >>>
> >>>> a) add a getValueMap() method to Resource - default implementation in
> >>>> AbstractResource does the same as ResourceUtil does today
> >>>
> >>> In essence ?
> >>>
> >>>> ValueMap AbstractResource.getValueMap() {
> >>>> return ResourceUtil.getValueMap(this);
> >>>> }
> >>>
> >>> or rather copy the ResourceUtil.getValueMap(Resource) method to
> >>> AbstractResource.getValueMap(), implement the deep-read logic there
> and do
> >>>
> >>>> ValueMap ResourceUtil.getValueMap(Resource r) {
> >>>> return r.getValueMap();
> >>>> }
> >>>
> >>> while at the same time deprecating ResourceUtil.getValueMap(Resource) ?
> >>>
> >>>
> >>>> b) clearly state that deep gets are allowed for reading from those
> maps
> >>>
> >>> That would go to the JavaDoc of Resource.getValueMap() along with the
> >>> requirement to never return null.
> >>>
> >>>> c) provide utility code in AbstractResource (or maybe somewhere else)
> so
> >>>> implementations do not need to copy the same code over and over again
> >>>
> >>> What kind of utility code ?
> >>>
> >>> What would existing implementations do ?
> >>>
> >>> I would assume the JCR-based one would have to be touched to not
> support
> >>> deep reads itself, others will benefit. Right ?
> >>>
> >>> Regards
> >>> Felix
> >>>
> >>>>
> >>>> This would mean:
> >>>> a) current code does not need to change, regardless whether
> >>> ResourceUtil or
> >>>> adaptTo is used
> >>>> b) a value map is always provided
> >>>> c) all value maps support deep reads
> >>>> d) no code duplication necessary
> >>>>
> >>>> Carsten
> >>>>
> >>>>
> >>>> 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
> >>>>
> >>>>> The idea behind ResourceUtil.getValueMap is that it never returns
> null
> >>>>> while resource.adaptTo(ValueMap) can.
> >>>>> That's the whole point of this utility method.
> >>>>>
> >>>>> I assume people who do resource.adaptTo(ValueMap) never check for
> null
> >>>>> which is bound to fail
> >>>>>
> >>>>> Carsten
> >>>>>
> >>>>>
> >>>>> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
> >>>>>
> >>>>>> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in
> >>> rendering
> >>>>>> code.
> >>>>>> +1
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Carsten Ziegeler
> >>>>> cziegeler@apache.org
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> Carsten Ziegeler
> >>>> cziegeler@apache.org
> >>>
> >>>
> >>
> >>
> >> --
> >> Carsten Ziegeler
> >> cziegeler@apache.org
> >>
> >
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
>
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Alexander Klimetschek <ak...@adobe.com>.
IIUC, a deep read is now done generically by fetching sub resources first and each value map will from now on only read their "local" values.
I think this introduces overhead for a lot of common operations. For every descendant node you now have to read and instantiate a resource and value map. So far with the JCR property map this was left to the JCR repo.
IMO we should not change much here and simply support deep reads whereever possible in the resource implemention (and the missing part here is in the /mnt/overlay resource merger AFAIU).
Cheers,
Alex
On 14.03.2014, at 08:45, Carsten Ziegeler <cz...@apache.org> wrote:
> I just found out that we have to change our idea a little bit, we can't
> demand that Resource#adaptTo(ValueMap.class) always returns a value map.
> The nice exception is the JcrPropertyResource...
>
> Regards
> Carsten
>
>
> 2014-03-14 15:08 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
>
>> Hi Felix,
>>
>> yes, the changes I just committed in fact deprecate
>> ResourceUtil.getValueMap() and let that method call resource.getValueMap()
>> (if resource is not null of course).
>>
>> The utility code is an implementation of the value map which supports the
>> deep read methods. See the new DeepReadValueMapDecorator class.
>>
>> Existing implementations which currently return a value map simply need to
>> wrap their value map with this new decorator. Of course they are free to
>> implement the deep reads by themselves.
>>
>> I wanted to change the jcr resource provider, but that would introduce
>> incompatibilities to a lot of wired path encoding stuff in the
>> implementation. So it's safer to leave it as is.
>>
>> Carsten
>>
>>
>> 2014-03-14 14:58 GMT+01:00 Felix Meschberger <fm...@adobe.com>:
>>
>> Hi
>>>
>>> Am 14.03.2014 um 11:42 schrieb Carsten Ziegeler <cz...@apache.org>:
>>>
>>>> The only other option I see is to make ValueMap a first class citizen
>>> and:
>>>
>>> I think this makes sense independently of deep reads or not -- and maybe
>>> we should have done this right when we introduced the ValueMap...
>>>
>>>> a) add a getValueMap() method to Resource - default implementation in
>>>> AbstractResource does the same as ResourceUtil does today
>>>
>>> In essence ?
>>>
>>>> ValueMap AbstractResource.getValueMap() {
>>>> return ResourceUtil.getValueMap(this);
>>>> }
>>>
>>> or rather copy the ResourceUtil.getValueMap(Resource) method to
>>> AbstractResource.getValueMap(), implement the deep-read logic there and do
>>>
>>>> ValueMap ResourceUtil.getValueMap(Resource r) {
>>>> return r.getValueMap();
>>>> }
>>>
>>> while at the same time deprecating ResourceUtil.getValueMap(Resource) ?
>>>
>>>
>>>> b) clearly state that deep gets are allowed for reading from those maps
>>>
>>> That would go to the JavaDoc of Resource.getValueMap() along with the
>>> requirement to never return null.
>>>
>>>> c) provide utility code in AbstractResource (or maybe somewhere else) so
>>>> implementations do not need to copy the same code over and over again
>>>
>>> What kind of utility code ?
>>>
>>> What would existing implementations do ?
>>>
>>> I would assume the JCR-based one would have to be touched to not support
>>> deep reads itself, others will benefit. Right ?
>>>
>>> Regards
>>> Felix
>>>
>>>>
>>>> This would mean:
>>>> a) current code does not need to change, regardless whether
>>> ResourceUtil or
>>>> adaptTo is used
>>>> b) a value map is always provided
>>>> c) all value maps support deep reads
>>>> d) no code duplication necessary
>>>>
>>>> Carsten
>>>>
>>>>
>>>> 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
>>>>
>>>>> The idea behind ResourceUtil.getValueMap is that it never returns null
>>>>> while resource.adaptTo(ValueMap) can.
>>>>> That's the whole point of this utility method.
>>>>>
>>>>> I assume people who do resource.adaptTo(ValueMap) never check for null
>>>>> which is bound to fail
>>>>>
>>>>> Carsten
>>>>>
>>>>>
>>>>> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
>>>>>
>>>>>> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in
>>> rendering
>>>>>> code.
>>>>>> +1
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Carsten Ziegeler
>>>>> cziegeler@apache.org
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Carsten Ziegeler
>>>> cziegeler@apache.org
>>>
>>>
>>
>>
>> --
>> Carsten Ziegeler
>> cziegeler@apache.org
>>
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
I just found out that we have to change our idea a little bit, we can't
demand that Resource#adaptTo(ValueMap.class) always returns a value map.
The nice exception is the JcrPropertyResource...
Regards
Carsten
2014-03-14 15:08 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
> Hi Felix,
>
> yes, the changes I just committed in fact deprecate
> ResourceUtil.getValueMap() and let that method call resource.getValueMap()
> (if resource is not null of course).
>
> The utility code is an implementation of the value map which supports the
> deep read methods. See the new DeepReadValueMapDecorator class.
>
> Existing implementations which currently return a value map simply need to
> wrap their value map with this new decorator. Of course they are free to
> implement the deep reads by themselves.
>
> I wanted to change the jcr resource provider, but that would introduce
> incompatibilities to a lot of wired path encoding stuff in the
> implementation. So it's safer to leave it as is.
>
> Carsten
>
>
> 2014-03-14 14:58 GMT+01:00 Felix Meschberger <fm...@adobe.com>:
>
> Hi
>>
>> Am 14.03.2014 um 11:42 schrieb Carsten Ziegeler <cz...@apache.org>:
>>
>> > The only other option I see is to make ValueMap a first class citizen
>> and:
>>
>> I think this makes sense independently of deep reads or not -- and maybe
>> we should have done this right when we introduced the ValueMap...
>>
>> > a) add a getValueMap() method to Resource - default implementation in
>> > AbstractResource does the same as ResourceUtil does today
>>
>> In essence ?
>>
>> > ValueMap AbstractResource.getValueMap() {
>> > return ResourceUtil.getValueMap(this);
>> > }
>>
>> or rather copy the ResourceUtil.getValueMap(Resource) method to
>> AbstractResource.getValueMap(), implement the deep-read logic there and do
>>
>> > ValueMap ResourceUtil.getValueMap(Resource r) {
>> > return r.getValueMap();
>> > }
>>
>> while at the same time deprecating ResourceUtil.getValueMap(Resource) ?
>>
>>
>> > b) clearly state that deep gets are allowed for reading from those maps
>>
>> That would go to the JavaDoc of Resource.getValueMap() along with the
>> requirement to never return null.
>>
>> > c) provide utility code in AbstractResource (or maybe somewhere else) so
>> > implementations do not need to copy the same code over and over again
>>
>> What kind of utility code ?
>>
>> What would existing implementations do ?
>>
>> I would assume the JCR-based one would have to be touched to not support
>> deep reads itself, others will benefit. Right ?
>>
>> Regards
>> Felix
>>
>> >
>> > This would mean:
>> > a) current code does not need to change, regardless whether
>> ResourceUtil or
>> > adaptTo is used
>> > b) a value map is always provided
>> > c) all value maps support deep reads
>> > d) no code duplication necessary
>> >
>> > Carsten
>> >
>> >
>> > 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
>> >
>> >> The idea behind ResourceUtil.getValueMap is that it never returns null
>> >> while resource.adaptTo(ValueMap) can.
>> >> That's the whole point of this utility method.
>> >>
>> >> I assume people who do resource.adaptTo(ValueMap) never check for null
>> >> which is bound to fail
>> >>
>> >> Carsten
>> >>
>> >>
>> >> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
>> >>
>> >>> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in
>> rendering
>> >>> code.
>> >>> +1
>> >>>
>> >>>
>> >>
>> >>
>> >> --
>> >> Carsten Ziegeler
>> >> cziegeler@apache.org
>> >>
>> >
>> >
>> >
>> > --
>> > Carsten Ziegeler
>> > cziegeler@apache.org
>>
>>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
Hi Felix,
yes, the changes I just committed in fact deprecate
ResourceUtil.getValueMap() and let that method call resource.getValueMap()
(if resource is not null of course).
The utility code is an implementation of the value map which supports the
deep read methods. See the new DeepReadValueMapDecorator class.
Existing implementations which currently return a value map simply need to
wrap their value map with this new decorator. Of course they are free to
implement the deep reads by themselves.
I wanted to change the jcr resource provider, but that would introduce
incompatibilities to a lot of wired path encoding stuff in the
implementation. So it's safer to leave it as is.
Carsten
2014-03-14 14:58 GMT+01:00 Felix Meschberger <fm...@adobe.com>:
> Hi
>
> Am 14.03.2014 um 11:42 schrieb Carsten Ziegeler <cz...@apache.org>:
>
> > The only other option I see is to make ValueMap a first class citizen
> and:
>
> I think this makes sense independently of deep reads or not -- and maybe we
> should have done this right when we introduced the ValueMap...
>
> > a) add a getValueMap() method to Resource - default implementation in
> > AbstractResource does the same as ResourceUtil does today
>
> In essence ?
>
> > ValueMap AbstractResource.getValueMap() {
> > return ResourceUtil.getValueMap(this);
> > }
>
> or rather copy the ResourceUtil.getValueMap(Resource) method to
> AbstractResource.getValueMap(), implement the deep-read logic there and do
>
> > ValueMap ResourceUtil.getValueMap(Resource r) {
> > return r.getValueMap();
> > }
>
> while at the same time deprecating ResourceUtil.getValueMap(Resource) ?
>
>
> > b) clearly state that deep gets are allowed for reading from those maps
>
> That would go to the JavaDoc of Resource.getValueMap() along with the
> requirement to never return null.
>
> > c) provide utility code in AbstractResource (or maybe somewhere else) so
> > implementations do not need to copy the same code over and over again
>
> What kind of utility code ?
>
> What would existing implementations do ?
>
> I would assume the JCR-based one would have to be touched to not support
> deep reads itself, others will benefit. Right ?
>
> Regards
> Felix
>
> >
> > This would mean:
> > a) current code does not need to change, regardless whether ResourceUtil
> or
> > adaptTo is used
> > b) a value map is always provided
> > c) all value maps support deep reads
> > d) no code duplication necessary
> >
> > Carsten
> >
> >
> > 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
> >
> >> The idea behind ResourceUtil.getValueMap is that it never returns null
> >> while resource.adaptTo(ValueMap) can.
> >> That's the whole point of this utility method.
> >>
> >> I assume people who do resource.adaptTo(ValueMap) never check for null
> >> which is bound to fail
> >>
> >> Carsten
> >>
> >>
> >> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
> >>
> >>> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in
> rendering
> >>> code.
> >>> +1
> >>>
> >>>
> >>
> >>
> >> --
> >> Carsten Ziegeler
> >> cziegeler@apache.org
> >>
> >
> >
> >
> > --
> > Carsten Ziegeler
> > cziegeler@apache.org
>
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Felix Meschberger <fm...@adobe.com>.
Hi
Am 14.03.2014 um 11:42 schrieb Carsten Ziegeler <cz...@apache.org>:
> The only other option I see is to make ValueMap a first class citizen and:
I think this makes sense independently of deep reads or not — and maybe we should have done this right when we introduced the ValueMap...
> a) add a getValueMap() method to Resource - default implementation in
> AbstractResource does the same as ResourceUtil does today
In essence ?
> ValueMap AbstractResource.getValueMap() {
> return ResourceUtil.getValueMap(this);
> }
or rather copy the ResourceUtil.getValueMap(Resource) method to AbstractResource.getValueMap(), implement the deep-read logic there and do
> ValueMap ResourceUtil.getValueMap(Resource r) {
> return r.getValueMap();
> }
while at the same time deprecating ResourceUtil.getValueMap(Resource) ?
> b) clearly state that deep gets are allowed for reading from those maps
That would go to the JavaDoc of Resource.getValueMap() along with the requirement to never return null.
> c) provide utility code in AbstractResource (or maybe somewhere else) so
> implementations do not need to copy the same code over and over again
What kind of utility code ?
What would existing implementations do ?
I would assume the JCR-based one would have to be touched to not support deep reads itself, others will benefit. Right ?
Regards
Felix
>
> This would mean:
> a) current code does not need to change, regardless whether ResourceUtil or
> adaptTo is used
> b) a value map is always provided
> c) all value maps support deep reads
> d) no code duplication necessary
>
> Carsten
>
>
> 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
>
>> The idea behind ResourceUtil.getValueMap is that it never returns null
>> while resource.adaptTo(ValueMap) can.
>> That's the whole point of this utility method.
>>
>> I assume people who do resource.adaptTo(ValueMap) never check for null
>> which is bound to fail
>>
>> Carsten
>>
>>
>> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
>>
>>> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in rendering
>>> code.
>>> +1
>>>
>>>
>>
>>
>> --
>> Carsten Ziegeler
>> cziegeler@apache.org
>>
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
I've commited a first version based on this. The good news is that only a
few bundles are affected.
Apart from API, we need to update the JMX Resource Provider, the Merge
Resource Provider and the Mongo DB Resource Provider.
The JCR Resource Provider has already an implementation - while this is
wrong, changing this would be incompatible (due to encoding stuff). So I
think we should leave it as is.
The bundle resource provider never implemented adaptTo(ValueMap) so it
reverts to the new default implementation returning an empty map
While the servlet and the file resource provider do not implement deep
reading, I think we can leave them as is as resources provided by those are
leaves in the resource tree and don't have any child resources.
Regards
Carsten
2014-03-14 11:42 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
> The only other option I see is to make ValueMap a first class citizen and:
> a) add a getValueMap() method to Resource - default implementation in
> AbstractResource does the same as ResourceUtil does today
> b) clearly state that deep gets are allowed for reading from those maps
> c) provide utility code in AbstractResource (or maybe somewhere else) so
> implementations do not need to copy the same code over and over again
>
> This would mean:
> a) current code does not need to change, regardless whether ResourceUtil
> or adaptTo is used
> b) a value map is always provided
> c) all value maps support deep reads
> d) no code duplication necessary
>
> Carsten
>
>
> 2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
>
> The idea behind ResourceUtil.getValueMap is that it never returns null
>> while resource.adaptTo(ValueMap) can.
>> That's the whole point of this utility method.
>>
>> I assume people who do resource.adaptTo(ValueMap) never check for null
>> which is bound to fail
>>
>> Carsten
>>
>>
>> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
>>
>> > FWIW, there are lots of calls to resource.adaptTo(ValueMap) in
>>> rendering code.
>>> +1
>>>
>>>
>>
>>
>> --
>> Carsten Ziegeler
>> cziegeler@apache.org
>>
>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
The only other option I see is to make ValueMap a first class citizen and:
a) add a getValueMap() method to Resource - default implementation in
AbstractResource does the same as ResourceUtil does today
b) clearly state that deep gets are allowed for reading from those maps
c) provide utility code in AbstractResource (or maybe somewhere else) so
implementations do not need to copy the same code over and over again
This would mean:
a) current code does not need to change, regardless whether ResourceUtil or
adaptTo is used
b) a value map is always provided
c) all value maps support deep reads
d) no code duplication necessary
Carsten
2014-03-14 11:37 GMT+01:00 Carsten Ziegeler <cz...@apache.org>:
> The idea behind ResourceUtil.getValueMap is that it never returns null
> while resource.adaptTo(ValueMap) can.
> That's the whole point of this utility method.
>
> I assume people who do resource.adaptTo(ValueMap) never check for null
> which is bound to fail
>
> Carsten
>
>
> 2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
>
> > FWIW, there are lots of calls to resource.adaptTo(ValueMap) in rendering
>> code.
>> +1
>>
>>
>
>
> --
> Carsten Ziegeler
> cziegeler@apache.org
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
The idea behind ResourceUtil.getValueMap is that it never returns null
while resource.adaptTo(ValueMap) can.
That's the whole point of this utility method.
I assume people who do resource.adaptTo(ValueMap) never check for null
which is bound to fail
Carsten
2014-03-14 11:30 GMT+01:00 Amit.. Gupta. <am...@adobe.com>:
> > FWIW, there are lots of calls to resource.adaptTo(ValueMap) in rendering
> code.
> +1
>
>
--
Carsten Ziegeler
cziegeler@apache.org
RE: [RT] Support for deep reads from a value map
Posted by "Amit.. Gupta." <am...@adobe.com>.
> FWIW, there are lots of calls to resource.adaptTo(ValueMap) in rendering code.
+1
Re: [RT] Support for deep reads from a value map
Posted by Jeff Young <je...@adobe.com>.
FWIW, there are lots of calls to resource.adaptTo(ValueMap) in rendering
code.
Cheers,
Jeff.
On 14/03/2014 10:19, "Bertrand Delacretaz" <bd...@apache.org> wrote:
>On Fri, Mar 14, 2014 at 11:03 AM, Carsten Ziegeler <cz...@apache.org>
>wrote:
>> ...Just for rendering code, it is quiet handy to have deep reads - and
>> rendering code is using ResourceUtil.getValueMap()...
>
>Why would rendering code use this over Resource.adaptTo? Sling makes
>the current resource available to scripts, so AFAIK there's no
>incentive to use ResourceUtil more than adaptTo - but maybe I'm
>missing something.
>
>I'm not opposed to changing just ResourceUtil.getValueMap() to provide
>"deep" value maps, just trying to understand the reasoning behind it.
>
>-Bertrand
Re: [RT] Support for deep reads from a value map
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Fri, Mar 14, 2014 at 11:03 AM, Carsten Ziegeler <cz...@apache.org> wrote:
> ...Just for rendering code, it is quiet handy to have deep reads - and
> rendering code is using ResourceUtil.getValueMap()...
Why would rendering code use this over Resource.adaptTo? Sling makes
the current resource available to scripts, so AFAIK there's no
incentive to use ResourceUtil more than adaptTo - but maybe I'm
missing something.
I'm not opposed to changing just ResourceUtil.getValueMap() to provide
"deep" value maps, just trying to understand the reasoning behind it.
-Bertrand
Re: [RT] Support for deep reads from a value map
Posted by Carsten Ziegeler <cz...@apache.org>.
2014-03-14 10:58 GMT+01:00 Bertrand Delacretaz <bd...@apache.org>:
> On Fri, Mar 14, 2014 at 9:19 AM, Carsten Ziegeler <cz...@apache.org>
> wrote:
> > ...The simplest solution would be to enhance ResourceUtil.getValueMap()
> to
> > return a wrapper of the value map which allows deep reads...
>
> Sounds reasonable, but will that also work if I just call
> Resource.adaptTo(ValueMap.class)?
> Or do we need to fix all Resource implementations to achieve that?
>
>
That would need a change in the API contract :) and all implementations
need to be fixed as well.
The contract of the returned ValueMap from a resource is to just provide
access to it's properties.
Just for rendering code, it is quiet handy to have deep reads - and
rendering code is using ResourceUtil.getValueMap().
Regards
Carsten
--
Carsten Ziegeler
cziegeler@apache.org
Re: [RT] Support for deep reads from a value map
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Fri, Mar 14, 2014 at 9:19 AM, Carsten Ziegeler <cz...@apache.org> wrote:
> ...The simplest solution would be to enhance ResourceUtil.getValueMap() to
> return a wrapper of the value map which allows deep reads...
Sounds reasonable, but will that also work if I just call
Resource.adaptTo(ValueMap.class)?
Or do we need to fix all Resource implementations to achieve that?
-Bertrand