Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / DALLibrary.java @ 40435

History | View | Annotate | Download (4.6 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

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 IVER T.I. S.A.   {{Task}}
26
 */
27
package org.gvsig.fmap.dal;
28

    
29
import java.util.ArrayList;
30
import java.util.List;
31

    
32
import org.cresques.ProjectionLibrary;
33

    
34
import org.gvsig.fmap.dal.resource.ResourceManager;
35
import org.gvsig.fmap.geom.GeometryLibrary;
36
import org.gvsig.metadata.MetadataLibrary;
37
import org.gvsig.metadata.MetadataLocator;
38
import org.gvsig.metadata.MetadataManager;
39
import org.gvsig.metadata.exceptions.MetadataException;
40
import org.gvsig.timesupport.TimeSupportLibrary;
41
import org.gvsig.tools.ToolsLibrary;
42
import org.gvsig.tools.library.AbstractLibrary;
43
import org.gvsig.tools.library.LibraryException;
44
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
45

    
46
/**
47
 * Initializes gvSIG's desktop DAL by registering the default implementation for
48
 * {@link DataManager} and {@link ResourceManager}.
49
 * 
50
 */
51
public class DALLibrary extends AbstractLibrary {
52

    
53
    public void doRegistration() {
54
        registerAsAPI(DALLibrary.class);
55
        require(ToolsLibrary.class);
56
        require(MetadataLibrary.class);
57
        require(ProjectionLibrary.class);
58
        require(GeometryLibrary.class);
59
        require(TimeSupportLibrary.class);
60
    }
61

    
62
    protected void doInitialize() throws LibraryException {
63
        // Do nothing
64
    }
65

    
66
    protected void doPostInitialize() throws LibraryException {
67
        List exs = new ArrayList();
68

    
69
        try {
70
            registerDataStoreMetadataDefinition();
71
        } catch (MetadataException e) {
72
            exs.add(e);
73
        }
74
        try {
75
            registerSpatialDataStoreMetadataDefinition();
76
        } catch (MetadataException e) {
77
            exs.add(e);
78
        }
79
        try {
80
            registerFeatureStoreMetadataDefinition();
81
        } catch (MetadataException e) {
82
            exs.add(e);
83
        }
84

    
85
        // Validate there is any implementation registered.
86
        DataManager dataManager = DALLocator.getDataManager();
87
        if (dataManager == null) {
88
            throw new ReferenceNotRegisteredException(
89
                DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance());
90
        }
91

    
92
        if (exs.size() > 0) {
93
            throw new LibraryException(this.getClass(), exs);
94
        }
95
    }
96

    
97
    private void registerDataStoreMetadataDefinition() throws MetadataException {
98
        MetadataManager manager = MetadataLocator.getMetadataManager();
99
        if (manager.getDefinition(DataStore.METADATA_DEFINITION_NAME) == null) {
100
            manager
101
                .addDefinition(DataStore.METADATA_DEFINITION_NAME,
102
                    DALLibrary.class
103
                        .getResourceAsStream("MetadataDefinitions.xml"),
104
                    DALLibrary.class.getClassLoader());
105
        }
106
    }
107

    
108
    private void registerSpatialDataStoreMetadataDefinition()
109
        throws MetadataException {
110
        MetadataManager manager = MetadataLocator.getMetadataManager();
111
        if (manager.getDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME) == null) {
112
            manager
113
                .addDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME,
114
                    DALLibrary.class
115
                        .getResourceAsStream("MetadataDefinitions.xml"),
116
                    DALLibrary.class.getClassLoader());
117
        }
118
    }
119

    
120
    private void registerFeatureStoreMetadataDefinition()
121
        throws MetadataException {
122
        MetadataManager manager = MetadataLocator.getMetadataManager();
123
        if (manager.getDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME) == null) {
124
            manager
125
                .addDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME,
126
                    DALLibrary.class
127
                        .getResourceAsStream("MetadataDefinitions.xml"),
128
                    DALLibrary.class.getClassLoader());
129
        }
130
    }
131

    
132
}