svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.jdbc / src / main / java / org / gvsig / exportto / swing / prov / jdbc / BaseExporttoJDBCProviderFactory.java @ 41632
History | View | Annotate | Download (3.98 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.exportto.swing.prov.jdbc; |
25 |
|
26 |
import java.util.Iterator; |
27 |
import java.util.List; |
28 |
import org.cresques.cts.IProjection; |
29 |
import org.gvsig.exportto.swing.ExporttoSwingManager; |
30 |
import org.gvsig.exportto.swing.spi.AbstractExporttoProviderFactory; |
31 |
import org.gvsig.fmap.dal.DALLocator; |
32 |
import org.gvsig.fmap.dal.DataManager; |
33 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
34 |
import org.gvsig.fmap.dal.exception.DataException; |
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
36 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
37 |
import org.gvsig.i18n.Messages; |
38 |
import org.gvsig.tools.dynobject.DynObject; |
39 |
import org.gvsig.tools.service.ServiceException; |
40 |
import org.gvsig.tools.service.spi.Provider; |
41 |
import org.gvsig.tools.service.spi.ProviderServices; |
42 |
|
43 |
/**
|
44 |
* Factory of file {@link ExportoProvider} objects.
|
45 |
*
|
46 |
* @author gvSIG Team
|
47 |
* @version $Id$
|
48 |
*/
|
49 |
public class BaseExporttoJDBCProviderFactory extends |
50 |
AbstractExporttoProviderFactory { |
51 |
|
52 |
private static final String PROVIDER_NAME = "JDBC"; |
53 |
|
54 |
public BaseExporttoJDBCProviderFactory() {
|
55 |
super(new int[]{ |
56 |
ExporttoSwingManager.VECTORIAL_TABLE_WITHOUT_GEOMETRY, |
57 |
ExporttoSwingManager.VECTORIAL_TABLE_WITH_GEOMETRY}); |
58 |
} |
59 |
|
60 |
public String getName() { |
61 |
return PROVIDER_NAME;
|
62 |
} |
63 |
|
64 |
public String getDescription() { |
65 |
return Messages.getText("general_exporter_description", |
66 |
new String[]{"DataBase (" + getConnectorNames() + " throws JDBC)"}); |
67 |
} |
68 |
|
69 |
public String getLabel() { |
70 |
return Messages.getText("general_exporter_label", |
71 |
new String[]{"DataBase (throws JDBC)"}); |
72 |
} |
73 |
|
74 |
private String getConnectorNames() { |
75 |
try {
|
76 |
StringBuilder names = new StringBuilder(); |
77 |
|
78 |
DataManager dataManager = DALLocator.getDataManager(); |
79 |
List<String> explorers = dataManager.getExplorerProviders(); |
80 |
|
81 |
DataServerExplorerParameters params; |
82 |
|
83 |
Iterator<String> it = explorers.iterator(); |
84 |
while ( it.hasNext() ) {
|
85 |
String explorerName = it.next();
|
86 |
try {
|
87 |
params = dataManager.createServerExplorerParameters(explorerName); |
88 |
} catch (DataException e) {
|
89 |
continue;
|
90 |
} |
91 |
if ( params instanceof JDBCServerExplorerParameters ) { |
92 |
JDBCServerExplorerParameters dbParams = (JDBCServerExplorerParameters) params; |
93 |
if ( names.length() > 0 ) { |
94 |
names.append(", ");
|
95 |
} |
96 |
names.append(dbParams.getExplorerName()); |
97 |
} |
98 |
} |
99 |
return names.toString();
|
100 |
} catch (Exception ex) { |
101 |
return ""; |
102 |
} |
103 |
} |
104 |
|
105 |
public Provider create(DynObject parameters, ProviderServices services) throws ServiceException { |
106 |
return new BaseExporttoJDBCProvider(services, |
107 |
(FeatureStore) parameters.getDynValue(PARAMETER_FEATURESTORE), |
108 |
(IProjection) parameters.getDynValue(PARAMETER_PROJECTION)); |
109 |
} |
110 |
|
111 |
} |