.. ******************************************************************************* * MetaFactory.io R2 * Technical Documentation * * File name : EL_Functions.rst * Created by : Niels de Nies * Last update : 01-04-2021 * Updated by : Niels de Nies * * MetaFactory BV Amsterdam ******************************************************************************* .. include:: /inline-images.txt Functions ========= Functions can be used in expressions (patterns) or from a (Freemarker or Velocity) snippet by using the generator context variable. Based at the functionality we distinguish the following function categories: - String functions Globale beschrijving - Metadata functions Globale beschrijving - Miscellaneous Other String functions ---------------- .. list-table:: :widths: 20 80 20 :header-rows: 1 :class: tight-table * - Name - Description - Details * - allLower - Converts all characters to lower case. - * - allUpper - Converts all characters to upper case. - * - camelToAllUpperUnderscore - - * - firstLower - Converts the first character to lower case. Example: .. code-block:: ... ... ... - * - firstUpper - Converts the first character to upper case. - Metadata functions ------------------ .. list-table:: :widths: 20 80 20 :header-rows: 1 :class: tight-table * - Name - Description - Details * - Naam - Beschrijving - Miscellaneous ------------- .. list-table:: :widths: 20 80 20 :header-rows: 1 :class: tight-table * - Name - Description - Details * - extendsFromObject - Returns true if specified model object extends from some other object (using the extends attribute). - * - getActionType - - * - getHibernateType - - * - 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 - * - isParentOfObject - Returns true if there are model objects in the current model package which extends from the specified model object. - * - isPrimitiveJavaType(String sxmiType) - Returns true if the java type that belongs to the sxmiType is a primitive type(boolean, short, int etc.), otherwise false - * - length - - * - packageToPath - - * - propertyExists - Returns true if the property is present (referenced in the expression), otherwise – false. Example: .. code-block:: javax.persistence.Column ${attribute.type} ${snippet.java.annotation.jpa.column} ${snippet.java.annotation.jpa.required} ${snippet.java.annotation.hibernate.validator.length} ${model.property.attribute.entity.default.value} ${snippet.java.model.operation.setter} - * - 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. - * - 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 - * - 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 - * - getObjectName(String objectname, String associationPath) - Finds the name of the object, the last part of the associationPath it belongs to. When associationPath is contactPerson.workAddress.streetName, and the objectName is Relatation, and the Relation object has a reference named 'contactPerson' (the starting point of the associationPath) it returns the name of the object where streetName (model attribute) belongs to. In this case it returns Address and the Address model object has a attribute named streetName. - * - 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 An associationPath is a path through the model: e.g. project.responsiblePerson.homeAddress - @return Type : (object name) of reference - @throws InvalidPatternException Thrown if objectElement is not a object or last part of associationPath is not a valid reference. - * - 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: Example: .. code-block:: 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 - * - getValue(String expression, String defaultValue) - Evaluates the expression and returns defaultValue if the outcome of the expression is empty (nil or an empty string) - * - isAttribute(String objectname, String associationPath) - Checks the last element of the associationPath and returns true if it’s a model attribute - * - isReference(String objectname, String associationPath) - Checks the last element of the associationPath and returns true if it’s a model reference - * - 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 - * - map(String mapName, String key) - - * - 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 -