public class HyphenatedNameMapper extends Object implements NameMapper
separator
and
upperCase
properties, so that FooBar can be converted
to FOO_BAR if needed, by calling the constructor
new HyphenatedNameMapper(true, "_")
.Modifier and Type | Field and Description |
---|---|
private String |
separator
the separator used to seperate words, which defaults to '-'
|
private boolean |
upperCase
whether upper or lower case conversions should be performed
|
Constructor and Description |
---|
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,
String separator)
Construct a hyphenated name mapper.
|
Modifier and Type | Method and Description |
---|---|
protected char |
convertChar(char ch)
Performs type conversion on the given character based on whether
upper or lower case conversions are being used
|
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?
Otherwise, it will be converted to lower case.
|
String |
mapTypeToElementName(String typeName)
The words within the bean name are deduced assuming the camel's hump naming
convention.
|
void |
setSeparator(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.
|
private String separator
private boolean upperCase
public HyphenatedNameMapper()
public HyphenatedNameMapper(boolean upperCase)
upperCase
- should the type name be converted (entirely) to upper casepublic HyphenatedNameMapper(boolean upperCase, String separator)
upperCase
- should the type name be converted (entirely) to upper caseseparator
- 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.public String mapTypeToElementName(String typeName)
The words within the bean name are deduced assuming the 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.
mapTypeToElementName
in interface NameMapper
typeName
- the name string to convertpublic String getSeparator()
public void setSeparator(String separator)
separator
- the string inserted to separate wordspublic boolean isUpperCase()
public void setUpperCase(boolean upperCase)
upperCase
- whether the name is to be converted to upper caseprotected char convertChar(char ch)
ch
- the character to be convertedisUpperCase
otherwise to lower case