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.
extractFieldNameFromField
public final String extractFieldNameFromField(Field field)
Extracts the field name part from the Field. Mostly it cuts away
prefixes like '_'.
- extractFieldNameFromField in interface JavaNaming
field
- the Field to process
- The extracted field name.
org.castor.xml.JavaNaming.extractFieldNameFromField(java.lang.reflect.Field)
extractFieldNameFromMethod
public final String extractFieldNameFromMethod(Method method)
Extracts the filed name part from the methods name. Mostly it cuts
away the method prefix.
- extractFieldNameFromMethod in interface JavaNaming
method
- the Method to process
org.castor.xml.JavaNaming.extractFieldNameFromMethod(java.lang.reflect.Method)
getAddMethodNameForField
public final String getAddMethodNameForField(String fieldName)
Generates the name of an add method for the given field name.
- getAddMethodNameForField in interface JavaNaming
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.
- getClassName in interface JavaNaming
clazz
- The class to retrieve the name from
- the class name without package part or null
org.castor.xml.JavaNaming.getClassName(java.lang.Class)
getCreateMethodNameForField
public final String getCreateMethodNameForField(String fieldName)
Generates the name of a set method for the given field name.
- getCreateMethodNameForField in interface JavaNaming
fieldName
- the field name to generate a method name for
- the generated set method name
getGetMethodNameForField
public final String getGetMethodNameForField(String fieldName)
Generates the name of a get method for the given field name.
- getGetMethodNameForField in interface JavaNaming
fieldName
- the field name to generate a method name for
- the generated get method name
getIsMethodNameForField
public final String getIsMethodNameForField(String fieldName)
Generates the name of an is method for the given field name.
- getIsMethodNameForField in interface JavaNaming
fieldName
- the field name to generate a method name for
- the generated is method name
getPackageName
public final String getPackageName(String className)
Gets the package name of the given class name.
- getPackageName in interface JavaNaming
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.
org.castor.xml.JavaNaming.getPackageName(java.lang.String)
getQualifiedFileName
public final 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
.
- getQualifiedFileName in interface JavaNaming
fileName
- The file name to be qualified.packageName
- The package name to be used for qualifying.
org.castor.xml.JavaNaming.getQualifiedFileName(java.lang.String,java.lang.String)
getSetMethodNameForField
public final String getSetMethodNameForField(String fieldName)
Generates the name of a create method for the given field name.
- getSetMethodNameForField in interface JavaNaming
fieldName
- the field name to generate a method name for
- the generated create method name
isAddMethod
public final boolean isAddMethod(Method method)
Checks if the given method is an add method.
- isAddMethod in interface JavaNaming
method
- the Method to check
- true if it is an add method
org.castor.xml.JavaNaming.isAddMethod(java.lang.reflect.Method)
isCreateMethod
public final boolean isCreateMethod(Method method)
Checks if the given method is a create method.
- isCreateMethod in interface JavaNaming
method
- the Method to check
- true if it is a create method
org.castor.xml.JavaNaming.isCreateMethod(java.lang.reflect.Method)
isGetMethod
public final boolean isGetMethod(Method method)
Checks if the given method is a get method.
- isGetMethod in interface JavaNaming
method
- the Method to check
- true if it is a get method
org.castor.xml.JavaNaming.isGetMethod(java.lang.reflect.Method)
isIsMethod
public final boolean isIsMethod(Method method)
Checks if the given method is a 'is' method.
- isIsMethod in interface JavaNaming
method
- the Method to check
- true if it is a 'is' method
org.castor.xml.JavaNaming.isIsMethod(java.lang.reflect.Method)
isKeyword
public final 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.
- isKeyword in interface JavaNaming
org.castor.xml.JavaNaming.isKeyword(java.lang.String)
isSetMethod
public final boolean isSetMethod(Method method)
Checks if the given method is a set method.
- isSetMethod in interface JavaNaming
method
- the Method to check
- true if it is a set method
org.castor.xml.JavaNaming.isSetMethod(java.lang.reflect.Method)
isValidJavaIdentifier
public final boolean isValidJavaIdentifier(String string)
Returns true if the given String matches the production of a valid Java
identifier.
- isValidJavaIdentifier in interface JavaNaming
string
- The String to check the production of.
- true if the given String matches the production of a valid Java
name, otherwise false.
org.castor.xml.JavaNaming.isValidJavaIdentifier(java.lang.String)
isValidPackageName
public final boolean isValidPackageName(String packageName)
Checks if the given pacckage name is valid or not. Empty pacakge names
are considered valid!
- isValidPackageName in interface JavaNaming
packageName
- name of package as String with periods
- true if package name is valid
org.castor.xml.JavaNaming.isValidPackageName(java.lang.String)
packageToPath
public final String packageToPath(String packageName)
Converts the given Package name to it's corresponding Path. The path will
be a relative path.
- packageToPath in interface JavaNaming
packageName
- the package name to convert
- a String containing the resulting patch
org.castor.xml.JavaNaming.packageToPath(java.lang.String)
toJavaClassName
public final String toJavaClassName(String name)
Cuts away a leading namespace prefix (if there is one in place).
- toJavaClassName in interface JavaNaming
name
- the XML name to convert to a Java name
- a name which follows Java naming conventions
org.castor.xml.JavaNaming.toJavaClassName(java.lang.String)
toJavaMemberName
public final String toJavaMemberName(String name)
Appends a leading '_' and converts the given name to a java name.
- toJavaMemberName in interface JavaNaming
name
- the XML name to convert
- a Java member name starting with a leading _
org.castor.xml.JavaNaming.toJavaMemberName(java.lang.String)
toJavaMemberName
public final String toJavaMemberName(String name,
boolean useKeywordSubstitutions)
Appends a leading '_' and converts the given name to a java name.
- toJavaMemberName in interface JavaNaming
name
- the XML name to convertuseKeywordSubstitutions
- set to true to turn on keyword substitution
- a Java member name starting with a leading _
org.castor.xml.JavaNaming.toJavaMemberName(java.lang.String,boolean)