commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Rall <...@finemaltcoding.com>
Subject Re: [Betwixt] Using NameMapper
Date Wed, 13 Aug 2003 18:53:26 GMT
Daniel Rall <dlr@finemaltcoding.com> writes:
...
> is it possible to use HyphenatedNameMapper's
> mapTypeToElementName(String typeName) (or something of the sort) to
> transform ScarabIssues.class into the String "scarab-issues" (to
> obviate the hard-coding of magic strings)?

To answer my own quesiton, it is possible:

http://scarab.tigris.org/source/browse/scarab/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java.diff?r1=1.25&r2=1.26

You'll notice that I had to add a local mapTypeToElementName(Class,
NameMapper) method which strips the package name off of the class name
before handing off to HyphenatedNameMapper for resolution to a XML
element.  This same code must be present somewhere within Betwixt, and
I would prefer to take advantage of it rather than re-implementing it
in Scarab's ImportIssues class.  It may be only a few trivial lines,
but I feel that my inclusion of it infringes on ideal encapsulation
(even with my update of Betwixt's JavaDoc).  A possible improvement
would be to loosen the API of NameMapper to accept Object rather than
String, then use "instanceof Class" inside of HyphenatedNameMapper to
detemine whether a package name should be stripped off of the input.
This would shift all mapping responsibility out of elsewhere in
Betwixt (called from somewhere in BeanReader, I assume) down into
NameMapper implementations.  Perhaps not what is wanted, of course --
just a suggestion.

 - Dan

Mime
View raw message