Class JavaNamingImpl

java.lang.Object
org.castor.xml.JavaNamingImpl
All Implemented Interfaces:
JavaNaming

public class JavaNamingImpl extends 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$
Author:
Joachim Grueneis
  • Field Details

    • UPPER_CASE_AFTER_UNDERSCORE_PROPERTY

      public static final String UPPER_CASE_AFTER_UNDERSCORE_PROPERTY
      The property name to use in the castor.properties file to specify the value of the upperCaseAfterUnderscore variable.
      See Also:
    • _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.
  • Constructor Details

    • JavaNamingImpl

      public JavaNamingImpl()
    • JavaNamingImpl

      public JavaNamingImpl(InternalContext context)
  • Method Details

    • 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.
      Specified by:
      isKeyword in interface JavaNaming
      Parameters:
      name - the name to check
      Returns:
      true if it is a keyword
    • isValidJavaIdentifier

      public final boolean isValidJavaIdentifier(String string)
      Returns true if the given String matches the production of a valid Java identifier.
      Specified by:
      isValidJavaIdentifier in interface JavaNaming
      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

      public final String toJavaClassName(String name)
      Cuts away a leading namespace prefix (if there is one in place).
      Specified by:
      toJavaClassName in interface JavaNaming
      Parameters:
      name - the XML name to convert to a Java name
      Returns:
      a name which follows Java naming conventions
    • toJavaMemberName

      public final String toJavaMemberName(String name)
      Appends a leading '_' and converts the given name to a java name.
      Specified by:
      toJavaMemberName in interface JavaNaming
      Parameters:
      name - the XML name to convert
      Returns:
      a Java member name starting with a leading _
    • toJavaMemberName

      public final String toJavaMemberName(String name, boolean useKeywordSubstitutions)
      Appends a leading '_' and converts the given name to a java name.
      Specified by:
      toJavaMemberName in interface JavaNaming
      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

      public final boolean isValidPackageName(String packageName)
      Checks if the given pacckage name is valid or not. Empty pacakge names are considered valid!
      Specified by:
      isValidPackageName in interface JavaNaming
      Parameters:
      packageName - name of package as String with periods
      Returns:
      true if package name is valid
    • packageToPath

      public final String packageToPath(String packageName)
      Converts the given Package name to it's corresponding Path. The path will be a relative path.
      Specified by:
      packageToPath in interface JavaNaming
      Parameters:
      packageName - the package name to convert
      Returns:
      a String containing the resulting patch
    • 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.
      Specified by:
      getQualifiedFileName in interface JavaNaming
      Parameters:
      fileName - The file name to be qualified.
      packageName - The package name to be used for qualifying.
      Returns:
      The qualified file path.
    • getPackageName

      public final String getPackageName(String className)
      Gets the package name of the given class name.
      Specified by:
      getPackageName in interface JavaNaming
      Parameters:
      className - The class name to retrieve the package name from.
      Returns:
      The package name or the empty String if className is null or does not contain a package.
    • extractFieldNameFromMethod

      public final String extractFieldNameFromMethod(Method method)
      Extracts the filed name part from the methods name. Mostly it cuts away the method prefix.
      Specified by:
      extractFieldNameFromMethod in interface JavaNaming
      Parameters:
      method - the Method to process
      Returns:
      the extracted field name
    • extractFieldNameFromField

      public final String extractFieldNameFromField(Field field)
      Extracts the field name part from the Field. Mostly it cuts away prefixes like '_'.
      Specified by:
      extractFieldNameFromField in interface JavaNaming
      Parameters:
      field - the Field to process
      Returns:
      The extracted field name.
    • isSetMethod

      public final boolean isSetMethod(Method method)
      Checks if the given method is a set method.
      Specified by:
      isSetMethod in interface JavaNaming
      Parameters:
      method - the Method to check
      Returns:
      true if it is a set method
    • isCreateMethod

      public final boolean isCreateMethod(Method method)
      Checks if the given method is a create method.
      Specified by:
      isCreateMethod in interface JavaNaming
      Parameters:
      method - the Method to check
      Returns:
      true if it is a create method
    • isGetMethod

      public final boolean isGetMethod(Method method)
      Checks if the given method is a get method.
      Specified by:
      isGetMethod in interface JavaNaming
      Parameters:
      method - the Method to check
      Returns:
      true if it is a get method
    • isIsMethod

      public final boolean isIsMethod(Method method)
      Checks if the given method is a 'is' method.
      Specified by:
      isIsMethod in interface JavaNaming
      Parameters:
      method - the Method to check
      Returns:
      true if it is a 'is' method
    • isAddMethod

      public final boolean isAddMethod(Method method)
      Checks if the given method is an add method.
      Specified by:
      isAddMethod in interface JavaNaming
      Parameters:
      method - the Method to check
      Returns:
      true if it is an add method
    • getAddMethodNameForField

      public final String getAddMethodNameForField(String fieldName)
      Generates the name of an add method for the given field name.
      Specified by:
      getAddMethodNameForField in interface JavaNaming
      Parameters:
      fieldName - the field name to generate a method name for
      Returns:
      the generated add method name
    • getCreateMethodNameForField

      public final String getCreateMethodNameForField(String fieldName)
      Generates the name of a set method for the given field name.
      Specified by:
      getCreateMethodNameForField in interface JavaNaming
      Parameters:
      fieldName - the field name to generate a method name for
      Returns:
      the generated set method name
    • getGetMethodNameForField

      public final String getGetMethodNameForField(String fieldName)
      Generates the name of a get method for the given field name.
      Specified by:
      getGetMethodNameForField in interface JavaNaming
      Parameters:
      fieldName - the field name to generate a method name for
      Returns:
      the generated get method name
    • getIsMethodNameForField

      public final String getIsMethodNameForField(String fieldName)
      Generates the name of an is method for the given field name.
      Specified by:
      getIsMethodNameForField in interface JavaNaming
      Parameters:
      fieldName - the field name to generate a method name for
      Returns:
      the generated is method name
    • getSetMethodNameForField

      public final String getSetMethodNameForField(String fieldName)
      Generates the name of a create method for the given field name.
      Specified by:
      getSetMethodNameForField in interface JavaNaming
      Parameters:
      fieldName - the field name to generate a method name for
      Returns:
      the generated create method name
    • getClassName

      public String getClassName(Class<?> clazz)
      Gets the class name without package part.
      Specified by:
      getClassName in interface JavaNaming
      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