Class AbstractNamingStrategy

java.lang.Object
com.sap.cloud.sdk.datamodel.odata.utility.AbstractNamingStrategy
All Implemented Interfaces:
NamingStrategy
Direct Known Subclasses:
S4HanaNamingStrategy, SimpleNamingStrategy

@Beta public abstract class AbstractNamingStrategy extends Object implements NamingStrategy
Represents an abstract base implementation of the NamingStrategy. It provides convenience methods (such as convertToJavaClassName(String, String)) for inheritors to leverage.
  • Constructor Details

    • AbstractNamingStrategy

      public AbstractNamingStrategy(NameSource nameSource)
    • AbstractNamingStrategy

      public AbstractNamingStrategy()
  • Method Details

    • isReservedKeyword

      public boolean isReservedKeyword(@Nonnull String name)
      Description copied from interface: NamingStrategy
      Determines whether the proposedName is a language reserved keyword.
      Specified by:
      isReservedKeyword in interface NamingStrategy
      Parameters:
      name - String to check
      Returns:
      true if proposedName is a reserved keyword, false otherwise.
    • generateJavaClassName

      @Nonnull public String generateJavaClassName(@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 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 interface NamingStrategy
      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

      @Nonnull protected String finishJavaClassNameGeneration(@Nonnull String className)
      Allows post-processing of the Java identifier generated by generateJavaClassName(String, String).
      Parameters:
      className - The Java class name to post-process.
      Returns:
      The processed Java class name.
    • generateJavaFieldName

      @Nonnull public String generateJavaFieldName(@Nonnull String name, @Nullable String label)
      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 interface NamingStrategy
      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

      @Nonnull protected String finishJavaFieldNameGeneration(@Nonnull String fieldName)
      Allows post-processing of the Java identifier generated by generateJavaFieldName(String, String).
      Parameters:
      fieldName - The Java field name to post-process.
      Returns:
      The processed Java field name.
    • generateJavaConstantName

      @Nonnull public String generateJavaConstantName(@Nonnull String name, @Nullable String label)
      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 interface NamingStrategy
      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

      @Nonnull protected String finishJavaConstantNameGeneration(@Nonnull String constantName)
      Allows post-processing of the Java identifier generated by generateJavaConstantName(String, String).
      Parameters:
      constantName - The Java constant name to post-process.
      Returns:
      The processed Java constant name.
    • generateJavaNavigationPropertyFieldName

      @Nonnull public String generateJavaNavigationPropertyFieldName(@Nonnull String name)
      Description copied from interface: NamingStrategy
      Called by the VDM generator to convert the name and the label of an OData navigation property into a suitable Java member variable name. These are the members of VDM entity classes that hold references to other VDM entities (as defined by navigation properties in the metadata file).
      Specified by:
      generateJavaNavigationPropertyFieldName in interface NamingStrategy
      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 member variable name that the VDM generator will use to create a member variable in the newly generated VDM entity class.
    • finishJavaNavigationPropertyFieldNameGeneration

      @Nonnull protected String finishJavaNavigationPropertyFieldNameGeneration(@Nonnull String fieldName)
      Allows post-processing of the Java identifier generated by generateJavaNavigationPropertyFieldName(String).
      Parameters:
      fieldName - The Java field name to post-process.
      Returns:
      The processed Java field name.
    • generateJavaNavigationPropertyConstantName

      @Nonnull public String generateJavaNavigationPropertyConstantName(@Nonnull String name)
      Description copied from interface: NamingStrategy
      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. These constants are the fluent helper fields and they end up in the newly generated VDM entity classes.
      Specified by:
      generateJavaNavigationPropertyConstantName in interface NamingStrategy
      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 constant name that the VDM generator will use to create a constant in the newly generated VDM entity class.
    • finishJavaNavigationPropertyConstantNameGeneration

      @Nonnull protected String finishJavaNavigationPropertyConstantNameGeneration(@Nonnull String constantName)
      Allows post-processing of the Java identifier generated by generateJavaNavigationPropertyConstantName(String).
      Parameters:
      constantName - The Java constant name to post-process.
      Returns:
      The processed Java constant name.
    • generateJavaMethodName

      @Nonnull public String generateJavaMethodName(@Nonnull String name)
      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 interface NamingStrategy
      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.
    • finishJavaMethodNameGeneration

      @Nonnull protected String finishJavaMethodNameGeneration(@Nonnull String methodName)
      Allows post-processing of the Java identifier generated by generateJavaMethodName(String).
      Parameters:
      methodName - The Java method name to post-process.
      Returns:
      The processed Java method name.
    • generateJavaBuilderMethodName

      @Nonnull public String generateJavaBuilderMethodName(@Nonnull String name)
      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 interface NamingStrategy
      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

      @Nonnull protected String finishJavaBuilderMethodNameGeneration(@Nonnull String methodName)
      Allows post-processing of the Java identifier generated by generateJavaBuilderMethodName(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 interface NamingStrategy
      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

      @Nonnull protected String finishJavaOperationMethodNameGeneration(@Nonnull String methodName)
      Allows post-processing of the Java identifier generated by generateJavaOperationMethodName(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 interface NamingStrategy
      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

      @Nonnull protected String finishJavaMethodParameterNameGeneration(@Nonnull String parameterName)
      Allows post-processing of the Java identifier generated by generateJavaMethodParameterName(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 interface NamingStrategy
      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

      @Nonnull protected String finishJavaFluentHelperClassNameGeneration(@Nonnull String className)
      Allows post-processing of the Java identifier generated by generateJavaFluentHelperClassName(String, String).
      Parameters:
      className - The Java class name to post-process.
      Returns:
      The processed Java class name.
    • convertToJavaClassName

      @Nonnull protected String convertToJavaClassName(@Nonnull String name, @Nullable String label)
      Chooses between the given name and label based on the used NameSource. 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

      @Nonnull protected String convertToJavaFieldName(@Nonnull String name, @Nullable String label)
      Chooses between the given name and label based on the used NameSource. 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

      @Nonnull protected String convertToJavaConstantName(@Nonnull String name, @Nullable String label)
      Chooses between the given name and label based on the used NameSource. 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

      @Nonnull protected String convertToJavaMethodName(@Nonnull String name, @Nullable String label)
      Chooses between the given name and label based on the used NameSource. 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

      @Nonnull protected String chooseBetweenNameAndLabel(@Nonnull String name, @Nullable String label)
      Selects either the given name or the label based on the used NameSource.
      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 the label.
    • removeWhiteSpaces

      @Nonnull protected final String removeWhiteSpaces(@Nonnull String name)
      Removes all white spaces from the given name.
      Parameters:
      name - The name to modify.
      Returns:
      The modified name.
    • removeInvalidJavaCharacters

      @Nonnull protected final String removeInvalidJavaCharacters(@Nonnull CharSequence name)
      Removes all characters that are not valid Java syntax from the given name.
      Parameters:
      name - The name to modify.
      Returns:
      The modified name.
    • uncapitalizeLeadingAcronym

      @Nonnull protected final String uncapitalizeLeadingAcronym(@Nonnull String name)
      Converts a leading acronym into lower case format.

      Example: uncapitalizeLeadingAcronym("URLAddress") -> "urlAddress"
      Parameters:
      name - The name to modify.
      Returns:
      The modified name.
    • removeRepeatedUnderscores

      @Nonnull protected final String removeRepeatedUnderscores(@Nonnull String name)
      Removes repeated underscores ("_") from the given name.
      Parameters:
      name - The name to modify.
      Returns:
      The modified name.
    • fixAcronymsInConstantNames

      @Nonnull protected final String fixAcronymsInConstantNames(@Nonnull String name)
      Removes underscores ("_") from in between the letters on acronyms from the given name.

      Example: 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 given suffix to the given name, if the name is a reserved keyword.
      Parameters:
      name - The name to modify.
      suffix - The suffix to append, in case the name 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)
      Throws an IllegalStateException if the given conversionOutput is null or empty.
      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 an IllegalStateException if the given conversionOutput 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

      public NameSource getNameSource()
      Description copied from interface: NamingStrategy
      Returns the NameSource used by this NamingStrategy.
      Specified by:
      getNameSource in interface NamingStrategy
      Returns:
      The used NameSource.
    • setNameSource

      public void setNameSource(NameSource nameSource)
      Description copied from interface: NamingStrategy
      Sets the NameSource that should be used by this NamingStrategy.
      Specified by:
      setNameSource in interface NamingStrategy
      Parameters:
      nameSource - The NameSource to use.