小编Vij*_*van的帖子

一个简单的设计模式来开发一个小规则引擎

我有一个要求,它需要对java值对象进行大量验证并生成结果.(我们不能使用我们公司的任何规则引擎应用程序,许多手续和许多问题需要回答).因此,我建议实现一个简单和可扩展的小规则引擎,而不是像在java代码中那样实现规则.要遵循哪种设计模式?

我在下面添加了一个粗略的xml结构,定义了规则.

  <rule-set>    
    <name>Example1</name>
    <description>Example rules defined</description>

    <beans>
        <bean class="com.example.Customer" alias="cust"/>
        <bean class="com.example.Account" alias="acnt"/>
        <bean class="com.example.Transaction" alias="trans"/>
    </beans>

    <rule name="CustomerInfo" description="This rule validates if all the customer values are present">
        <if lhs="cust.getFirstName" rhs="null" operator="!="/>
        <if lhs="cust.getLastName" rhs="null" operator="!=" logicaloperator="&amp;&amp;"/>
        <if lhs="cust.getCountry" rhs="null" operator="!=" logicaloperator="||"/>
        <if lhs="cust.getCity" rhs="null" operator="!=" logicaloperator="&amp;&amp;"/>
        <if lhs="cust.getPhone" rhs="null" operator="!=" logicaloperator="&amp;&amp;"/>
        <if lhs="cust.getEmail" rhs="null" operator="!=" logicaloperator="&amp;&amp;"/>
        <then do="cust.completeFlag" arg1="true"/>
    </rule>

    <rule name="Transaction" description="Transfer the money from one ac to another">
        <if lhs="trans.fromAccount" operator="!=" rhs="null"/>
        <if lhs="trans.toAccount" operator="!=" …
Run Code Online (Sandbox Code Playgroud)

java rule-engine

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×1

rule-engine ×1