|
From: Keith D. <kd...@cs...> - 2004-03-21 22:59:11
|
Ahile back I ran across this point Howard Lewis Ship made on the DebugInterceptor's handling of argument styling (particularly arrays): "You can see [below] the Debug interceptor catching the invocations of toString() as well as add(). It doesn't do a great job [rendering] arguments." Debug interceptor: count=2 invocation=[Invocation: method=[public abstract int springex.Adder.add(int,int)] args=[Ljava.lang.Object;@1b9240e] target is of class springex.impl.AdderImpl] I've since created some utility interfaces/classes that encapsulate string styling algorithms for any type of object (arrays, maps, classes, methods, invocations, entries, null, etc.) and placed them in the sandbox under sandbox/util. Internally the implementation leverages the visitor pattern to nicely encapsulate styling algorithms (specifically a form of visitor based on reflection.) The classes are: ObjectStyler (interface) - a generic interface - a single style(Object) method accepts an object, returns the styled string form. DefaultObjectStyler - styles an object according to Spring conventions. I don't know all the styling conventions, so feel free to polish this class if I styled a particular type of object incorrectly (or add new styled types.) There is also a class called ToStringBuilder (which uses a ToStringStyler, which delegates to an ObjectStyler for styling field values) to style toString() method output flexibly yet consistently and with less LoC. I got the ideas for this from jakarta-lang (though my implementation differs considerably). I also got the idea for combining visitor with reflection from Bob Lee. I think these would be a nice addition to the core.util module post 1.0. Keith |