root / tags / v2_0_0_Build_2050 / libraries / org.gvsig.newlayer / org.gvsig.newlayer.prov / org.gvsig.newlayer.prov.generic / src / main / java / org / gvsig / newlayer / prov / generic / NewLayerGenericProvider.java @ 38695
History | View | Annotate | Download (7.76 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 |
package org.gvsig.newlayer.prov.generic; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.Iterator; |
26 |
import java.util.List; |
27 |
|
28 |
import org.gvsig.fmap.dal.DALLocator; |
29 |
import org.gvsig.fmap.dal.DataManager; |
30 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
31 |
import org.gvsig.fmap.dal.DataStoreParameters; |
32 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.exception.InitializeException; |
35 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
36 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
37 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
38 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
39 |
import org.gvsig.newlayer.NewLayerProviderPanel; |
40 |
import org.gvsig.newlayer.NewLayerService; |
41 |
import org.gvsig.newlayer.prov.generic.panels.ExplorerParamsPanel; |
42 |
import org.gvsig.newlayer.prov.generic.panels.SelectExplorerPanel; |
43 |
import org.gvsig.newlayer.prov.generic.panels.SelectStoreTypePanel; |
44 |
import org.gvsig.newlayer.prov.generic.panels.StoreParamsPanel; |
45 |
import org.gvsig.newlayer.spi.AbstractNewLayerProvider; |
46 |
import org.gvsig.tools.exception.BaseRuntimeException; |
47 |
import org.slf4j.Logger; |
48 |
import org.slf4j.LoggerFactory; |
49 |
|
50 |
/**
|
51 |
* NewLayer provider which create a NewLayer.
|
52 |
*
|
53 |
* @author gvSIG Team
|
54 |
* @version $Id$
|
55 |
*/
|
56 |
public class NewLayerGenericProvider extends AbstractNewLayerProvider { |
57 |
|
58 |
List<NewLayerProviderPanel> panels = new ArrayList<NewLayerProviderPanel>(); |
59 |
private String explorerName = null; |
60 |
private DataServerExplorerParameters explorerParameters = null; |
61 |
private NewFeatureStoreParameters storeParameters = null; |
62 |
private EditableFeatureType featureType = null; |
63 |
|
64 |
protected NewLayerGenericProvider(NewLayerService service) {
|
65 |
super(service);
|
66 |
panels.add(new SelectExplorerPanel(this)); |
67 |
panels.add(new ExplorerParamsPanel(this)); |
68 |
panels.add(new SelectStoreTypePanel(this)); |
69 |
panels.add(new StoreParamsPanel(this)); |
70 |
} |
71 |
|
72 |
private static final Logger LOG = |
73 |
LoggerFactory.getLogger(NewLayerGenericProvider.class); |
74 |
|
75 |
public EditableFeatureType getFeatureType() {
|
76 |
// if (this.featureType!=null){
|
77 |
// if (this.storeParameters != null){
|
78 |
// if (this.storeParameters.getDataStoreName().equals(this.getStoreName())){
|
79 |
// return this.featureType;
|
80 |
// }
|
81 |
// }
|
82 |
// }
|
83 |
// this.featureType = this.getNewStoreParameters().getDefaultFeatureType();
|
84 |
// return this.featureType;
|
85 |
return this.getNewStoreParameters().getDefaultFeatureType(); |
86 |
} |
87 |
|
88 |
public NewFeatureStoreParameters getNewStoreParameters() {
|
89 |
if (storeParameters != null){ |
90 |
if (storeParameters.getDataStoreName().equals(this.getStoreName())){ |
91 |
return storeParameters;
|
92 |
} |
93 |
} |
94 |
try {
|
95 |
storeParameters = (NewFeatureStoreParameters) getExplorer().getAddParameters(this.getStoreName());
|
96 |
return storeParameters;
|
97 |
} catch (InitializeException e) {
|
98 |
LOG.error("Can't initialize store parameters.");
|
99 |
throw new CantInitializeStoreParametersException(e); |
100 |
} catch (ProviderNotRegisteredException e) {
|
101 |
LOG.error("Can't create store parameters, provider not registered.");
|
102 |
throw new CantCreateStoreParametersException(e); |
103 |
} catch (DataException e) {
|
104 |
LOG.error("Can't create store parameters, provider not registered.");
|
105 |
throw new CantCreateStoreParametersException(e); |
106 |
} |
107 |
} |
108 |
|
109 |
public DataStoreParameters getOpenStoreParameters() {
|
110 |
DataManager dataManager = DALLocator.getDataManager(); |
111 |
try {
|
112 |
DataStoreParameters storeParameters = (DataStoreParameters) dataManager |
113 |
.createStoreParameters(this.getStoreName());
|
114 |
return storeParameters;
|
115 |
} catch (InitializeException e) {
|
116 |
throw new CantInitializeStoreParametersException(e); |
117 |
} catch (ProviderNotRegisteredException e) {
|
118 |
throw new CantCreateStoreParametersException(e); |
119 |
} |
120 |
} |
121 |
|
122 |
class CantCreateStoreParametersException extends BaseRuntimeException { |
123 |
/**
|
124 |
*
|
125 |
*/
|
126 |
private static final long serialVersionUID = -3487961532247258393L; |
127 |
private final static String MESSAGE_FORMAT = "Can't create store parameters, provider not registered."; |
128 |
private final static String MESSAGE_KEY = "_Cant_create_store_parameters_provider_not_registered"; |
129 |
|
130 |
public CantCreateStoreParametersException(Throwable cause) { |
131 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
|
132 |
} |
133 |
} |
134 |
|
135 |
class CantInitializeStoreParametersException extends BaseRuntimeException { |
136 |
/**
|
137 |
*
|
138 |
*/
|
139 |
private static final long serialVersionUID = -5263149018209261288L; |
140 |
private final static String MESSAGE_FORMAT = "Can't initialize store parameters."; |
141 |
private final static String MESSAGE_KEY = "_Cant_initialize_store_parameters"; |
142 |
|
143 |
public CantInitializeStoreParametersException(Throwable cause) { |
144 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
|
145 |
} |
146 |
} |
147 |
|
148 |
|
149 |
public List<NewLayerProviderPanel> getPanels() { |
150 |
return panels;
|
151 |
} |
152 |
|
153 |
public List<String> getExplorerNames(){ |
154 |
DataManager dataManager = DALLocator.getDataManager(); |
155 |
return dataManager.getExplorerProviders();
|
156 |
} |
157 |
|
158 |
public List<String> getStoreNames(){ |
159 |
DataManager dataManager = DALLocator.getDataManager(); |
160 |
List<String> writables = new ArrayList<String>(); |
161 |
if (getExplorer()!=null){ |
162 |
List<String> storeProviders = getExplorer().getDataStoreProviderNames();// dataManager.getStoreProviders(); // |
163 |
|
164 |
for (Iterator iterator = storeProviders.iterator(); iterator.hasNext();) { |
165 |
String name = (String) iterator.next(); |
166 |
DataStoreProviderFactory factory = dataManager.getStoreProviderFactory(name); |
167 |
if (factory != null && factory.allowCreate()!=DataStoreProviderFactory.NO){ |
168 |
writables.add(name); |
169 |
} |
170 |
} |
171 |
} |
172 |
|
173 |
return writables;
|
174 |
} |
175 |
|
176 |
public void setStoreName(String storeName) { |
177 |
this.storeName = storeName;
|
178 |
} |
179 |
|
180 |
public String getExplorerName(){ |
181 |
return this.explorerName; |
182 |
} |
183 |
|
184 |
public void setExplorerName(String explorerName) { |
185 |
this.explorerName = explorerName;
|
186 |
} |
187 |
|
188 |
public DataServerExplorerParameters getExplorerParameters() throws InitializeException, ProviderNotRegisteredException{ |
189 |
if (this.explorerParameters==null || !this.explorerParameters.getExplorerName().equalsIgnoreCase(this.getExplorerName())) { |
190 |
if (this.explorerName == null) { |
191 |
LOG.error("Can't create explorer parameters, unknow explorer name.");
|
192 |
throw new RuntimeException("Can't create explorer parameters, unknow explorer name."); |
193 |
} |
194 |
DataManager manager = DALLocator.getDataManager(); |
195 |
this.explorerParameters = manager.createServerExplorerParameters(this.getExplorerName()); |
196 |
|
197 |
} |
198 |
return this.explorerParameters; |
199 |
} |
200 |
|
201 |
public void createExplorer() { |
202 |
DataManager manager = DALLocator.getDataManager(); |
203 |
try {
|
204 |
explorer = manager.openServerExplorer(getExplorerName(), getExplorerParameters()); |
205 |
} catch (ValidateDataParametersException e) {
|
206 |
// TODO Auto-generated catch block
|
207 |
e.printStackTrace(); |
208 |
} catch (InitializeException e) {
|
209 |
// TODO Auto-generated catch block
|
210 |
e.printStackTrace(); |
211 |
} catch (ProviderNotRegisteredException e) {
|
212 |
// TODO Auto-generated catch block
|
213 |
e.printStackTrace(); |
214 |
} |
215 |
} |
216 |
} |