Copiar o linkLink copiado para a área de transferência!
Warning
The XML rule language has not been updated to support functionality introduced in Drools 5.x and is consider a deprecated feature.
As an option, JBoss Rules supports a "native" rule language as an alternative to DRL. This allows you to capture and manage your rules as XML data. Just like the non-XML DRL format, the XML format is parsed into the internal "AST" representation as fast as possible (using a SAX parser). There is no external transformation step required.
Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
Expand
Table 19.1. XML Elements
Name
Description
global
Defines global objects that can be referred to in the rules.
function
Contains a function declaration for a function to be used in the rules. You have to specify a return type, a unique name and parameters, in the body goes a snippet of code.
import
Imports the types you wish to use in the rule.
Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
This example rule has LHS and RHS (conditions and consequence) sections. The RHS is a block of semantic code that will be executed when the rule is activated. The LHS is slightly more complicated as it contains nested elements for conditional elements, constraints and restrictions:
Copiar o linkLink copiado para a área de transferência!
Expand
Table 19.2. XML Rule Elements
Element
Description
Pattern
This allows you to specify a type (class) and perhaps bind a variable to an instance of that class. Nested under the pattern object are constraints and restrictions that have to be met. The Predicate and Return Value constraints allow Java expressions to be embedded.
Conditional elements (not, exists, and, or)
These work like their DRL counterparts. Elements that are nested under and an "and" element are logically "anded" together. Likewise with "or" (and you can nest things further). "Exists" and "Not" work around patterns, to check for the existence or nonexistence of a fact meeting the pattern's constraints.
Eval
Allows the execution of a valid snippet of Java code as long as it evaluates to a boolean (do not end it with a semi-colon, as it is just a fragment). This can include calling a function. The Eval is less efficient than the columns, as the rule engine has to evaluate it each time, but it is a "catch all" feature for when you can express what you need to do with Column constraints.
Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
JBoss Rules comes with some utility classes to transform between formats. This works by parsing the rules from the source format into the AST and then "dumping" out to the appropriate target format. This allows you to, for example, write rules in DRL and export them to XML.
Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
These are the classes to use when transforming between XML and DRL files. Using combinations of these, you can convert between any format (including round trip):
DrlDumper - for exporting DRL
DrlParser - for reading DRL
XmlPackageReader - for reading XML
Note
DSLs will not be preserved (from DRLs that are using a DSL) - but they will be able to be converted.
Copiar o linkLink copiado para a área de transferência!
Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.
Tornando o open source mais inclusivo
A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.
Sobre a Red Hat
Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.