I had been thinking about EOQualifier ..... I even poked around a little in 
_EOQualifierParser with JD initially for ideas, but the only thing that drove 
me to check if there was some other simple boolean variable expression parser 
out there was the fact that I wanted to write concise boolean expressions such 
as:
        canCreateCustomers AND canViewCustomers AND NOT canViewMediaTemplates

... instead of the more verbose
        canCreateCustomers = 'true' AND canViewCustomers = 'true' AND NOT 
canViewMediaTemplates = 'true'

So, anyway, I revisited this this morning and with a little regex matching and 
replacement, I get the simplicity of EOQualifier evaluation on a KVC object 
that returns the value (true or false) of the boolean tokens and I get the 
desired concise boolean expression format as input.

The end result is I can take expression like this:
        canCreateCustomers AND canViewCustomers AND NOT canViewMediaTemplates

and by applying regex matching sth like this:

        public static String qualifierFormatFromBooleanExpression(String 
expression) {
                StringBuffer sb = new StringBuffer();
                Matcher matcher = 
Constants.PRIVILEGE_TOKEN_REGEX.matcher(expression);
                while( matcher.find()) {
                        String replacement = "(" + matcher.group() + " = 
'true')";
                        matcher.appendReplacement(sb, replacement);
                }
                matcher.appendTail(sb);
                return sb.toString();
        }

I convert to a qualifier format like this:
   (canCreateCustomers = 'true') AND (canViewCustomers = 'true') AND NOT 
(canViewMediaTemplates = 'true')

and I then simply make EOQualifier using EOQualifier.qualifierWithFormat( ...)

and get result using qualifier.evaluateWithObject( kvcObject )

where kvcObject evaluates the keys to true or false in a particular context

.... and it all works great, as well as being the simplest approach :-)

Thanks y'all for the idea/suggestion responses,

Regards, Kieran


On Oct 5, 2010, at 12:09 AM, Mike Schrag wrote:

> EOQualifier?
> 
> On Oct 5, 2010, at 12:03 AM, Kieran Kelleher wrote:
> 
>> Rather than reinvent the wheel, I am trying to find a real simple library or 
>> java class that will just do boolean expression only parsing and allow me to 
>> evaluate the value of the symbols to true or false (via callback or sth like 
>> that)
>> 
>> For example and expression might look like this:
>> 
>>      "(canViewFood && canEatFood) || (canBuyFood && !canCookFood)"
>> 
>> I want a lib or java class that will walk the expression, calling my method 
>> to evaluate whether each symbol (canViewFood, canEatFood, etc.) is true or 
>> false which logically would turn the expression into something like this:
>> 
>>      "(true && true) || (false && !true)"
>> 
>> 
>> and then evaluate the entire expression to be true or false.
>> 
>> Possible candidates:
>>      https://javacc.dev.java.net/
>>      http://sourceforge.net/projects/jep/
>> 
>> Anyone have experience with this kind of application requirement and would 
>> share opinions and/or experiences?
>> 
>> Regards, Kieran
>> 
>> 
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list      ([email protected])
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com
>> 
>> This email sent to [email protected]
> 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to