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

History | View | Annotate | Download (6.5 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.fmap.dal.store.json.JsonFilesystemServerProvider;
46
import org.gvsig.fmap.dal.store.json.JsonStoreParameters;
47
import org.gvsig.fmap.dal.store.json.JsonStoreProvider;
48
import org.gvsig.fmap.dal.store.json.JsonStoreProviderFactory;
49
import org.gvsig.metadata.exceptions.MetadataException;
50
import org.gvsig.tools.library.AbstractLibrary;
51
import org.gvsig.tools.library.LibraryException;
52

    
53
public class SimpleReaderLibrary extends AbstractLibrary {
54

    
55
    @Override
56
    public void doRegistration() {
57
        registerAsServiceOf(DALLibrary.class);
58
        require(DALFileLibrary.class);
59
    }
60

    
61
    @Override
62
    protected void doInitialize() throws LibraryException {
63
    }
64

    
65
    @Override
66
    protected void doPostInitialize() throws LibraryException {
67
        List<Throwable> exs = new ArrayList<Throwable>();
68

    
69
        try {
70
            FileHelper.registerParametersDefinition(
71
                    CSVStoreParameters.PARAMETERS_DEFINITION_NAME,
72
                    CSVStoreParameters.class, "CSVParameters.xml"
73
            );
74
            FileHelper.registerParametersDefinition(
75
                    CSVNewStoreParameters.PARAMETERS_DEFINITION_NAME,
76
                    CSVNewStoreParameters.class, "CSVParameters.xml"
77
            );
78

    
79
            FileHelper.registerParametersDefinition(
80
                    GMLStoreParameters.PARAMETERS_DEFINITION_NAME,
81
                    GMLStoreParameters.class, "GMLParameters.xml"
82
            );
83
            FileHelper.registerParametersDefinition(
84
                    JsonStoreParameters.PARAMETERS_DEFINITION_NAME,
85
                    JsonStoreParameters.class, "JsonParameters.xml"
86
            );
87
        } catch (Exception e) {
88
            exs.add(e);
89
        }
90
        
91
        try {
92
            FileHelper.registerMetadataDefinition(
93
                    CSVStoreProvider.METADATA_DEFINITION_NAME,
94
                    CSVStoreProvider.class, "CSVMetadata.xml"
95
            );
96
            FileHelper.registerMetadataDefinition(
97
                    GMLStoreProvider.METADATA_DEFINITION_NAME,
98
                    GMLStoreProvider.class, "GMLMetadata.xml"
99
            );
100
            FileHelper.registerMetadataDefinition(
101
                    JsonStoreProvider.METADATA_DEFINITION_NAME,
102
                    JsonStoreProvider.class, "JsonMetadata.xml"
103
            );
104
        } catch (MetadataException e) {
105
            exs.add(e);
106
        }
107

    
108
        DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator
109
                .getDataManager();
110

    
111
        try {
112
            if (!dataman.getStoreProviders().contains(CSVStoreProvider.NAME)) {
113
                dataman.registerStoreProviderFactory(
114
                        new CSVStoreProviderFactory(
115
                                CSVStoreProvider.NAME, 
116
                                CSVStoreProvider.DESCRIPTION
117
                        )
118
                );
119
            }
120
            if (!dataman.getStoreProviders().contains(GMLStoreProvider.NAME)) {
121
                dataman.registerStoreProviderFactory(
122
                        new GMLStoreProviderFactory(
123
                                GMLStoreProvider.NAME, 
124
                                GMLStoreProvider.DESCRIPTION
125
                        )
126
                );
127
            }
128
            if (!dataman.getStoreProviders().contains(JsonStoreProvider.NAME)) {
129
                dataman.registerStoreProviderFactory(
130
                        new JsonStoreProviderFactory(
131
                                JsonStoreProvider.NAME, 
132
                                JsonStoreProvider.DESCRIPTION
133
                        )
134
                );
135
            }
136
        } catch (RuntimeException e) {
137
            exs.add(e);
138
        }
139

    
140
        try {
141
            FilesystemServerExplorerManager filesystemServerExplorerManager = 
142
                    DALFileLocator.getFilesystemServerExplorerManager();
143
            filesystemServerExplorerManager.registerProvider(
144
                    CSVStoreProvider.NAME,
145
                    CSVStoreProvider.DESCRIPTION,
146
                    CSVFilesystemServerProvider.class
147
            );
148
            filesystemServerExplorerManager.registerProvider(
149
                    GMLStoreProvider.NAME,
150
                    GMLStoreProvider.DESCRIPTION,
151
                    GMLFilesystemServerProvider.class
152
            );
153
            filesystemServerExplorerManager.registerProvider(
154
                    JsonStoreProvider.NAME,
155
                    JsonStoreProvider.DESCRIPTION,
156
                    JsonFilesystemServerProvider.class
157
            );
158
        } catch (RuntimeException e) {
159
            exs.add(e);
160
        }
161

    
162
        if (exs.size() > 0) {
163
            throw new LibraryException(this.getClass(), exs);
164
        }
165
    }
166
}