What's wrong with:
<%
final Resource res = YourUtil.getPageResourceFrom(slingRequest);//resource
might be sufficient for you from <sling:defineObjects/>
final Metadata metadata =
YourUtil.getMetadataOf(slingRequest.getRequestPathInfo().getSelectors(),
res);
%>

I am not sure why you are trying to implement your own AdapterFactory.
Get those utility methods work first. If you have to make .adaptTo() work
 (for scripting support?), you can do as Justin said:
<%
final Metadata metadata = slingRequest.adaptTo(Metadata.class);
%>

But I don't see a reason for reflection there.


On Thu, Sep 8, 2011 at 10:12 PM, Justin Edelson <[email protected]>wrote:

> Yeah, you're best bet in this case is to treat the request as the
> adaptable.
>
> If this was a real edge case and adapting the request was going to
> mess up your code too much, you could also stick the request in a
> ThreadLocal (I'd put that in a separate filter). But I think this has
> the tendency to make the code a bit hard to read.
>
> Justin
>
> On Thu, Sep 8, 2011 at 9:53 PM, Dan Check <[email protected]> wrote:
> > Hi all,
> >
> > I have a situation where I¹d like to vary the object returned by an
> > resource.adaptTo call based on selectors in the request.  Is it possible
> to
> > get access to the selectors inside of an adaptTo call?  If not, should I
> be
> > treating the request object as adaptable, rather than the resource?
> >
> > The use case here is that I need to return an object containing metadata
> > about the page itself; for most pages, that¹s contained with the resource
> > object alone, but for some, the metadata varies based on the selectors
> that
> > come in as part of the request.
> >
> > Thanks in advance for your help.
> >
> > Best,
> > Dan
> >
>

Reply via email to