svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / DALLibrary.java @ 40333
History | View | Annotate | Download (5.79 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.feature.spi.memory.MemoryResource; |
35 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters; |
36 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
37 |
import org.gvsig.fmap.dal.resource.spi.MultiResource; |
38 |
import org.gvsig.fmap.dal.resource.spi.MultiResourceParameters; |
39 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
40 |
import org.gvsig.fmap.geom.GeometryLibrary; |
41 |
import org.gvsig.metadata.MetadataLibrary; |
42 |
import org.gvsig.metadata.MetadataLocator; |
43 |
import org.gvsig.metadata.MetadataManager; |
44 |
import org.gvsig.metadata.exceptions.MetadataException; |
45 |
import org.gvsig.timesupport.TimeSupportLibrary; |
46 |
import org.gvsig.tools.ToolsLibrary; |
47 |
import org.gvsig.tools.library.AbstractLibrary; |
48 |
import org.gvsig.tools.library.LibraryException; |
49 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
50 |
|
51 |
/**
|
52 |
* Initializes gvSIG's desktop DAL by registering the default implementation for
|
53 |
* {@link DataManager} and {@link ResourceManager}.
|
54 |
*
|
55 |
*/
|
56 |
public class DALLibrary extends AbstractLibrary { |
57 |
|
58 |
public void doRegistration() { |
59 |
registerAsAPI(DALLibrary.class); |
60 |
require(ToolsLibrary.class); |
61 |
require(MetadataLibrary.class); |
62 |
require(ProjectionLibrary.class); |
63 |
require(GeometryLibrary.class); |
64 |
require(TimeSupportLibrary.class); |
65 |
} |
66 |
|
67 |
protected void doInitialize() throws LibraryException { |
68 |
// Do nothing
|
69 |
} |
70 |
|
71 |
protected void doPostInitialize() throws LibraryException { |
72 |
List exs = new ArrayList(); |
73 |
|
74 |
try {
|
75 |
registerDataStoreMetadataDefinition(); |
76 |
} catch (MetadataException e) {
|
77 |
exs.add(e); |
78 |
} |
79 |
try {
|
80 |
registerSpatialDataStoreMetadataDefinition(); |
81 |
} catch (MetadataException e) {
|
82 |
exs.add(e); |
83 |
} |
84 |
try {
|
85 |
registerFeatureStoreMetadataDefinition(); |
86 |
} catch (MetadataException e) {
|
87 |
exs.add(e); |
88 |
} |
89 |
|
90 |
// Validate there is any implementation registered.
|
91 |
DataManager dataManager = DALLocator.getDataManager(); |
92 |
if (dataManager == null) { |
93 |
throw new ReferenceNotRegisteredException( |
94 |
DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance()); |
95 |
} |
96 |
|
97 |
ResourceManagerProviderServices resourceManager = |
98 |
(ResourceManagerProviderServices) DALLocator.getResourceManager(); |
99 |
if (resourceManager == null) { |
100 |
throw new ReferenceNotRegisteredException( |
101 |
DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance()); |
102 |
} |
103 |
|
104 |
if (!resourceManager.getResourceProviders().contains(
|
105 |
MultiResource.TYPE_NAME)) { |
106 |
resourceManager.register(MultiResource.TYPE_NAME, |
107 |
MultiResource.DESCRIPTION, MultiResource.class, |
108 |
MultiResourceParameters.class); |
109 |
} |
110 |
|
111 |
if (!resourceManager.getResourceProviders().contains(
|
112 |
MemoryResource.NAME)) { |
113 |
resourceManager.register(MemoryResource.NAME, |
114 |
MemoryResource.DESCRIPTION, MemoryResource.class, |
115 |
MemoryResourceParameters.class); |
116 |
} |
117 |
|
118 |
if (exs.size() > 0) { |
119 |
throw new LibraryException(this.getClass(), exs); |
120 |
} |
121 |
} |
122 |
|
123 |
private void registerDataStoreMetadataDefinition() throws MetadataException { |
124 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
125 |
if (manager.getDefinition(DataStore.METADATA_DEFINITION_NAME) == null) { |
126 |
manager |
127 |
.addDefinition(DataStore.METADATA_DEFINITION_NAME, |
128 |
DALLibrary.class |
129 |
.getResourceAsStream("MetadataDefinitions.xml"),
|
130 |
DALLibrary.class.getClassLoader()); |
131 |
} |
132 |
} |
133 |
|
134 |
private void registerSpatialDataStoreMetadataDefinition() |
135 |
throws MetadataException {
|
136 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
137 |
if (manager.getDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME) == null) { |
138 |
manager |
139 |
.addDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME, |
140 |
DALLibrary.class |
141 |
.getResourceAsStream("MetadataDefinitions.xml"),
|
142 |
DALLibrary.class.getClassLoader()); |
143 |
} |
144 |
} |
145 |
|
146 |
private void registerFeatureStoreMetadataDefinition() |
147 |
throws MetadataException {
|
148 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
149 |
if (manager.getDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME) == null) { |
150 |
manager |
151 |
.addDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME, |
152 |
DALLibrary.class |
153 |
.getResourceAsStream("MetadataDefinitions.xml"),
|
154 |
DALLibrary.class.getClassLoader()); |
155 |
} |
156 |
} |
157 |
|
158 |
} |