Class InternationalStringDatatypeHelper

java.lang.Object
org.faktorips.codegen.dthelpers.AbstractDatatypeHelper
org.faktorips.codegen.dthelpers.InternationalStringDatatypeHelper
All Implemented Interfaces:
BaseDatatypeHelper<JavaCodeFragment>, DatatypeHelper

public class InternationalStringDatatypeHelper extends AbstractDatatypeHelper
  • Constructor Details

    • InternationalStringDatatypeHelper

      public InternationalStringDatatypeHelper(boolean useInterface)
  • Method Details

    • getDatatype

      public Datatype getDatatype()
      Description copied from interface: DatatypeHelper
      Returns the datatype this is a helper for.
      Specified by:
      getDatatype in interface BaseDatatypeHelper<JavaCodeFragment>
      Specified by:
      getDatatype in interface DatatypeHelper
      Overrides:
      getDatatype in class AbstractDatatypeHelper
    • getJavaClassName

      public String getJavaClassName()
      Description copied from interface: DatatypeHelper
      Returns the qualified Java class name the datatype represents.
    • setDatatype

      public void setDatatype(Datatype datatype)
      Description copied from interface: DatatypeHelper
      Sets the datatype this is a helper for. Introduced to enable setter based dependency injection, needed for example for Eclipse's extension point mechanism.
      Specified by:
      setDatatype in interface BaseDatatypeHelper<JavaCodeFragment>
      Specified by:
      setDatatype in interface DatatypeHelper
      Overrides:
      setDatatype in class AbstractDatatypeHelper
    • newInstance

      public JavaCodeFragment newInstance(String value)
      Description copied from interface: DatatypeHelper
      Returns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given value. If the value is null the fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object.
    • newInstanceFromExpression

      public JavaCodeFragment newInstanceFromExpression(String expression, boolean checkForNull)
      Returns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given expression. If the expression is null the fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object. When evaluated the expression must return a string

      In the implementation of InternationalStringDatatypeHelper we ignore the checkForNull because international string variables should never be null at all.

      Specified by:
      newInstanceFromExpression in interface BaseDatatypeHelper<JavaCodeFragment>
      Specified by:
      newInstanceFromExpression in interface DatatypeHelper
      Overrides:
      newInstanceFromExpression in class AbstractDatatypeHelper
      Parameters:
      expression - A Java source code expression that yields a String. Examples are a constant String like "FOO", a variable like foo or a method call like getÍd().
      checkForNull - true if this helper has to assume that the given expression can yield null or the empty string. Can be used to generate simpler code, if the null check is not necessary.
    • valueOfExpression

      protected JavaCodeFragment valueOfExpression(String valueExpression)
      Description copied from class: AbstractDatatypeHelper
      This method is supposed to be overridden by subclasses.

      It is used within the newInstanceFromExpression(String) method. It returns a JavaCodeFragment with sourcecode that creates an instance of the datatype's Java class with the given expression.

      If the expression is null the fragment's sourcecode is either the String "null" or the sourcecode to get an instance of the appropriate null object. Preconditions: Expression may not be null or empty. When evaluated the expression must return a String.

      Specified by:
      valueOfExpression in class AbstractDatatypeHelper
    • getToStringExpression

      public JavaCodeFragment getToStringExpression(String fieldName)
      Returns a JavaCodeFragment containing the code for converting the value (of the given field) to a string representation with respect to its data type. The String must be built so that it can be read using the valueOf-Expression. If the value is null, the toString-code will yield null as a result.

      The default implementation will call the values toString() method or return null . The default implementation for generic (extensible) data types will call the method defined using setToStringMethodName(). Custom DatatypeHelpers may override.

      For international string we do not use the string representation! We simply return the field name because every use of the international string should handle the type directly. This is a big difference to all other datatypes but is necessary to read and write international strings in a proper format.

      Specified by:
      getToStringExpression in interface BaseDatatypeHelper<JavaCodeFragment>
      Specified by:
      getToStringExpression in interface DatatypeHelper
      Overrides:
      getToStringExpression in class AbstractDatatypeHelper
      Parameters:
      fieldName - the name of the field in the generated class that should be converted to a string
      Returns:
      a JavaCodeFragment containing the toString() code.