Class AbstractNamingStrategy
java.lang.Object
com.sap.cloud.sdk.datamodel.odata.utility.AbstractNamingStrategy
- All Implemented Interfaces:
NamingStrategy
- Direct Known Subclasses:
S4HanaNamingStrategy
,SimpleNamingStrategy
Represents an abstract base implementation of the
NamingStrategy
. It provides convenience methods (such as
convertToJavaClassName(String, String)
) for inheritors to leverage.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final String
appendSuffixIfNameIsReservedKeyword
(String name, String suffix) Appends the givensuffix
to the givenname
, if thename
is a reserved keyword.protected String
chooseBetweenNameAndLabel
(String name, String label) protected String
convertToJavaClassName
(String name, String label) protected String
convertToJavaConstantName
(String name, String label) protected String
convertToJavaFieldName
(String name, String label) protected String
convertToJavaMethodName
(String name, String label) protected String
finishJavaBuilderMethodNameGeneration
(String methodName) Allows post-processing of the Java identifier generated bygenerateJavaBuilderMethodName(String)
.protected String
finishJavaClassNameGeneration
(String className) Allows post-processing of the Java identifier generated bygenerateJavaClassName(String, String)
.protected String
finishJavaConstantNameGeneration
(String constantName) Allows post-processing of the Java identifier generated bygenerateJavaConstantName(String, String)
.protected String
finishJavaFieldNameGeneration
(String fieldName) Allows post-processing of the Java identifier generated bygenerateJavaFieldName(String, String)
.protected String
finishJavaFluentHelperClassNameGeneration
(String className) Allows post-processing of the Java identifier generated bygenerateJavaFluentHelperClassName(String, String)
.protected String
finishJavaMethodNameGeneration
(String methodName) Allows post-processing of the Java identifier generated bygenerateJavaMethodName(String)
.protected String
finishJavaMethodParameterNameGeneration
(String parameterName) Allows post-processing of the Java identifier generated bygenerateJavaMethodParameterName(String, String)
.protected String
finishJavaNavigationPropertyConstantNameGeneration
(String constantName) Allows post-processing of the Java identifier generated bygenerateJavaNavigationPropertyConstantName(String)
.protected String
Allows post-processing of the Java identifier generated bygenerateJavaNavigationPropertyFieldName(String)
.protected String
finishJavaOperationMethodNameGeneration
(String methodName) Allows post-processing of the Java identifier generated bygenerateJavaOperationMethodName(String, String)
.protected final String
Removes underscores ("_"
) from in between the letters on acronyms from the givenname
.Called by the VDM generator to convert the name and the label of an OData navigation property into a Lombok builder method name.generateJavaClassName
(String name, String label) Called by the VDM generator to convert the name and the label of an OData entity type into a suitable Java class name.generateJavaConstantName
(String name, String label) Called by the VDM generator to convert the property name and the label of an OData entity type into a suitable Java constant (public static final
) name.generateJavaFieldName
(String name, String label) Called by the VDM generator to convert the name and the label of a property within an OData entity type into a suitable Java member variable name.generateJavaFluentHelperClassName
(String name, String label) Called by the VDM generator to convert the name and the label of an OData operation (e.g.generateJavaMethodName
(String name) Called by the VDM generator to convert the name and the label of an OData navigation property into a partial Java method name.generateJavaMethodParameterName
(String name, String label) Called by the VDM generator to convert the name and the label of an OData operation (e.g.Called by the VDM generator to convert the name and the label of an OData navigation property into a suitable Java constant (public static final
) name.Called by the VDM generator to convert the name and the label of an OData navigation property into a suitable Java member variable name.generateJavaOperationMethodName
(String name, String label) Called by the VDM generator to convert the name and the label of an OData operation (e.g.Returns theNameSource
used by thisNamingStrategy
.boolean
isReservedKeyword
(String name) Determines whether theproposedName
is a language reserved keyword.protected final String
Removes all characters that are not valid Java syntax from the givenname
.protected final String
Removes repeated underscores ("_"
) from the givenname
.protected final String
removeWhiteSpaces
(String name) Removes all white spaces from the givenname
.void
setNameSource
(NameSource nameSource) Sets theNameSource
that should be used by thisNamingStrategy
.protected final void
throwIfConversionResultIsNullOrEmpty
(String conversionInputName, String conversionInputLabel, CharSequence conversionOutput, String conversionTarget) protected final void
throwIfConversionResultIsReservedKeyword
(String conversionInputName, String conversionInputLabel, String conversionOutput, String conversionTarget) Throws anIllegalStateException
if the givenconversionOutput
is a reserved keyword.protected final String
Converts a leading acronym into lower case format.
-
Constructor Details
-
AbstractNamingStrategy
-
AbstractNamingStrategy
public AbstractNamingStrategy()
-
-
Method Details
-
isReservedKeyword
Description copied from interface:NamingStrategy
Determines whether theproposedName
is a language reserved keyword.- Specified by:
isReservedKeyword
in interfaceNamingStrategy
- Parameters:
name
- String to check- Returns:
true
ifproposedName
is a reserved keyword,false
otherwise.
-
generateJavaClassName
Description copied from interface:NamingStrategy
Called by the VDM generator to convert the name and the label of an OData entity type into a suitable Java class name. The resulting name is used to generate the following:- Class that represents the entity type
- Entity retrieval fluent helpers (
...FluentHelper
and...ByKeyFluentHelper
) - Entity modification fluent helpers (
...CreateFluentHelper
,...UpdateFluentHelper
,...DeleteFluentHelper
)
- Specified by:
generateJavaClassName
in interfaceNamingStrategy
- Parameters:
name
- Provided by the VDM generator. It reads the Name attribute value of an EntityType tag in the metadata file.label
- Provided by the VDM generator. I reads the sap:label attribute of an EntityType tag in the metadata file.- Returns:
- A suitable Java class name that the VDM generator will use to create new VDM classes.
-
finishJavaClassNameGeneration
Allows post-processing of the Java identifier generated bygenerateJavaClassName(String, String)
.- Parameters:
className
- The Java class name to post-process.- Returns:
- The processed Java class name.
-
generateJavaFieldName
Description copied from interface:NamingStrategy
Called by the VDM generator to convert the name and the label of a property within an OData entity type into a suitable Java member variable name. These are the members of VDM entity classes that hold the values of entity properties.- Specified by:
generateJavaFieldName
in interfaceNamingStrategy
- Parameters:
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a Property tag, which is within an EntityType tag.label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of a Property tag, which is within an EntityType tag.- Returns:
- A suitable Java member variable name that the VDM generator will use to create a member variable in the newly generated VDM entity class.
-
finishJavaFieldNameGeneration
Allows post-processing of the Java identifier generated bygenerateJavaFieldName(String, String)
.- Parameters:
fieldName
- The Java field name to post-process.- Returns:
- The processed Java field name.
-
generateJavaConstantName
Description copied from interface:NamingStrategy
Called by the VDM generator to convert the property name and the label of an OData entity type into a suitable Java constant (public static final
) name. These constants are the fluent helper fields and they end up in the newly generated VDM entity classes.- Specified by:
generateJavaConstantName
in interfaceNamingStrategy
- Parameters:
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a Property tag, which is within an EntityType tag.label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of a Property tag, which is within an EntityType tag.- Returns:
- A suitable Java constant name that the VDM generator will use to create a constant in the newly generated VDM entity class.
-
finishJavaConstantNameGeneration
Allows post-processing of the Java identifier generated bygenerateJavaConstantName(String, String)
.- Parameters:
constantName
- The Java constant name to post-process.- Returns:
- The processed Java constant name.
-
generateJavaMethodName
Description copied from interface:NamingStrategy
Called by the VDM generator to convert the name and the label of an OData navigation property into a partial Java method name. The generator uses the result to create the following methods in the VDM entity class for accessing an OData navigation property:- Retrieval methods -
fetch...()
,get...OrNull()
,get...OrFetch()
- Modification methods -
set...()
,add...()
- Specified by:
generateJavaMethodName
in interfaceNamingStrategy
- Parameters:
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a NavigationProperty tag, which is within an EntityType tag.- Returns:
- A suitable Java method name that the VDM generator will use to create methods in the newly generated VDM entity class.
- Retrieval methods -
-
finishJavaMethodNameGeneration
Allows post-processing of the Java identifier generated bygenerateJavaMethodName(String)
.- Parameters:
methodName
- The Java method name to post-process.- Returns:
- The processed Java method name.
-
generateJavaBuilderMethodName
Description copied from interface:NamingStrategy
Called by the VDM generator to convert the name and the label of an OData navigation property into a Lombok builder method name. The generator uses the result to augment the Lombok builder of a VDM entity class with methods to populate references to other VDM entities (navigation properties). For builder methods, a different naming convention should be used that is consistent with the Lombok builder pattern.- Specified by:
generateJavaBuilderMethodName
in interfaceNamingStrategy
- Parameters:
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a NavigationProperty tag, which is within an EntityType tag.- Returns:
- A suitable Java method name that the VDM generator will use to create a method in the builder inner class of newly generated VDM entity classes.
- See Also:
-
finishJavaBuilderMethodNameGeneration
Allows post-processing of the Java identifier generated bygenerateJavaBuilderMethodName(String)
.- Parameters:
methodName
- The Java method name to post-process.- Returns:
- The processed Java method name.
-
generateJavaOperationMethodName
@Nonnull public String generateJavaOperationMethodName(@Nonnull String name, @Nullable String label) Description copied from interface:NamingStrategy
Called by the VDM generator to convert the name and the label of an OData operation (e.g. (un-)bound actions or functions) into a suitable Java method name. The generator uses the result to create a method in the associated service class which calls the OData operation.- Specified by:
generateJavaOperationMethodName
in interfaceNamingStrategy
- Parameters:
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of an operation (e.g. FunctionImport inside the EntityContainer tag).label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of an operation (e.g. FunctionImport inside the EntityContainer tag).- Returns:
- A suitable Java method name that the VDM generator will use to create a method in the newly generated VDM service class.
-
finishJavaOperationMethodNameGeneration
Allows post-processing of the Java identifier generated bygenerateJavaOperationMethodName(String, String)
.- Parameters:
methodName
- The Java method name to post-process.- Returns:
- The processed Java method name.
-
generateJavaMethodParameterName
@Nonnull public String generateJavaMethodParameterName(@Nonnull String name, @Nullable String label) Description copied from interface:NamingStrategy
Called by the VDM generator to convert the name and the label of an OData operation (e.g. (un-)bound actions or functions) parameter into a suitable Java variable (method parameter) name. The generator uses the result to populate the method it created for the function import with the parameter.- Specified by:
generateJavaMethodParameterName
in interfaceNamingStrategy
- Parameters:
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a Parameter tag, which is within the operation tag (e.g. FunctionImport inside the EntityContainer tag).label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of a Parameter tag, which is within the operation tag (e.g. FunctionImport inside the EntityContainer tag).- Returns:
- A suitable Java variable name that the VDM generator will use to populate the function import method with parameters.
-
finishJavaMethodParameterNameGeneration
Allows post-processing of the Java identifier generated bygenerateJavaMethodParameterName(String, String)
.- Parameters:
parameterName
- The Java method parameter name to post-process.- Returns:
- The processed Java method parameter name.
-
generateJavaFluentHelperClassName
@Nonnull public String generateJavaFluentHelperClassName(@Nonnull String name, @Nullable String label) Description copied from interface:NamingStrategy
Called by the VDM generator to convert the name and the label of an OData operation (e.g. (un-)bound actions or functions) into a suitable Java class name. The generator uses the result to create a fluent helper class for calling an OData function import. This fluent helper is returned by the function import method in the associated VDM service class.- Specified by:
generateJavaFluentHelperClassName
in interfaceNamingStrategy
- Parameters:
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of an operation (e.g. FunctionImport inside the EntityContainer tag).label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of an operation (e.g. FunctionImport inside the EntityContainer tag).- Returns:
- A suitable Java class name that the VDM generator will use to create a function import fluent helper class.
-
finishJavaFluentHelperClassNameGeneration
Allows post-processing of the Java identifier generated bygenerateJavaFluentHelperClassName(String, String)
.- Parameters:
className
- The Java class name to post-process.- Returns:
- The processed Java class name.
-
convertToJavaClassName
Chooses between the givenname
andlabel
based on the usedNameSource
. The chosen string will then be converted into a syntactically valid Java class name.- Parameters:
name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.- Returns:
- A syntactically correct Java class name.
-
convertToJavaFieldName
Chooses between the givenname
andlabel
based on the usedNameSource
. The chosen string will then be converted into a syntactically valid Java field name.- Parameters:
name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.- Returns:
- A syntactically correct Java field name.
-
convertToJavaConstantName
Chooses between the givenname
andlabel
based on the usedNameSource
. The chosen string will then be converted into a syntactically valid Java constant name.- Parameters:
name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.- Returns:
- A syntactically correct Java constant name.
-
convertToJavaMethodName
Chooses between the givenname
andlabel
based on the usedNameSource
. The chosen string will then be converted into a syntactically valid Java method name.- Parameters:
name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.- Returns:
- A syntactically correct Java method name.
-
chooseBetweenNameAndLabel
- Parameters:
name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.- Returns:
- Either the
name
or thelabel
.
-
removeWhiteSpaces
Removes all white spaces from the givenname
.- Parameters:
name
- The name to modify.- Returns:
- The modified
name
.
-
removeInvalidJavaCharacters
Removes all characters that are not valid Java syntax from the givenname
.- Parameters:
name
- The name to modify.- Returns:
- The modified
name
.
-
uncapitalizeLeadingAcronym
Converts a leading acronym into lower case format.uncapitalizeLeadingAcronym("URLAddress") -> "urlAddress"
- Parameters:
name
- The name to modify.- Returns:
- The modified
name
.
-
removeRepeatedUnderscores
Removes repeated underscores ("_"
) from the givenname
.- Parameters:
name
- The name to modify.- Returns:
- The modified
name
.
-
fixAcronymsInConstantNames
Removes underscores ("_"
) from in between the letters on acronyms from the givenname
.fixAcronymsInConstantNames("U_R_L_ADDRESS") -> "URL_ADDRESS"
- Parameters:
name
- The name to modify.- Returns:
- The modofied
name
.
-
appendSuffixIfNameIsReservedKeyword
@Nonnull protected final String appendSuffixIfNameIsReservedKeyword(@Nonnull String name, @Nonnull String suffix) Appends the givensuffix
to the givenname
, if thename
is a reserved keyword.- Parameters:
name
- The name to modify.suffix
- The suffix to append, in case thename
is a reserved keyword.- Returns:
- The modified
name
.
-
throwIfConversionResultIsNullOrEmpty
protected final void throwIfConversionResultIsNullOrEmpty(@Nonnull String conversionInputName, @Nullable String conversionInputLabel, @Nullable CharSequence conversionOutput, @Nonnull String conversionTarget) - Parameters:
conversionInputName
- The original input name, taken for example from the name tag of an OData Entity, which was used for the conversion.conversionInputLabel
- The original input label, taken for example from the sap:label tag of an OData Entity, which was used for the conversion.conversionOutput
- The output of the conversion.conversionTarget
- The target type of the conversion. Example:"Java class name"
.
-
throwIfConversionResultIsReservedKeyword
protected final void throwIfConversionResultIsReservedKeyword(@Nonnull String conversionInputName, @Nullable String conversionInputLabel, @Nonnull String conversionOutput, @Nonnull String conversionTarget) Throws anIllegalStateException
if the givenconversionOutput
is a reserved keyword.- Parameters:
conversionInputName
- The original input name, taken for example from the name tag of an OData Entity, which was used for the conversion.conversionInputLabel
- The original input label, taken for example from the sap:label tag of an OData Entity, which was used for the conversion.conversionOutput
- The output of the conversion.conversionTarget
- The target type of the conversion. Example:"Java class name"
.
-
getNameSource
Description copied from interface:NamingStrategy
Returns theNameSource
used by thisNamingStrategy
.- Specified by:
getNameSource
in interfaceNamingStrategy
- Returns:
- The used
NameSource
.
-
setNameSource
Description copied from interface:NamingStrategy
Sets theNameSource
that should be used by thisNamingStrategy
.- Specified by:
setNameSource
in interfaceNamingStrategy
- Parameters:
nameSource
- TheNameSource
to use.
-