These types of solution would 'fit' in the current framework in the sense of "wedge-in I this feature" but I do think that this causes the purpose of the builder and style classes to become muddled.
Perhaps the more OO manner of dealing with this issue would be to create a ToStringBuilder subclass used for reflection purposes (ReflectionToStringBuilder?). After all, we are talking about two completely different ways of dealing with the problem statement "Give me a toString()". It is in such a class that I would see processing oriented overrides possible. The class could then be made more configurable than what we can do today with the static methods on ToStringBuilder. Gary -----Original Message----- From: Stephen Colebourne [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 28, 2003 14:16 To: Jakarta Commons Users List Subject: Re: [lang] ToStringBuilder.reflectionToString() problem Adding a method to ToStringStyle like: boolean includeReflectionField(Field f) would allow the style to control the output. It ought to work, but I haven't checked it. Maybe the same approach could be adapted to do the 'only output a field once' processing (avoiding infinite recursion). Stephen ----- Original Message ----- From: "Gary Gregory" <[EMAIL PROTECTED]> To: "'Jakarta Commons Users List'" <[EMAIL PROTECTED]> Sent: Wednesday, May 28, 2003 12:11 AM Subject: RE: ToStringBuilder.reflectionToString() problem > Right, this is a good idea that I have considered in the past. The way we > specify whether or not to output transients is a bit bogus IMHO, there is > room in all of this for an object that would let you tweak all of this > behavior. I'll think about this tonight and propose something if I can come > up with something not too nasty. > > Gary > > -----Original Message----- > From: Tolley Shorn [mailto:[EMAIL PROTECTED] > Sent: Tuesday, May 27, 2003 16:07 > To: Jakarta Commons Users List > Subject: RE: ToStringBuilder.reflectionToString() problem > > > It's workable, I did it last night in order to keep going. It just means I > don't get (almost) free toString()s anymore. > > What about making the worker methods non-static and overridable instead? > Then I could subclass ToStringBuilder to build in the knowledge. > Or factoring out a worker class that can be plugged in similarly to > ToStringStyle? > Or some kind of extension of the mechanism that specifies whether or not to > use transients? > > Cheers, > Shorn. > > > -----Original Message----- > > From: Gary Gregory [mailto:[EMAIL PROTECTED] > > Sent: Wednesday, 28 May 2003 2:37 AM > > To: 'Jakarta Commons Users List' > > Subject: RE: ToStringBuilder.reflectionToString() problem > > > > > > Hello, > > > > The quick answer to your question (without adding features to > > ToStringBuilder) is to use the non-reflection APIs. For example: > > > > public String toString() { > > return new ToStringBuilder(this). > > append("name", name). > > append("age", age). > > append("smoker", smoker). > > toString(); > > } > > > > If this is not acceptable, we can discuss how to make your > > feature request > > fit in the ToStringBuilder framework. I am not sure the > > proposed solution > > fits: (1) It breaks the model-view type of separation b/w the > > builder and > > the style class and (2) it requires the access to be set on a > > per field > > basis, which, the current impl is not factored to do. > > > > So, in a nutshell, is the above example workable for you (or not)? > > Obviously, using the reflection method is less code. > > > > Gary > > > > -----Original Message----- > > From: Tolley Shorn [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, May 27, 2003 02:51 > > To: [EMAIL PROTECTED] > > Subject: ToStringBuilder.reflectionToString() problem > > > > Hi folks, > > > > I've got a bit of a problem with the ToStringBuilder's > > reflectionToString > > method. > > I'd like to suggest a very small improvement (I think) to the > > ToStringBuilder interface. > > > > We're using Hibernate to provide the persistence of our domain model. > > I would like to use ToStringBuilder to provide accurate > > toString() methods > > for the classes in our domain model. > > Unfortunately, in some circumstances Hibernate uses an OS library call > > CgLib. > > CgLib is a pretty nifty little library that dynamically constructs JVM > > bytecode. > > Hibernate uses CgLib to provide transparent proxies. > > > > Unfortunately, becuase of the structure of our app (not > > really Hibernate or > > CgLib's fault), the reflectionToString() method will cause an > > exception > > because it will try to access the CgLib class outside of an > > appropriate > > scope (becuase we call toString() outside of the appropriate scope). > > > > Basically, I would like to be able to customize the ToStringBuilder to > > decide on a per-attribute basis whether or not to access a > > given field using > > reflection. > > > > What I'd like the reflectionToString method to do is to implement the > > template design pattern by delegating the actual access and > > formatting of > > the individual attribute to a method on the ToStringStyle. > > > > The basic ToStringStyle could just delegate this decision > > straight back to > > the ordinary ToStringBuiler, so for ordinary use the > > interface wouldn't > > change at all. > > With this functionality you could have all kinds of fun with > > doing special > > things for certain attribute names or types. > > > > What this change would allow me to do is something like this: > > > > class BaseEntity{ > > public toString(){ > > return ToStringBuilder.reflectionToString(this, new > > CgLibAwareToStringStyle()); > > } > > } > > > > CgLibAwareToStringStyle extends StandardToStringStyle { > > public String appendField(ToStringBuilder builder, Field f){ > > if( > > f.getType().isAssignableFrom(CgLibMarkerInterface.class) > > ){ > > // do a special CgLib appropriate thing > > that won't > > make my app barf :) > > } > > else { > > builder.append(f); > > } > > } > > } > > > > Maybe I'm missing a better way of doing this with the current > > ToStringBuilder interface? > > At the moment it appears I'll have to duplicate the > > ToStringBuilder in our > > app and extend it so I can keep going (or forfeit > > ToStringBuiler's labour > > saving functionality). > > > > What do you folks think? > > > > Cheers, > > Shorn. > > > > > > ************************************************************** > > ********** > > The information in this e-mail together with any attachments is > > intended only for the person or entity to which it is addressed > > and may contain confidential and/or privileged material. > > > > Any form of review, disclosure, modification, distribution > > and/or publication of this e-mail message is prohibited. > > > > If you have received this message in error, you are asked to > > inform the sender as quickly as possible and delete this message > > and any copies of this message from your computer and/or your > > computer system network. > > ************************************************************** > > ********** > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > ************************************************************************ > The information in this e-mail together with any attachments is > intended only for the person or entity to which it is addressed > and may contain confidential and/or privileged material. > > Any form of review, disclosure, modification, distribution > and/or publication of this e-mail message is prohibited. > > If you have received this message in error, you are asked to > inform the sender as quickly as possible and delete this message > and any copies of this message from your computer and/or your > computer system network. > ************************************************************************ > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
