Author: nbelaevski
Date: 2009-05-28 11:12:27 -0400 (Thu, 28 May 2009)
New Revision: 14395
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/ModifiableModel.java
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java
branches/community/3.3.X/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java
Log:
https://jira.jboss.org/jira/browse/RF-7204
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/ModifiableModel.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/ModifiableModel.java 2009-05-28
13:03:43 UTC (rev 14394)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/ModifiableModel.java 2009-05-28
15:12:27 UTC (rev 14395)
@@ -54,7 +54,7 @@
private Object key;
- public ExtendedJavaBeanWrapper(Object key, Object o, Map<String, Object> props)
{
+ public ExtendedJavaBeanWrapper(Object key, Object o, Map<Object, Object> props)
{
super(o, props);
this.key = key;
}
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java 2009-05-28
13:03:43 UTC (rev 14394)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/JavaBeanWrapper.java 2009-05-28
15:12:27 UTC (rev 14395)
@@ -29,18 +29,18 @@
*/
public class JavaBeanWrapper {
private Object wrappedObject;
- private Map<String, Object> properties;
+ private Map<Object, Object> properties;
- public JavaBeanWrapper(Object o, Map<String, Object> props) {
+ public JavaBeanWrapper(Object o, Map<Object, Object> props) {
wrappedObject = o;
properties = props;
}
- public Object getProperty(String expression) {
+ public Object getProperty(Object expression) {
return properties.get(expression);
}
- public Map<String, Object> getProperties() {
+ public Map<Object, Object> getProperties() {
return properties;
}
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java 2009-05-28
13:03:43 UTC (rev 14394)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/ObjectWrapperFactory.java 2009-05-28
15:12:27 UTC (rev 14395)
@@ -22,6 +22,7 @@
package org.richfaces.model.impl.expressive;
import java.util.HashMap;
+import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
@@ -51,7 +52,10 @@
public Object convert(Object o);
}
+ private Object[] expressionKeys;
private Expression [] expressions;
+ private boolean isIdentityKeys = false;
+
private FacesContext context;
private String var;
private Object varValue;
@@ -68,7 +72,8 @@
SortField[] sortFields = sortOrder.getFields();
expressions = new Expression[sortFields.length];
-
+ expressionKeys = new Object[expressions.length];
+
for (int i = 0; i < sortFields.length; i++) {
final SortField field = sortFields[i];
final String name = field.getName();
@@ -85,6 +90,8 @@
expressions[i] = new SimplePropertyExpression(name, elContext, resolver);
}
+
+ expressionKeys[i] = name;
}
@@ -92,6 +99,7 @@
}
public ObjectWrapperFactory(FacesContext context, final String var, List<? extends
Field> sortOrder) {
+ this.isIdentityKeys = true;
this.context = context;
Application application = context.getApplication();
@@ -100,6 +108,7 @@
this.var = var;
expressions = new Expression[sortOrder.size()];
+ expressionKeys = new Object[expressions.length];
int i = 0;
for (Field field : sortOrder) {
@@ -125,7 +134,11 @@
} else {
throw new IllegalArgumentException();
}
- expressions[i++] = expression;
+
+ expressions[i] = expression;
+ expressionKeys[i] = elExpression;
+
+ i++;
}
}
@@ -182,11 +195,18 @@
}
public JavaBeanWrapper wrapObject(Object o) {
- Map<String, Object> props = new HashMap<String, Object>();
+ Map<Object, Object> props;
+
+ if (isIdentityKeys) {
+ props = new IdentityHashMap<Object, Object>();
+ } else {
+ props = new HashMap<Object, Object>();
+ }
+
for (int i = 0; i < expressions.length; i++) {
Expression expression = expressions[i];
- props.put(expression.getExpressionString(), expression.evaluate(o));
+ props.put(expressionKeys[i], expression.evaluate(o));
}
return new JavaBeanWrapper(o, props);
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java 2009-05-28
13:03:43 UTC (rev 14394)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanComparator2.java 2009-05-28
15:12:27 UTC (rev 14395)
@@ -87,11 +87,10 @@
for (Iterator<SortField2> iterator = sortFields.iterator(); iterator.hasNext()
&& result == 0;) {
SortField2 field = iterator.next();
Expression expression = field.getExpression();
- String prop = expression.getExpressionString();
Ordering ordering = field.getOrdering();
if (ordering != null) {
- Object p1 = w1.getProperty(prop);
- Object p2 = w2.getProperty(prop);
+ Object p1 = w1.getProperty(expression);
+ Object p2 = w2.getProperty(expression);
if (p1 == p2 && p1 instanceof Comparator) {
result = ((Comparator<Object>)p1).compare(w1.getWrappedObject(),
w2.getWrappedObject());
} else if (p1 instanceof String && p2 instanceof String) {
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java
===================================================================
---
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java 2009-05-28
13:03:43 UTC (rev 14394)
+++
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/model/impl/expressive/WrappedBeanFilter.java 2009-05-28
15:12:27 UTC (rev 14395)
@@ -47,7 +47,7 @@
public boolean accept(JavaBeanWrapper wrapper) {
for (FilterField filterField : filterFields) {
if (filterField instanceof ExtendedFilterField) {
- Object property =
wrapper.getProperty(filterField.getExpression().getExpressionString());
+ Object property = wrapper.getProperty(filterField.getExpression());
String filterValue = ((ExtendedFilterField)filterField).getFilterValue();
if(filterValue != null) {
filterValue = filterValue.trim().toUpperCase(currentLocale);
@@ -58,7 +58,7 @@
}
}
} else {
- Object property =
wrapper.getProperty(filterField.getExpression().getExpressionString());
+ Object property = wrapper.getProperty(filterField.getExpression());
if(!((Boolean)property).booleanValue()) {
return false;
}
Modified:
branches/community/3.3.X/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java
===================================================================
---
branches/community/3.3.X/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java 2009-05-28
13:03:43 UTC (rev 14394)
+++
branches/community/3.3.X/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java 2009-05-28
15:12:27 UTC (rev 14395)
@@ -21,6 +21,7 @@
package org.richfaces.model.impl.expressive;
import java.util.HashMap;
+import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -38,6 +39,10 @@
private List<FilterField> filterFields;
private WrappedBeanFilter filter;
+
+ private MockValueExpression keyTrue = new MockValueExpression("keyTrue");
+ private MockValueExpression keyFalse = new MockValueExpression("keyFalse");
+
/**
* @param name
*/
@@ -51,7 +56,7 @@
protected void setUp() throws Exception {
super.setUp();
filterFields = new LinkedList<FilterField>();
- filterFields.add(new FilterField(new MockValueExpression("keyTrue")));
+ filterFields.add(new FilterField(keyTrue));
filter = new WrappedBeanFilter(filterFields);
}
@@ -62,6 +67,8 @@
super.tearDown();
filter = null;
filterFields = null;
+ keyTrue = null;
+ keyFalse = null;
}
/**
@@ -77,12 +84,12 @@
*/
public final void testAccept() {
TestObj obj = new TestObj("TestObj");
- Map<String, Object> props = new HashMap<String, Object>();
- props.put("keyTrue", Boolean.TRUE);
- props.put("keyFalse", Boolean.FALSE);
+ Map<Object, Object> props = new IdentityHashMap<Object, Object>();
+ props.put(keyTrue, Boolean.TRUE);
+ props.put(keyFalse, Boolean.FALSE);
JavaBeanWrapper wrapper = new JavaBeanWrapper(obj, props);
assertTrue(filter.accept(wrapper));
- filterFields.add(new FilterField(new MockValueExpression("keyFalse")));
+ filterFields.add(new FilterField(keyFalse));
assertFalse(filter.accept(wrapper));
}