You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Dan Klco <da...@sixdimensions.com> on 2013/03/29 20:14:17 UTC

Sling Dynamic Proxy

Hello Everyone,



A colleague (Michael Kelleher) and I have built an extension we would be interested in incorporating into Sling, as a contributed module.



A short synopsis of this is, it functions as a far simpler, read-only ORM for Sling.  It allows a developer to define an Interface, and with the use of Annotations, and a Service, create an instance backed by resource(s) within JCR.  The mapping of method names to JCR properties is configured with annotations and interpreted by the Java Proxy InvocationHandler to map back to Sling Resources and properties.



Here's an example usage of the Sling Dynamic Proxy:



public interface Page extends ISlingProxy {



                /**

                * Gets the property jcr:created

                */

                @SlingProperty(name="jcr:created")

                public Date getCreationDate();



                /**

                * Gets the property jcr:description at the sub path jcr:content, the path is not required and can be absolute

                */

                @SlingProperty(name="jcr:description", path="jcr:content")

                public String getDescription();



                /**

                * Gets the property jcr:title at the sub path jcr:content, the path is not required and can be absolute

                */

                @SlingProperty(name="jcr:title", path="jcr:content")

                public String getTitle();



                /**

                * Gets the content resource, this could also return a class which can be adapted from a resource or another proxy instance.

                */

                @SlingReference(path="jcr:content")

                public Resource getContentResource();



                /**

                * Gets the children of the current resource, the return type should match the return type in the generic of the return Iterator.

                */

                @SlingChildren(returnType=Resource.class, path="")

                public Iterator<Resource> getChildren();

}



You could then retrieve an instance of the proxy as such:



Resource resource;

ISlingProxyService slingProxyService;

{...}

Page page = slingProxyService.getProxy(resource, Page.class);



You can check out the code, including some basic tests on GitHub:

https://github.com/sixdimensions/sling-proxy



We both hope this project will be of interest to the Sling developers and the Sling community.



Thanks,

Dan Klco
Senior Staff Engineer, Adobe WEM / Day CQ5
San Ramon, CA / Dayton, OH

[Description: Description: Description: cid:image003.gif@01CCF856.90108760]<http://www.sixdimensions.com/>
Cell (937) 231-3050
Office (937) 343-1326
Fax (877) 510-5082
LinkedIn<http://www.linkedin.com/in/klcodanr> | @KlcoDanR<https://twitter.com/klcodanr>

People. Deliver. Progress.


RE: Sling Dynamic Proxy

Posted by Dan Klco <da...@sixdimensions.com>.
Fair enough, I will go ahead and update the code to remove the I prefix to comply with project standards.

Thanks,
Dan

-----Original Message-----
From: Felix Meschberger [mailto:fmeschbe@adobe.com] 
Sent: Tuesday, April 02, 2013 8:21 AM
To: dev@sling.apache.org
Subject: Re: Sling Dynamic Proxy

Hi

Sounds like an interesting proposal (except that we don't use the "I" prefix for interfaces).

Am 29.03.2013 um 20:14 schrieb Dan Klco:

Hello Everyone,

A colleague (Michael Kelleher) and I have built an extension we would be interested in incorporating into Sling, as a contributed module.

A short synopsis of this is, it functions as a far simpler, read-only ORM for Sling.  It allows a developer to define an Interface, and with the use of Annotations, and a Service, create an instance backed by resource(s) within JCR.  The mapping of method names to JCR properties is configured with annotations and interpreted by the Java Proxy InvocationHandler to map back to Sling Resources and properties.

Here's an example usage of the Sling Dynamic Proxy:

public interface Page extends ISlingProxy {

                /**
                * Gets the property jcr:created
                */
                @SlingProperty(name="jcr:created")
                public Date getCreationDate();

                /**
                * Gets the property jcr:description at the sub path jcr:content, the path is not required and can be absolute
                */
                @SlingProperty(name="jcr:description", path="jcr:content")
                public String getDescription();

What's the difference to something like:

                @SlingProperty(name="jcr:content/jcr:description")

would that be like a "search path" ?

Regards
Felix


                /**
                * Gets the property jcr:title at the sub path jcr:content, the path is not required and can be absolute
                */
                @SlingProperty(name="jcr:title", path="jcr:content")
                public String getTitle();

                /**
                * Gets the content resource, this could also return a class which can be adapted from a resource or another proxy instance.
                */
                @SlingReference(path="jcr:content")
                public Resource getContentResource();

                /**
                * Gets the children of the current resource, the return type should match the return type in the generic of the return Iterator.
                */
                @SlingChildren(returnType=Resource.class, path="")
                public Iterator<Resource> getChildren(); }

You could then retrieve an instance of the proxy as such:

Resource resource;
ISlingProxyService slingProxyService;
{...}
Page page = slingProxyService.getProxy(resource, Page.class);

You can check out the code, including some basic tests on GitHub:
https://github.com/sixdimensions/sling-proxy

We both hope this project will be of interest to the Sling developers and the Sling community.

Thanks,

Dan Klco
Senior Staff Engineer, Adobe WEM / Day CQ5 San Ramon, CA / Dayton, OH

<http://www.sixdimensions.com/>
Cell (937) 231-3050
Office (937) 343-1326
Fax (877) 510-5082
LinkedIn<http://www.linkedin.com/in/klcodanr> | @KlcoDanR<https://twitter.com/klcodanr>

People. Deliver. Progress.



--
Felix Meschberger | Principal Scientist | Adobe








-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.3267 / Virus Database: 3161/6217 - Release Date: 03/31/13


Re: Sling Dynamic Proxy

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

Sounds like an interesting proposal (except that we don't use the "I" prefix for interfaces).

Am 29.03.2013 um 20:14 schrieb Dan Klco:

Hello Everyone,

A colleague (Michael Kelleher) and I have built an extension we would be interested in incorporating into Sling, as a contributed module.

A short synopsis of this is, it functions as a far simpler, read-only ORM for Sling.  It allows a developer to define an Interface, and with the use of Annotations, and a Service, create an instance backed by resource(s) within JCR.  The mapping of method names to JCR properties is configured with annotations and interpreted by the Java Proxy InvocationHandler to map back to Sling Resources and properties.

Here’s an example usage of the Sling Dynamic Proxy:

public interface Page extends ISlingProxy {

                /**
                * Gets the property jcr:created
                */
                @SlingProperty(name=”jcr:created”)
                public Date getCreationDate();

                /**
                * Gets the property jcr:description at the sub path jcr:content, the path is not required and can be absolute
                */
                @SlingProperty(name=”jcr:description”, path=”jcr:content”)
                public String getDescription();

What's the difference to something like:

                @SlingProperty(name=”jcr:content/jcr:description”)

would that be like a "search path" ?

Regards
Felix


                /**
                * Gets the property jcr:title at the sub path jcr:content, the path is not required and can be absolute
                */
                @SlingProperty(name=”jcr:title”, path=”jcr:content”)
                public String getTitle();

                /**
                * Gets the content resource, this could also return a class which can be adapted from a resource or another proxy instance.
                */
                @SlingReference(path=”jcr:content”)
                public Resource getContentResource();

                /**
                * Gets the children of the current resource, the return type should match the return type in the generic of the return Iterator.
                */
                @SlingChildren(returnType=Resource.class, path=””)
                public Iterator<Resource> getChildren();
}

You could then retrieve an instance of the proxy as such:

Resource resource;
ISlingProxyService slingProxyService;
{…}
Page page = slingProxyService.getProxy(resource, Page.class);

You can check out the code, including some basic tests on GitHub:
https://github.com/sixdimensions/sling-proxy

We both hope this project will be of interest to the Sling developers and the Sling community.

Thanks,

Dan Klco
Senior Staff Engineer, Adobe WEM / Day CQ5
San Ramon, CA / Dayton, OH

<http://www.sixdimensions.com/>
Cell (937) 231-3050
Office (937) 343-1326
Fax (877) 510-5082
LinkedIn<http://www.linkedin.com/in/klcodanr> | @KlcoDanR<https://twitter.com/klcodanr>

People. Deliver. Progress.



--
Felix Meschberger | Principal Scientist | Adobe








RE: Sling Dynamic Proxy

Posted by Dan Klco <da...@sixdimensions.com>.
Alex,

In my experience, yes.  Though it depends a lot on the project.  

Some of the projects I have been on leverage a lot of structured data for building out pages and the process of  building out the DAO/DTO layer gets rather tedious, especially when you have to retrieve multiple resources to retrieve the data required.  

-Dan

-----Original Message-----
From: Alexander Klimetschek [mailto:aklimets@adobe.com] 
Sent: Tuesday, April 02, 2013 8:19 AM
To: dev@sling.apache.org
Subject: Re: Sling Dynamic Proxy

On 29.03.2013, at 20:14, Dan Klco <da...@sixdimensions.com> wrote:

>                 @SlingProperty(name="jcr:created")
>                 public Date getCreationDate();

Is this really worth the additional complexity compared to the following?

public Date getCreationDate() {
    return properties.get("jcr:created", Date.class); }

This is far more flexible in case you want to do more complex things for certain getters...

Granted, you also need an adapter factory for that, but once that's set up, it's easy to add new adapters.

Cheers,
Alex

-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.3267 / Virus Database: 3161/6217 - Release Date: 03/31/13


Re: Sling Dynamic Proxy

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 29.03.2013, at 20:14, Dan Klco <da...@sixdimensions.com> wrote:

>                 @SlingProperty(name=”jcr:created”)
>                 public Date getCreationDate();

Is this really worth the additional complexity compared to the following?

public Date getCreationDate() {
    return properties.get("jcr:created", Date.class);
}

This is far more flexible in case you want to do more complex things for certain getters...

Granted, you also need an adapter factory for that, but once that's set up, it's easy to add new adapters.

Cheers,
Alex

RE: Sling Dynamic Proxy

Posted by Dan Klco <da...@sixdimensions.com>.
This makes sense to me, I would assume this would run after the standard adaption process if no adapter is found?  Could multiple of these be specified?  

Thanks,
Dan

-----Original Message-----
From: Felix Meschberger [mailto:fmeschbe@adobe.com] 
Sent: Tuesday, April 02, 2013 8:19 AM
To: dev@sling.apache.org
Subject: Re: Sling Dynamic Proxy

Hi

Am 29.03.2013 um 21:18 schrieb Justin Edelson:

> Fixing/changing AdapterManager shouldn't be out of the question :)

Absolutely: How about a special adaptable and adapter class name of "*" which just means "any" ?

Regards
Felix

> 
> 
> 
> 
> On Fri, Mar 29, 2013 at 4:04 PM, Dan Klco <da...@sixdimensions.com>wrote:
> 
>> Justin,
>> 
>> I total agree, however I didn't see a way to inject adaptables into 
>> the Sling Adapter Manager without knowing the exact class to be 
>> adapted ahead of time.  I would imagine there would be a way to 
>> change this, but I can't see one which would not require changing the Sling Adapter Manager.
>> 
>> If we could add a hook where you could specify an AdapterFactory to 
>> handle requests for a subclass of a particular class, assuming the 
>> exact class is not matched then we should be able to support adapting 
>> to proxy instances without further code for implementers.
>> 
>> At the moment, there is an abstract class included in the Sling Proxy 
>> project which will make it easier for implementers to implement an 
>> AdapterFactory for their interfaces.
>> 
>> Thanks for the feedback and please let me know if I missed something,
>> 
>> -Dan
>> 
>> -----Original Message-----
>> From: justinedelson@gmail.com [mailto:justinedelson@gmail.com] On 
>> Behalf Of Justin Edelson
>> Sent: Friday, March 29, 2013 3:36 PM
>> To: dev@sling.apache.org
>> Subject: Re: Sling Dynamic Proxy
>> 
>> Hi Dan,
>> This looks very interesting, but I'm curious why this code:
>> 
>> ISlingProxyService slingProxyService;****
>> 
>> {...}****
>> 
>> Page page = slingProxyService.getProxy(resource, Page.class);
>> 
>> Is not just
>> 
>> Page page = resource.adaptTo(Page.class);
>> 
>> 
>> Regards,
>> 
>> Justin
>> 
>> 
>> On Fri, Mar 29, 2013 at 3:14 PM, Dan Klco <dan.klco@sixdimensions.com
>>> wrote:
>> 
>>> Hello Everyone,****
>>> 
>>> ****
>>> 
>>> A colleague (Michael Kelleher) and I have built an extension we 
>>> would be interested in incorporating into Sling, as a contributed module.
>>> ****
>>> 
>>> ****
>>> 
>>> A short synopsis of this is, it functions as a far simpler, 
>>> read-only ORM for Sling.  It allows a developer to define an 
>>> Interface, and with the use of Annotations, and a Service, create an 
>>> instance backed by
>>> resource(s) within JCR.  The mapping of method names to JCR 
>>> properties is configured with annotations and interpreted by the 
>>> Java Proxy InvocationHandler to map back to Sling Resources and 
>>> properties.****
>>> 
>>> ****
>>> 
>>> Here's an example usage of the Sling Dynamic Proxy:****
>>> 
>>> ****
>>> 
>>> public interface Page extends ISlingProxy {****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the property jcr:created****
>>> 
>>>                */****
>>> 
>>>                @SlingProperty(name="jcr:created")****
>>> 
>>>                public Date getCreationDate();****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the property jcr:description at the sub path 
>>> jcr:content, the path is not required and can be absolute****
>>> 
>>>                */****
>>> 
>>>                @SlingProperty(name="jcr:description",
>>> path="jcr:content")
>>> ****
>>> 
>>>                public String getDescription();****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the property jcr:title at the sub path 
>>> jcr:content, the path is not required and can be absolute****
>>> 
>>>                */****
>>> 
>>>                @SlingProperty(name="jcr:title",
>>> path="jcr:content")****
>>> 
>>>                public String getTitle();****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the content resource, this could also return a 
>>> class which can be adapted from a resource or another proxy
>>> instance.****
>>> 
>>>                */****
>>> 
>>>                @SlingReference(path="jcr:content")****
>>> 
>>>                public Resource getContentResource();****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the children of the current resource, the 
>>> return type should match the return type in the generic of the 
>>> return
>>> Iterator.**
>>> **
>>> 
>>>                */****
>>> 
>>>                @SlingChildren(returnType=Resource.class, 
>>> path="")****
>>> 
>>>                public Iterator<Resource> getChildren();****
>>> 
>>> }****
>>> 
>>> ****
>>> 
>>> You could then retrieve an instance of the proxy as such:****
>>> 
>>> ****
>>> 
>>> Resource resource;****
>>> 
>>> ISlingProxyService slingProxyService;****
>>> 
>>> {...}****
>>> 
>>> Page page = slingProxyService.getProxy(resource, Page.class);****
>>> 
>>> ****
>>> 
>>> You can check out the code, including some basic tests on 
>>> GitHub:****
>>> 
>>> https://github.com/sixdimensions/sling-proxy****
>>> 
>>> ****
>>> 
>>> We both hope this project will be of interest to the Sling 
>>> developers and the Sling community.****
>>> 
>>> ****
>>> 
>>> Thanks,****
>>> 
>>> ** **
>>> 
>>> Dan Klco****
>>> 
>>> Senior Staff Engineer, Adobe WEM / Day CQ5****
>>> 
>>> San Ramon, CA / Dayton, OH****
>>> 
>>> ** **
>>> 
>>> [image: Description: Description: Description:
>>> cid:image003.gif@01CCF856.90108760]
>>> <http://www.sixdimensions.com/>****
>>> 
>>> Cell (937) 231-3050****
>>> 
>>> Office (937) 343-1326****
>>> 
>>> Fax (877) 510-5082****
>>> 
>>> LinkedIn <http://www.linkedin.com/in/klcodanr> | 
>>> @KlcoDanR<https://twitter.com/klcodanr>
>>> ****
>>> 
>>> ** **
>>> 
>>> *People. Deliver. Progress.*
>>> 
>>> ** **
>>> 
>> 
>> -----
>> No virus found in this message.
>> Checked by AVG - www.avg.com
>> Version: 2013.0.2904 / Virus Database: 2641/6211 - Release Date: 
>> 03/28/13
>> 
>> 


--
Felix Meschberger | Principal Scientist | Adobe









-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.3267 / Virus Database: 3161/6217 - Release Date: 03/31/13


Re: Sling Dynamic Proxy

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

Am 29.03.2013 um 21:18 schrieb Justin Edelson:

> Fixing/changing AdapterManager shouldn't be out of the question :)

Absolutely: How about a special adaptable and adapter class name of "*" which just means "any" ?

Regards
Felix

> 
> 
> 
> 
> On Fri, Mar 29, 2013 at 4:04 PM, Dan Klco <da...@sixdimensions.com>wrote:
> 
>> Justin,
>> 
>> I total agree, however I didn't see a way to inject adaptables into the
>> Sling Adapter Manager without knowing the exact class to be adapted ahead
>> of time.  I would imagine there would be a way to change this, but I can't
>> see one which would not require changing the Sling Adapter Manager.
>> 
>> If we could add a hook where you could specify an AdapterFactory to handle
>> requests for a subclass of a particular class, assuming the exact class is
>> not matched then we should be able to support adapting to proxy instances
>> without further code for implementers.
>> 
>> At the moment, there is an abstract class included in the Sling Proxy
>> project which will make it easier for implementers to implement an
>> AdapterFactory for their interfaces.
>> 
>> Thanks for the feedback and please let me know if I missed something,
>> 
>> -Dan
>> 
>> -----Original Message-----
>> From: justinedelson@gmail.com [mailto:justinedelson@gmail.com] On Behalf
>> Of Justin Edelson
>> Sent: Friday, March 29, 2013 3:36 PM
>> To: dev@sling.apache.org
>> Subject: Re: Sling Dynamic Proxy
>> 
>> Hi Dan,
>> This looks very interesting, but I'm curious why this code:
>> 
>> ISlingProxyService slingProxyService;****
>> 
>> {...}****
>> 
>> Page page = slingProxyService.getProxy(resource, Page.class);
>> 
>> Is not just
>> 
>> Page page = resource.adaptTo(Page.class);
>> 
>> 
>> Regards,
>> 
>> Justin
>> 
>> 
>> On Fri, Mar 29, 2013 at 3:14 PM, Dan Klco <dan.klco@sixdimensions.com
>>> wrote:
>> 
>>> Hello Everyone,****
>>> 
>>> ****
>>> 
>>> A colleague (Michael Kelleher) and I have built an extension we would
>>> be interested in incorporating into Sling, as a contributed module.
>>> ****
>>> 
>>> ****
>>> 
>>> A short synopsis of this is, it functions as a far simpler, read-only
>>> ORM for Sling.  It allows a developer to define an Interface, and with
>>> the use of Annotations, and a Service, create an instance backed by
>>> resource(s) within JCR.  The mapping of method names to JCR properties
>>> is configured with annotations and interpreted by the Java Proxy
>>> InvocationHandler to map back to Sling Resources and properties.****
>>> 
>>> ****
>>> 
>>> Here's an example usage of the Sling Dynamic Proxy:****
>>> 
>>> ****
>>> 
>>> public interface Page extends ISlingProxy {****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the property jcr:created****
>>> 
>>>                */****
>>> 
>>>                @SlingProperty(name="jcr:created")****
>>> 
>>>                public Date getCreationDate();****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the property jcr:description at the sub path
>>> jcr:content, the path is not required and can be absolute****
>>> 
>>>                */****
>>> 
>>>                @SlingProperty(name="jcr:description",
>>> path="jcr:content")
>>> ****
>>> 
>>>                public String getDescription();****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the property jcr:title at the sub path
>>> jcr:content, the path is not required and can be absolute****
>>> 
>>>                */****
>>> 
>>>                @SlingProperty(name="jcr:title",
>>> path="jcr:content")****
>>> 
>>>                public String getTitle();****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the content resource, this could also return a
>>> class which can be adapted from a resource or another proxy
>>> instance.****
>>> 
>>>                */****
>>> 
>>>                @SlingReference(path="jcr:content")****
>>> 
>>>                public Resource getContentResource();****
>>> 
>>> ****
>>> 
>>>                /******
>>> 
>>>                * Gets the children of the current resource, the
>>> return type should match the return type in the generic of the return
>>> Iterator.**
>>> **
>>> 
>>>                */****
>>> 
>>>                @SlingChildren(returnType=Resource.class, path="")****
>>> 
>>>                public Iterator<Resource> getChildren();****
>>> 
>>> }****
>>> 
>>> ****
>>> 
>>> You could then retrieve an instance of the proxy as such:****
>>> 
>>> ****
>>> 
>>> Resource resource;****
>>> 
>>> ISlingProxyService slingProxyService;****
>>> 
>>> {...}****
>>> 
>>> Page page = slingProxyService.getProxy(resource, Page.class);****
>>> 
>>> ****
>>> 
>>> You can check out the code, including some basic tests on GitHub:****
>>> 
>>> https://github.com/sixdimensions/sling-proxy****
>>> 
>>> ****
>>> 
>>> We both hope this project will be of interest to the Sling developers
>>> and the Sling community.****
>>> 
>>> ****
>>> 
>>> Thanks,****
>>> 
>>> ** **
>>> 
>>> Dan Klco****
>>> 
>>> Senior Staff Engineer, Adobe WEM / Day CQ5****
>>> 
>>> San Ramon, CA / Dayton, OH****
>>> 
>>> ** **
>>> 
>>> [image: Description: Description: Description:
>>> cid:image003.gif@01CCF856.90108760]
>>> <http://www.sixdimensions.com/>****
>>> 
>>> Cell (937) 231-3050****
>>> 
>>> Office (937) 343-1326****
>>> 
>>> Fax (877) 510-5082****
>>> 
>>> LinkedIn <http://www.linkedin.com/in/klcodanr> |
>>> @KlcoDanR<https://twitter.com/klcodanr>
>>> ****
>>> 
>>> ** **
>>> 
>>> *People. Deliver. Progress.*
>>> 
>>> ** **
>>> 
>> 
>> -----
>> No virus found in this message.
>> Checked by AVG - www.avg.com
>> Version: 2013.0.2904 / Virus Database: 2641/6211 - Release Date: 03/28/13
>> 
>> 


--
Felix Meschberger | Principal Scientist | Adobe








Re: Sling Dynamic Proxy

Posted by Justin Edelson <ju...@justinedelson.com>.
Fixing/changing AdapterManager shouldn't be out of the question :)




On Fri, Mar 29, 2013 at 4:04 PM, Dan Klco <da...@sixdimensions.com>wrote:

> Justin,
>
> I total agree, however I didn't see a way to inject adaptables into the
> Sling Adapter Manager without knowing the exact class to be adapted ahead
> of time.  I would imagine there would be a way to change this, but I can't
> see one which would not require changing the Sling Adapter Manager.
>
> If we could add a hook where you could specify an AdapterFactory to handle
> requests for a subclass of a particular class, assuming the exact class is
> not matched then we should be able to support adapting to proxy instances
> without further code for implementers.
>
>  At the moment, there is an abstract class included in the Sling Proxy
> project which will make it easier for implementers to implement an
> AdapterFactory for their interfaces.
>
> Thanks for the feedback and please let me know if I missed something,
>
> -Dan
>
> -----Original Message-----
> From: justinedelson@gmail.com [mailto:justinedelson@gmail.com] On Behalf
> Of Justin Edelson
> Sent: Friday, March 29, 2013 3:36 PM
> To: dev@sling.apache.org
> Subject: Re: Sling Dynamic Proxy
>
> Hi Dan,
> This looks very interesting, but I'm curious why this code:
>
> ISlingProxyService slingProxyService;****
>
> {...}****
>
> Page page = slingProxyService.getProxy(resource, Page.class);
>
> Is not just
>
> Page page = resource.adaptTo(Page.class);
>
>
> Regards,
>
> Justin
>
>
> On Fri, Mar 29, 2013 at 3:14 PM, Dan Klco <dan.klco@sixdimensions.com
> >wrote:
>
> >  Hello Everyone,****
> >
> >  ****
> >
> > A colleague (Michael Kelleher) and I have built an extension we would
> > be interested in incorporating into Sling, as a contributed module.
> > ****
> >
> >  ****
> >
> > A short synopsis of this is, it functions as a far simpler, read-only
> > ORM for Sling.  It allows a developer to define an Interface, and with
> > the use of Annotations, and a Service, create an instance backed by
> > resource(s) within JCR.  The mapping of method names to JCR properties
> > is configured with annotations and interpreted by the Java Proxy
> > InvocationHandler to map back to Sling Resources and properties.****
> >
> >  ****
> >
> > Here's an example usage of the Sling Dynamic Proxy:****
> >
> >  ****
> >
> > public interface Page extends ISlingProxy {****
> >
> >  ****
> >
> >                 /******
> >
> >                 * Gets the property jcr:created****
> >
> >                 */****
> >
> >                 @SlingProperty(name="jcr:created")****
> >
> >                 public Date getCreationDate();****
> >
> >  ****
> >
> >                 /******
> >
> >                 * Gets the property jcr:description at the sub path
> > jcr:content, the path is not required and can be absolute****
> >
> >                 */****
> >
> >                 @SlingProperty(name="jcr:description",
> > path="jcr:content")
> > ****
> >
> >                 public String getDescription();****
> >
> >  ****
> >
> >                 /******
> >
> >                 * Gets the property jcr:title at the sub path
> > jcr:content, the path is not required and can be absolute****
> >
> >                 */****
> >
> >                 @SlingProperty(name="jcr:title",
> > path="jcr:content")****
> >
> >                 public String getTitle();****
> >
> >  ****
> >
> >                 /******
> >
> >                 * Gets the content resource, this could also return a
> > class which can be adapted from a resource or another proxy
> > instance.****
> >
> >                 */****
> >
> >                 @SlingReference(path="jcr:content")****
> >
> >                 public Resource getContentResource();****
> >
> >  ****
> >
> >                 /******
> >
> >                 * Gets the children of the current resource, the
> > return type should match the return type in the generic of the return
> > Iterator.**
> > **
> >
> >                 */****
> >
> >                 @SlingChildren(returnType=Resource.class, path="")****
> >
> >                 public Iterator<Resource> getChildren();****
> >
> > }****
> >
> >  ****
> >
> > You could then retrieve an instance of the proxy as such:****
> >
> >  ****
> >
> > Resource resource;****
> >
> > ISlingProxyService slingProxyService;****
> >
> > {...}****
> >
> > Page page = slingProxyService.getProxy(resource, Page.class);****
> >
> >  ****
> >
> > You can check out the code, including some basic tests on GitHub:****
> >
> > https://github.com/sixdimensions/sling-proxy****
> >
> >  ****
> >
> > We both hope this project will be of interest to the Sling developers
> > and the Sling community.****
> >
> >  ****
> >
> > Thanks,****
> >
> > ** **
> >
> > Dan Klco****
> >
> > Senior Staff Engineer, Adobe WEM / Day CQ5****
> >
> > San Ramon, CA / Dayton, OH****
> >
> > ** **
> >
> > [image: Description: Description: Description:
> > cid:image003.gif@01CCF856.90108760]
> > <http://www.sixdimensions.com/>****
> >
> > Cell (937) 231-3050****
> >
> > Office (937) 343-1326****
> >
> > Fax (877) 510-5082****
> >
> > LinkedIn <http://www.linkedin.com/in/klcodanr> |
> > @KlcoDanR<https://twitter.com/klcodanr>
> > ****
> >
> > ** **
> >
> > *People. Deliver. Progress.*
> >
> > ** **
> >
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2013.0.2904 / Virus Database: 2641/6211 - Release Date: 03/28/13
>
>

RE: Sling Dynamic Proxy

Posted by Dan Klco <da...@sixdimensions.com>.
Justin,

I total agree, however I didn't see a way to inject adaptables into the Sling Adapter Manager without knowing the exact class to be adapted ahead of time.  I would imagine there would be a way to change this, but I can't see one which would not require changing the Sling Adapter Manager.  

If we could add a hook where you could specify an AdapterFactory to handle requests for a subclass of a particular class, assuming the exact class is not matched then we should be able to support adapting to proxy instances without further code for implementers.

 At the moment, there is an abstract class included in the Sling Proxy project which will make it easier for implementers to implement an AdapterFactory for their interfaces.

Thanks for the feedback and please let me know if I missed something,

-Dan

-----Original Message-----
From: justinedelson@gmail.com [mailto:justinedelson@gmail.com] On Behalf Of Justin Edelson
Sent: Friday, March 29, 2013 3:36 PM
To: dev@sling.apache.org
Subject: Re: Sling Dynamic Proxy

Hi Dan,
This looks very interesting, but I'm curious why this code:

ISlingProxyService slingProxyService;****

{...}****

Page page = slingProxyService.getProxy(resource, Page.class);

Is not just

Page page = resource.adaptTo(Page.class);


Regards,

Justin


On Fri, Mar 29, 2013 at 3:14 PM, Dan Klco <da...@sixdimensions.com>wrote:

>  Hello Everyone,****
>
>  ****
>
> A colleague (Michael Kelleher) and I have built an extension we would 
> be interested in incorporating into Sling, as a contributed module. 
> ****
>
>  ****
>
> A short synopsis of this is, it functions as a far simpler, read-only 
> ORM for Sling.  It allows a developer to define an Interface, and with 
> the use of Annotations, and a Service, create an instance backed by 
> resource(s) within JCR.  The mapping of method names to JCR properties 
> is configured with annotations and interpreted by the Java Proxy 
> InvocationHandler to map back to Sling Resources and properties.****
>
>  ****
>
> Here's an example usage of the Sling Dynamic Proxy:****
>
>  ****
>
> public interface Page extends ISlingProxy {****
>
>  ****
>
>                 /******
>
>                 * Gets the property jcr:created****
>
>                 */****
>
>                 @SlingProperty(name="jcr:created")****
>
>                 public Date getCreationDate();****
>
>  ****
>
>                 /******
>
>                 * Gets the property jcr:description at the sub path 
> jcr:content, the path is not required and can be absolute****
>
>                 */****
>
>                 @SlingProperty(name="jcr:description", 
> path="jcr:content")
> ****
>
>                 public String getDescription();****
>
>  ****
>
>                 /******
>
>                 * Gets the property jcr:title at the sub path 
> jcr:content, the path is not required and can be absolute****
>
>                 */****
>
>                 @SlingProperty(name="jcr:title", 
> path="jcr:content")****
>
>                 public String getTitle();****
>
>  ****
>
>                 /******
>
>                 * Gets the content resource, this could also return a 
> class which can be adapted from a resource or another proxy 
> instance.****
>
>                 */****
>
>                 @SlingReference(path="jcr:content")****
>
>                 public Resource getContentResource();****
>
>  ****
>
>                 /******
>
>                 * Gets the children of the current resource, the 
> return type should match the return type in the generic of the return 
> Iterator.**
> **
>
>                 */****
>
>                 @SlingChildren(returnType=Resource.class, path="")****
>
>                 public Iterator<Resource> getChildren();****
>
> }****
>
>  ****
>
> You could then retrieve an instance of the proxy as such:****
>
>  ****
>
> Resource resource;****
>
> ISlingProxyService slingProxyService;****
>
> {...}****
>
> Page page = slingProxyService.getProxy(resource, Page.class);****
>
>  ****
>
> You can check out the code, including some basic tests on GitHub:****
>
> https://github.com/sixdimensions/sling-proxy****
>
>  ****
>
> We both hope this project will be of interest to the Sling developers 
> and the Sling community.****
>
>  ****
>
> Thanks,****
>
> ** **
>
> Dan Klco****
>
> Senior Staff Engineer, Adobe WEM / Day CQ5****
>
> San Ramon, CA / Dayton, OH****
>
> ** **
>
> [image: Description: Description: Description:
> cid:image003.gif@01CCF856.90108760] 
> <http://www.sixdimensions.com/>****
>
> Cell (937) 231-3050****
>
> Office (937) 343-1326****
>
> Fax (877) 510-5082****
>
> LinkedIn <http://www.linkedin.com/in/klcodanr> | 
> @KlcoDanR<https://twitter.com/klcodanr>
> ****
>
> ** **
>
> *People. Deliver. Progress.*
>
> ** **
>

-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.2904 / Virus Database: 2641/6211 - Release Date: 03/28/13


Re: Sling Dynamic Proxy

Posted by Justin Edelson <ju...@justinedelson.com>.
Hi Dan,
This looks very interesting, but I'm curious why this code:

ISlingProxyService slingProxyService;****

{…}****

Page page = slingProxyService.getProxy(resource, Page.class);

Is not just

Page page = resource.adaptTo(Page.class);


Regards,

Justin


On Fri, Mar 29, 2013 at 3:14 PM, Dan Klco <da...@sixdimensions.com>wrote:

>  Hello Everyone,****
>
>  ****
>
> A colleague (Michael Kelleher) and I have built an extension we would be
> interested in incorporating into Sling, as a contributed module. ****
>
>  ****
>
> A short synopsis of this is, it functions as a far simpler, read-only ORM
> for Sling.  It allows a developer to define an Interface, and with the use
> of Annotations, and a Service, create an instance backed by resource(s)
> within JCR.  The mapping of method names to JCR properties is configured
> with annotations and interpreted by the Java Proxy InvocationHandler to map
> back to Sling Resources and properties.****
>
>  ****
>
> Here’s an example usage of the Sling Dynamic Proxy:****
>
>  ****
>
> public interface Page extends ISlingProxy {****
>
>  ****
>
>                 /******
>
>                 * Gets the property jcr:created****
>
>                 */****
>
>                 @SlingProperty(name=”jcr:created”)****
>
>                 public Date getCreationDate();****
>
>  ****
>
>                 /******
>
>                 * Gets the property jcr:description at the sub path
> jcr:content, the path is not required and can be absolute****
>
>                 */****
>
>                 @SlingProperty(name=”jcr:description”, path=”jcr:content”)
> ****
>
>                 public String getDescription();****
>
>  ****
>
>                 /******
>
>                 * Gets the property jcr:title at the sub path jcr:content,
> the path is not required and can be absolute****
>
>                 */****
>
>                 @SlingProperty(name=”jcr:title”, path=”jcr:content”)****
>
>                 public String getTitle();****
>
>  ****
>
>                 /******
>
>                 * Gets the content resource, this could also return a
> class which can be adapted from a resource or another proxy instance.****
>
>                 */****
>
>                 @SlingReference(path=”jcr:content”)****
>
>                 public Resource getContentResource();****
>
>  ****
>
>                 /******
>
>                 * Gets the children of the current resource, the return
> type should match the return type in the generic of the return Iterator.**
> **
>
>                 */****
>
>                 @SlingChildren(returnType=Resource.class, path=””)****
>
>                 public Iterator<Resource> getChildren();****
>
> }****
>
>  ****
>
> You could then retrieve an instance of the proxy as such:****
>
>  ****
>
> Resource resource;****
>
> ISlingProxyService slingProxyService;****
>
> {…}****
>
> Page page = slingProxyService.getProxy(resource, Page.class);****
>
>  ****
>
> You can check out the code, including some basic tests on GitHub:****
>
> https://github.com/sixdimensions/sling-proxy****
>
>  ****
>
> We both hope this project will be of interest to the Sling developers and
> the Sling community.****
>
>  ****
>
> Thanks,****
>
> ** **
>
> Dan Klco****
>
> Senior Staff Engineer, Adobe WEM / Day CQ5****
>
> San Ramon, CA / Dayton, OH****
>
> ** **
>
> [image: Description: Description: Description:
> cid:image003.gif@01CCF856.90108760] <http://www.sixdimensions.com/>****
>
> Cell (937) 231-3050****
>
> Office (937) 343-1326****
>
> Fax (877) 510-5082****
>
> LinkedIn <http://www.linkedin.com/in/klcodanr> | @KlcoDanR<https://twitter.com/klcodanr>
> ****
>
> ** **
>
> *People. Deliver. Progress.*
>
> ** **
>