Statistics
| Revision:

gvsig-sqlite / trunk / org.gvsig.spatialite / org.gvsig.spatialite.provider / src / main / java / org / gvsig / spatialite / dal / SpatiaLiteLibrary.java @ 195

History | View | Annotate | Download (4.13 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.spatialite.dal;
23

    
24
import org.gvsig.fmap.dal.DALLibrary;
25
import org.gvsig.fmap.dal.DALLocator;
26
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
27
import org.gvsig.fmap.dal.store.db.DBHelper;
28
import org.gvsig.fmap.dal.store.jdbc2.JDBCLibrary;
29
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCStoreProviderBase;
30
import org.gvsig.metadata.exceptions.MetadataException;
31
import org.gvsig.tools.library.AbstractLibrary;
32
import org.gvsig.tools.library.LibraryException;
33

    
34
public class SpatiaLiteLibrary extends AbstractLibrary {
35

    
36
    public static final String NAME = "SpatiaLite";
37

    
38
    @Override
39
    public void doRegistration() {
40
        registerAsServiceOf(DALLibrary.class);
41
        require(JDBCLibrary.class);
42
    }
43

    
44
    @Override
45
    protected void doInitialize() throws LibraryException {
46
    }
47

    
48
    @Override
49
    protected void doPostInitialize() throws LibraryException {
50
        LibraryException ex = null;
51

    
52
        DataManagerProviderServices dataman = 
53
                (DataManagerProviderServices) DALLocator.getDataManager();
54

    
55
        try {
56
            Class.forName(SpatiaLiteHelper.SPATIALITE_JDBC_DRIVER);
57
        } catch(Throwable th) {
58
            SpatiaLiteHelper.LOGGER.warn("Can't load SpatiaLite JDBC Driver.",th);
59
        }
60
        
61
        DBHelper.registerParametersDefinition(
62
                NAME + "StoreParameters",
63
                SpatiaLiteStoreParameters.class,
64
                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
65
        );
66
        DBHelper.registerParametersDefinition(
67
                NAME + "NewStoreParameters",
68
                SpatiaLiteNewStoreParameters.class,
69
                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
70
        );
71
        DBHelper.registerParametersDefinition(
72
                NAME + "ServerExplorerParameters",
73
                SpatiaLiteExplorerParameters.class,
74
                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
75
        );
76
//        DBHelper.registerParametersDefinition(
77
//                NAME + "ResourceParameters",
78
//                SpatiaLiteResourceParameters.class,
79
//                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
80
//        );
81
        try {
82
            DBHelper.registerMetadataDefinition(
83
                NAME,
84
                JDBCStoreProviderBase.class,
85
                dataman.getResourceAsStream(this, NAME + "Metadata.xml")
86
            );
87
        } catch (MetadataException e) {
88
            ex = new LibraryException(this.getClass(), e);
89
        }
90

    
91
//        ResourceManagerProviderServices resman = (ResourceManagerProviderServices) DALLocator
92
//                .getResourceManager();
93
//
94
//        if (!resman.getResourceProviders().contains(NAME)) {
95
//            resman.register(NAME,
96
//                "Resource for " + NAME,
97
//                SpatiaLiteResource.class,
98
//                SpatiaLiteResourceParameters.class
99
//            );
100
//        }
101

    
102
        if (!dataman.getStoreProviderRegister().exits(NAME)) {
103
            dataman.registerStoreProviderFactory(new SpatiaLiteStoreProviderFactory());
104
        }
105

    
106
        if (!dataman.getServerExplorerRegister().exits(NAME)) {
107
            dataman.registerServerExplorerFactory(new SpatiaLiteExplorerFactory());
108
        }
109
        if (ex != null) {
110
            throw ex;
111
        }
112
    }
113

    
114
}