[rules-users] Drools function not working with Javassist facts
Ayush
ayush.vatsyayan at alcatel-lucent.com
Wed May 16 03:25:21 EDT 2012
Hello,
I'm trying to build a rule which accepts the dynamic facts. The dynamic
facts are created using the javassist API. The rule works fine when I'm
adding a single rule but as soon as I declare any function in the drl file
the rule doesn't compile.
*Following is the code sample for creating the dynamic facts.*
// creating class object
final ClassPool pool = ClassPool.getDefault ();
CtClass evalClass = pool.makeClass ("drools.dynamic.MyDynamicClass");
// creating class field
final CtField nameField = new CtField (CtClass.intType, "Count",
evalClass);
nameField.setModifiers (Modifier.PRIVATE);
evalClass.addField (nameField);
// creating getter for the above created field.
final CtMethod getter = CtNewMethod.getter ("getCount", nameField);
evalClass.addMethod (getter);
// creating setter for the above created field.
final CtMethod setter = CtNewMethod.setter ("setCount", nameField);
evalClass.addMethod (setter);
// finally creating class
final Class tempClass = evalClass.toClass ();
// creating class object
Object obj = tempClass.newInstance()
// inserting it in drools
droolsSession.insert(obj)
*Following is the rule *
rule "DynamicFactRule"
dialect "mvel"
when
$obj : MyDynamicClass()
then
$obj.setCount(8);
System.out.println("Count set is: "+$obj.getCount(8));
end
*This rule works fine but when I'm adding a function in drl file then it
throws error: *
1) Unable to resolve ObjectType 'MyDynamicClass'
2)Error importing : 'defaultpkg.LogMessage.logMessage'
*The function I added is*
function void logMessage() {
System.out.println("This is log message");
}
*Following is the environment I'm using*
- Drools 5.3.0
- JBoss 6.x
- JDK6
I looked at many approaches but I'm confused and out of soln, as none of it
is working. I also tried looking at Drools trait but it's going over my head
I'll highly appreciate if someone can please suggest what should be the
ideal approach to solve it.
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-function-not-working-with-Javassist-facts-tp3996584.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
More information about the rules-users
mailing list