01: package org.geotools.data.complex.filter;
02:
03: import java.util.Map;
04:
05: import org.apache.commons.jxpath.JXPathContext;
06: import org.geotools.factory.Hints;
07: import org.geotools.feature.IllegalAttributeException;
08: import org.geotools.filter.expression.PropertyAccessor;
09: import org.geotools.filter.expression.PropertyAccessorFactory;
10:
11: /**
12: * A {@link PropertyAccessorFactory} that returns a {@link PropertyAccessor}
13: * capable of evaluating single attribute names from a {@link Map}.
14: *
15: * @author Gabriel Roldan
16: *
17: */
18: public class MapPropertyAccessorFactory implements
19: PropertyAccessorFactory {
20:
21: /**
22: * Creates a property accessor for a particular class.
23: *
24: * @param type
25: * The type of object to be accessed.
26: * @param xpath
27: * The xpath expression to evaluate.
28: * @param target
29: * The kind of result we are expecting (ie Geometry)
30: * @param hints
31: * Hints to be used when creatign the accessor.
32: *
33: * @return The property accessor, or <code>null</code> if this factory
34: * cannot create an accessor for the specified type.
35: */
36: public PropertyAccessor createPropertyAccessor(Class type,
37: String xpath, Class target, Hints hints) {
38: if (Map.class.isAssignableFrom(type)) {
39: return MAP_ACCESSOR;
40: }
41: return null;
42: }
43:
44: private static PropertyAccessor MAP_ACCESSOR = new PropertyAccessor() {
45:
46: public boolean canHandle(Object object, String xpath,
47: Class target) {
48: return object instanceof Map;
49: }
50:
51: public Object get(Object object, String xpath, Class target)
52: throws IllegalArgumentException {
53: JXPathContext context = JXPathContext.newContext(object);
54: context.setLenient(true);
55: Object value = context.getValue(xpath);
56: return value;
57: }
58:
59: public void set(Object object, String xpath, Object value,
60: Class target) throws IllegalAttributeException,
61: IllegalArgumentException {
62: throw new IllegalAttributeException("not implemented");
63: }
64:
65: };
66: }
|