Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 12576 invoked from network); 22 Mar 2004 19:30:00 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 22 Mar 2004 19:30:00 -0000 Received: (qmail 68871 invoked by uid 500); 22 Mar 2004 19:29:46 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 68839 invoked by uid 500); 22 Mar 2004 19:29:46 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 68825 invoked from network); 22 Mar 2004 19:29:46 -0000 Received: from unknown (HELO mars.lunarpages.com) (64.235.234.30) by daedalus.apache.org with SMTP; 22 Mar 2004 19:29:46 -0000 Received: from [156.80.176.132] (helo=msgarlata) by mars.lunarpages.com with asmtp (Exim 4.24) id 1B5V7O-0006XJ-CB for commons-dev@jakarta.apache.org; Mon, 22 Mar 2004 11:29:50 -0800 Message-ID: <020301c41044$0b6140c0$84b0509c@radpbi.bah.com> From: "Matthew Sgarlata" To: "Jakarta Commons Developers List" References: <9CFD7198D93C6441932CA80CA30D266108BA425A@gsnmp08es.ny.fw.gs.com> Subject: Re: [convert] Use cases not currently covered Date: Mon, 22 Mar 2004 14:29:47 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - mars.lunarpages.com X-AntiAbuse: Original Domain - jakarta.apache.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - crystalcognition.com X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I like all those suggestions a lot. Your use cases are very convincing (probably b/c they're from a real live app!) What do you think of the ConversionFactory.getMatchPercent method? This seems inappropriate for an interface to me. This seems like it belongs in an implementation of ConversionFactory and that the ConversionFactory interface should be simplified. I think this relates to point #2 of yours below... Matt ----- Original Message ----- From: "Legostaev, Andrei" To: Sent: Monday, March 22, 2004 1:55 PM Subject: [convert] Use cases not currently covered > > Greetings All > > I have been corresponding with Stephen regarding some design decisions > being made in [convert]. I'd like to make a couple of pugnacious > declarations and hope that ensuing discussion generates good ideas and > consensus. > > > I'll first state my beliefs, then I'll try to justify them belief at > great length :-) > > > 1) The actual conversion logic should be implemented in small chunks, > inside the most primitive, bare code-container, interface : > > public interface Conversion { > public Object convert(Object value) throws Exception; > } > > One implementation should do one simple, well-specified conversion, > e.g. String to Integer. The implementation should be free to make > documented assumptions about its input and free to throw any exception > if an assumed precondition is broken. > > > 2) There should be multiple manager classes to implementing distinct > policies for choosing a Conversion. ConversionRegistry will be one > such manager. Other managers may build transitive Conversion chains, > handle inheritance, provide accessors for primitives, etc. Clients > will work with managers, never Conversions themselves. Managers will > wrap exceptions thrown by Conversions in ConversionExceptions. There > is no one interface that could sum up all possible managers. > > > I recently implemented a framework similar to [convert], also inspired > by the limitations of BeanUtils. The framework evolved to support a > large (1.5m lines) family of business applications. The result of the > painful evolution was what I described above. > > > For example, having the concepts of "from type" and "to type" near the > core of the framework proved unhelpful. > > > One use case where this broke down was this : > > Legacy business objects often use java.util.Date to represent any or all > of a) bare date b) bare time c) date-time. Therefore in flattening the > properties of such objects to text three different rules are applied for > the java.util.Date -> java.lang.String conversion. > > By eliminating the "from type"/"to type" concept from the core, this use > case can be handled cleanly. It requires a simple manager semantic that > associates a Conversion with a Method or property name. > > > Another use case forced the simplification of the Conversion interface : > > There are cases where a Conversion is highly customized or involves > non-public types. Being able to implement it as an anonymous class > is very important. > > registry.register(GUID.class, new Converter() { > protected Object convert(Object value) { > String string = value.toString(); > return new GUID(string.startsWith("0x") ? string.substring(2) : string); > } > }); > > This code snippet deals with a quirk of a minor legacy API that may or may > not add a "0x" prefix to hexadecimal values. If it were hard to implement > the rule in-line, clients would've opted to hack around the conversion > framework, sharply reducing its value. > > > I am currently negotiating with my employer to release the code to Jakarta. > Hopefully it will help generate some more ideas. > > Andrei > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org