-
Notifications
You must be signed in to change notification settings - Fork 4
/
FilterMockData.java
419 lines (323 loc) · 13 KB
/
FilterMockData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.filter.v1_1;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import javax.xml.namespace.QName;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.opengis.filter.And;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.Not;
import org.opengis.filter.Or;
import org.opengis.filter.PropertyIsEqualTo;
import org.opengis.filter.PropertyIsGreaterThan;
import org.opengis.filter.PropertyIsGreaterThanOrEqualTo;
import org.opengis.filter.PropertyIsLessThan;
import org.opengis.filter.PropertyIsLessThanOrEqualTo;
import org.opengis.filter.PropertyIsNotEqualTo;
import org.opengis.filter.expression.Add;
import org.opengis.filter.expression.Divide;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.Multiply;
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.expression.Subtract;
import org.opengis.filter.identity.GmlObjectId;
import org.opengis.filter.sort.SortBy;
import org.opengis.filter.sort.SortOrder;
import org.opengis.filter.spatial.Beyond;
import org.opengis.filter.spatial.Contains;
import org.opengis.filter.spatial.Crosses;
import org.opengis.filter.spatial.DWithin;
import org.opengis.filter.spatial.Disjoint;
import org.opengis.filter.spatial.Equals;
import org.opengis.filter.spatial.Intersects;
import org.opengis.filter.spatial.Overlaps;
import org.opengis.filter.spatial.Touches;
import org.opengis.filter.spatial.Within;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.gml3.GML;
/**
* Mock data class used for filter binding tests.
*
* @author Justin Deoliveira, The Open Planning Project
*
*
*
* @source $URL$
*/
public class FilterMockData {
static FilterFactory2 f = (FilterFactory2) CommonFactoryFinder.getFilterFactory(null);
static Element propertyName(Document document, Node parent) {
return propertyName("foo", document, parent);
}
static Element propertyName(String property, Document document, Node parent) {
Element propertyName = element(document, parent, OGC.PropertyName);
propertyName.appendChild(document.createTextNode(property));
return propertyName;
}
static PropertyName propertyName() {
return propertyName("foo");
}
static PropertyName propertyName(String property) {
return f.property(property);
}
static Element literal(Document document, Node parent) {
return literal("foo", document, parent);
}
static Element literal(String value, Document document, Node parent) {
Element literal = element(document, parent, OGC.Literal);
literal.appendChild(document.createTextNode(value));
return literal;
}
static Literal literal() {
return literal("foo");
}
static Literal literal(Object value) {
return f.literal(value);
}
static Element propertyIsEqualTo(Document document, Node parent) {
return binaryComparisonOp(document, parent, OGC.PropertyIsEqualTo);
}
static PropertyIsEqualTo propertyIsEqualTo() {
return f.equals(propertyName(), literal());
}
static Element propertyIsNotEqualTo(Document document, Node parent) {
return binaryComparisonOp(document, parent, OGC.PropertyIsNotEqualTo);
}
static PropertyIsNotEqualTo propertyIsNotEqualTo() {
return f.notEqual(propertyName(), literal(), false);
}
static Element propertyIsLessThan(Document document, Node parent) {
return binaryComparisonOp(document, parent, OGC.PropertyIsLessThan);
}
static PropertyIsLessThan propertyIsLessThan() {
return f.less(propertyName(), literal());
}
static Element propertyIsLessThanOrEqualTo(Document document, Node parent) {
return binaryComparisonOp(document, parent, OGC.PropertyIsLessThanOrEqualTo);
}
static PropertyIsLessThanOrEqualTo propertyIsLessThanOrEqualTo() {
return f.lessOrEqual(propertyName(), literal());
}
static Element propertyIsGreaterThan(Document document, Node parent) {
return binaryComparisonOp(document, parent, OGC.PropertyIsGreaterThan);
}
static PropertyIsGreaterThan propertyIsGreaterThan() {
return f.greater(propertyName(), literal());
}
static Element propertyIsGreaterThanOrEqualTo(Document document, Node parent) {
return binaryComparisonOp(document, parent, OGC.PropertyIsGreaterThanOrEqualTo);
}
static PropertyIsGreaterThanOrEqualTo propertyIsGreaterThanOrEqualTo() {
return f.greaterOrEqual(propertyName(), literal());
}
static Element binaryComparisonOp(Document document, Node parent, QName name) {
Element binaryComparisonOp = element(document, parent, name);
propertyName(document, binaryComparisonOp);
literal(document, binaryComparisonOp);
return binaryComparisonOp;
}
static Element and(Document document, Node parent) {
Element and = element(document, parent, OGC.And);
propertyIsEqualTo(document, and);
propertyIsNotEqualTo(document, and);
return and;
}
static And and() {
return f.and(propertyIsEqualTo(), propertyIsNotEqualTo());
}
static Element or(Document document, Node parent) {
Element or = element(document, parent, OGC.Or);
propertyIsEqualTo(document, or);
propertyIsNotEqualTo(document, or);
return or;
}
static Or or() {
return f.or(propertyIsEqualTo(), propertyIsNotEqualTo());
}
static Not not() {
return f.not(propertyIsEqualTo());
}
static Element not(Document document, Node parent) {
Element not = element(document, parent, OGC.Not);
propertyIsEqualTo(document, not);
return not;
}
static Beyond beyond() {
return f.beyond(f.property("the_geom"), f.literal(geometry()), 1.0d, "m");
}
static DWithin dwithin() {
return f.dwithin(f.property("the_geom"), f.literal(geometry()), 1.0d, "m");
}
static Element beyond(Document document, Node parent) {
return distanceBufferOperator(document, parent, OGC.Beyond);
}
static Element dwithin(Document document, Node parent) {
return distanceBufferOperator(document, parent, OGC.DWithin);
}
static Element distanceBufferOperator(Document document, Node parent, QName name) {
Element doperator = binarySpatialOperator(document, parent, name);
Element distance = element(document, doperator, new QName(OGC.NAMESPACE, "Distance"));
distance.appendChild(document.createTextNode("1.0"));
distance.setAttribute("units", "m");
return doperator;
}
static Element contains(Document document, Node parent) {
return binarySpatialOperator(document, parent, OGC.Contains);
}
static Contains contains() {
return f.contains(f.property("the_geom"), f.literal(geometry()));
}
static Element crosses(Document document, Node parent) {
return binarySpatialOperator(document, parent, OGC.Crosses);
}
static Crosses crosses() {
return f.crosses(f.property("the_geom"), f.literal(geometry()));
}
static Element disjoint(Document document, Node parent) {
return binarySpatialOperator(document, parent, OGC.Disjoint);
}
static Disjoint disjoint() {
return f.disjoint(f.property("the_geom"), f.literal(geometry()));
}
static Element equals(Document document, Node parent) {
return binarySpatialOperator(document, parent, OGC.Equals);
}
static Equals equals() {
return f.equal(f.property("the_geom"), f.literal(geometry()));
}
static Element intersects(Document document, Node parent) {
return binarySpatialOperator(document, parent, OGC.Intersects);
}
static Intersects intersects() {
return f.intersects(f.property("the_geom"), f.literal(geometry()));
}
static Element overlaps(Document document, Node parent) {
return binarySpatialOperator(document, parent, OGC.Overlaps);
}
static Overlaps overlaps() {
return f.overlaps(f.property("the_geom"), f.literal(geometry()));
}
static Element touches(Document document, Node parent) {
return binarySpatialOperator(document, parent, OGC.Touches);
}
static Touches touches() {
return f.touches(f.property("the_geom"), f.literal(geometry()));
}
static Element within(Document document, Node parent) {
return binarySpatialOperator(document, parent, OGC.Within);
}
static Within within() {
return f.within(f.property("the_geom"), f.literal(geometry()));
}
static Element binarySpatialOperator(Document document, Node parent, QName name) {
Element spatial = element(document, parent, name);
propertyName(document, spatial);
geometry(document, spatial);
return spatial;
}
static Geometry geometry() {
return new GeometryFactory().createPoint(new Coordinate(1, 1));
}
static Element geometry(Document document, Node parent) {
Element geometry = element(document, parent, GML.Point);
Element pos = element(document, geometry, GML.pos);
pos.appendChild(document.createTextNode("1 1"));
return geometry;
}
static Element envelope(Document document, Node parent) {
Element envelope = element(document, parent, GML.Envelope);
Element lower = element(document, envelope, new QName(GML.NAMESPACE, "lowerCorner"));
lower.appendChild(document.createTextNode("0 0"));
Element upper = element(document, envelope, new QName(GML.NAMESPACE, "upperCorner"));
upper.appendChild(document.createTextNode("1 1"));
return envelope;
}
static Element add(Document document, Node parent) {
return binaryExpression(document, parent, OGC.Add);
}
static Add add() {
return f.add(f.literal(1), f.literal(2));
}
static Element sub(Document document, Node parent) {
return binaryExpression(document, parent, OGC.Sub);
}
static Subtract sub() {
return f.subtract(f.literal(1), f.literal(2));
}
static Element mul(Document document, Node parent) {
return binaryExpression(document, parent, OGC.Mul);
}
static Multiply mul() {
return f.multiply(f.literal(1), f.literal(2));
}
static Element div(Document document, Node parent) {
return binaryExpression(document, parent, OGC.Div);
}
static Divide div() {
return f.divide(f.literal(1), f.literal(2));
}
static Element binaryExpression(Document document, Node parent, QName name) {
Element binaryExpression = element(document, parent, name);
literal(document, binaryExpression);
literal(document, binaryExpression);
return binaryExpression;
}
// Identifiers
static Element gmlObjectId(Document document, Node parent) {
Element gmlObjectId = element(document, parent, OGC.GmlObjectId);
gmlObjectId.setAttributeNS(GML.NAMESPACE, "id", "foo");
return gmlObjectId;
}
static GmlObjectId gmlObjectId() {
return f.gmlObjectId("foo");
}
//sorting
static Element sortBy(Document document, Node parent) {
Element sortBy = element(document, parent, OGC.SortBy);
sortProperty(document, sortBy);
sortProperty(document, sortBy);
return sortBy;
}
static SortBy[] sortBy() {
return new SortBy[] { sortProperty(), sortProperty() };
}
static Element sortProperty(Document document, Node parent) {
Element sortProperty = element(document, parent, new QName(OGC.NAMESPACE, "SortProperty"));
propertyName(document, sortProperty);
sortOrder(document, sortProperty);
return sortProperty;
}
static SortBy sortProperty() {
return f.sort("foo", SortOrder.ASCENDING);
}
static Element sortOrder(Document document, Node parent) {
Element sortOrder = element(document, parent, new QName(OGC.NAMESPACE, "SortOrder"));
sortOrder.appendChild(document.createTextNode("ASC"));
return sortOrder;
}
static Element element(Document document, Node parent, QName name) {
Element element = document.createElementNS(name.getNamespaceURI(), name.getLocalPart());
if (parent != null) {
parent.appendChild(element);
}
return element;
}
}