我有一个要求,它需要对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="&&"/>
<if lhs="cust.getCountry" rhs="null" operator="!=" logicaloperator="||"/>
<if lhs="cust.getCity" rhs="null" operator="!=" logicaloperator="&&"/>
<if lhs="cust.getPhone" rhs="null" operator="!=" logicaloperator="&&"/>
<if lhs="cust.getEmail" rhs="null" operator="!=" logicaloperator="&&"/>
<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)