svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / fmap / dal / store / wfs / WFSStoreProvider.java @ 28430
History | View | Annotate | Download (5.85 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.DataParameters; |
36 |
import org.gvsig.fmap.dal.DataServerExplorer; |
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.ProviderNotRegisteredException; |
41 |
import org.gvsig.fmap.dal.exception.ReadException; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
45 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
46 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
47 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer; |
48 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorerParameters; |
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.DelegatedDynObject; |
55 |
import org.gvsig.tools.dynobject.DynClass; |
56 |
import org.gvsig.tools.dynobject.DynField; |
57 |
import org.gvsig.tools.dynobject.DynObjectManager; |
58 |
|
59 |
|
60 |
/**
|
61 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
62 |
*/
|
63 |
public class WFSStoreProvider extends GPEStoreProvider implements |
64 |
ResourceConsumer { |
65 |
public static String NAME = "WFSStore"; |
66 |
public static String DESCRIPTION = "WFS store to load WFS resources"; |
67 |
private static final String DYNCLASS_NAME = "WFSStore"; |
68 |
protected static DynClass DYNCLASS = null; |
69 |
private WFSStoreParameters wfsParameters;
|
70 |
|
71 |
//WFS Parameters
|
72 |
private WFSClient wfsClient = null; |
73 |
private WFSStatus wfsStatus = null; |
74 |
|
75 |
public WFSStoreProvider() {
|
76 |
super();
|
77 |
} |
78 |
|
79 |
public WFSStoreProvider(DataParameters params)
|
80 |
throws InitializeException {
|
81 |
this();
|
82 |
|
83 |
this.wfsParameters = (WFSStoreParameters) params;
|
84 |
this.dynObject = (DelegatedDynObject) ToolsLocator
|
85 |
.getDynObjectManager().createDynObject(DYNCLASS); |
86 |
|
87 |
try {
|
88 |
if (wfsParameters.getVersion() == null){ |
89 |
wfsClient = new WFSClient(wfsParameters.getUrl());
|
90 |
wfsParameters.setVersion(wfsClient.getVersion()); |
91 |
}else{
|
92 |
wfsClient = new WFSClient(wfsParameters.getUrl(), wfsParameters.getVersion());
|
93 |
} |
94 |
} catch (IOException e) { |
95 |
throw new InitializeException(e); |
96 |
} |
97 |
wfsStatus = new WFSStatus( wfsParameters.getFeatureType(),
|
98 |
wfsParameters.getFeaturePrefix()); |
99 |
wfsStatus.setNamespace(wfsParameters.getFeatureNamespace()); |
100 |
wfsStatus.setFields(wfsParameters.getFields()); |
101 |
wfsStatus.setFilterQuery(wfsParameters.getFilterEncoding()); |
102 |
wfsStatus.setTimeout(wfsParameters.getTimeOut()); |
103 |
wfsStatus.setBuffer(wfsParameters.getMaxFeatures()); |
104 |
wfsStatus.setUserName(wfsParameters.getUser()); |
105 |
wfsStatus.setPassword(wfsParameters.getPassword()); |
106 |
} |
107 |
|
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see org.gvsig.fmap.dal.store.gpe.GPEStoreProvider#open()
|
111 |
*/
|
112 |
public void open() throws OpenException { |
113 |
super.open();
|
114 |
try {
|
115 |
List featureTypes = this.store.getFeatureTypes(); |
116 |
for (int i=0 ; i<featureTypes.size() ; i++){ |
117 |
FeatureType featureType = (FeatureType)featureTypes.get(i); |
118 |
|
119 |
} |
120 |
} catch (DataException e) {
|
121 |
throw new OpenException("Reading the geometry type", e); |
122 |
} |
123 |
} |
124 |
|
125 |
protected static void registerDynClass() { |
126 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
127 |
DynClass dynClass; |
128 |
DynField field; |
129 |
if (DYNCLASS == null) { |
130 |
|
131 |
dynClass = dynman.add(DYNCLASS_NAME); |
132 |
dynClass.extend(dynman.get(FeatureStore.DYNCLASS_NAME)); |
133 |
|
134 |
DYNCLASS = dynClass; |
135 |
} |
136 |
|
137 |
} |
138 |
|
139 |
/*
|
140 |
* (non-Javadoc)
|
141 |
* @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#initialize(org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices)
|
142 |
*/
|
143 |
public FeatureStoreProvider initialize(FeatureStoreProviderServices store) throws InitializeException{ |
144 |
retrieveFile(); |
145 |
super.initialize(store);
|
146 |
return this; |
147 |
} |
148 |
|
149 |
protected void retrieveFile() throws InitializeException{ |
150 |
try {
|
151 |
m_Fich = wfsClient.getFeature(wfsStatus, true, null); |
152 |
} catch (WFSException e) {
|
153 |
throw new InitializeException("Impossible to retrieve the file", e); |
154 |
} |
155 |
} |
156 |
|
157 |
/* (non-Javadoc)
|
158 |
* @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#getExplorer()
|
159 |
*/
|
160 |
public DataServerExplorer getExplorer() throws ReadException { |
161 |
DataManager manager = DALLocator.getDataManager(); |
162 |
WFSServerExplorerParameters params; |
163 |
try {
|
164 |
params = (WFSServerExplorerParameters) manager |
165 |
.createServerExplorerParameters(WFSServerExplorer.NAME); |
166 |
params.setUrl(wfsClient.getHost()); |
167 |
return manager.createServerExplorer(params);
|
168 |
} catch (Exception e) { |
169 |
throw new ReadException(this.getName(), e); |
170 |
} |
171 |
} |
172 |
|
173 |
|
174 |
/* (non-Javadoc)
|
175 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getName()
|
176 |
*/
|
177 |
public String getName() { |
178 |
return NAME;
|
179 |
} |
180 |
} |
181 |
|