Study the code in drools-verifier-5.5.0.Final-sources.jar, package
org/drools/verifier/components, which will guide you to the "core"
classes used to represent rules. Note that the expression syntax has
been extended considerably since 5.2, with consequences as to the
complexity of the AST representing full (Java or MVEL) expressions.
All of this is in the "unstable" API, subject to change without
notice.
-W
On 23/01/2013, jeetendray <jeetcyb(a)gmail.com> wrote:
Let me explain my requirement again, if its unclear from my prev
email.
Ref DRL:
package drools
import drools.ProposalLight
rule Proposal bugdet rule
when
$obj : ProposalLight(proposalName.equals("Jeet") || proposalId
==
121)
then
$obj.addFailedRule("Proposal bugdet rule");
end;
I have a POJO ProposalLight with properties: proposalName, proposalId....
and more.
I have annotations on these properties in the class. So here's is what I
do:
1. Find the properties of POJO in the DRL which construct the condition.
e.g. proposalName and proposalId.
2. Apply logic based on annotation on these properties.
3. do further processing.
For step 1: I used to locate these properties in DRL using Drools 4.xx with
below code snippet. But since few of the classes have been deprecated in
Drools 5.5 hence can;t make use of ORConstriants & LiteralConstraints.
private Set<KeyValuePair> getRestrictedRules(RuleBase ruleBase) throws
PBAppException {
Set<KeyValuePair> restrictedRuleCollection = new
HashSet<KeyValuePair>();
Field alphaConstraintsField = unrestrictOrConstraints();
if (ruleBase != null) {
Package[] packages = ruleBase.getPackages();
if (!DSMGeneralUtil.isArrayEmptyOrNull(packages)) {
for (Package pack : packages) {
Rule[] rules = pack.getRules();
if (!DSMGeneralUtil.isArrayEmptyOrNull(rules)) {
for (Rule rule : rules) {
GroupElement groupElement = rule.getLhs();
List children = groupElement.getChildren();
if (!DSMGeneralUtil.isCollectionEmptyOrNull(children)) {
for (Object childrenObject : children) {
if (childrenObject instanceof Pattern) {
Pattern pattern = (Pattern) childrenObject;
List constraints = pattern.getConstraints();
if
(!DSMGeneralUtil.isCollectionEmptyOrNull(constraints)) {
for (Object constraintObject : constraints) {
LiteralConstraint literalConstraint = null;
OrConstraint orConstraint = null;
// if the rule is AND rule then we will find all the
// conditions as instances of LiteralConstraint.
if (constraintObject instanceof LiteralConstraint)
{
literalConstraint = (LiteralConstraint)
constraintObject;
if
(addFieldIfApplicable(restrictedRuleCollection,
literalConstraint,
rule.getName(), restrictedFieldNameGroup)) {
break;
}
// if the rule is OR rule then we will find all
the
// conditions as instances of OrConstraint.
} else if (constraintObject instanceof
OrConstraint)
{
orConstraint = (OrConstraint) constraintObject;
if
(getGeoRestrictedRulesForOrConstraints(restrictedRuleCollection,
orConstraint, rule.getName(),
alphaConstraintsField, restrictedFieldNameGroup)) {
break;
}
}
}
}
}
}
}
}
}
}
}
}
return restrictedRuleCollection;
}
some code from addFieldIfApplicable method:
Object fieldExtractorObject = literalConstraint.getFieldExtractor();
if (fieldExtractorObject instanceof ClassFieldExtractor) {
ClassFieldExtractor classFieldExtractor =
(ClassFieldExtractor)fieldExtractorObject;
String fieldName = classFieldExtractor.getFieldName(); // this is
what
i need
Thanks,
Jeetendra.
--
View this message in context:
http://drools.46999.n3.nabble.com/how-to-get-field-names-from-Rule-using-...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users