Statistics
| Revision:

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 @ 43920

History | View | Annotate | Download (3.95 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.gvsig.exportto.swing.ExporttoSwingManager;
29
import org.gvsig.exportto.swing.spi.AbstractExporttoProviderFactory;
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.exception.DataException;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
36
import org.gvsig.i18n.Messages;
37
import org.gvsig.tools.dynobject.DynObject;
38
import org.gvsig.tools.service.ServiceException;
39
import org.gvsig.tools.service.spi.Provider;
40
import org.gvsig.tools.service.spi.ProviderServices;
41

    
42
/**
43
 * Factory of file {@link ExportoProvider} objects.
44
 *
45
 * @author gvSIG Team
46
 * @version $Id$
47
 */
48
public class BaseExporttoJDBCProviderFactory extends
49
        AbstractExporttoProviderFactory {
50

    
51
    private static final String PROVIDER_NAME = "JDBC";
52

    
53
    public BaseExporttoJDBCProviderFactory() {
54
        super(new int[]{
55
            ExporttoSwingManager.VECTORIAL_TABLE_WITHOUT_GEOMETRY,
56
            ExporttoSwingManager.VECTORIAL_TABLE_WITH_GEOMETRY});
57
    }
58

    
59
    @Override
60
    public String getName() {
61
        return PROVIDER_NAME;
62
    }
63

    
64
    @Override
65
    public String getDescription() {
66
        return Messages.getText("general_exporter_description",
67
                new String[]{"DataBase (" + getConnectorNames() + " throws JDBC)"});
68
    }
69

    
70
    @Override
71
    public String getLabel() {
72
        return Messages.getText("general_exporter_label",
73
                new String[]{"DataBase (throws JDBC)"});
74
    }
75

    
76
    private String getConnectorNames() {
77
        try {
78
            StringBuilder names = new StringBuilder();
79

    
80
            DataManager dataManager = DALLocator.getDataManager();
81
            List<String> explorers = dataManager.getExplorerProviders();
82

    
83
            DataServerExplorerParameters params;
84

    
85
            Iterator<String> it = explorers.iterator();
86
            while ( it.hasNext() ) {
87
                String explorerName = it.next();
88
                try {
89
                    params = dataManager.createServerExplorerParameters(explorerName);
90
                } catch (DataException e) {
91
                    continue;
92
                }
93
                if ( params instanceof JDBCServerExplorerParameters ) {
94
                    JDBCServerExplorerParameters dbParams = (JDBCServerExplorerParameters) params;
95
                    if ( names.length() > 0 ) {
96
                        names.append(", ");
97
                    }
98
                    names.append(dbParams.getExplorerName());
99
                }
100
            }
101
            return names.toString();
102
        } catch (Exception ex) {
103
            return "";
104
        }
105
    }
106

    
107
    @Override
108
    public Provider create(DynObject parameters, ProviderServices services) throws ServiceException {
109
        return new BaseExporttoJDBCProvider(
110
                services,
111
                (FeatureStore) parameters.getDynValue(PARAMETER_FEATURESTORE)
112
        );
113
    }
114

    
115
}