Hi,
I've published a page to the wiki about a concept I've been working on
to consolidate the various appproaches I have seen in the wild to
model object creation. I'm calling this YAMF for now, although ideally
we'll just call it Sling Models :)

Without repeating the whole contents of the wiki page, at a high
level, this is a purely annotation driven approach supporting both
classes and interfaces. Your model class simply needs to declare from
which other classes it can be adapted:

@Model(adaptables=Resource.class)

And then annotate the fields (for classes) and methods (for
interfaces) which need injection:

@Inject
private String propertyName;

You can inject properties, OSGi services, request attributes, and
entries from SlingBindings.

New injector types can be created through an SPI.

Additional annotations are supported for special cases:

@Optional - mark a field/method as optional.
@Filter - provide a filter (i.e. for OSGi services)
@Named - specify a name (other than the default field/method name) to
use for the inejction lookup.

More detail can be found here:
https://cwiki.apache.org/confluence/display/SLING/YAMF+-+Yet+Another+Model+Factory

The working code is up in my whiteboard:
https://svn.apache.org/repos/asf/sling/whiteboard/justin/yamf/

Look forward to your feedback.

Regards,
Justin

Reply via email to