JavaNaming is a service which collects all methods that are related to
create (modify) Java names. E.g. convert from XML name to Java name,
get a Java member name or such. These rules can be exchanged by a different
implementation to get a different naming style for e.g. JAXB.
FIELD_UNDERSCORE_PREFIX
public static final char FIELD_UNDERSCORE_PREFIX
The underscore field prefix.
METHOD_PREFIX_ADD
public static final String METHOD_PREFIX_ADD
Add methods start with: add.
METHOD_PREFIX_CREATE
public static final String METHOD_PREFIX_CREATE
Create methods start with: create.
METHOD_PREFIX_GET
public static final String METHOD_PREFIX_GET
Get methods start with: get.
METHOD_PREFIX_IS
public static final String METHOD_PREFIX_IS
Is methods start with: is.
METHOD_PREFIX_SET
public static final String METHOD_PREFIX_SET
Set methods start with: set.
extractFieldNameFromField
public String extractFieldNameFromField(Field field)
Extracts the field name part from the Field. Mostly it cuts away
prefixes like '_'.
field
- the Field to process
- The extracted field name.
extractFieldNameFromMethod
public String extractFieldNameFromMethod(Method method)
Extracts the filed name part from the methods name. Mostly it cuts
away the method prefix.
method
- The Method to process.
- The extracted field name.
getAddMethodNameForField
public String getAddMethodNameForField(String fieldName)
Generates the name of an add method for the given field name.
fieldName
- The field name to generate a method name for.
- The generated add method name.
getClassName
public String getClassName(Class clazz)
Gets the class name without package part.
clazz
- The class to retrieve the name from
- the class name without package part or null
getCreateMethodNameForField
public String getCreateMethodNameForField(String fieldName)
Generates the name of a create method for the given field name.
fieldName
- The field name to generate a method name for.
- The generated create method name.
getGetMethodNameForField
public String getGetMethodNameForField(String fieldName)
Generates the name of a get method for the given field name.
fieldName
- The field name to generate a method name for.
- The generated get method name.
getIsMethodNameForField
public String getIsMethodNameForField(String fieldName)
Generates the name of an is method for the given field name.
fieldName
- The field name to generate a method name for.
- The generated is method name.
getPackageName
public String getPackageName(String className)
Gets the package name of the given class name.
className
- The class name to retrieve the package name from.
- The package name or the empty String if
className
is null
or does not contain a package.
getQualifiedFileName
public String getQualifiedFileName(String fileName,
String packageName)
Qualifies the given fileName
with the given
packageName
and returns the resulting file path.
If packageName
is null
or a zero-length
String, this method will return fileName
.
fileName
- The file name to be qualified.packageName
- The package name to be used for qualifying.
getSetMethodNameForField
public String getSetMethodNameForField(String fieldName)
Generates the name of a set method for the given field name.
fieldName
- The field name to generate a method name for.
- The generated set method name.
isAddMethod
public boolean isAddMethod(Method method)
Checks if the given method is an add method.
method
- The Method to check.
- true if it is an add method.
isCreateMethod
public boolean isCreateMethod(Method method)
Checks if the given method is a create method.
method
- The Method to check.
- true if it is a create method.
isGetMethod
public boolean isGetMethod(Method method)
Checks if the given method is a get method.
method
- The Method to check.
- true if it is a get method.
isIsMethod
public boolean isIsMethod(Method method)
Checks if the given method is an is method.
method
- The Method to check.
- true if it is an is method.
isKeyword
public boolean isKeyword(String name)
Returns true if the given String is a Java keyword which will cause a
problem when used as a variable name.
name
- The name to check.
isSetMethod
public boolean isSetMethod(Method method)
Checks if the given method is a set method.
method
- The Method to check
- true if it is a set method
isValidJavaIdentifier
public boolean isValidJavaIdentifier(String string)
Returns true if the given String matches the production of a valid Java
identifier.
string
- The String to check the production of.
- true if the given String matches the production of a valid Java
name, otherwise false.
isValidPackageName
public boolean isValidPackageName(String packageName)
Checks if the given package name is valid or not. Empty package names
are considered valid!
packageName
- Name of package as String with periods.
- true if package name is valid.
packageToPath
public String packageToPath(String packageName)
Converts the given Package name to it's corresponding Path. The path will
be a relative path.
packageName
- The package name to convert.
- A String containing the resulting patch.
toJavaClassName
public String toJavaClassName(String name)
Cuts away a leading namespace prefix (if there is one in place).
name
- The XML name to convert to a Java name.
- A name which follows Java naming conventions.
toJavaMemberName
public String toJavaMemberName(String name)
Appends a leading '_' and converts the given name to a java name.
name
- the XML name to convert.
- A Java member name starting with a leading '_'.
toJavaMemberName
public String toJavaMemberName(String name,
boolean useKeywordSubstitutions)
Appends a leading '_' and converts the given name to a java name.
name
- The XML name to convert.useKeywordSubstitutions
- Set to true to turn on keyword substitution.
- A Java member name starting with a leading '_'.