01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.wfs;
17:
18: import java.util.Iterator;
19: import java.util.List;
20:
21: import org.geotools.data.wfs.Action.UpdateAction;
22: import org.opengis.filter.Filter;
23: import org.opengis.filter.FilterFactory;
24: import org.geotools.factory.CommonFactoryFinder;
25: import org.geotools.filter.visitor.ClientTransactionAccessor;
26:
27: public class WFSTransactionAccessor implements
28: ClientTransactionAccessor {
29:
30: private List actions;
31: private static FilterFactory ff = CommonFactoryFinder
32: .getFilterFactory(null);
33:
34: WFSTransactionAccessor(List actions) {
35: this .actions = actions;
36: }
37:
38: /**
39: * Returns all the filters indicating deleted feature anded together. This is used to tell the server what features
40: * to NOT return.
41: *
42: * @return all the filters indicating deleted feature anded together.
43: */
44: public Filter getDeleteFilter() {
45: List l = actions;
46: Iterator i = l.iterator();
47: Filter deleteFilter = null;
48: while (i.hasNext()) {
49: Action a = (Action) i.next();
50: if (a.getType() == Action.DELETE) {
51:
52: if (deleteFilter == null)
53: deleteFilter = a.getFilter();
54: else
55: deleteFilter = ff.and(deleteFilter, a.getFilter());
56: }
57: }
58: return deleteFilter;
59: }
60:
61: /**
62: * Returns all the filters of updates that affect the attribute in the expression ored together.
63: *
64: * @param attributePath the xpath identifier of the attribute.
65: * @return all the filters of updates that affect the attribute in the expression ORed together.
66: */
67: public Filter getUpdateFilter(String attributePath) {
68: Iterator i = actions.iterator();
69: Filter updateFilter = null;
70: while (i.hasNext()) {
71: Action a = (Action) i.next();
72: if (a.getType() == Action.UPDATE) {
73: UpdateAction ua = (UpdateAction) a;
74: if (ua.getProperty(attributePath) != null) {
75: if (updateFilter == null)
76: updateFilter = a.getFilter();
77: else
78: updateFilter = ff.and(updateFilter, a
79: .getFilter());
80: }
81: }
82: }
83: return updateFilter;
84: }
85:
86: }
|