Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.csv / src / main / java / org / gvsig / fmap / dal / store / simplereader / SimpleReaderLibrary.java @ 47638

History | View | Annotate | Download (5.29 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.fmap.dal.store.simplereader;
25

    
26
import java.util.ArrayList;
27
import java.util.List;
28

    
29
import org.gvsig.fmap.dal.DALFileLibrary;
30
import org.gvsig.fmap.dal.DALFileLocator;
31
import org.gvsig.fmap.dal.DALLibrary;
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.FileHelper;
34
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerManager;
35
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
36
import org.gvsig.fmap.dal.store.csv.CSVFilesystemServerProvider;
37
import org.gvsig.fmap.dal.store.csv.CSVNewStoreParameters;
38
import org.gvsig.fmap.dal.store.csv.CSVStoreParameters;
39
import org.gvsig.fmap.dal.store.csv.CSVStoreProvider;
40
import org.gvsig.fmap.dal.store.csv.CSVStoreProviderFactory;
41
import org.gvsig.fmap.dal.store.gml.GMLFilesystemServerProvider;
42
import org.gvsig.fmap.dal.store.gml.GMLStoreParameters;
43
import org.gvsig.fmap.dal.store.gml.GMLStoreProvider;
44
import org.gvsig.fmap.dal.store.gml.GMLStoreProviderFactory;
45
import org.gvsig.metadata.exceptions.MetadataException;
46
import org.gvsig.tools.library.AbstractLibrary;
47
import org.gvsig.tools.library.LibraryException;
48

    
49
public class SimpleReaderLibrary extends AbstractLibrary {
50

    
51
    @Override
52
    public void doRegistration() {
53
        registerAsServiceOf(DALLibrary.class);
54
        require(DALFileLibrary.class);
55
    }
56

    
57
    @Override
58
    protected void doInitialize() throws LibraryException {
59
    }
60

    
61
    @Override
62
    protected void doPostInitialize() throws LibraryException {
63
        List<Throwable> exs = new ArrayList<Throwable>();
64

    
65
        try {
66
            FileHelper.registerParametersDefinition(
67
                    CSVStoreParameters.PARAMETERS_DEFINITION_NAME,
68
                    CSVStoreParameters.class, "CSVParameters.xml"
69
            );
70
            FileHelper.registerParametersDefinition(
71
                    CSVNewStoreParameters.PARAMETERS_DEFINITION_NAME,
72
                    CSVNewStoreParameters.class, "CSVParameters.xml"
73
            );
74

    
75
            FileHelper.registerParametersDefinition(
76
                    GMLStoreParameters.PARAMETERS_DEFINITION_NAME,
77
                    GMLStoreParameters.class, "GMLParameters.xml"
78
            );
79
        } catch (Exception e) {
80
            exs.add(e);
81
        }
82
        
83
        try {
84
            FileHelper.registerMetadataDefinition(
85
                    CSVStoreProvider.METADATA_DEFINITION_NAME,
86
                    CSVStoreProvider.class, "CSVMetadata.xml"
87
            );
88
            FileHelper.registerMetadataDefinition(
89
                    GMLStoreProvider.METADATA_DEFINITION_NAME,
90
                    GMLStoreProvider.class, "GMLMetadata.xml"
91
            );
92
        } catch (MetadataException e) {
93
            exs.add(e);
94
        }
95

    
96
        DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator
97
                .getDataManager();
98

    
99
        try {
100
            if (!dataman.getStoreProviders().contains(CSVStoreProvider.NAME)) {
101
                dataman.registerStoreProviderFactory(
102
                        new CSVStoreProviderFactory(
103
                                CSVStoreProvider.NAME, 
104
                                CSVStoreProvider.DESCRIPTION
105
                        )
106
                );
107
            }
108
            if (!dataman.getStoreProviders().contains(GMLStoreProvider.NAME)) {
109
                dataman.registerStoreProviderFactory(
110
                        new GMLStoreProviderFactory(
111
                                GMLStoreProvider.NAME, 
112
                                GMLStoreProvider.DESCRIPTION
113
                        )
114
                );
115
            }
116
        } catch (RuntimeException e) {
117
            exs.add(e);
118
        }
119

    
120
        try {
121
            FilesystemServerExplorerManager filesystemServerExplorerManager = 
122
                    DALFileLocator.getFilesystemServerExplorerManager();
123
            filesystemServerExplorerManager.registerProvider(
124
                    CSVStoreProvider.NAME,
125
                    CSVStoreProvider.DESCRIPTION,
126
                    CSVFilesystemServerProvider.class
127
            );
128
            filesystemServerExplorerManager.registerProvider(
129
                    GMLStoreProvider.NAME,
130
                    GMLStoreProvider.DESCRIPTION,
131
                    GMLFilesystemServerProvider.class
132
            );
133
        } catch (RuntimeException e) {
134
            exs.add(e);
135
        }
136

    
137
        if (exs.size() > 0) {
138
            throw new LibraryException(this.getClass(), exs);
139
        }
140
    }
141
}