2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Apache > HiveMind
Font size:      

Conditional Contributions

In certain cases, it is desirable to conditionally contribute to a configuration point, or to a service point. One way of doing this is to factor the contributions into their own module, and control whether that module (and its descriptor) is on the classpath at runtime. This can be cumbersome, however.

A second method is to mark certain contributions (<contribution>, <implementation>, and <sub-module> elements) as conditional, using the if attribute.

When the if attribute is non-null, it is evaluated as a conditional expression. If the expression evaluates to true, then the contribution is used. If false, the the contribution is silently discarded. The expression evaluation occurs while the Registry is being constructed.

This mechanism allows you to test for certain conditions, such as the presense of a particular class or a particular JVM system property. These basic conditions can be combined with and, or and not operators, and parenthesis to control order of evaluation.

For example, the expression class org.springframework.beans.factory.BeanFactory would evaluate to true if the BeanFactory class was on the classpath.

The format for conditional expressions is:

expression := term or expression
           := term and expression
           := term
term       := ( expression )
           := not ( expression )
           := property symbol
           := class symbol

The keywords ("and", "or", "not", "property", "class") are not case sensitive.

Symbols are Java identifiers ... they are either JVM system properties or fully qualified Java class names. In addition, they may contain the dash character.

Whitespace is ignored.

The property keyword treats its symbol as a JVM system property, as with Boolean.getBoolean().

The class keyword treats its symbol as a Java class name, evaluating to true if such a class exists.