svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / fmap / dal / store / wfs / WFSStoreProvider.java @ 29326
History | View | Annotate | Download (6.69 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program 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
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.dal.store.wfs; |
29 |
|
30 |
import java.io.IOException; |
31 |
import java.util.List; |
32 |
|
33 |
import org.gvsig.fmap.dal.DALLocator; |
34 |
import org.gvsig.fmap.dal.DataManager; |
35 |
import org.gvsig.fmap.dal.DataServerExplorer; |
36 |
import org.gvsig.fmap.dal.DataStoreParameters; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.dal.exception.InitializeException; |
39 |
import org.gvsig.fmap.dal.exception.OpenException; |
40 |
import org.gvsig.fmap.dal.exception.ReadException; |
41 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
45 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
46 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer; |
47 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorerParameters; |
48 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
49 |
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider; |
50 |
import org.gvsig.remoteClient.wfs.WFSClient; |
51 |
import org.gvsig.remoteClient.wfs.WFSStatus; |
52 |
import org.gvsig.remoteClient.wfs.exceptions.WFSException; |
53 |
import org.gvsig.tools.ToolsLocator; |
54 |
import org.gvsig.tools.dynobject.DynClass; |
55 |
import org.gvsig.tools.dynobject.DynField; |
56 |
import org.gvsig.tools.dynobject.DynObjectManager; |
57 |
|
58 |
|
59 |
/**
|
60 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
61 |
*/
|
62 |
public class WFSStoreProvider extends GPEStoreProvider implements |
63 |
ResourceConsumer { |
64 |
public static String NAME = "WFSStore"; |
65 |
public static String DESCRIPTION = "WFS store to load WFS resources"; |
66 |
private static final String DYNCLASS_NAME = "WFSStore"; |
67 |
protected static DynClass DYNCLASS = null; |
68 |
|
69 |
//WFS Parameters
|
70 |
private WFSClient wfsClient = null; |
71 |
private WFSStatus wfsStatus = null; |
72 |
|
73 |
|
74 |
public WFSStoreProvider(DataStoreParameters params,
|
75 |
DataStoreProviderServices storeServices) |
76 |
throws InitializeException {
|
77 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
78 |
.createDynObject(DYNCLASS)); |
79 |
|
80 |
WFSStoreParameters wfsParameters = getWFSParameters(); |
81 |
try {
|
82 |
if (wfsParameters.getVersion() == null){ |
83 |
wfsClient = new WFSClient(wfsParameters.getUrl());
|
84 |
wfsParameters.setVersion(wfsClient.getVersion()); |
85 |
}else{
|
86 |
wfsClient = new WFSClient(wfsParameters.getUrl(), wfsParameters.getVersion());
|
87 |
} |
88 |
} catch (IOException e) { |
89 |
throw new InitializeException(e); |
90 |
} |
91 |
wfsStatus = new WFSStatus( wfsParameters.getFeatureType(),
|
92 |
wfsParameters.getFeaturePrefix()); |
93 |
wfsStatus.setNamespace(wfsParameters.getFeatureNamespace()); |
94 |
wfsStatus.setFields(wfsParameters.getFields()); |
95 |
//wfsStatus.setFilterQuery(wfsParameters.getFilterEncoding());
|
96 |
wfsStatus.setTimeout(wfsParameters.getTimeOut()); |
97 |
wfsStatus.setBuffer(wfsParameters.getMaxFeatures()); |
98 |
wfsStatus.setUserName(wfsParameters.getUser()); |
99 |
wfsStatus.setPassword(wfsParameters.getPassword()); |
100 |
} |
101 |
|
102 |
private WFSStoreParameters getWFSParameters() {
|
103 |
return (WFSStoreParameters) getParameters();
|
104 |
} |
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see org.gvsig.fmap.dal.store.gpe.GPEStoreProvider#open()
|
108 |
*/
|
109 |
public void open() throws OpenException { |
110 |
super.open();
|
111 |
try {
|
112 |
List featureTypes = this.getFeatureStore().getFeatureTypes(); |
113 |
for (int i=0 ; i<featureTypes.size() ; i++){ |
114 |
FeatureType featureType = (FeatureType)featureTypes.get(i); |
115 |
|
116 |
} |
117 |
} catch (DataException e) {
|
118 |
throw new OpenException("Reading the geometry type", e); |
119 |
} |
120 |
} |
121 |
|
122 |
protected static void registerDynClass() { |
123 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
124 |
DynClass dynClass; |
125 |
DynField field; |
126 |
if (DYNCLASS == null) { |
127 |
|
128 |
dynClass = dynman.add(DYNCLASS_NAME); |
129 |
dynClass.extend(dynman.get(FeatureStore.DYNCLASS_NAME)); |
130 |
|
131 |
DYNCLASS = dynClass; |
132 |
} |
133 |
|
134 |
} |
135 |
|
136 |
protected void retrieveFile() throws InitializeException{ |
137 |
try {
|
138 |
m_Fich = wfsClient.getFeature(wfsStatus, true, null); |
139 |
} catch (WFSException e) {
|
140 |
throw new InitializeException("Impossible to retrieve the file", e); |
141 |
} |
142 |
} |
143 |
|
144 |
/* (non-Javadoc)
|
145 |
* @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#getExplorer()
|
146 |
*/
|
147 |
public DataServerExplorer getExplorer() throws ReadException { |
148 |
DataManager manager = DALLocator.getDataManager(); |
149 |
WFSServerExplorerParameters params; |
150 |
try {
|
151 |
params = (WFSServerExplorerParameters) manager |
152 |
.createServerExplorerParameters(WFSServerExplorer.NAME); |
153 |
params.setUrl(wfsClient.getHost()); |
154 |
return manager.createServerExplorer(params);
|
155 |
} catch (Exception e) { |
156 |
throw new ReadException(this.getName(), e); |
157 |
} |
158 |
} |
159 |
|
160 |
|
161 |
/* (non-Javadoc)
|
162 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getName()
|
163 |
*/
|
164 |
public String getName() { |
165 |
return NAME;
|
166 |
} |
167 |
|
168 |
/* (non-Javadoc)
|
169 |
* @see org.gvsig.fmap.dal.store.gpe.GPEStoreProvider#createSet(org.gvsig.fmap.dal.feature.FeatureQuery)
|
170 |
*/
|
171 |
@Override
|
172 |
public FeatureSetProvider createSet(FeatureQuery query)
|
173 |
throws DataException {
|
174 |
executeQuery(query); |
175 |
return super.createSet(query); |
176 |
} |
177 |
|
178 |
/* (non-Javadoc)
|
179 |
* @see org.gvsig.fmap.dal.store.gpe.GPEStoreProvider#createSet(org.gvsig.fmap.dal.feature.FeatureQuery, org.gvsig.fmap.dal.feature.FeatureType)
|
180 |
*/
|
181 |
@Override
|
182 |
public FeatureSetProvider createSet(FeatureQuery query,
|
183 |
FeatureType featureType) throws DataException {
|
184 |
executeQuery(query); |
185 |
return super.createSet(query, featureType); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Executes a new query sending the FilterEncoding request to the server
|
190 |
* @param query
|
191 |
* The Query to send
|
192 |
* @throws InitializeException
|
193 |
* If there is a problem with the request or the parsing process
|
194 |
*/
|
195 |
private void executeQuery(FeatureQuery query) throws DataException{ |
196 |
// if (query.getFilter() instanceof FEIntersectsEvaluator){
|
197 |
// wfsStatus.setFilterQuery(((FEIntersectsEvaluator)query.getFilter()).getFilterEncoding());
|
198 |
// wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST);
|
199 |
// //Retrieve the new GML and parse it
|
200 |
// initialize(getStoreServices());
|
201 |
// }
|
202 |
} |
203 |
} |
204 |
|