Package org.castor.xml
Class JavaNamingNGImpl
java.lang.Object
org.castor.xml.JavaNamingNGImpl
- All Implemented Interfaces:
JavaNaming
This class converts XML Names to proper Java names. As Java names are not
completely defined this implementation is Castor specific.
The first implementation was done by Keith Visco
but had been changed radically since.
- Version:
- $Id: JavaNamingImpl.java 9078 2011-11-03 20:50:10Z wguttmn $
- Author:
- Joachim Grueneis
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic boolean
Used for backward compatibility, if you wish to be backward compatible with 0.9.3.9 and earlier set this boolean to true.static final String
The property name to use in the castor.properties file to specify the value of theupperCaseAfterUnderscore
variable.Fields inherited from interface org.castor.xml.JavaNaming
FIELD_UNDERSCORE_PREFIX, METHOD_PREFIX_ADD, METHOD_PREFIX_CREATE, METHOD_PREFIX_GET, METHOD_PREFIX_IS, METHOD_PREFIX_SET
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal String
extractFieldNameFromField
(Field field) Extracts the field name part from the Field.final String
extractFieldNameFromMethod
(Method method) Extracts the filed name part from the methods name.final String
getAddMethodNameForField
(String fieldName) Generates the name of an add method for the given field name.getClassName
(Class clazz) Gets the class name without package part.final String
getCreateMethodNameForField
(String fieldName) Generates the name of a set method for the given field name.final String
getGetMethodNameForField
(String fieldName) Generates the name of a get method for the given field name.final String
getIsMethodNameForField
(String fieldName) Generates the name of an is method for the given field name.final String
getPackageName
(String className) Gets the package name of the given class name.final String
getQualifiedFileName
(String fileName, String packageName) Qualifies the givenfileName
with the givenpackageName
and returns the resulting file path.
IfpackageName
isnull
or a zero-length String, this method will returnfileName
.final String
getSetMethodNameForField
(String fieldName) Generates the name of a create method for the given field name.final boolean
isAddMethod
(Method method) Checks if the given method is an add method.final boolean
isCreateMethod
(Method method) Checks if the given method is a create method.final boolean
isGetMethod
(Method method) Checks if the given method is a get method.final boolean
isIsMethod
(Method method) Checks if the given method is a 'is' method.final boolean
Returns true if the given String is a Java keyword which will cause a problem when used as a variable name.final boolean
isSetMethod
(Method method) Checks if the given method is a set method.final boolean
isValidJavaIdentifier
(String string) Returns true if the given String matches the production of a valid Java identifier.final boolean
isValidPackageName
(String packageName) Checks if the given package name is valid or not.final String
packageToPath
(String packageName) Converts the given Package name to it's corresponding Path.final String
toJavaClassName
(String name) Cuts away a leading namespace prefix (if there is one in place).final String
toJavaMemberName
(String name) Converts the given name to a valid Java name.final String
toJavaMemberName
(String name, boolean useKeywordSubstitutions) Converts the given name to a valid Java name.
-
Field Details
-
UPPER_CASE_AFTER_UNDERSCORE_PROPERTY
The property name to use in the castor.properties file to specify the value of theupperCaseAfterUnderscore
variable.- See Also:
-
_upperCaseAfterUnderscore
public static boolean _upperCaseAfterUnderscoreUsed for backward compatibility, if you wish to be backward compatible with 0.9.3.9 and earlier set this boolean to true.
-
-
Constructor Details
-
JavaNamingNGImpl
public JavaNamingNGImpl()private constructor. -
JavaNamingNGImpl
-
-
Method Details
-
isKeyword
Returns true if the given String is a Java keyword which will cause a problem when used as a variable name.- Specified by:
isKeyword
in interfaceJavaNaming
- Parameters:
name
- the name to check- Returns:
- true if it is a keyword
- See Also:
-
isValidJavaIdentifier
Returns true if the given String matches the production of a valid Java identifier.- Specified by:
isValidJavaIdentifier
in interfaceJavaNaming
- Parameters:
string
- The String to check the production of.- Returns:
- true if the given String matches the production of a valid Java name, otherwise false.
- See Also:
-
toJavaClassName
Cuts away a leading namespace prefix (if there is one in place).- Specified by:
toJavaClassName
in interfaceJavaNaming
- Parameters:
name
- the XML name to convert to a Java name- Returns:
- a name which follows Java naming conventions
- See Also:
-
toJavaMemberName
Converts the given name to a valid Java name.- Specified by:
toJavaMemberName
in interfaceJavaNaming
- Parameters:
name
- the XML name to convert- Returns:
- a valid Java member name
- See Also:
-
toJavaMemberName
Converts the given name to a valid Java name.- Specified by:
toJavaMemberName
in interfaceJavaNaming
- Parameters:
name
- the XML name to convertuseKeywordSubstitutions
- set to true to turn on keyword substitution- Returns:
- a valid Java member name
- See Also:
-
isValidPackageName
Checks if the given package name is valid or not. Empty package names are considered valid!- Specified by:
isValidPackageName
in interfaceJavaNaming
- Parameters:
packageName
- name of package as String with periods- Returns:
- true if package name is valid
- See Also:
-
packageToPath
Converts the given Package name to it's corresponding Path. The path will be a relative path.- Specified by:
packageToPath
in interfaceJavaNaming
- Parameters:
packageName
- the package name to convert- Returns:
- a String containing the resulting patch
- See Also:
-
getQualifiedFileName
Qualifies the givenfileName
with the givenpackageName
and returns the resulting file path.
IfpackageName
isnull
or a zero-length String, this method will returnfileName
.- Specified by:
getQualifiedFileName
in interfaceJavaNaming
- Parameters:
fileName
- The file name to be qualified.packageName
- The package name to be used for qualifying.- Returns:
- The qualified file path.
- See Also:
-
getPackageName
Gets the package name of the given class name.- Specified by:
getPackageName
in interfaceJavaNaming
- Parameters:
className
- The class name to retrieve the package name from.- Returns:
- The package name or the empty String if
className
isnull
or does not contain a package. - See Also:
-
extractFieldNameFromMethod
Extracts the filed name part from the methods name. Mostly it cuts away the method prefix.- Specified by:
extractFieldNameFromMethod
in interfaceJavaNaming
- Parameters:
method
- the Method to process- Returns:
- the extracted field name
- See Also:
-
extractFieldNameFromField
Extracts the field name part from the Field. Mostly it cuts away prefixes like '_'.- Specified by:
extractFieldNameFromField
in interfaceJavaNaming
- Parameters:
field
- the Field to process- Returns:
- The extracted field name.
- See Also:
-
isSetMethod
Checks if the given method is a set method.- Specified by:
isSetMethod
in interfaceJavaNaming
- Parameters:
method
- the Method to check- Returns:
- true if it is a set method
- See Also:
-
isCreateMethod
Checks if the given method is a create method.- Specified by:
isCreateMethod
in interfaceJavaNaming
- Parameters:
method
- the Method to check- Returns:
- true if it is a create method
- See Also:
-
isGetMethod
Checks if the given method is a get method.- Specified by:
isGetMethod
in interfaceJavaNaming
- Parameters:
method
- the Method to check- Returns:
- true if it is a get method
- See Also:
-
isIsMethod
Checks if the given method is a 'is' method.- Specified by:
isIsMethod
in interfaceJavaNaming
- Parameters:
method
- the Method to check- Returns:
- true if it is a 'is' method
- See Also:
-
isAddMethod
Checks if the given method is an add method.- Specified by:
isAddMethod
in interfaceJavaNaming
- Parameters:
method
- the Method to check- Returns:
- true if it is an add method
- See Also:
-
getAddMethodNameForField
Generates the name of an add method for the given field name.- Specified by:
getAddMethodNameForField
in interfaceJavaNaming
- Parameters:
fieldName
- the field name to generate a method name for- Returns:
- the generated add method name
-
getCreateMethodNameForField
Generates the name of a set method for the given field name.- Specified by:
getCreateMethodNameForField
in interfaceJavaNaming
- Parameters:
fieldName
- the field name to generate a method name for- Returns:
- the generated set method name
-
getGetMethodNameForField
Generates the name of a get method for the given field name.- Specified by:
getGetMethodNameForField
in interfaceJavaNaming
- Parameters:
fieldName
- the field name to generate a method name for- Returns:
- the generated get method name
-
getIsMethodNameForField
Generates the name of an is method for the given field name.- Specified by:
getIsMethodNameForField
in interfaceJavaNaming
- Parameters:
fieldName
- the field name to generate a method name for- Returns:
- the generated is method name
-
getSetMethodNameForField
Generates the name of a create method for the given field name.- Specified by:
getSetMethodNameForField
in interfaceJavaNaming
- Parameters:
fieldName
- the field name to generate a method name for- Returns:
- the generated create method name
-
getClassName
Gets the class name without package part.- Specified by:
getClassName
in interfaceJavaNaming
- Parameters:
clazz
- The class to retrieve the name from- Returns:
- the class name without package part or null the class name without package part or null
- See Also:
-