MENU

  /   Functions

Functions can be used in expressions (pattern) or from a snippet (freemarker or velocity) by using the generator context variable.

Functions with 1 parameter

  • firstLower

    example:

    <pattern>
    ...
      <class name="${firstLower(${object.name})}"
    ...
      </class>
    ...
    </pattern>
    
  • firstUpper¬†Makes the first letter a capital letter.
  • allLower
  • allUpper
  • camelToAllUpperUnderscore
  • getHibernateType
  • getActionType
  • packageToPath
  • length
  • propertyExists: Returns true if the property is present (referenced in the expression), otherwise – false.

    Example:

    <attribute name="${attribute.name}" foreach="attribute" access="rw">
      <library>javax.persistence.Column</library>
      <datatype>${attribute.type}</datatype>
      <annotation.getter>${snippet.java.annotation.jpa.column}</annotation.getter>
      <annotation.getter>${snippet.java.annotation.jpa.required}</annotation.getter>
      <annotation.getter evaluate="true">${snippet.java.annotation.hibernate.validator.length}</annotation.getter>
      <body condition="${propertyExists(${model.property.attribute.entity.default.value})}">${model.property.attribute.entity.default.value}</body>
      <setterBody>${snippet.java.model.operation.setter}</setterBody>
    </attribute>
  • getJavaType(String sxmiType): Returns the java type that belongs to the given sxmiType
  • getJavaWrapperClass(String sxmiType): Returns the wrapper class (Boolean, Short, Integer etc.) which is part of the java type that belongs to the given sxmiType
  • isPrimitiveJavaType(String sxmiType): Returns true if the java type that belongs to the sxmiType is a primitive type(boolean, short, int etc.), otherwise false

Functions with 2 parameters

  • getSetterName(String referenceType, String modelObjectName):
    Finds the name of the setter from referenceType of the property modelObjectName. It looks in all modelObjects for an object with name “referenceType”. From this object it looks for a reference with type “modelObjectName”. The setterName is constructed and returned from the name of this reference.example:

    <model>
       <object name="Object1">
    
         <reference name="myObject2" type="Object2" multiplicity="1..1" />
       </object>
    
       <object name="Object2">
         <reference name=myObject1 type="Object1" multiplicity="0..n" />
       </object>
    </model>

    getSetterName(“Object1”, “Object2”) = setMyObject2

    The reference to modelObjectName must have a multiplicity of 0..n or 1..n
    otherwise a InvalidPatternException is thrown

    @param referenceType object name (not reference!!) to look for
    @param modelObjectName reference with type modelObjectName to look for
    @return name of the setter for the reference
    @throws InvalidPatternException if model or reference not found

  • map(String mapName, String key):
  • getValue(String expression, String defaultValue):Evaluates the expression and returns defaultValue if the outcome of the expression is empty (nil or an empty string)
  • firstToken(String expression, String token):Evaluates the expression, divides the outcome by means of the given token (see java.lang.String.split(token)).
    Returns the 1st String from the array which that split produces
  • lastToken():Evaluates the expression, divides the outcome by means of the given token (see java.lang.String.split(token)).
    Returns the last String from the array which that split produces
  • getAttributeType(String objectname, String associationPath):Finds the type of the attribute which is specified in the last part of associationPath.@param objectname Name of object element to start associationPath
    @param associationPath
    @return Type (sxmi type) of attribute
    @throws InvalidPatternException thrown if objectElement is not a object or last part of associationPath is not a attributeAn associationPath is a path through the model: e.g. project.responsiblePerson.homeAddress
  • getReferenceType(String objectname, String associationPath):Finds the type of the reference which is specified in the last part of associationPath.@param objectname Name of object element to start associationPath
    @param associationPath
    @return Type (object name) of reference
    @throws InvalidPatternException thrown if objectElement is not a object or last part of associationPath is not a valid referenceAn associationPath is a path through the model: e.g. project.responsiblePerson.homeAddress
  • getLastElementFromAssociationPath(String associationPath, Element parentElement):Finds the last element by starting with parentElement and following all associations in associationPath.@param associationPath
    @param parentElement
    @return Element corresponding with last part of association path. It can be a attribute element or a reference element
    @throws InvalidPatternException thrown if association path does not contain a dot, or elements are not found when following associationPathAn associationPath is a path through the model: e.g. companyAddress.address.street

Functions with 3 parameters

  • getTokenByIndex(String expression, String token, String tokenNumberString):
    Finds a token in expression, by splitting expression using token as seperator. The tokenNumber is the number of token to find
    @param expression String to find token in
    @param token Token to use when splitting expression
    @param tokenNumberString Index of token array to return@return Found token
    @throws InvalidPatternException Thrown if token not found in expression or tokenNumber is larger than size of array of tokenized expression, or when tokenNumberString can not be converted to a integer