I have just been skimming this thread, but I wonder if having the ability to use closures and/or higher-order functions might help to solve this problem more easy. Perhaps, a polygot solution using ScalaĆ
Jason On 2/9/12 2:24 PM, "Sergey Beryozkin" <[email protected]> wrote: >Hi Dave >On 09/02/12 17:53, hdave wrote: >> Sergey -- Just wanted to close the loop on this. >> >> Because I will want to perform schema validation (in the future) on my >> response payloads, it was necessary to add a collection of hyperlinks >>as a >> Java/JAX-B type to every class in my domain model. I could see no way >> around it. However, I judged this minor leakage of concerns to be far >> better than creating 100+ JAX-B adapters. >> >> Once I did this, all that was left was to insert the hyperlinks into the >> domain objects response representation(s) from within my resource >>classes. >> Knowing that I must, for performance reasons, send nested object graphs >>to >> the client, I needed to traverse the response object graph to insert >> hyperlinks. For this I used the visitor pattern. In this way, I >> concentrated all the logic about hypermedia into a single >>HypermediaVisitor >> class. All I have to do is invoke the visitor on the root object in the >> response graph before return the value from my resource service method. >> >> I thought about creating an annotation for this that would take the >>name of >> the hypermedia visitor, but I don't know exactly how to do this and am >> running short on time. I also thought about invoking the visitor using >>AOP, >> but I am wary of having too much magic. >> >> In any event, it works well and seems reasonably loosely coupled. I am >> hoping the brain-trust behind REST 2.0 will do a good job and get >>something >> out soon. > >Thanks for this update. I guess when the links are part of the domain >schema it is probably not worth for the runtime to attempt to facilitate >the creation of these data. > >However I'm interested to explore the idea of the runtime calling back >into custom visitors during the serialization process. >For example, please see option 2 & 3 for wrapping domain data such as >Book into Atom feed/entry transparently under the hood, and those custom >builders can be used to create the links: > >https://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+Data+Bindings# >JAX-RSDataBindings-Atom, > >for ex, > >http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/extensions/providers/src/m >ain/java/org/apache/cxf/jaxrs/ext/provider/atom/AbstractAtomElementBuilder >.java > >So may be if say JAXBElementProvider gets a Visitor registered then it >can create a custom writer and call back to the visitor and request to >return a list of links for a given element...or something similar... >May be we can come up with some idea after all :-) > >Thanks, Sergey >> >> Best, >> Dave >> >> -- >> View this message in context: >>http://cxf.547215.n5.nabble.com/Good-way-to-add-link-relations-to-REST-re >>sponses-tp5461580p5470228.html >> Sent from the cxf-user mailing list archive at Nabble.com. > > >-- >Sergey Beryozkin > >Talend Community Coders >http://coders.talend.com/ > >Blog: http://sberyozkin.blogspot.com ________________________________________________________________________ In order to protect our email recipients, Betfair Group use SkyScan from MessageLabs to scan all Incoming and Outgoing mail for viruses. ________________________________________________________________________
