Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Filters

hseeberger edited this page Sep 16, 2010 · 2 revisions

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.

Filter operations

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"

Combining filter operations

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.

Clone this wiki locally