Package org.castor.xml
Interface JavaNaming
-
- All Known Implementing Classes:
JavaNamingImpl
public interface JavaNamingJavaNaming 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.- Version:
- $Id: JavaNaming.java 7390 2008-01-25 15:59:42Z jgrueneis $
- Author:
- Joachim Grueneis
-
-
Field Summary
Fields Modifier and Type Field Description static charFIELD_UNDERSCORE_PREFIXThe underscore field prefix.static java.lang.StringMETHOD_PREFIX_ADDAdd methods start with: add.static java.lang.StringMETHOD_PREFIX_CREATECreate methods start with: create.static java.lang.StringMETHOD_PREFIX_GETGet methods start with: get.static java.lang.StringMETHOD_PREFIX_ISIs methods start with: is.static java.lang.StringMETHOD_PREFIX_SETSet methods start with: set.
-
Method Summary
All Methods Instance Methods Abstract 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 create 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 set 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 an 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 package 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
-
METHOD_PREFIX_ADD
static final java.lang.String METHOD_PREFIX_ADD
Add methods start with: add.- See Also:
- Constant Field Values
-
METHOD_PREFIX_GET
static final java.lang.String METHOD_PREFIX_GET
Get methods start with: get.- See Also:
- Constant Field Values
-
METHOD_PREFIX_IS
static final java.lang.String METHOD_PREFIX_IS
Is methods start with: is.- See Also:
- Constant Field Values
-
METHOD_PREFIX_SET
static final java.lang.String METHOD_PREFIX_SET
Set methods start with: set.- See Also:
- Constant Field Values
-
METHOD_PREFIX_CREATE
static final java.lang.String METHOD_PREFIX_CREATE
Create methods start with: create.- See Also:
- Constant Field Values
-
FIELD_UNDERSCORE_PREFIX
static final char FIELD_UNDERSCORE_PREFIX
The underscore field prefix.- See Also:
- Constant Field Values
-
-
Method Detail
-
isKeyword
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.- Parameters:
name- The name to check.- Returns:
- true if it is a keyword.
-
isValidJavaIdentifier
boolean isValidJavaIdentifier(java.lang.String string)
Returns true if the given String matches the production of a valid Java identifier.- 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.
-
toJavaClassName
java.lang.String toJavaClassName(java.lang.String name)
Cuts away a leading namespace prefix (if there is one in place).- Parameters:
name- The XML name to convert to a Java name.- Returns:
- A name which follows Java naming conventions.
-
toJavaMemberName
java.lang.String toJavaMemberName(java.lang.String name)
Appends a leading '_' and converts the given name to a java name.- Parameters:
name- the XML name to convert.- Returns:
- A Java member name starting with a leading '_'.
-
toJavaMemberName
java.lang.String toJavaMemberName(java.lang.String name, boolean useKeywordSubstitutions)Appends a leading '_' and converts the given name to a java name.- Parameters:
name- The XML name to convert.useKeywordSubstitutions- Set to true to turn on keyword substitution.- Returns:
- A Java member name starting with a leading '_'.
-
isValidPackageName
boolean isValidPackageName(java.lang.String packageName)
Checks if the given package name is valid or not. Empty package names are considered valid!- Parameters:
packageName- Name of package as String with periods.- Returns:
- true if package name is valid.
-
packageToPath
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.- Parameters:
packageName- The package name to convert.- Returns:
- A String containing the resulting patch.
-
getQualifiedFileName
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.- Parameters:
fileName- The file name to be qualified.packageName- The package name to be used for qualifying.- Returns:
- The qualified file path.
-
getClassName
java.lang.String getClassName(java.lang.Class clazz)
Gets the class name without package part.- Parameters:
clazz- The class to retrieve the name from- Returns:
- the class name without package part or null
-
getPackageName
java.lang.String getPackageName(java.lang.String className)
Gets the package name of the given class name.- 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.
-
extractFieldNameFromMethod
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.- Parameters:
method- The Method to process.- Returns:
- The extracted field name.
-
extractFieldNameFromField
java.lang.String extractFieldNameFromField(java.lang.reflect.Field field)
Extracts the field name part from the Field. Mostly it cuts away prefixes like '_'.- Parameters:
field- the Field to process- Returns:
- The extracted field name.
-
isSetMethod
boolean isSetMethod(java.lang.reflect.Method method)
Checks if the given method is a set method.- Parameters:
method- The Method to check- Returns:
- true if it is a set method
-
isCreateMethod
boolean isCreateMethod(java.lang.reflect.Method method)
Checks if the given method is a create method.- Parameters:
method- The Method to check.- Returns:
- true if it is a create method.
-
isGetMethod
boolean isGetMethod(java.lang.reflect.Method method)
Checks if the given method is a get method.- Parameters:
method- The Method to check.- Returns:
- true if it is a get method.
-
isIsMethod
boolean isIsMethod(java.lang.reflect.Method method)
Checks if the given method is an is method.- Parameters:
method- The Method to check.- Returns:
- true if it is an is method.
-
isAddMethod
boolean isAddMethod(java.lang.reflect.Method method)
Checks if the given method is an add method.- Parameters:
method- The Method to check.- Returns:
- true if it is an add method.
-
getAddMethodNameForField
java.lang.String getAddMethodNameForField(java.lang.String fieldName)
Generates the name of an add method for the given field name.- Parameters:
fieldName- The field name to generate a method name for.- Returns:
- The generated add method name.
-
getSetMethodNameForField
java.lang.String getSetMethodNameForField(java.lang.String fieldName)
Generates the name of a set method for the given field name.- Parameters:
fieldName- The field name to generate a method name for.- Returns:
- The generated set method name.
-
getGetMethodNameForField
java.lang.String getGetMethodNameForField(java.lang.String fieldName)
Generates the name of a get method for the given field name.- Parameters:
fieldName- The field name to generate a method name for.- Returns:
- The generated get method name.
-
getIsMethodNameForField
java.lang.String getIsMethodNameForField(java.lang.String fieldName)
Generates the name of an is method for the given field name.- Parameters:
fieldName- The field name to generate a method name for.- Returns:
- The generated is method name.
-
getCreateMethodNameForField
java.lang.String getCreateMethodNameForField(java.lang.String fieldName)
Generates the name of a create method for the given field name.- Parameters:
fieldName- The field name to generate a method name for.- Returns:
- The generated create method name.
-
-