SWF-832 - Reimplement MapAdaptableELResolver to not depend on MapELResolver el-api implementation

This commit is contained in:
Jeremy Grelle
2008-08-12 20:19:26 +00:00
parent e9d25ee4b6
commit 05c1bca58c
2 changed files with 131 additions and 19 deletions

View File

@@ -15,11 +15,14 @@
*/
package org.springframework.binding.expression.el;
import java.util.Iterator;
import java.util.Map;
import javax.el.ELContext;
import javax.el.ELException;
import javax.el.ELResolver;
import javax.el.MapELResolver;
import javax.el.PropertyNotFoundException;
import javax.el.PropertyNotWritableException;
import org.springframework.binding.collection.MapAdaptable;
@@ -27,35 +30,75 @@ import org.springframework.binding.collection.MapAdaptable;
* An {@link ELResolver} for properly resolving variables in an instance of {@link MapAdaptable}
* @author Jeremy Grelle
*/
public class MapAdaptableELResolver extends MapELResolver {
public class MapAdaptableELResolver extends ELResolver {
public Class getType(ELContext context, Object base, Object property) {
public Class getCommonPropertyType(ELContext context, Object base) {
if (base instanceof MapAdaptable) {
return super.getType(context, adapt(base), property);
} else {
return null;
return Object.class;
}
return null;
}
public Object getValue(ELContext context, Object base, Object property) {
if (base instanceof MapAdaptable) {
return super.getValue(context, adapt(base), property);
} else {
return null;
}
public Iterator getFeatureDescriptors(ELContext context, Object base) {
return null;
}
public boolean isReadOnly(ELContext context, Object base, Object property) {
if (base instanceof MapAdaptable) {
return super.isReadOnly(context, adapt(base), property);
} else {
return false;
public Class getType(ELContext context, Object base, Object property) throws NullPointerException,
PropertyNotFoundException, ELException {
if (context == null) {
throw new NullPointerException("The ELContext is null.");
}
if (base instanceof MapAdaptable) {
context.setPropertyResolved(true);
Object obj = adapt(base).get(property);
return (obj != null) ? obj.getClass() : null;
}
return null;
}
public void setValue(ELContext context, Object base, Object property, Object value) {
public Object getValue(ELContext context, Object base, Object property) throws NullPointerException,
PropertyNotFoundException, ELException {
if (context == null) {
throw new NullPointerException("The ELContext is null.");
}
if (base instanceof MapAdaptable) {
super.setValue(context, adapt(base), property, value);
context.setPropertyResolved(true);
return adapt(base).get(property);
}
return null;
}
public boolean isReadOnly(ELContext context, Object base, Object property) throws NullPointerException,
PropertyNotFoundException, ELException {
if (context == null) {
throw new NullPointerException("The ELContext is null.");
}
if (base instanceof MapAdaptable) {
context.setPropertyResolved(true);
}
return false;
}
public void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException,
PropertyNotFoundException, PropertyNotWritableException, ELException {
if (context == null) {
throw new NullPointerException("The ELContext is null.");
}
if (base instanceof MapAdaptable) {
context.setPropertyResolved(true);
try {
adapt(base).put(property, value);
} catch (UnsupportedOperationException e) {
throw new PropertyNotWritableException(e);
}
}
}