SourceForge.net Logo

filter composing language

The filter composing language is a very simple logic language BERSERK interprets. It allows the use of the three basic logic connectors (and, or and not) and to explicitly specify the execution precedence (using parenthesis - ( and )).

This simple logic language allows the reuse of filter's code, by applying them in different circumstances. For instance, the same filter that checks if a user is accessing a service from the local network, can be used in different expressions in several filter chains, allowing to compose differente semantics for chains.

the grammar

  The grammar is given by the following regular expresions:

LPAREN ::= "(" ;
RPAREN ::= ")" ;
AND ::= "&&";
OR ::= "||"; 
NOT ::= "!";
LETTER ::= ("_" | "a" | [...] | "z" | "A" | [...] | "Z");
ALGARISM ::= ( "0" |"1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9");
LITERAL ::= LETTER (LETTER | ALGARISM)*;
WS ::= ( " " | "\r" | "\n" | "\t");
EXPR ::= ATOM ((AND|OR) ATOM)* EOF;
ATOM ::= LITERAL | NOT ATOM | LPAREN ATOM RPAREN;
							

EOF is the usual special character that signals the end of an input stream. Using the LITERAL token to specify the filters names, applications can build arbitrary filters combinations using conjunctions and disjunctions, allowing a high reuse of filters and/or criteria.

Those expressions (in the context of a filter chain) can also be reused by multiple services.

how to write filter chain expressions

Writing filter chain expressions is as easy as writing first order logic expressions. The only difference is that by BERSERK V1.0 the only predicates you have is 0-ary predicates. For predicates with parameters see News and Status page.

Predicate names are filters' names as in their configuration. For example if you have the following configuration:

<filterDefinitions>
	<filter>
		<idInternal>1</idInternal>
		<name>OnlyIntegers</name>
		<implementationClass>filters.RequesterIsIntegerFilter</implementationClass>
		<description>Checks if the requester can be converted to a java.lang.Integer</description>
		<isTransactional>false</isTransactional>
	</filter>
</filterDefinitions>						
						

You may use the OnlyIntegers predicate to invoke this specific filter.

To compose filters as you want, you have the AND (&&), OR (||), NOT (!). The execution priorities are specified, as usual with parenthesis (( and ) ).

For example if you had a filter named OnlyPositive you could compose the expression OnlyInteger && OnlyPositive and you would get a chain that would evaluate to true only when the requester were a positive integer. On the other hand if you composed the OnlyInteger || OnlyPositive the chain would evaluate to true for all positive numbers and for any negative integer.

Details about how BERSERK handle logical values of filters are exposed on the Exception Handling page.

© 2003, Gonçalo Luiz