-
Notifications
You must be signed in to change notification settings - Fork 17
Filters
According to the OSGi specification filters are defined using the “string representation of LDAP search filters”, which is a quite cumbersome and errorprone notation. ScalaModules offers the following easy and intuitive DSL.
All of the following except for the last one are binary operations. These take a String attribute and an Any value which is converted into a String by calling its toString method. The present operation is unary, i.e. only takes a String attribute.
- equal or ===
- approx or ~==
- >== or ge or greaterEqual
- <== or le or lessEqual
- ~ or present
Here are some examples:
"name" === "polite"
"value" === 1
"serviceLevel" >== 95
"experimental".present
~"experimental"
Often you only need a single filter operation. But of course ScalaModules lets you combine filter operations:
- && or and: Logical “and” (binary)
- || or or: Logical “or” (binary)
- ! or not: Logical “not” (unary)
Here are some examples:
"name" === "polite" && !("value" === 1) // Not recommended!
("name" === "polite") && !("value" === 1) // Recommended!
((("name" === "polite") and !("value" === 1)) or (~"experimental")) // Parentheses required!
Please be careful when creating complex filters: While Scala’s precedence rules ensure that (binary) filter operations have got higher precedence than (binary) combinations, e.g. === has got higher precedence than &&, you better should use parenthesis to make precedence explicit. If you prefer the “wordy” alternatives, e.g. equal and and instead of === and or you have to use parentheses anyway.