svn-gvsig-desktop / tags / v2_0_0_Build_2020 / libraries / libRemoteServices / src / org / gvsig / remoteclient / wfs / edition / WFSTTransaction.java @ 33910
History | View | Annotate | Download (7.49 KB)
1 | 29678 | jpiera | package org.gvsig.remoteclient.wfs.edition; |
---|---|---|---|
2 | 18271 | jpiera | |
3 | import java.util.ArrayList; |
||
4 | |||
5 | 29678 | jpiera | import org.gvsig.remoteclient.utils.CapabilitiesTags; |
6 | import org.gvsig.remoteclient.wfs.WFSOperation; |
||
7 | 31835 | jpiera | import org.gvsig.remoteclient.wfs.filters.filterencoding.FilterEncoding; |
8 | 18271 | jpiera | |
9 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
10 | *
|
||
11 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
12 | *
|
||
13 | * This program is free software; you can redistribute it and/or
|
||
14 | * modify it under the terms of the GNU General Public License
|
||
15 | * as published by the Free Software Foundation; either version 2
|
||
16 | * of the License, or (at your option) any later version.
|
||
17 | *
|
||
18 | * This program is distributed in the hope that it will be useful,
|
||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
21 | * GNU General Public License for more details.
|
||
22 | *
|
||
23 | * You should have received a copy of the GNU General Public License
|
||
24 | * along with this program; if not, write to the Free Software
|
||
25 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
26 | *
|
||
27 | * For more information, contact:
|
||
28 | *
|
||
29 | * Generalitat Valenciana
|
||
30 | * Conselleria d'Infraestructures i Transport
|
||
31 | * Av. Blasco Ib??ez, 50
|
||
32 | * 46010 VALENCIA
|
||
33 | * SPAIN
|
||
34 | *
|
||
35 | * +34 963862235
|
||
36 | * gvsig@gva.es
|
||
37 | * www.gvsig.gva.es
|
||
38 | *
|
||
39 | * or
|
||
40 | *
|
||
41 | * IVER T.I. S.A
|
||
42 | * Salamanca 50
|
||
43 | * 46005 Valencia
|
||
44 | * Spain
|
||
45 | *
|
||
46 | * +34 963163400
|
||
47 | * dac@iver.es
|
||
48 | */
|
||
49 | /* CVS MESSAGES:
|
||
50 | *
|
||
51 | * $Id$
|
||
52 | * $Log$
|
||
53 | *
|
||
54 | */
|
||
55 | /**
|
||
56 | * @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
||
57 | */
|
||
58 | public abstract class WFSTTransaction { |
||
59 | private ArrayList operations = null; |
||
60 | private String typename = null; |
||
61 | private String namespace = null; |
||
62 | private String namespaceprefix = null; |
||
63 | |||
64 | //Features Locked
|
||
65 | private ArrayList featuresLocked = null; |
||
66 | |||
67 | //Transaction message
|
||
68 | public String message = null; |
||
69 | |||
70 | //Status
|
||
71 | public static final int STATUS_NO_EXECUTED = 0; |
||
72 | public static final int STATUS_FAILED = 1; |
||
73 | public static final int STATUS_SUCCESS = 2; |
||
74 | private int status = 0; |
||
75 | |||
76 | WFSTTransaction(){ |
||
77 | status = STATUS_NO_EXECUTED; |
||
78 | operations = new ArrayList(); |
||
79 | featuresLocked = new ArrayList(); |
||
80 | } |
||
81 | |||
82 | WFSTTransaction(String typename, String namespaceprefix, String namespace, ArrayList featuresLocked){ |
||
83 | status = STATUS_NO_EXECUTED; |
||
84 | operations = new ArrayList(); |
||
85 | this.typename = typename;
|
||
86 | this.namespaceprefix = namespaceprefix;
|
||
87 | this.namespace = namespace;
|
||
88 | this.featuresLocked = featuresLocked;
|
||
89 | } |
||
90 | |||
91 | /**
|
||
92 | * Adds a delete operation
|
||
93 | * @param ids
|
||
94 | * The identifiers of the features to delete
|
||
95 | */
|
||
96 | public void addDeleteOperation(ArrayList ids){ |
||
97 | FilterEncoding fe = new FilterEncoding();
|
||
98 | fe.setQualified(true);
|
||
99 | for (int i=0 ; i<ids.size() ; i++){ |
||
100 | fe.addFeatureById(ids.get(i)); |
||
101 | } |
||
102 | operations.add(new WFSTDeleteOperation(typename, fe.toString()));
|
||
103 | } |
||
104 | |||
105 | /**
|
||
106 | * Adds a delete operation
|
||
107 | * @param id
|
||
108 | * The identifies of the feature to delete
|
||
109 | */
|
||
110 | public void addDeleteOperation(String id){ |
||
111 | ArrayList ids = new ArrayList(); |
||
112 | ids.add(id); |
||
113 | addDeleteOperation(ids); |
||
114 | } |
||
115 | |||
116 | /**
|
||
117 | * Adds a delete operation
|
||
118 | * @param gml
|
||
119 | * The new Feature
|
||
120 | */
|
||
121 | public void addInsertOperation(String gml){ |
||
122 | operations.add(new WFSTInsertOperation(typename, gml));
|
||
123 | } |
||
124 | |||
125 | /**
|
||
126 | * Adds a update operation
|
||
127 | * @param ids
|
||
128 | * The identifiers of the features to update
|
||
129 | * @param gml
|
||
130 | * The update operation
|
||
131 | */
|
||
132 | public void addUpdateOperation(ArrayList ids, String gml){ |
||
133 | FilterEncoding fe = new FilterEncoding();
|
||
134 | fe.setQualified(true);
|
||
135 | for (int i=0 ; i<ids.size() ; i++){ |
||
136 | fe.addFeatureById(ids.get(i)); |
||
137 | } |
||
138 | operations.add(new WFSTUpdateOperation(typename, fe.toString(), gml));
|
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * Adds a update operation
|
||
143 | * @param ids
|
||
144 | * The identifier of the feature to update
|
||
145 | * @param gml
|
||
146 | * The update operation
|
||
147 | */
|
||
148 | public void addUpdateOperation(String id, String gml){ |
||
149 | ArrayList ids = new ArrayList(); |
||
150 | ids.add(id); |
||
151 | addUpdateOperation(ids,gml); |
||
152 | } |
||
153 | |||
154 | /**
|
||
155 | * @return the WFS version
|
||
156 | */
|
||
157 | protected abstract String getVersion(); |
||
158 | |||
159 | /**
|
||
160 | * @return the transaction schema location
|
||
161 | */
|
||
162 | protected abstract String getSchemaLocation(); |
||
163 | |||
164 | /**
|
||
165 | * @return the WFS-T request to execute
|
||
166 | * the transaction
|
||
167 | */
|
||
168 | public String getWFSTRequest(){ |
||
169 | StringBuffer request = new StringBuffer(); |
||
170 | request.append(getWFSTRequestStartHeader()); |
||
171 | request.append(getWFSTRequestLockID()); |
||
172 | for (int i=0 ; i<getOperationSize() ; i++){ |
||
173 | WFSTOperation operation = getOperationAt(i); |
||
174 | request.append(operation.getRequest()); |
||
175 | } |
||
176 | request.append(getWFSTRequestEndHeader()); |
||
177 | return request.toString();
|
||
178 | } |
||
179 | |||
180 | /**
|
||
181 | * Create the lockID request
|
||
182 | * @return
|
||
183 | */
|
||
184 | private Object getWFSTRequestLockID() { |
||
185 | StringBuffer request = new StringBuffer(); |
||
186 | 18290 | jpiera | // for (int i=0 ; i<featuresLocked.size() ; i++){
|
187 | // request.append("<" + WFSTTags.WFS_NAMESPACE_PREFIX + ":" + WFSTTags.WFST_LOCKID + ">" );
|
||
188 | // request.append(featuresLocked.get(i));
|
||
189 | // request.append("</" + WFSTTags.WFS_NAMESPACE_PREFIX + ":" + WFSTTags.WFST_LOCKID + ">" );
|
||
190 | // }
|
||
191 | 18271 | jpiera | return request.toString();
|
192 | } |
||
193 | |||
194 | /**
|
||
195 | * @return the XML header of the WFS Transaction
|
||
196 | * request
|
||
197 | */
|
||
198 | private String getWFSTRequestStartHeader(){ |
||
199 | StringBuffer request = new StringBuffer(); |
||
200 | request.append(WFSTTags.XML_ROOT); |
||
201 | request.append("<" + WFSTTags.WFS_NAMESPACE_PREFIX + ":"); |
||
202 | request.append(CapabilitiesTags.WFS_TRANSACTION + " ");
|
||
203 | request.append(CapabilitiesTags.VERSION + "=\"" + getVersion() + "\" "); |
||
204 | request.append(WFSTTags.WFST_RELEASEACTION + "=\"ALL\" ");
|
||
205 | request.append(WFSTTags.WFST_SERVICE + "=\"WFS\" ");
|
||
206 | request.append(WFSTTags.XMLNS + ":" + WFSTTags.OGC_NAMESPACE_PREFIX);
|
||
207 | request.append("=\"" + WFSTTags.OGC_NAMESPACE + "\" "); |
||
208 | request.append(WFSTTags.XMLNS + ":" + WFSTTags.WFS_NAMESPACE_PREFIX);
|
||
209 | request.append("=\"" + WFSTTags.WFS_NAMESPACE + "\" "); |
||
210 | request.append(WFSTTags.XMLNS + ":" + WFSTTags.XML_NAMESPACE_PREFIX);
|
||
211 | request.append("=\"" + WFSTTags.XML_NAMESPACE + "\" "); |
||
212 | request.append(WFSTTags.XMLNS + ":" + WFSTTags.GML_NAMESPACE_PREFIX);
|
||
213 | request.append("=\"" + WFSTTags.GML_NAMESPACE + "\" "); |
||
214 | request.append(WFSTTags.XMLNS + ":" + namespaceprefix);
|
||
215 | request.append("=\"" + namespace + "\" "); |
||
216 | request.append(WFSTTags.XML_NAMESPACE_PREFIX + ":" + WFSTTags.XML_SCHEMALOCATION);
|
||
217 | request.append("=\"" + WFSTTags.WFS_NAMESPACE + " "); |
||
218 | request.append(getSchemaLocation()); |
||
219 | request.append("\">");
|
||
220 | return request.toString();
|
||
221 | } |
||
222 | |||
223 | /**
|
||
224 | * @return the end of the WFS Transaction request header
|
||
225 | */
|
||
226 | private String getWFSTRequestEndHeader(){ |
||
227 | StringBuffer request = new StringBuffer(); |
||
228 | request.append("</" + WFSTTags.WFS_NAMESPACE_PREFIX + ":"); |
||
229 | request.append(CapabilitiesTags.WFS_TRANSACTION + ">");
|
||
230 | return request.toString();
|
||
231 | } |
||
232 | |||
233 | /**
|
||
234 | * @return the operation size
|
||
235 | */
|
||
236 | public int getOperationSize() { |
||
237 | return operations.size();
|
||
238 | } |
||
239 | |||
240 | /**
|
||
241 | * Gets an operation
|
||
242 | * @param i
|
||
243 | * Operation position
|
||
244 | * @return
|
||
245 | * A operation
|
||
246 | */
|
||
247 | public WFSTOperation getOperationAt(int i){ |
||
248 | if (i>getOperationSize()){
|
||
249 | return null; |
||
250 | } |
||
251 | return (WFSTOperation)operations.get(i);
|
||
252 | } |
||
253 | |||
254 | /**
|
||
255 | * Adds a new operation
|
||
256 | * @param operation the operation to add
|
||
257 | */
|
||
258 | public void addOperation(WFSOperation operation) { |
||
259 | operations.add(operation); |
||
260 | } |
||
261 | |||
262 | /**
|
||
263 | * @return the status
|
||
264 | */
|
||
265 | public int getStatus() { |
||
266 | return status;
|
||
267 | } |
||
268 | |||
269 | /**
|
||
270 | * @param status the status to set
|
||
271 | */
|
||
272 | public void setStatus(int status) { |
||
273 | this.status = status;
|
||
274 | } |
||
275 | |||
276 | /**
|
||
277 | * @return the message
|
||
278 | */
|
||
279 | public String getMessage() { |
||
280 | return message;
|
||
281 | } |
||
282 | |||
283 | /**
|
||
284 | * @param message the message to set
|
||
285 | */
|
||
286 | public void setMessage(String message) { |
||
287 | this.message = message;
|
||
288 | } |
||
289 | } |