Statistics
| Revision:

root / branches / dal_time_support / libraries / libFMap_dal / src / org / gvsig / fmap / dal / DALLibrary.java @ 35196

History | View | Annotate | Download (5.89 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.AbsoluteInstant;
44
import org.gvsig.timesupport.AbsoluteInterval;
45
import org.gvsig.timesupport.RelativeInstant;
46
import org.gvsig.timesupport.RelativeInterval;
47
import org.gvsig.tools.ToolsLibrary;
48
import org.gvsig.tools.ToolsLocator;
49
import org.gvsig.tools.dataTypes.DataTypesManager;
50
import org.gvsig.tools.library.AbstractLibrary;
51
import org.gvsig.tools.library.LibraryException;
52
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
53

    
54
/**
55
 * Initializes gvSIG's desktop DAL by registering the default implementation for
56
 * {@link DataManager} and {@link ResourceManager}.
57
 * 
58
 */
59
public class DALLibrary extends AbstractLibrary {
60

    
61
    public void doRegistration() {
62
        registerAsAPI(DALLibrary.class);
63
        require(GeometryLibrary.class);
64
        require(ToolsLibrary.class);
65
        require(MetadataLibrary.class);
66
    }
67

    
68
    protected void doInitialize() throws LibraryException {
69
        // Do nothing
70
    }
71

    
72
    protected void doPostInitialize() throws LibraryException {
73
        List exs = new ArrayList();
74
        
75
        try {
76
            registerDataStoreMetadataDefinition();
77
        } catch (MetadataException e) {
78
            exs.add(e);
79
        }
80
        try {
81
            registerSpatialDataStoreMetadataDefinition();
82
        } catch (MetadataException e) {
83
            exs.add(e);
84
        }
85
        try {
86
            registerFeatureStoreMetadataDefinition();
87
        } catch (MetadataException e) {
88
            exs.add(e);
89
        }
90

    
91
        // Validate there is any implementation registered.
92
        DataManager dataManager = DALLocator.getDataManager();
93
        if (dataManager == null) {
94
            throw new ReferenceNotRegisteredException(
95
                DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance());
96
        }
97

    
98
        ResourceManagerProviderServices resourceManager =
99
            (ResourceManagerProviderServices) DALLocator.getResourceManager();
100
        if (resourceManager == null) {
101
            throw new ReferenceNotRegisteredException(
102
                DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance());
103
        }
104

    
105
        if (!resourceManager.getResourceProviders().contains(
106
            MultiResource.TYPE_NAME)) {
107
            resourceManager.register(MultiResource.TYPE_NAME,
108
                MultiResource.DESCRIPTION, MultiResource.class,
109
                MultiResourceParameters.class);
110
        }
111

    
112
        if (!resourceManager.getResourceProviders().contains(
113
            MemoryResource.NAME)) {
114
            resourceManager.register(MemoryResource.NAME,
115
                MemoryResource.DESCRIPTION, MemoryResource.class,
116
                MemoryResourceParameters.class);
117
        }
118

    
119
        if (exs.size() > 0) {
120
            throw new LibraryException(this.getClass(), exs);
121
        }
122
    }
123

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

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

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

    
159
}