Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libRemoteServices / src / org / gvsig / remoteClient / wfs / edition / WFSTTransaction.java @ 18316

History | View | Annotate | Download (7.52 KB)

1
package org.gvsig.remoteClient.wfs.edition;
2

    
3
import java.util.ArrayList;
4

    
5
import org.gvsig.remoteClient.utils.CapabilitiesTags;
6
import org.gvsig.remoteClient.wfs.WFSOperation;
7
import org.gvsig.remoteClient.wfs.filters.FilterEncoding;
8

    
9
import com.sun.org.apache.bcel.internal.generic.NEWARRAY;
10

    
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
 *
13
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
 *
29
 * For more information, contact:
30
 *
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Ib??ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 *
37
 *      +34 963862235
38
 *   gvsig@gva.es
39
 *      www.gvsig.gva.es
40
 *
41
 *    or
42
 *
43
 *   IVER T.I. S.A
44
 *   Salamanca 50
45
 *   46005 Valencia
46
 *   Spain
47
 *
48
 *   +34 963163400
49
 *   dac@iver.es
50
 */
51
/* CVS MESSAGES:
52
 *
53
 * $Id$
54
 * $Log$
55
 *
56
 */
57
/**
58
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
59
 */
60
public abstract class WFSTTransaction {
61
        private ArrayList operations = null;
62
        private String typename = null;
63
        private String namespace = null;
64
        private String namespaceprefix = null;
65
        
66
        //Features Locked
67
        private ArrayList featuresLocked = null;        
68
        
69
        //Transaction message
70
        public String message = null;
71
        
72
        //Status
73
        public static final int STATUS_NO_EXECUTED = 0;
74
        public static final int STATUS_FAILED = 1;
75
        public static final int STATUS_SUCCESS = 2;
76
        private int status = 0;
77
                
78
        WFSTTransaction(){
79
                status = STATUS_NO_EXECUTED;        
80
                operations = new ArrayList();        
81
                featuresLocked = new ArrayList();
82
        }
83
        
84
        WFSTTransaction(String typename, String namespaceprefix, String namespace, ArrayList featuresLocked){
85
                status = STATUS_NO_EXECUTED;        
86
                operations = new ArrayList();
87
                this.typename = typename;
88
                this.namespaceprefix = namespaceprefix;
89
                this.namespace = namespace;
90
                this.featuresLocked = featuresLocked;
91
        }
92
        
93
        /**
94
         * Adds a delete operation
95
         * @param ids
96
         * The identifiers of the features to delete
97
         */
98
        public void addDeleteOperation(ArrayList ids){
99
                FilterEncoding fe = new FilterEncoding();
100
                fe.setQualified(true);
101
                for (int i=0 ; i<ids.size() ; i++){
102
                        fe.addFeatureById(ids.get(i));
103
                }
104
                operations.add(new WFSTDeleteOperation(typename, fe.toString()));                
105
        }
106
        
107
        /**
108
         * Adds a delete operation
109
         * @param id
110
         * The identifies of the feature to delete
111
         */
112
        public void addDeleteOperation(String id){
113
                ArrayList ids = new ArrayList();
114
                ids.add(id);
115
                addDeleteOperation(ids);                
116
        }
117
        
118
        /**
119
         * Adds a delete operation
120
          * @param gml
121
         * The new Feature
122
         */
123
        public void addInsertOperation(String gml){
124
                operations.add(new WFSTInsertOperation(typename, gml));                
125
        }
126
        
127
        /**
128
         * Adds a update operation
129
         * @param ids
130
         * The identifiers of the features to update
131
         * @param gml
132
         * The update operation
133
         */
134
        public void addUpdateOperation(ArrayList ids, String gml){
135
                FilterEncoding fe = new FilterEncoding();
136
                fe.setQualified(true);
137
                for (int i=0 ; i<ids.size() ; i++){
138
                        fe.addFeatureById(ids.get(i));
139
                }
140
                operations.add(new WFSTUpdateOperation(typename, fe.toString(), gml));                
141
        }
142
        
143
        /**
144
         * Adds a update operation
145
         * @param ids
146
         * The identifier of the feature to update
147
         * @param gml
148
         * The update operation
149
         */
150
        public void addUpdateOperation(String id, String gml){
151
                ArrayList ids = new ArrayList();
152
                ids.add(id);
153
                addUpdateOperation(ids,gml);                        
154
        }
155

    
156
        /**
157
         * @return the WFS version
158
         */
159
        protected abstract String getVersion();
160
        
161
        /**
162
         * @return the transaction schema location
163
         */
164
        protected abstract String getSchemaLocation();
165
        
166
        /**
167
         * @return the WFS-T request to execute
168
         * the transaction
169
         */
170
        public String getWFSTRequest(){
171
                StringBuffer request = new StringBuffer();
172
                request.append(getWFSTRequestStartHeader());
173
                request.append(getWFSTRequestLockID());
174
                for (int i=0 ; i<getOperationSize() ; i++){
175
                        WFSTOperation operation = getOperationAt(i);
176
                        request.append(operation.getRequest());
177
                }
178
                request.append(getWFSTRequestEndHeader());
179
                return request.toString();
180
        }        
181
        
182
        /**
183
         * Create the lockID request
184
         * @return
185
         */
186
        private Object getWFSTRequestLockID() {
187
                StringBuffer request = new StringBuffer();
188
                for (int i=0 ; i<featuresLocked.size() ; i++){
189
                        request.append("<" + WFSTTags.WFS_NAMESPACE_PREFIX + ":" + WFSTTags.WFST_LOCKID + ">" );
190
                        request.append(featuresLocked.get(i));
191
                        request.append("</" + WFSTTags.WFS_NAMESPACE_PREFIX + ":" + WFSTTags.WFST_LOCKID + ">" );
192
                }
193
                return request.toString();
194
        }
195

    
196
        /**
197
         * @return the XML header of the WFS Transaction 
198
         * request
199
         */
200
        private String getWFSTRequestStartHeader(){
201
                StringBuffer request = new StringBuffer();
202
                request.append(WFSTTags.XML_ROOT);
203
                request.append("<" + WFSTTags.WFS_NAMESPACE_PREFIX + ":");
204
                request.append(CapabilitiesTags.WFS_TRANSACTION + " ");
205
                request.append(CapabilitiesTags.VERSION + "=\"" + getVersion() + "\" ");
206
                request.append(WFSTTags.WFST_RELEASEACTION + "=\"ALL\" ");
207
                request.append(WFSTTags.WFST_SERVICE + "=\"WFS\" ");
208
                request.append(WFSTTags.XMLNS + ":" + WFSTTags.OGC_NAMESPACE_PREFIX);
209
                request.append("=\"" + WFSTTags.OGC_NAMESPACE + "\" ");
210
                request.append(WFSTTags.XMLNS + ":" + WFSTTags.WFS_NAMESPACE_PREFIX);
211
                request.append("=\"" + WFSTTags.WFS_NAMESPACE + "\" ");
212
                request.append(WFSTTags.XMLNS + ":" + WFSTTags.XML_NAMESPACE_PREFIX);
213
                request.append("=\"" + WFSTTags.XML_NAMESPACE + "\" ");
214
                request.append(WFSTTags.XMLNS + ":" + WFSTTags.GML_NAMESPACE_PREFIX);
215
                request.append("=\"" + WFSTTags.GML_NAMESPACE + "\" ");
216
                request.append(WFSTTags.XMLNS + ":" + namespaceprefix);
217
                request.append("=\"" + namespace + "\" ");
218
                request.append(WFSTTags.XML_NAMESPACE_PREFIX + ":" + WFSTTags.XML_SCHEMALOCATION);
219
                request.append("=\"" + WFSTTags.WFS_NAMESPACE + " ");
220
                request.append(getSchemaLocation());
221
                request.append("\">");
222
                return request.toString();
223
        }        
224
        
225
        /**
226
         * @return the end of the WFS Transaction request header
227
         */
228
        private String getWFSTRequestEndHeader(){
229
                StringBuffer request = new StringBuffer();
230
                request.append("</" + WFSTTags.WFS_NAMESPACE_PREFIX + ":");
231
                request.append(CapabilitiesTags.WFS_TRANSACTION + ">");
232
                return request.toString();
233
        }        
234
        
235
        /**
236
         * @return the operation size
237
         */
238
        public int getOperationSize() {
239
                return operations.size();
240
        }
241

    
242
        /**
243
         * Gets an operation
244
         * @param i
245
         * Operation position
246
         * @return
247
         * A operation
248
         */
249
        public WFSTOperation getOperationAt(int i){
250
                if (i>getOperationSize()){
251
                        return null;
252
                }
253
                return (WFSTOperation)operations.get(i);
254
        }
255
        
256
        /**
257
         * Adds a new operation
258
         * @param operation the operation to add
259
         */
260
        public void addOperation(WFSOperation operation) {
261
                operations.add(operation);
262
        }
263

    
264
        /**
265
         * @return the status
266
         */
267
        public int getStatus() {
268
                return status;
269
        }
270

    
271
        /**
272
         * @param status the status to set
273
         */
274
        public void setStatus(int status) {
275
                this.status = status;
276
        }
277

    
278
        /**
279
         * @return the message
280
         */
281
        public String getMessage() {
282
                return message;
283
        }
284

    
285
        /**
286
         * @param message the message to set
287
         */
288
        public void setMessage(String message) {
289
                this.message = message;
290
        }        
291
}