01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.wfs.xml.filter.v1_1;
06:
07: import org.geotools.xml.ElementInstance;
08: import org.geotools.xml.Node;
09: import org.opengis.filter.Filter;
10: import org.opengis.filter.FilterFactory;
11: import org.opengis.filter.Id;
12: import org.opengis.filter.identity.Identifier;
13: import java.util.HashSet;
14: import java.util.Iterator;
15:
16: public class FilterTypeBinding extends
17: org.geotools.filter.v1_1.FilterTypeBinding {
18: public FilterTypeBinding(FilterFactory filterFactory) {
19: super (filterFactory);
20: }
21:
22: public Object parse(ElementInstance instance, Node node,
23: Object value) throws Exception {
24: Filter filter = (Filter) super .parse(instance, node, value);
25:
26: //some checks, these should perhaps be made part of the Filter binding
27: if (filter instanceof Id) {
28: Id idFilter = (Id) filter;
29:
30: if (idFilter.getIdentifiers().size() > 1) {
31: //there should only be one type of id specified
32: HashSet types = new HashSet();
33:
34: for (Iterator i = idFilter.getIdentifiers().iterator(); i
35: .hasNext();) {
36: Identifier id = (Identifier) i.next();
37: types.add(id.getClass());
38: }
39:
40: if (types.size() != 1) {
41: throw new Exception(
42: "Only one type of Id can be supplied in a single filter");
43: }
44: }
45: }
46:
47: return filter;
48: }
49: }
|