The JetspeedBeanDefinitionFilter makes it possible to dynamically filter out a BeanDefinition
before it is registered in a Spring BeanFactory based on category meta data in the Spring configuration.
Categories definitions are loaded from one or more properties files and are simply sets of names to
evaluate bean definitions against. A categories set is a comma separated list of names.
Multiple sets of categories can be defined in the provided properties files, and also reference (include)
each other using standard ${property} syntax.
A specific property containing the categories to be used for filtering is defined through
method
#setCategoriesKey, or as JetspeedBeanDefinitionFilter.categoriesKey
property in one of the loaded property files, or as System (-D) parameter.
A System parameter is checked first, then the loaded properties and only as last resort the bean property itself.
The categories set to be used can also be set directly through the
#categories method.
Beans which needs to be matched against active categories must define a:
<meta key="j2:cat" value="<categories>"/>
meta value within the bean definition.
The bean categories value is parsed as a standard logical expression that can utilize the unary
NOT operator, the binary AND and OR operators, and parentheses. Categories within the expression are
substituted with TRUE and FALSE values depending on whether the category is defined for filtering
or not, respectively. The bean matches if the whole expression evaluates to TRUE.
Unmatched beans (having a "j2:cat" meta value expression that evaluates to FALSE) will not be registered
in the Spring beanFactory (see:
FilteringListableBeanFactory. By not defining an id or name attribute,
or a unique one not referenced by other beans with different (or no) set of categories, different versions
of a similar bean can be defined within a single Spring configuration file.
Additionally an alias can be defined as bean meta value, allowing multiple beans to
be defined using the same alias:
<meta key="j2:alias" value="<alias>"/>
Only a matched bean its alias will be registered and thereby able to be referenced by other beans
(on this dynamically created alias).
For this type of "enabling" only one of many possible beans definitions, these beans should
not define an id or name attribute directly, or only an unique one which is not referenced or
only referenced by other beans which have a "matching" j2:cat meta value.