Re: [rules-users] Problem in using genrics with drools4.0.1.

2007-10-09 Thread Mark Proctor
Drools, and probably the underlying MVEL that the 'from' uses, has no 
understanding of Generics, so I expect thats your problem.


Mark
Gaurav2007 wrote:

HI ALL,

I am using drool 4.0.1 in my project.
I am facing problem in using generics feature of jdk1.5.

My objective is to perform validation on the basis of data type of variable.
for storing values of variable i have one Attribute Class it contains getter
setter for values of attribute and attributeId which is a string but value
of attribute is of deferent type so i am thinking to use generics here.

public class Attribute {

public String qualifiedName;


public T newValue;

public T oldValue;

public String getQualifiedName() {
return qualifiedName;
}

public void setQualifiedName(String qualifiedName) {
this.qualifiedName = qualifiedName;
}

public T getNewValue() {
return (T)newValue;
}

public void setNewValue(T newValue) {
this.newValue = newValue;
}

public T getOldValue() {
return oldValue;
}

public void setOldValue(T oldValue) {
this.oldValue = oldValue;
}
}


my rule for date comparison looks like:

//Date Comparison.
rule "W250.1 DateComparison"
when
$dto : DataProvider()
Attribute(newValue < "29-Oct-2007") from $dto.getValue("W250.1")
then
System.out.println ("Error in Date check \t");
end

DataProvider class it is responsible to give instance of attribute
corresponding to attributeId:

public class DataProvider {

HashMap fieldMap=new HashMap();

public DataProvider() {

populateMap();
}

public Attribute  getValue(String qualifiedName){

Attribute attribute = fieldMap.get(qualifiedName);
return attribute;
}

public void populateMap(){

Attribute attribute = new Attribute();
SimpleDateFormat format = new SimpleDateFormat("dd-MMM-");
   Date date;
try {
date = format.parse("27-Oct-2007");
attribute.setQualifiedName("W250.1");
attribute.setOldValue(date);
attribute.setNewValue(date);
fieldMap.put(attribute.getQualifiedName(),attribute);

}

catch (ParseException e) {
e.printStackTrace();
}

}
}

in this case i am getting exception:
Exception in thread "main" java.lang.ClassCastException: java.lang.String

when i am not using generics this rule is working fine.
but in this case how should i perform validation depending upon data type of
attribute.

can you please help me in solving this problem.

Thanks,
Gaurav Joshi

  



___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Problem in using genrics with drools4.0.1.

2007-10-08 Thread Gaurav2007

HI ALL,

I am using drool 4.0.1 in my project.
I am facing problem in using generics feature of jdk1.5.

My objective is to perform validation on the basis of data type of variable.
for storing values of variable i have one Attribute Class it contains getter
setter for values of attribute and attributeId which is a string but value
of attribute is of deferent type so i am thinking to use generics here.

public class Attribute {

public String qualifiedName;

public T newValue;

public T oldValue;

public String getQualifiedName() {
return qualifiedName;
}

public void setQualifiedName(String qualifiedName) {
this.qualifiedName = qualifiedName;
}

public T getNewValue() {
return (T)newValue;
}

public void setNewValue(T newValue) {
this.newValue = newValue;
}

public T getOldValue() {
return oldValue;
}

public void setOldValue(T oldValue) {
this.oldValue = oldValue;
}
}


my rule for date comparison looks like:

//Date Comparison.
rule "W250.1 DateComparison"
when
$dto : DataProvider()
Attribute(newValue < "29-Oct-2007") from $dto.getValue("W250.1")
then
System.out.println ("Error in Date check \t");
end

DataProvider class it is responsible to give instance of attribute
corresponding to attributeId:

public class DataProvider {

HashMap fieldMap=new HashMap();

public DataProvider() {
populateMap();
}

public Attribute  getValue(String qualifiedName){
Attribute attribute = fieldMap.get(qualifiedName);
return attribute;
}

public void populateMap(){
Attribute attribute = new Attribute();
SimpleDateFormat format = new SimpleDateFormat("dd-MMM-");
   Date date;
try {
date = format.parse("27-Oct-2007");
attribute.setQualifiedName("W250.1");
attribute.setOldValue(date);
attribute.setNewValue(date);
fieldMap.put(attribute.getQualifiedName(),attribute);

}
catch (ParseException e) {
e.printStackTrace();
}

}
}

in this case i am getting exception:
Exception in thread "main" java.lang.ClassCastException: java.lang.String

when i am not using generics this rule is working fine.
but in this case how should i perform validation depending upon data type of
attribute.

can you please help me in solving this problem.

Thanks,
Gaurav Joshi

-- 
View this message in context: 
http://www.nabble.com/Problem-in-using-genrics-with-drools4.0.1.-tf4586550.html#a13092212
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users