[rules-users] Getter/Setter Methods for declared types

droolster quant.coder at gmail.com
Fri Jun 28 03:49:35 EDT 2013


Hello,

At compile time, are the getter and setter methods automatically created for
a declared type. In the Drools Expert PDF it gives the following example:

declare Person
    name : String
    dateOfBirth : java.util.Date
    address : Address
end

and it states that the following class is generated:

public class Person implements Serializable {
     private String name;
     private java.util.Date dateOfBirth;
     private Address address;
     // empty constructor

    public Person() {...}
    // constructor with all fields
   
    public Person( String name, Date dateOfBirth, Address address ) {...}
    // if keys are defined, constructor with keys
   
    public Person( ...keys... ) {...}

    *// getters and setters*
    // equals/hashCode
    // toString
}

Then the setter is referenced as follows:

rule "Using a declared Type"
    when
       $p : Person( name == "Bob" )
    then

    // Insert Mark, who is Bob's mate.

   Person mark = new Person();
   *mark.setName("Mark");*
   insert( mark );
end

----

I tried the same with this simple declared type:

declare Foo
    bar : int
end

rule "abc"
    when
       some condition
    then
       Foo e = new Foo();
     * e.setBar = 2;*
       insert (e);
end

But the compiler complains indicating that it "cannot be resolved or is not
a field".

Do I need to specify the getter/setters in my DRL file explicitly?

Thank you for your help in advance.

Regards



--
View this message in context: http://drools.46999.n3.nabble.com/Getter-Setter-Methods-for-declared-types-tp4024609.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list