Thanks Felix.
I noticed the typo (ADAPTER_CLASSES).
Indeed, @Property annotation taking Class object would be nicer.

I was using these as examples:
http://svn.apache.org/repos/asf/sling/whiteboard/fmeschbe/adapterfactory/src/main/java/org/apache/sling/jcr/jackrabbit/adapterfactory/

<http://svn.apache.org/repos/asf/sling/whiteboard/fmeschbe/adapterfactory/src/main/java/org/apache/sling/jcr/jackrabbit/adapterfactory/>
On Fri, Feb 11, 2011 at 4:24 AM, Felix Meschberger <fmesc...@adobe.com>wrote:

> Hi Sam,
>
> Am Donnerstag, den 10.02.2011, 20:03 +0000 schrieb sam lee:
> > Hey,
> >
> > I am using Sling and Felix (Day CQ to be exact).
> >
> > I am trying to provide my own AdapterFactory so that I can do
> > resource.adaptTo(Foo.class);
> >
> > This is what I have:
> >
> > @Component(name="...", metatype=false, immediate=true)
> > @Service
> > public class FooAdapterFactory implements AdapterFactory {
> > ...
> >     @Property(value={Resource.class.getCanonicalName()})
> >     private static final String ADAPTERS =
> AdapterFactory.ADAPTER_CLASSES;
> > }
> >
> >
> > Obviously, this won't compile because Resource.class.getCanonicalName()
> is
> > not constant expression.
> >
> >
> > Workaround would be  using String literal:
> >     @Property(value={"org.apache.sling.api.resource.Resource"})
> >     private static final String ADAPTERS =
> AdapterFactory.ADAPTER_CLASSES;
>
> This is actually wrong because ADAPTER_CLASSES lists the target classes
> to adapt the objects to. In addition, instead of introducing unneeded
> additional constants, I declare such things on the class level such as:
>
>
> > @Properties({
> >     @Property(name = AdapterFactory.ADAPTABLE_CLASSES, value = {
> >         "org.apache.sling.api.resource.ResourceResolver",
> >         "org.apache.sling.api.resource.Resource" }),
> >     @Property(name = AdapterFactory.ADAPTER_CLASSES, value = {
> >         "javax.jcr.security.AccessControlManager",
> >
> "org.apache.jackrabbit.api.security.JackrabbitAccessControlManager" }) })
>
> >
> >
> >
> > Is there other way to register AdapterFactory to Felix?
> > @Property annotation does not take Class ....
> >
> > And I don't want to use string literal.
>
> Currently there is no way to use something like xyz.class. But out of my
> belly it sounds like a reasonable extension to support something like
>
>  @Property(name = AdapterFactory.ADAPTABLE_CLASSES,
>       classValue = {
>          org.apache.sling.api.resource.ResourceResolver.class,
>          org.apache.sling.api.resource.Resource.class
> })
>
> where the class objects will then be converted to their fully qualified
> names as is done for the @Service annotation.
>
> Regards
> Felix
>
>
> > Thanks.
>
>
>

Reply via email to