Skip to main content

OGNL expression Syntax

OGNL expressions in mapping

Expressions in the mapping files are interpreted as OGNL expressions.

OGNL syntax

/* Properties */
dataElement.name // property
dataElement["name"] // property as index
dataElement.equals(targetElement) // method call

/* Lists */
fields[0] // index
{ 'Ln01', 'Ln02' } // create list

/* Classes */
new net.demo.MyHelper() // constructor
@net.demo.MyUtils@getThing() // static method

OGNL Operators

e1 == e2, e1 eq e2 // equal
e1 != e2, e1 neq e2 // not equal
!e1, not e1 // boolean inverse
e1 || e2, e1 or e2 // boolean OR
e1 && e2, e1 and e2 // boolean AND

field in fields // list contains

e1 ? e2 : e3 // If-then-else

OGNL Lambdas

:[ e ] // Define lambda
fields.{ name } // map list
fields.{? linkField != null } // filter
fields.{^ name == 'name' } // first match
#this // current item, context
#root // root context of the expression

Composites

// Check if option is present
c.getOption("opt").defined
c.getOption("opt").empty
// Get option value
c.getOption("opt").value
c.getOption("opt").getValueOrElse("defaultValue")
c.getOption("opt").getValueOrElseGet(:[ lambda ])

// Get model extension
c.extensions["Ext"]

NSX functions

/* Strings */
s1.toUpper, s1.upper
s1.toLower, s1.lower
s1.firstToUpper, s1.firstToLower
s1.toPath, s1.path // package to path
s1.camelCase, s1.snakeCase, s1.pascalCase
s1.kebabCase, s1.kebab
format('Hello ${name}!') // template string

/* Lists */
l1.notEmpty
l1.flatten // [[a], [b, c]] => [a, b, c]
l1.exists(:[ predicate ]) // True if 1 item matches
l1.distinct // Remove duplicates
l1.reverse // In reverse order
l1.first // Get first item or throw
l1.firstOrNull // Get first item or null
l1.last // Get last item or throw
l1.lastOrNull // Get last item

Context Variables

expansionSource, dataElement // target element
component, application // ancestor elements
module, program // model context

expansionContext // context wrapper
expander // expander composite
feature, expanderFeature, expansionStep
expansionResource // ER manifest

/* Element lookup */
dataRegistry.getComposites("net.democr...")
/* Java Class name helper */
classBuilder.from(dataElement)
/* Predicate to filter elements */
filters.forLayer(layerType)
/* Get native type for field */
nativeTypes.get(field, concern, technology)
/* Check tag */
tags.on(dataElement).has('#tag1')
/* Check technology */
technologies.has('ANGULAR')