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