开发者

Declare new type Jboss Drools

开发者 https://www.devze.com 2023-04-01 08:38 出处:网络
i need declare a new type in my drl like this example. package com.sample import com.sample.DroolsTest.Message;

i need declare a new type in my drl like this example.

package com.sample


import com.sample.DroolsTest.Message;

declare Variavel
    valor : Intege开发者_开发技巧r
end



rule "Hello World"
    when

        m : Message( status == Message.HELLO, myMessage : message )

-----> v : Variavel() Problem here, the variable is not instantiated

    then


        System.out.println( myMessage );
        m.setMessage( "Goodbye cruel world" );
        m.setStatus( Message.GOODBYE );
        update( m );
end

rule "GoodBye"
    when
        Message( status == Message.GOODBYE, myMessage : message )
    then
        System.out.println( myMessage );

end

My problem: I want use the variable without put this code

FactType personType = kbase.getFactType( "com.sample","Variavel" );
Object test = personType.newInstance();
                ksession.insert(test);

Its possible use the declared field without put this code when i fire the rule, like a static field?


A type declaration in Drools is like declaring a class in Java. You have the type there, but no instances. What you can do is have a higher priority rule instantiate and insert it as a fact instead of having the application doing it. E.g.:


declare Variavel
    valor : Integer
end

rule "create variable"
    salience 100
when
then
    insert( new Variavel() );
end

rule "Hello World"
when
    m : Message( status == Message.HELLO, myMessage : message )
    v : Variavel()
then
    // do something
end

0

精彩评论

暂无评论...
验证码 换一张
取 消