Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.h2 / src / main / java / org / gvsig / fmap / dal / store / h2 / H2SpatialLibrary.java @ 45425

History | View | Annotate | Download (3.64 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.fmap.dal.store.h2;
23

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

    
36
public class H2SpatialLibrary extends AbstractLibrary {
37

    
38
    public static final String NAME = DataStore.H2SPATIAL_PROVIDER_NAME;
39

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

    
46
    @Override
47
    protected void doInitialize() throws LibraryException {
48
    }
49

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

    
54
        DataManagerProviderServices dataman = 
55
                (DataManagerProviderServices) DALLocator.getDataManager();
56

    
57
        try {
58
            Class.forName(H2SpatialHelper.H2SPATIAL_JDBC_DRIVER);
59
        } catch(Throwable th) {
60
            H2SpatialHelper.LOGGER.warn("Can't load H2Spatial JDBC Driver.",th);
61
        }
62
        
63
        DBHelper.registerParametersDefinition(
64
                NAME + "StoreParameters",
65
                H2SpatialStoreParameters.class,
66
                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
67
        );
68
        DBHelper.registerParametersDefinition(
69
                NAME + "NewStoreParameters",
70
                H2SpatialNewStoreParameters.class,
71
                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
72
        );
73
        DBHelper.registerParametersDefinition(
74
                NAME + "ServerExplorerParameters",
75
                H2SpatialExplorerParameters.class,
76
                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
77
        );
78
        try {
79
            DBHelper.registerMetadataDefinition(
80
                NAME,
81
                JDBCStoreProviderBase.class,
82
                dataman.getResourceAsStream(this, NAME + "Metadata.xml")
83
            );
84
        } catch (MetadataException e) {
85
            ex = new LibraryException(this.getClass(), e);
86
        }
87

    
88
        if (!dataman.getStoreProviderRegister().exits(NAME)) {
89
            dataman.registerStoreProviderFactory(new H2SpatialStoreProviderFactory());
90
        }
91

    
92
        if (!dataman.getServerExplorerRegister().exits(NAME)) {
93
            dataman.registerServerExplorerFactory(new H2SpatialExplorerFactory());
94
        }
95
        Json.registerSerializer(H2SpatialExplorerParameters.class);
96
        if (ex != null) {
97
            throw ex;
98
        }
99
    }
100

    
101
}