root / 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 | 27885 | jpiera | /* 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 | 29292 | jmvivo | *
|
6 | 27885 | jpiera | * 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 | 29292 | jmvivo | *
|
11 | 27885 | jpiera | * 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 | 29292 | jmvivo | *
|
16 | 27885 | jpiera | * 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 | 29292 | jmvivo | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 27885 | jpiera | * MA 02110-1301, USA.
|
20 | 29292 | jmvivo | *
|
21 | 27885 | jpiera | */
|
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 | 28430 | jpiera | import java.io.IOException; |
31 | 27945 | jpiera | import java.util.List; |
32 | |||
33 | 27885 | jpiera | import org.gvsig.fmap.dal.DALLocator; |
34 | import org.gvsig.fmap.dal.DataManager; |
||
35 | import org.gvsig.fmap.dal.DataServerExplorer; |
||
36 | 29326 | jmvivo | import org.gvsig.fmap.dal.DataStoreParameters; |
37 | 27945 | jpiera | import org.gvsig.fmap.dal.exception.DataException; |
38 | 27885 | jpiera | import org.gvsig.fmap.dal.exception.InitializeException; |
39 | 27945 | jpiera | import org.gvsig.fmap.dal.exception.OpenException; |
40 | 27885 | jpiera | import org.gvsig.fmap.dal.exception.ReadException; |
41 | 29198 | jpiera | import org.gvsig.fmap.dal.feature.FeatureQuery; |
42 | 27885 | jpiera | import org.gvsig.fmap.dal.feature.FeatureStore; |
43 | 27945 | jpiera | import org.gvsig.fmap.dal.feature.FeatureType; |
44 | 29198 | jpiera | import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
45 | 27885 | jpiera | 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 | 29326 | jmvivo | import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
49 | 27885 | jpiera | 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 | 29326 | jmvivo | public WFSStoreProvider(DataStoreParameters params,
|
75 | DataStoreProviderServices storeServices) |
||
76 | 27885 | jpiera | throws InitializeException {
|
77 | 29326 | jmvivo | super(params, storeServices, ToolsLocator.getDynObjectManager()
|
78 | .createDynObject(DYNCLASS)); |
||
79 | 29200 | jpiera | |
80 | 29326 | jmvivo | WFSStoreParameters wfsParameters = getWFSParameters(); |
81 | 28430 | jpiera | 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 | 27885 | jpiera | wfsStatus = new WFSStatus( wfsParameters.getFeatureType(),
|
92 | wfsParameters.getFeaturePrefix()); |
||
93 | wfsStatus.setNamespace(wfsParameters.getFeatureNamespace()); |
||
94 | wfsStatus.setFields(wfsParameters.getFields()); |
||
95 | 29270 | jpiera | //wfsStatus.setFilterQuery(wfsParameters.getFilterEncoding());
|
96 | 27885 | jpiera | wfsStatus.setTimeout(wfsParameters.getTimeOut()); |
97 | wfsStatus.setBuffer(wfsParameters.getMaxFeatures()); |
||
98 | wfsStatus.setUserName(wfsParameters.getUser()); |
||
99 | wfsStatus.setPassword(wfsParameters.getPassword()); |
||
100 | 28430 | jpiera | } |
101 | 27945 | jpiera | |
102 | 29326 | jmvivo | private WFSStoreParameters getWFSParameters() {
|
103 | return (WFSStoreParameters) getParameters();
|
||
104 | } |
||
105 | 29200 | jpiera | |
106 | 27945 | jpiera | /* (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 | 29326 | jmvivo | List featureTypes = this.getFeatureStore().getFeatureTypes(); |
113 | 27945 | jpiera | 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 | 27885 | jpiera | } |
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 | 29292 | jmvivo | } |
142 | 27885 | jpiera | } |
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 | 29292 | jmvivo | WFSServerExplorerParameters params; |
150 | 27885 | jpiera | try {
|
151 | params = (WFSServerExplorerParameters) manager |
||
152 | 29200 | jpiera | .createServerExplorerParameters(WFSServerExplorer.NAME); |
153 | 27885 | jpiera | params.setUrl(wfsClient.getHost()); |
154 | return manager.createServerExplorer(params);
|
||
155 | } catch (Exception e) { |
||
156 | throw new ReadException(this.getName(), e); |
||
157 | 29292 | jmvivo | } |
158 | 27885 | jpiera | } |
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 | 29198 | jpiera | |
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 | 29200 | jpiera | throws DataException {
|
174 | executeQuery(query); |
||
175 | 29198 | jpiera | 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 | 29200 | jpiera | executeQuery(query); |
185 | 29292 | jmvivo | return super.createSet(query, featureType); |
186 | 29200 | jpiera | } |
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 | 29270 | jpiera | // 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 | 29292 | jmvivo | // initialize(getStoreServices());
|
201 | 29270 | jpiera | // }
|
202 | 29198 | jpiera | } |
203 | 27885 | jpiera | } |