Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / DALLibrary.java @ 37297

History | View | Annotate | Download (5.71 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.gvsig.fmap.dal.feature.spi.memory.MemoryResource;
33
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters;
34
import org.gvsig.fmap.dal.resource.ResourceManager;
35
import org.gvsig.fmap.dal.resource.spi.MultiResource;
36
import org.gvsig.fmap.dal.resource.spi.MultiResourceParameters;
37
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
38
import org.gvsig.fmap.geom.GeometryLibrary;
39
import org.gvsig.metadata.MetadataLibrary;
40
import org.gvsig.metadata.MetadataLocator;
41
import org.gvsig.metadata.MetadataManager;
42
import org.gvsig.metadata.exceptions.MetadataException;
43
import org.gvsig.timesupport.TimeSupportLibrary;
44
import org.gvsig.tools.ToolsLibrary;
45
import org.gvsig.tools.library.AbstractLibrary;
46
import org.gvsig.tools.library.LibraryException;
47
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
48

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

    
56
    public void doRegistration() {
57
        registerAsAPI(DALLibrary.class);
58
        require(GeometryLibrary.class);
59
        require(ToolsLibrary.class);
60
        require(MetadataLibrary.class);
61
        require(TimeSupportLibrary.class);
62
    }
63

    
64
    protected void doInitialize() throws LibraryException {
65
        // Do nothing
66
    }
67

    
68
    protected void doPostInitialize() throws LibraryException {
69
        List exs = new ArrayList();
70

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

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

    
94
        ResourceManagerProviderServices resourceManager =
95
            (ResourceManagerProviderServices) DALLocator.getResourceManager();
96
        if (resourceManager == null) {
97
            throw new ReferenceNotRegisteredException(
98
                DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance());
99
        }
100

    
101
        if (!resourceManager.getResourceProviders().contains(
102
            MultiResource.TYPE_NAME)) {
103
            resourceManager.register(MultiResource.TYPE_NAME,
104
                MultiResource.DESCRIPTION, MultiResource.class,
105
                MultiResourceParameters.class);
106
        }
107

    
108
        if (!resourceManager.getResourceProviders().contains(
109
            MemoryResource.NAME)) {
110
            resourceManager.register(MemoryResource.NAME,
111
                MemoryResource.DESCRIPTION, MemoryResource.class,
112
                MemoryResourceParameters.class);
113
        }
114

    
115
        if (exs.size() > 0) {
116
            throw new LibraryException(this.getClass(), exs);
117
        }
118
    }
119

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

    
131
    private void registerSpatialDataStoreMetadataDefinition()
132
        throws MetadataException {
133
        MetadataManager manager = MetadataLocator.getMetadataManager();
134
        if (manager.getDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME) == null) {
135
            manager
136
                .addDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME,
137
                    DALLibrary.class
138
                        .getResourceAsStream("MetadataDefinitions.xml"),
139
                    DALLibrary.class.getClassLoader());
140
        }
141
    }
142

    
143
    private void registerFeatureStoreMetadataDefinition()
144
        throws MetadataException {
145
        MetadataManager manager = MetadataLocator.getMetadataManager();
146
        if (manager.getDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME) == null) {
147
            manager
148
                .addDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME,
149
                    DALLibrary.class
150
                        .getResourceAsStream("MetadataDefinitions.xml"),
151
                    DALLibrary.class.getClassLoader());
152
        }
153
    }
154

    
155
}