[
https://issues.apache.org/jira/browse/SLING-8269?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Julian Sedding updated SLING-8269:
----------------------------------
Description:
In the "new" {{ResourceProvider}} SPI a resource provider always "owns" its
root. This means that below that path no other RP is asked for resources
(unless it's registered on a more specific root path). In order to allow for
the scenario where a RP falls back to \{{Resource}}s provided by other RPs, an
API was added, that I gather should be used as follows:
{code:java}
public Iterator<Resource> listChildren(ResolveContext<Whatever> ctx, Resource
parent) {
Iterator<Resource> ownChildren = ... // compute child resource
ResolveContext<?> parentCtx = ctx.getParentResolveContext();
ResourceProvider<?> parentProvider = ctx.getParentResourceProvider();
if (parentCtx == null || parentProvider == null) {
return null;
}
return merge(ownChildren, parentProvider.listChildren(parentCtx, parent));
}
{code}
However, the {{parentCtx}} on the last line does not match the signature of
{{listChildren(ResourceContext<T>, Resource)}}, because the generic type of
both {{ResolveContext<?>}} and {{ResourceContext<T>}} (from the
{{listChildren}} method signature) do not match, leading to the following
compile-time error:
{noformat}
incompatible types:
org.apache.sling.spi.resource.provider.ResolveContext<capture#1 of ?> cannot be
converted to org.apache.sling.spi.resource.provider.ResolveContext<capture#2 of
?>
{noformat}
This can be worked around by dropping generic types of the local variables and
accepting an "unchecked type" warning, i.e.:
{code:java}
ResolveContext parentCtx = ctx.getParentResolveContext();
ResourceProvider parentProvider = ctx.getParentResourceProvider();
{code}
cc [~cziegeler]
was:
In the "new" {{ResourceProvider}} SPI a resource provider always "owns" its
root. This means that below that path no other RP is asked for resources
(unless it's registered on a more specific root path). In order to allow for
the scenario where a RP falls back to \{{Resource}}s provided by other RPs, an
API was added, that I gather should be used as follows:
{code:java}
public Iterator<Resource> listChildren(ResolveContext<Whatever> ctx, Resource
parent) {
Iterator<Resource> ownChildren = ... // compute child resource
ResolveContext<?> parentCtx = ctx.getParentResolveContext();
ResourceProvider<?> parentProvider = ctx.getParentResourceProvider();
if (parentCtx == null || parentProvider == null) {
return null;
}
return parentProvider.listChildren(parentCtx, parent);
}
{code}
However, the {{parentCtx}} on the last line does not match the signature of
{{listChildren(ResourceContext<T>, Resource)}}, because the generic type of
both {{ResolveContext<?>}} and {{ResourceContext<T>}} (from the
{{listChildren}} method signature) do not match, leading to the following
compile-time error:
{noformat}
incompatible types:
org.apache.sling.spi.resource.provider.ResolveContext<capture#1 of ?> cannot be
converted to org.apache.sling.spi.resource.provider.ResolveContext<capture#2 of
?>
{noformat}
This can be worked around by dropping generic types of the local variables and
accepting an "unchecked type" warning, i.e.:
{code:java}
ResolveContext parentCtx = ctx.getParentResolveContext();
ResourceProvider parentProvider = ctx.getParentResourceProvider();
{code}
cc [~cziegeler]
> Generics in ResourceProvider SPI don't resolve
> ----------------------------------------------
>
> Key: SLING-8269
> URL: https://issues.apache.org/jira/browse/SLING-8269
> Project: Sling
> Issue Type: Improvement
> Components: API
> Affects Versions: API 2.11.0
> Reporter: Julian Sedding
> Priority: Minor
>
> In the "new" {{ResourceProvider}} SPI a resource provider always "owns" its
> root. This means that below that path no other RP is asked for resources
> (unless it's registered on a more specific root path). In order to allow for
> the scenario where a RP falls back to \{{Resource}}s provided by other RPs,
> an API was added, that I gather should be used as follows:
> {code:java}
> public Iterator<Resource> listChildren(ResolveContext<Whatever> ctx, Resource
> parent) {
> Iterator<Resource> ownChildren = ... // compute child resource
> ResolveContext<?> parentCtx = ctx.getParentResolveContext();
> ResourceProvider<?> parentProvider = ctx.getParentResourceProvider();
> if (parentCtx == null || parentProvider == null) {
> return null;
> }
> return merge(ownChildren, parentProvider.listChildren(parentCtx, parent));
> }
> {code}
>
> However, the {{parentCtx}} on the last line does not match the signature of
> {{listChildren(ResourceContext<T>, Resource)}}, because the generic type of
> both {{ResolveContext<?>}} and {{ResourceContext<T>}} (from the
> {{listChildren}} method signature) do not match, leading to the following
> compile-time error:
> {noformat}
> incompatible types:
> org.apache.sling.spi.resource.provider.ResolveContext<capture#1 of ?> cannot
> be converted to
> org.apache.sling.spi.resource.provider.ResolveContext<capture#2 of ?>
> {noformat}
> This can be worked around by dropping generic types of the local variables
> and accepting an "unchecked type" warning, i.e.:
> {code:java}
> ResolveContext parentCtx = ctx.getParentResolveContext();
> ResourceProvider parentProvider = ctx.getParentResourceProvider();
> {code}
> cc [~cziegeler]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)