Statistics
| Revision:

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

History | View | Annotate | Download (6.06 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.cts.IProjection;
33
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResource;
34
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters;
35
import org.gvsig.fmap.dal.resource.ResourceManager;
36
import org.gvsig.fmap.dal.resource.spi.MultiResource;
37
import org.gvsig.fmap.dal.resource.spi.MultiResourceParameters;
38
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
39
import org.gvsig.fmap.geom.Geometry;
40
import org.gvsig.fmap.geom.GeometryLibrary;
41
import org.gvsig.fmap.geom.primitive.Envelope;
42
import org.gvsig.metadata.MetadataLibrary;
43
import org.gvsig.metadata.MetadataLocator;
44
import org.gvsig.metadata.MetadataManager;
45
import org.gvsig.metadata.exceptions.MetadataException;
46
import org.gvsig.timesupport.Instant;
47
import org.gvsig.timesupport.Interval;
48
import org.gvsig.timesupport.Partial;
49
import org.gvsig.timesupport.Period;
50
import org.gvsig.tools.ToolsLibrary;
51
import org.gvsig.tools.ToolsLocator;
52
import org.gvsig.tools.dataTypes.DataTypesManager;
53
import org.gvsig.tools.library.AbstractLibrary;
54
import org.gvsig.tools.library.Library;
55
import org.gvsig.tools.library.LibraryException;
56
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
57

    
58
/**
59
 * Initializes gvSIG's desktop DAL by registering the default implementation for {@link DataManager}
60
 * and {@link ResourceManager}.
61
 *
62
 */
63
public class DALLibrary extends AbstractLibrary {
64

    
65
        public DALLibrary() {
66
                super(DALLibrary.class,Library.TYPE.API );
67
                require(GeometryLibrary.class);
68
                require(ToolsLibrary.class);
69
                require(MetadataLibrary.class);
70
        }
71
        
72
        protected void doInitialize() throws LibraryException {
73
                // Do nothing
74
        }
75

    
76
        protected void doPostInitialize() throws LibraryException {
77
                List exs = new ArrayList();
78
                
79
                DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
80
                dataTypesManager.addtype(DataTypes.GEOMETRY, "Geometry", "Geometry", Geometry.class, null);
81
                dataTypesManager.addtype(DataTypes.CRS, "CRS","CRS", IProjection.class, null);
82
                dataTypesManager.addtype(DataTypes.ENVELOPE, "Envelope", "Envelope", Envelope.class, null);
83
                dataTypesManager.addtype(DataTypes.INSTANT, "Instant", "Instant", Instant.class, null);
84
        dataTypesManager.addtype(DataTypes.INTERVAL, "Interval","Interval", Interval.class, null);
85
        dataTypesManager.addtype(DataTypes.PARTIAL, "Partial", "Partial", Partial.class, null);
86
        dataTypesManager.addtype(DataTypes.PERIOD, "Period", "Period", Period.class, null);
87

    
88
                
89
                try {
90
                        registerDataStoreMetadataDefinition();
91
                } catch (MetadataException e) {
92
                        exs.add(e);
93
                }
94
                try {
95
                        registerSpatialDataStoreMetadataDefinition();
96
                } catch (MetadataException e) {
97
                        exs.add(e);
98
                }
99
                try {
100
                        registerFeatureStoreMetadataDefinition();
101
                } catch (MetadataException e) {
102
                        exs.add(e);
103
                }
104

    
105
                // Validate there is any implementation registered.
106
                DataManager dataManager = DALLocator.getDataManager();
107
                if (dataManager == null) {
108
                        throw new ReferenceNotRegisteredException(
109
                                        DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance());
110
                }
111

    
112
                ResourceManagerProviderServices resourceManager =
113
                                (ResourceManagerProviderServices) DALLocator.getResourceManager();
114
                if (resourceManager == null) {
115
                        throw new ReferenceNotRegisteredException(
116
                                        DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance());
117
                }
118

    
119
                if (!resourceManager.getResourceProviders().contains(
120
                                MultiResource.TYPE_NAME)) {
121
                        resourceManager.register(MultiResource.TYPE_NAME,
122
                                        MultiResource.DESCRIPTION, MultiResource.class,
123
                                        MultiResourceParameters.class);
124
                }
125

    
126
                if (!resourceManager.getResourceProviders().contains(
127
                                MemoryResource.NAME)) {
128
                        resourceManager.register(MemoryResource.NAME,
129
                                        MemoryResource.DESCRIPTION, MemoryResource.class,
130
                                        MemoryResourceParameters.class);
131
                }
132

    
133
                if( exs.size()>0 ) {
134
                        throw new LibraryException(this.getClass(), exs);
135
                }
136
        }
137
        
138
        private void registerDataStoreMetadataDefinition() throws MetadataException {
139
                MetadataManager manager = MetadataLocator.getMetadataManager();
140
                if( manager.getDefinition(DataStore.METADATA_DEFINITION_NAME)==null ) {
141
                        manager.addDefinition(
142
                                        DataStore.METADATA_DEFINITION_NAME, 
143
                                        DALLibrary.class.getResourceAsStream("MetadataDefinitions.xml"),
144
                                        DALLibrary.class.getClassLoader()
145
                        );
146
                }
147
        }
148

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

    
160
        private void registerFeatureStoreMetadataDefinition() throws MetadataException {
161
                MetadataManager manager = MetadataLocator.getMetadataManager();
162
                if( manager.getDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME)==null ) {
163
                        manager.addDefinition(
164
                                        DataStore.FEATURE_METADATA_DEFINITION_NAME, 
165
                                        DALLibrary.class.getResourceAsStream("MetadataDefinitions.xml"),
166
                                        DALLibrary.class.getClassLoader()
167
                        );
168
                }
169
        }
170

    
171
}