org.apache.commons.betwixt.strategy
Class HyphenatedNameMapper

java.lang.Object
  extended by org.apache.commons.betwixt.strategy.HyphenatedNameMapper
All Implemented Interfaces:
NameMapper

public class HyphenatedNameMapper
extends java.lang.Object
implements NameMapper

A name mapper which converts types to a hypenated String. So a bean type of FooBar will be converted to the element name "foo-bar". The name mapper can be configured to convert to upper case and to use a different separator via the separator and upperCase properties, so that FooBar can be converted to FOO_BAR if needed, by calling the constructor new HyphenatedNameMapper(true, "_").

Version:
$Revision: 471234 $
Author:
Jason van Zyl, James Strachan

Constructor Summary
HyphenatedNameMapper()
          Construct a hyphenated name mapper that converts the name to lower case and uses the default separator.
HyphenatedNameMapper(boolean upperCase)
          Construct a hyphenated name mapper with default separator.
HyphenatedNameMapper(boolean upperCase, java.lang.String separator)
          Construct a hyphenated name mapper.
 
Method Summary
protected  char convertChar(char ch)
          Performs type conversion on the given character based on whether upper or lower case conversions are being used
 java.lang.String getSeparator()
          This separator will be inserted between the words in the bean name.
 boolean isUpperCase()
          Should the bean name be converted to upper case?
 java.lang.String mapTypeToElementName(java.lang.String typeName)
          The words within the bean name are deduced assuming the first-letter-capital (for example camel's hump) naming convention.
 void setSeparator(java.lang.String separator)
          Sets the separator used to seperate words, which defaults to '-'
 void setUpperCase(boolean upperCase)
          Sets whether upper or lower case conversions should be performed, which defaults to false for lower case.
 java.lang.String toString()
          Outputs brief description.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HyphenatedNameMapper

public HyphenatedNameMapper()
Construct a hyphenated name mapper that converts the name to lower case and uses the default separator.


HyphenatedNameMapper

public HyphenatedNameMapper(boolean upperCase)
Construct a hyphenated name mapper with default separator.

Parameters:
upperCase - should the type name be converted (entirely) to upper case

HyphenatedNameMapper

public HyphenatedNameMapper(boolean upperCase,
                            java.lang.String separator)
Construct a hyphenated name mapper.

Parameters:
upperCase - should the type name be converted (entirely) to upper case
separator - use this string to separate the words in the name returned. The words in the bean name are deduced by relying on the standard camel's hump property naming convention.
Method Detail

mapTypeToElementName

public java.lang.String mapTypeToElementName(java.lang.String typeName)

The words within the bean name are deduced assuming the first-letter-capital (for example camel's hump) naming convention. For example, the words in FooBar are foo and bar.

Next convert all letter in the bean name to either upper case or lower case based on the isUpperCase() property value.

Then the getSeparator() property value is inserted so that it separates each word.

Specified by:
mapTypeToElementName in interface NameMapper
Parameters:
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).
Returns:
the bean name converted to either upper or lower case with words separated by the separator.

getSeparator

public java.lang.String getSeparator()
This separator will be inserted between the words in the bean name.

Returns:
the separator used to seperate words, which defaults to '-'

setSeparator

public void setSeparator(java.lang.String separator)
Sets the separator used to seperate words, which defaults to '-'

Parameters:
separator - the string inserted to separate words

isUpperCase

public boolean isUpperCase()

Should the bean name be converted to upper case?

Otherwise, it will be converted to lower case.

Returns:
whether upper or lower case conversions should be performed, which defaults to false for lower case

setUpperCase

public void setUpperCase(boolean upperCase)
Sets whether upper or lower case conversions should be performed, which defaults to false for lower case.

Parameters:
upperCase - whether the name is to be converted to upper case

convertChar

protected char convertChar(char ch)
Performs type conversion on the given character based on whether upper or lower case conversions are being used

Parameters:
ch - the character to be converted
Returns:
converted to upper case if isUpperCase() otherwise to lower case

toString

public java.lang.String toString()
Outputs brief description.

Overrides:
toString in class java.lang.Object
Since:
0.8


Copyright © 2002-2008 The Apache Software Foundation. All Rights Reserved.