From: Matt S. <Mat...@wh...> - 2007-11-16 16:53:12
|
Sorry for not getting back to you sooner; work has been very busy the past couple weeks! My idea for Morph from the beginning has been that it should offer a rich set of default reflectors and transformers and then make it easy for you to make a few tweaks to suit your particular use case (the 80/20 rule). If all the defaults work well for you, then the Morph abstract class works great. If the defaults aren't quite right, it's kind of a PITA to work with the SimpleDelegatingTransformer, SDR, etc. Basically I think Morph addresses the 80% well but falls short the other 20% of the time. To address the other 20%, I have been thinking about introducing a non-static version of the Morph class that is customizable. This is kind of like the difference between BeanUtils and BeanUtilsBean in Commons-BeanUtils. Instead of calling the class MorphBean I opted for the name MorphSystem, but I am open for other suggested names. Morph2 delegates to a particular, unchangeable MorphSystem and will perhaps someday Morph2 will replace the old Morph class. Here is an example of what I am talking about ContainerToPrettyTextConverter containerConverter = new ContainerToPrettyTextConverter(); containerConverter.setPrefix(null); containerConverter.setSuffix(null); DefaultToTextConverter toTextConverter = new DefaultToTextConverter(new Transformer[] { containerConverter }, true); BeanToPrettyTextConverter converter = new BeanToPrettyTextConverter(); converter.setToTextConverter(toTextConverter); converter.setSeparator("&"); converter.setPrefix(null); converter.setSuffix(null); This part of the syntax I am OK with: ContainerToPrettyTextConverter containerConverter = new ContainerToPrettyTextConverter(); containerConverter.setPrefix(null); containerConverter.setSuffix(null); BeanToPrettyTextConverter converter = new BeanToPrettyTextConverter(); converter.setSeparator("&"); converter.setPrefix(null); converter.setSuffix(null); This part I am not OK with: DefaultToTextConverter toTextConverter = new DefaultToTextConverter(new Transformer[] { containerConverter }, true); converter.setToTextConverter(toTextConverter); For the part I am not OK with, instead I would like to see: MorphSystem m = new MorphSystem(); m.setComponent("containerConverter", containerConverter); m.setComponent("toTextConverter", toTextConverter); The idea here is that the MorphSystem looks for all the containerConverter references in all the converters that are part of it and appropriately wires them up to point to the custom containerConverter the user specifies. I actually started on a class called MorphSystem years ago and then shelved it because I thought that I was basically duplicating the work you see in a dependency injection framework. So, instead of going this route I figured it should be possible to use Spring or some other DI framework for the same effect. Experience has shown me that for this use DI is cumbersome at best and painfully counterintuitive at worst. So, what do you think about all this? Matt S Matt Benson wrote: > So, tell me about this... :) > > -Matt B > > > ____________________________________________________________________________________ > Be a better sports nut! Let your teams follow you > with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > morph-developer mailing list > mor...@li... > https://lists.sourceforge.net/lists/listinfo/morph-developer > > |