root / branches / v2_0_0_prep / libraries / org.gvsig.newlayer / org.gvsig.newlayer.prov / org.gvsig.newlayer.prov.generic / src / main / java / org / gvsig / newlayer / prov / generic / NewLayerGenericProvider.java @ 36022
History | View | Annotate | Download (5.01 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.List; |
26 |
|
27 |
import org.gvsig.fmap.dal.DALLocator; |
28 |
import org.gvsig.fmap.dal.DataManager; |
29 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
30 |
import org.gvsig.fmap.dal.exception.InitializeException; |
31 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
32 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
33 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
34 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
35 |
import org.gvsig.newlayer.NewLayerProviderPanel; |
36 |
import org.gvsig.newlayer.NewLayerService; |
37 |
import org.gvsig.newlayer.prov.generic.panels.ExplorerParamsPanel; |
38 |
import org.gvsig.newlayer.prov.generic.panels.SelectExplorerPanel; |
39 |
import org.gvsig.newlayer.prov.generic.panels.SelectStoreTypePanel; |
40 |
import org.gvsig.newlayer.prov.generic.panels.StoreParamsPanel; |
41 |
import org.gvsig.newlayer.spi.AbstractNewLayerProvider; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
/**
|
46 |
* NewLayer provider which create a NewLayer.
|
47 |
*
|
48 |
* @author gvSIG Team
|
49 |
* @version $Id$
|
50 |
*/
|
51 |
public class NewLayerGenericProvider extends AbstractNewLayerProvider { |
52 |
|
53 |
List<NewLayerProviderPanel> panels = new ArrayList<NewLayerProviderPanel>(); |
54 |
private String explorerName = null; |
55 |
private DataServerExplorerParameters explorerParameters = null; |
56 |
|
57 |
protected NewLayerGenericProvider(NewLayerService service) {
|
58 |
super(service);
|
59 |
panels.add(new SelectExplorerPanel(this)); |
60 |
panels.add(new ExplorerParamsPanel(this)); |
61 |
panels.add(new SelectStoreTypePanel(this)); |
62 |
panels.add(new StoreParamsPanel(this)); |
63 |
} |
64 |
|
65 |
private static final Logger LOG = |
66 |
LoggerFactory.getLogger(NewLayerGenericProvider.class); |
67 |
|
68 |
public EditableFeatureType getFeatureType() {
|
69 |
// TODO Auto-generated method stub
|
70 |
return null; |
71 |
} |
72 |
|
73 |
public NewFeatureStoreParameters getNewStoreParameters() {
|
74 |
DataManager dataManager = DALLocator.getDataManager(); |
75 |
try {
|
76 |
return (NewFeatureStoreParameters) dataManager.createNewStoreParameters(this.getExplorerName(), this.getStoreName()); |
77 |
} catch (InitializeException e) {
|
78 |
LOG.error("Can't initialize store parameters.");
|
79 |
throw new RuntimeException("Can't initialize store parameters."); |
80 |
} catch (ProviderNotRegisteredException e) {
|
81 |
LOG.error("Can't create store parameters, provider not registered.");
|
82 |
throw new RuntimeException("Can't create store parameters, provider not registered."); |
83 |
} |
84 |
} |
85 |
|
86 |
public List<NewLayerProviderPanel> getPanels() { |
87 |
return panels;
|
88 |
} |
89 |
|
90 |
public List<String> getExplorerNames(){ |
91 |
DataManager dataManager = DALLocator.getDataManager(); |
92 |
return dataManager.getExplorerProviders();
|
93 |
} |
94 |
|
95 |
public List<String> getStoreNames(){ |
96 |
DataManager dataManager = DALLocator.getDataManager(); |
97 |
return dataManager.getStoreProviders();
|
98 |
} |
99 |
|
100 |
public void setStoreName(String storeName) { |
101 |
this.storeName = storeName;
|
102 |
} |
103 |
|
104 |
public String getExplorerName(){ |
105 |
return this.explorerName; |
106 |
} |
107 |
|
108 |
public void setExplorerName(String explorerName) { |
109 |
this.explorerName = explorerName;
|
110 |
} |
111 |
|
112 |
public DataServerExplorerParameters getExplorerParameters() throws InitializeException, ProviderNotRegisteredException{ |
113 |
if (this.explorerParameters==null || !this.explorerParameters.getExplorerName().equalsIgnoreCase(this.getExplorerName())) { |
114 |
if (this.explorerName == null) { |
115 |
LOG.error("Can't create explorer parameters, unknow explorer name.");
|
116 |
throw new RuntimeException("Can't create explorer parameters, unknow explorer name."); |
117 |
} |
118 |
DataManager manager = DALLocator.getDataManager(); |
119 |
this.explorerParameters = manager.createServerExplorerParameters(this.getExplorerName()); |
120 |
|
121 |
} |
122 |
return this.explorerParameters; |
123 |
} |
124 |
|
125 |
public void createExplorer() { |
126 |
DataManager manager = DALLocator.getDataManager(); |
127 |
try {
|
128 |
explorer = manager.openServerExplorer(getExplorerName(), getExplorerParameters()); |
129 |
} catch (ValidateDataParametersException e) {
|
130 |
// TODO Auto-generated catch block
|
131 |
e.printStackTrace(); |
132 |
} catch (InitializeException e) {
|
133 |
// TODO Auto-generated catch block
|
134 |
e.printStackTrace(); |
135 |
} catch (ProviderNotRegisteredException e) {
|
136 |
// TODO Auto-generated catch block
|
137 |
e.printStackTrace(); |
138 |
} |
139 |
} |
140 |
} |