2017-02-10 9 views
2

に出力を送信するには条件はどのように以下のDroolsのJava

import com.sample.TestExample; 
import com.sample.TestExample.Message; 

rule "Hello World" 
when 
    m : Message(product == Message.tv, myMessage : message) 
then 
    System.out.println(Message.tv); 
    System.out.println("Product Spec is:: Service.TV_SAT"); // This output i want send back to java  
end 

rule "GoodBye" 
when 
    n : Message(product == Message.smart, myMessage : message) 
then 
    System.out.println(Message.smart); 
    System.out.println("Product Spec is:: Service.SMARTOFFICE"); // This output i want send back to java 
end 

rule "Else condition" 
when 
    e : Message(product != TestExample.productClass) 
then 
    System.out.println(TestExample.productClass); 
    System.out.println("in drools else condition"); // This output i want send back to java 
end 

に基づいて私が使用しているDroolsのある私はセットを使用してみましたとメソッドを取得しますが、それは働いていません。

すべてのヘルプ

は、「Javaへ送り返す」で

+0

は私が使用してのように試してみましたセット機能---- >> m.setProductSpec( "Service.TV_SAT"); – kanni

答えて

0

こんにちは私のコードは、Javaコードで

のpublic staticクラスのメッセージを、以下の変更を行った後、働いている{

private String message; 

    public static String product; 
    public static String tv="TV_SAT"; 
    public static String smart="SMART_OFFICE"; 

    public static String productSpec; 

    public static int status; 

    public String getProduct(){ 
     return Message.product; 
    } 

    public String getMessage() { 
     return this.message; 
    } 

    public void setMessage(String message) { 
     this.message = message; 
    } 

    public void setProduct(String product){ 
     Message.product=product; 
    } 

    public void setProductSpec(String product){ 

     Message.productSpec=product; 
    } 

    public String getProductSpec(){ 

     return 
       Message.productSpec; 

    } 
} 
0

あなたが何を意味するかわからない:-)理解されるであろう。

あなたがする必要があるのは、この「出力」をどこに保存するかによって異なります。あなたがフィールドMessagemessageTextを持っている場合は、これが動作しない場合は、

m.setMessageText("your message"); 

、あなたはこのセッターを宣言していないかもしれないこともできますし、他のいくつかのミスを犯している可能性があります。

グローバルList<String>を使用して、このコレクションオブジェクトにメッセージテキストを追加することができます(詳細については、設定ツールの宣言を参照する必要があります)。グローバルを使用する方法のドキュメントを参照してください。

+0

返信いただきありがとうございます:-) 「Javaに戻す」とは、println()メソッドによって書き出された出力が、現在の出力を保持するjava変数に返されることを意味します。 set()メソッドの助けを借りて、出力を表示していますが、その値を保存する必要があります – kanni

+0

文書リンクを共有してください – kanni

+0

"変数[...]は現在の出力を保持しています"?セッターは通常は保存するので、セッターのように動作するものを呼び出します。 - "doc"はディストリビューションに付属するdrools_documentationです。あなたはあなたのシステム上にそれを持っています。 – laune

0

最終DRLファイルは以下の通りです:

package com.sample 

import com.sample.TestExample; 
import com.sample.TestExample.Message; 

global java.util.List statuses; 

rule "Hello World" 
    when 
     m : Message(product == Message.tv, myMessage : message) 
    then 
     System.out.println("Product Class::"+Message.tv); 
     m.setProductSpec("Service.TV_SAT"); 
end 

rule "GoodBye" 
    when 
     n : Message(product == Message.smart, myMessage : message) 
    then 
     System.out.println("Product Class::"+Message.smart); 
     n.setProductSpec("Service.SmartOffice"); 
end 

rule "Else condition" 
    when 
     e : Message(product != TestExample.productClass) 
    then 
     System.out.println(TestExample.productClass); 
     System.out.println("in drools else condition"); 
end  
関連する問題