Thank you very much! I think I get that!

Best wishes

 


发件人: Scott Reed [mailto:[EMAIL PROTECTED]
发送时间: 2006年11月9 21:58
收件人: user@drools.codehaus.org
主题: Re: [drools-user] Unable to create Field Extractor

 

I can see how you were confused. You may use the full method name only for "non-getter" methods. If a method starts with "get" you must leave that off for the Drools engine to work. If you want Drools to call an accessor method that does not start with "get" you must use the complete method name. I am unsure what happens if you have two methods like toString() and getToString(), but I am guessing that it will call getToString().

张茂森's message received 11/9/2006 5:30 AM:

 

Hi Ali:

Yes, you are right!

 But in Drools’ user guide, it said this:

3.5.4.1. Field Constraints

Field constraints place constraints on the Fact objects for the rule engine to match/select out of working memory. They work comparing/evaluating "field" values from the fact object instances.

A "field" is not a field in the sense of a public or private member of a class. A field is an accessible method. If your model objects follow the java bean pattern, then fields are exposed using "getXXX" or "isXXX" methods (these are methods that take no arguments, and return something). You can access fields either by using the bean-name convention (so "getType" can be accessed as "type").

For example, refering to our Cheese class, the following : Cheese(type == ...) uses the getType() method on the a cheese instance. You can also access non getter methods, like "toString()" on the Object for instance (in which case, you do Cheese(toString == ..) - you use the full name of the method with correct capitalisation, but not brackets). Do please make sure that you are accessing methods that take no parameters, and are in-fact "accessors" (as in, they don't change the state of the object in a way that may effect the rules - remember that the rule engine effectively caches the results of its matching inbetween invocations to make it faster).

 

But I find it couldn’t work at all! Do I have a wrong understand?

Do you have some thoughts?

Thanks!

 

Reply via email to