Guided rules report error due to incorrect quotes around rule attribute values
------------------------------------------------------------------------------
Key: JBRULES-1578
URL:
http://jira.jboss.com/jira/browse/JBRULES-1578
Project: JBoss Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-brms, Eclipse IDE
Affects Versions: 4.0.4, 4.0.3
Environment: Windows XP SP2, Sun JRE 1.5.0_13
Reporter: Shahad Ahmed
Assigned To: Mark Proctor
In version 4.0.4, when using the guided editor in the eclipse plug-in or in the BRMS, if
you set any of the rule attributes Duration, Enabled, Auto-focus, or Lock-on-active in a
rule, then an error is reported when you save the rule in eclipse, or validate the rule in
the BRMS.
The problem can be illustrated by the following rule created in the guided editor:
WHEN
Integer [p]
+ intValue [is equal to][20]
THEN
Retract[p]
OPTIONS
Lock-on-active [x]
Setting the attribute lock-on-active results in the following error in eclipse, or when
validating the rule or building the rule package in the BRMS:
Format Name Message
brl test2 unknown:2:12 mismatched token:
[@6,25:30='"true"',<20>,2:12]; expecting type THEN
The problem appears to be due to drools incorrectly adding quotes around some of the rule
attribute values in the translated drl version of guided rules. For example, the
corresponding drl for the rule above in the "Generated DRL" tab of the eclipse
guided rule editor is incorrect as the lock-on-active attribute value true is in quotes
(i.e. "true"):
rule "test"
auto-focus "true"
dialect "mvel"
when
p : Integer( intValue == "10" )
then
retract( p );
end
It appears that for the enabled, auto-focus and lock-on-active attributes the Boolean
value of the argument is always incorrectly quoted in the generated DRL, and for Duration
the integer value is also quoted in the generated DRL. Similarly in the BRMS guided
editor, when you choose to view a rule or package source the attributes are quoted and the
package will not build in the BRMS, giving an error similar to the error above.
Note that although the eclipse plug-in reports an error, the generated .brl and .package
files are read and built by a PackageBuilder without an error. However, the problem is
more severe in the BRMS as the rule package will not build and always gives the error
shown earlier.
Looking at the source code, the problem may be in the toString() method of the following
class in the drools-compiler project:
drools-compiler\src\main\java\org\drools\brms\client\modeldriven\brl\RuleAttribute.java
In 4.0.4, the toString method only ensures the no-loop and salience attribute values are
not quoted, but always quotes values of attributes Duration, Enabled, Auto-focus, or
Lock-on-active. I can see that this problem has been partially fixed in the trunk now as
the toString method now ensures the Enabled attribute is not quoted, but I believe it
still fails to ensure that the Duration, auto-focus and lock-on-active attributes values
are not quoted. I fixed the problem in my own build by modifying the toString method as
follows:
public String toString() {
StringBuffer ret = new StringBuffer();
ret.append( this.attributeName );
if ( NOLOOP.equals( attributeName ) )
{
ret.append( " " );
ret.append( this.value == null ? "true" : this.value );
}
else if (SALIENCE.equals( this.attributeName ) ||
DURATION.equals( this.attributeName ))
{
ret.append( " " );
ret.append( this.value );
}
else if (ENABLED.equals( this.attributeName ) ||
AUTO_FOCUS.equals( this.attributeName ) ||
LOCK_ON_ACTIVE.equals( this.attributeName ))
{
ret.append( " " );
ret.append( this.value.equals("true") ? "true" :
"false" );
}
else if ( this.value != null ) {
ret.append( " \"" );
ret.append( this.value );
ret.append( "\"" );
}
return ret.toString();
}
Regards
Shahad
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira