Hi Justin Wow ! I really like this !
Still, as always, I have some comments: * I share Dan's concerns with respect to the @Inject annotation: Isn't that too generic ? (Yes, I am the strongly typed guy, so I love to know things upfront in a fail early style) * I see support for interfaces is implemented as proxies which are loaded through the interface type's class loader. But the InvocationHandler is created for each invocation of adaptTo. Would it make sense to cache the generated proxy classes and just create new instances of them on each invocation ? (well this maybe already falls into the optimization category) * I assum the value to @Filter is supposed to be a valid OSGi Filter argument. Should thus the respective sample in the wiki be fixed by having the string value be surrounded by parentheses ? Also, the existence of the @Filter annotation would stipulate the respective @Incject annotation to only be considered by the service injector. * I would think the api bundle and package should rather be called annotations, right ? * The annotations are currently RUNTIME scoped and the packaged classes are eagerly loaded on bundle start time (you might want to leverage the BundleTracker for easier tracking of bundles). This sounds like a performance problem. How about doing it like Declarative Services and tooling generate a descriptor which will be loaded on bundle startup and the respective classes loaded on-demand ? (OTOH this runtime analysis copes better with Java extensions) * YAMF model classes must be exported for them to be usable in code. Maybe that is just how this kind of thing works but we should be aware of that and that exporting these classes in fact defines API. This would fall into the Model class requirements category: Must be exported and is considered API, classes must have public default constructore, etc. Thanks Felix Am 19.12.2013 um 18:07 schrieb Justin Edelson <[email protected]>: > 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
