You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dl...@apache.org on 2003/08/13 20:28:01 UTC

cvs commit: jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy HyphenatedNameMapper.java NameMapper.java

dlr         2003/08/13 11:28:01

  Modified:    betwixt/src/java/org/apache/commons/betwixt/strategy
                        HyphenatedNameMapper.java NameMapper.java
  Log:
  * src/java/org/apache/commons/betwixt/strategy/NameMapper.java
  * src/java/org/apache/commons/betwixt/strategy/HyphenatedNameMapper.java
    mapTypeToElementName(String): Improved JavaDoc.
  
  Revision  Changes    Path
  1.8       +12 -8     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/HyphenatedNameMapper.java
  
  Index: HyphenatedNameMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/HyphenatedNameMapper.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -u -r1.7 -r1.8
  --- HyphenatedNameMapper.java	17 Feb 2003 19:41:56 -0000	1.7
  +++ HyphenatedNameMapper.java	13 Aug 2003 18:28:01 -0000	1.8
  @@ -114,8 +114,9 @@
       }
       
       /**
  -     * <p>The words within the bean name are deduced assuming the camel's hump naming
  -     * convention. For example, the words in <code>FooBar</code> are <code>foo</code> 
  +     * <p>The words within the bean name are deduced assuming the
  +     * first-letter-capital (e.g. camel's hump) naming convention. For
  +     * example, the words in <code>FooBar</code> are <code>foo</code>
        * and <code>bar</code>.</p>
        * 
        * <p>Next convert all letter in the bean name to either upper case or lower case
  @@ -124,7 +125,10 @@
        * <p>Then the {@link #getSeparator} property value is inserted so that it separates
        * each word.</p>
        *
  -     * @param typeName the name string to convert
  +     * @param typeName The name string to convert.  If a JavaBean
  +     * class name, should included only the last part of the name
  +     * rather than the fully qualified name (e.g. FooBar rather than
  +     * org.example.FooBar).
        * @return the bean name converted to either upper or lower case with words separated 
        * by the separator.
        */
  
  
  
  1.4       +9 -8      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/NameMapper.java
  
  Index: NameMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/NameMapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- NameMapper.java	6 Jan 2003 22:50:45 -0000	1.3
  +++ NameMapper.java	13 Aug 2003 18:28:01 -0000	1.4
  @@ -62,7 +62,8 @@
   package org.apache.commons.betwixt.strategy;
   
   /** 
  - * A plugin Strategy pattern for converting java type names into element names.
  + * A plugin Strategy pattern for converting Java type names into
  + * element names.
    * 
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
  @@ -70,8 +71,8 @@
   public interface NameMapper {
   
       /**
  -     * Convert the given bean or property name to name for use in xml 
  -     * (as an element or an attribute nqame).
  +     * Convert the given bean or property name to name for use in XML
  +     * (as an element or an attribute qname).
        *
        * @param typeName the string to convert 
        * @return the element name for the given bean type name
  
  
  

Re: [Betwixt] Using NameMapper

Posted by Daniel Rall <dl...@finemaltcoding.com>.
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 <rd...@apache.org> 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 <dl...@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.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Betwixt] Using NameMapper

Posted by Daniel Rall <dl...@finemaltcoding.com>.
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 <rd...@apache.org> 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 <dl...@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.

Re: [Betwixt] Using NameMapper

Posted by robert burrell donkin <rd...@apache.org>.
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 <dl...@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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@scarab.tigris.org
> For additional commands, e-mail: dev-help@scarab.tigris.org
>


Re: [Betwixt] Using NameMapper

Posted by robert burrell donkin <rd...@apache.org>.
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 <dl...@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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@scarab.tigris.org
> For additional commands, e-mail: dev-help@scarab.tigris.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Betwixt] Using NameMapper

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Daniel Rall <dl...@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

Re: [Betwixt] Using NameMapper

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Daniel Rall <dl...@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

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org