Steven,
It's probably not the best solution, but you can use the getFieldDescriptor()
method of AbstractFieldHandler (GeneralizedFieldHandler) to find out about the
which field is being processed and you can do the proper padding as necessary.
--Keith
[EMAIL PROTECTED] wrote:
Hi folks,
I'm trying to figure out how to do a custom FieldHandler that can have
some parameters.
In the on-going saga of my project, I have to apply some formatting
rules to some of the outgoing XML. Specifically, for certain steps I need
to have fixed-width content in the elements, and do one of the following:
truncate to length
pad right to length with 0 characters
pad right to length with spaces
pad left to length with 0 characters
pad left to length with spaces
I also have to do a FieldHandler to wrap all of the elements in CDATA[]
tags. This lead me to wonder if it makes sense to use a FieldHandler for
my output formatting as well. This lead me to actually read the docs at:
http://www.castor.org/xml-fieldhandlers.html
It looks like a custom FieldHandler is a good idea. The problem is
that I have to specify the field width and maybe a few other details,
otherwise I end up with classes like:
PadRight20SpacesFieldHandler.java
PadRight18SpacesFieldHandler.java
PadRight18zerosFieldHandler.java
And that is just silly :-).
What's a good way to get the parameter in?
If Castor doesn't have any support for something like this now, one
thought is add some sort of custom formatting attribute on
<field>, or possibly an element inside <field>. Or maybe use something
like Java Message Format
(http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html)
...though I'm not certain it will support the sort of formatting I need.
However, having a single string parameter that can use whatever formatting
syntax the custom FieldHandler desires (java MessageFormat, sprintf, etc)
might be a good middle ground.
Steven J. Owens
[EMAIL PROTECTED]
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------