Package org.castor.xml
Class JavaNamingImpl
- java.lang.Object
-
- org.castor.xml.JavaNamingImpl
-
- All Implemented Interfaces:
JavaNaming
public class JavaNamingImpl extends java.lang.Object implements 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 7437 2008-02-06 10:21:45Z jgrueneis $
- Author:
- Joachim Grueneis
-
-
Field Summary
Fields Modifier and Type Field Description 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.static java.lang.StringUPPER_CASE_AFTER_UNDERSCORE_PROPERTYThe property name to use in the castor.properties file to specify the value of theupperCaseAfterUnderscorevariable.-
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 Constructor Description JavaNamingImpl()private constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringextractFieldNameFromField(java.lang.reflect.Field field)Extracts the field name part from the Field.java.lang.StringextractFieldNameFromMethod(java.lang.reflect.Method method)Extracts the filed name part from the methods name.java.lang.StringgetAddMethodNameForField(java.lang.String fieldName)Generates the name of an add method for the given field name.java.lang.StringgetClassName(java.lang.Class clazz)Gets the class name without package part.java.lang.StringgetCreateMethodNameForField(java.lang.String fieldName)Generates the name of a set method for the given field name.java.lang.StringgetGetMethodNameForField(java.lang.String fieldName)Generates the name of a get method for the given field name.java.lang.StringgetIsMethodNameForField(java.lang.String fieldName)Generates the name of an is method for the given field name.java.lang.StringgetPackageName(java.lang.String className)Gets the package name of the given class name.java.lang.StringgetQualifiedFileName(java.lang.String fileName, java.lang.String packageName)Qualifies the givenfileNamewith the givenpackageNameand returns the resulting file path.
IfpackageNameisnullor a zero-length String, this method will returnfileName.java.lang.StringgetSetMethodNameForField(java.lang.String fieldName)Generates the name of a create method for the given field name.booleanisAddMethod(java.lang.reflect.Method method)Checks if the given method is an add method.booleanisCreateMethod(java.lang.reflect.Method method)Checks if the given method is a create method.booleanisGetMethod(java.lang.reflect.Method method)Checks if the given method is a get method.booleanisIsMethod(java.lang.reflect.Method method)Checks if the given method is a 'is' method.booleanisKeyword(java.lang.String name)Returns true if the given String is a Java keyword which will cause a problem when used as a variable name.booleanisSetMethod(java.lang.reflect.Method method)Checks if the given method is a set method.booleanisValidJavaIdentifier(java.lang.String string)Returns true if the given String matches the production of a valid Java identifier.booleanisValidPackageName(java.lang.String packageName)Checks if the given pacckage name is valid or not.java.lang.StringpackageToPath(java.lang.String packageName)Converts the given Package name to it's corresponding Path.java.lang.StringtoJavaClassName(java.lang.String name)Cuts away a leading namespace prefix (if there is one in place).java.lang.StringtoJavaMemberName(java.lang.String name)Appends a leading '_' and converts the given name to a java name.java.lang.StringtoJavaMemberName(java.lang.String name, boolean useKeywordSubstitutions)Appends a leading '_' and converts the given name to a java name.
-
-
-
Field Detail
-
UPPER_CASE_AFTER_UNDERSCORE_PROPERTY
public static final java.lang.String UPPER_CASE_AFTER_UNDERSCORE_PROPERTY
The property name to use in the castor.properties file to specify the value of theupperCaseAfterUnderscorevariable.- See Also:
- Constant Field Values
-
_upperCaseAfterUnderscore
public static boolean _upperCaseAfterUnderscore
Used for backward compatibility, if you wish to be backward compatible with 0.9.3.9 and earlier set this boolean to true.
-
-
Method Detail
-
isKeyword
public final boolean isKeyword(java.lang.String name)
Returns true if the given String is a Java keyword which will cause a problem when used as a variable name.- Specified by:
isKeywordin interfaceJavaNaming- Parameters:
name- the name to check- Returns:
- true if it is a keyword
- See Also:
JavaNaming.isKeyword(java.lang.String)
-
isValidJavaIdentifier
public final boolean isValidJavaIdentifier(java.lang.String string)
Returns true if the given String matches the production of a valid Java identifier.- Specified by:
isValidJavaIdentifierin 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:
JavaNaming.isValidJavaIdentifier(java.lang.String)
-
toJavaClassName
public final java.lang.String toJavaClassName(java.lang.String name)
Cuts away a leading namespace prefix (if there is one in place).- Specified by:
toJavaClassNamein interfaceJavaNaming- Parameters:
name- the XML name to convert to a Java name- Returns:
- a name which follows Java naming conventions
- See Also:
JavaNaming.toJavaClassName(java.lang.String)
-
toJavaMemberName
public final java.lang.String toJavaMemberName(java.lang.String name)
Appends a leading '_' and converts the given name to a java name.- Specified by:
toJavaMemberNamein interfaceJavaNaming- Parameters:
name- the XML name to convert- Returns:
- a Java member name starting with a leading _
- See Also:
JavaNaming.toJavaMemberName(java.lang.String)
-
toJavaMemberName
public final java.lang.String toJavaMemberName(java.lang.String name, boolean useKeywordSubstitutions)Appends a leading '_' and converts the given name to a java name.- Specified by:
toJavaMemberNamein interfaceJavaNaming- Parameters:
name- the XML name to convertuseKeywordSubstitutions- set to true to turn on keyword substitution- Returns:
- a Java member name starting with a leading _
- See Also:
JavaNaming.toJavaMemberName(java.lang.String,boolean)
-
isValidPackageName
public final boolean isValidPackageName(java.lang.String packageName)
Checks if the given pacckage name is valid or not. Empty pacakge names are considered valid!- Specified by:
isValidPackageNamein interfaceJavaNaming- Parameters:
packageName- name of package as String with periods- Returns:
- true if package name is valid
- See Also:
JavaNaming.isValidPackageName(java.lang.String)
-
packageToPath
public final java.lang.String packageToPath(java.lang.String packageName)
Converts the given Package name to it's corresponding Path. The path will be a relative path.- Specified by:
packageToPathin interfaceJavaNaming- Parameters:
packageName- the package name to convert- Returns:
- a String containing the resulting patch
- See Also:
JavaNaming.packageToPath(java.lang.String)
-
getQualifiedFileName
public final java.lang.String getQualifiedFileName(java.lang.String fileName, java.lang.String packageName)Qualifies the givenfileNamewith the givenpackageNameand returns the resulting file path.
IfpackageNameisnullor a zero-length String, this method will returnfileName.- Specified by:
getQualifiedFileNamein 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:
JavaNaming.getQualifiedFileName(java.lang.String,java.lang.String)
-
getPackageName
public final java.lang.String getPackageName(java.lang.String className)
Gets the package name of the given class name.- Specified by:
getPackageNamein interfaceJavaNaming- Parameters:
className- The class name to retrieve the package name from.- Returns:
- The package name or the empty String if
classNameisnullor does not contain a package. - See Also:
JavaNaming.getPackageName(java.lang.String)
-
extractFieldNameFromMethod
public final java.lang.String extractFieldNameFromMethod(java.lang.reflect.Method method)
Extracts the filed name part from the methods name. Mostly it cuts away the method prefix.- Specified by:
extractFieldNameFromMethodin interfaceJavaNaming- Parameters:
method- the Method to process- Returns:
- the extracted field name
- See Also:
JavaNaming.extractFieldNameFromMethod(java.lang.reflect.Method)
-
extractFieldNameFromField
public final java.lang.String extractFieldNameFromField(java.lang.reflect.Field field)
Extracts the field name part from the Field. Mostly it cuts away prefixes like '_'.- Specified by:
extractFieldNameFromFieldin interfaceJavaNaming- Parameters:
field- the Field to process- Returns:
- The extracted field name.
- See Also:
JavaNaming.extractFieldNameFromField(java.lang.reflect.Field)
-
isSetMethod
public final boolean isSetMethod(java.lang.reflect.Method method)
Checks if the given method is a set method.- Specified by:
isSetMethodin interfaceJavaNaming- Parameters:
method- the Method to check- Returns:
- true if it is a set method
- See Also:
JavaNaming.isSetMethod(java.lang.reflect.Method)
-
isCreateMethod
public final boolean isCreateMethod(java.lang.reflect.Method method)
Checks if the given method is a create method.- Specified by:
isCreateMethodin interfaceJavaNaming- Parameters:
method- the Method to check- Returns:
- true if it is a create method
- See Also:
JavaNaming.isCreateMethod(java.lang.reflect.Method)
-
isGetMethod
public final boolean isGetMethod(java.lang.reflect.Method method)
Checks if the given method is a get method.- Specified by:
isGetMethodin interfaceJavaNaming- Parameters:
method- the Method to check- Returns:
- true if it is a get method
- See Also:
JavaNaming.isGetMethod(java.lang.reflect.Method)
-
isIsMethod
public final boolean isIsMethod(java.lang.reflect.Method method)
Checks if the given method is a 'is' method.- Specified by:
isIsMethodin interfaceJavaNaming- Parameters:
method- the Method to check- Returns:
- true if it is a 'is' method
- See Also:
JavaNaming.isIsMethod(java.lang.reflect.Method)
-
isAddMethod
public final boolean isAddMethod(java.lang.reflect.Method method)
Checks if the given method is an add method.- Specified by:
isAddMethodin interfaceJavaNaming- Parameters:
method- the Method to check- Returns:
- true if it is an add method
- See Also:
JavaNaming.isAddMethod(java.lang.reflect.Method)
-
getAddMethodNameForField
public final java.lang.String getAddMethodNameForField(java.lang.String fieldName)
Generates the name of an add method for the given field name.- Specified by:
getAddMethodNameForFieldin interfaceJavaNaming- Parameters:
fieldName- the field name to generate a method name for- Returns:
- the generated add method name
-
getCreateMethodNameForField
public final java.lang.String getCreateMethodNameForField(java.lang.String fieldName)
Generates the name of a set method for the given field name.- Specified by:
getCreateMethodNameForFieldin interfaceJavaNaming- Parameters:
fieldName- the field name to generate a method name for- Returns:
- the generated set method name
-
getGetMethodNameForField
public final java.lang.String getGetMethodNameForField(java.lang.String fieldName)
Generates the name of a get method for the given field name.- Specified by:
getGetMethodNameForFieldin interfaceJavaNaming- Parameters:
fieldName- the field name to generate a method name for- Returns:
- the generated get method name
-
getIsMethodNameForField
public final java.lang.String getIsMethodNameForField(java.lang.String fieldName)
Generates the name of an is method for the given field name.- Specified by:
getIsMethodNameForFieldin interfaceJavaNaming- Parameters:
fieldName- the field name to generate a method name for- Returns:
- the generated is method name
-
getSetMethodNameForField
public final java.lang.String getSetMethodNameForField(java.lang.String fieldName)
Generates the name of a create method for the given field name.- Specified by:
getSetMethodNameForFieldin interfaceJavaNaming- Parameters:
fieldName- the field name to generate a method name for- Returns:
- the generated create method name
-
getClassName
public java.lang.String getClassName(java.lang.Class clazz)
Gets the class name without package part.- Specified by:
getClassNamein 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:
JavaNaming.getClassName(java.lang.Class)
-
-