Robert, using BeanDescriptor.getName() worked well, enabling me to
remove the custom parsing code from ImportIssues -- was that what you
had in mind? I didn't notice the new test case, and wrote this along
the way. Something I should check in?
Index: TestHyphenatedNameMapper.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestHyphenatedNameMapper.java,v
retrieving revision 1.5
diff -u -u -r1.5 TestHyphenatedNameMapper.java
--- TestHyphenatedNameMapper.java 30 Dec 2002 18:16:48 -0000 1.5
+++ TestHyphenatedNameMapper.java 15 Aug 2003 18:48:47 -0000
@@ -62,6 +62,7 @@
package org.apache.commons.betwixt.strategy;
+import java.beans.BeanDescriptor;
import java.util.ArrayList;
import junit.framework.Test;
@@ -93,6 +94,13 @@
assertEquals("foo-bar", result);
}
+ public void testLowerCaseViaBeanDescriptor() {
+ HyphenatedNameMapper mapper = new HyphenatedNameMapper(false, "_");
+ BeanDescriptor bd = new BeanDescriptor(getClass());
+ String result = mapper.mapTypeToElementName(bd.getName());
+ assertEquals("test_hyphenated_name_mapper", result);
+ }
+
public void testUpperCase() {
HyphenatedNameMapper mapper = new HyphenatedNameMapper(true, "_");
String result = mapper.mapTypeToElementName("FooBar");
robert burrell donkin <[EMAIL PROTECTED]> writes:
> hi daniel
>
> i've taken a look into this (and even added another test case to
> convince myself that i'm right). the BeanDescriptor name is passed to
> the name mapper to create the element. i'm pretty sure that this
> should be the class name without the package. (it is on my machine at
> least).
>
>
> it is possible that this is an issue with the alpha1 release that has
> resolved itself since then.
>
>
> - robert
>
> On Wednesday, August 13, 2003, at 07:53 PM, Daniel Rall wrote:
>
> > Daniel Rall <[EMAIL PROTECTED]> 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.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]