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 | 29956 | jmvivo | /* 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 | 24496 | jmvivo | package org.gvsig.fmap.dal; |
28 | 23754 | jjdelcerro | |
29 | 32880 | jjdelcerro | import java.util.ArrayList; |
30 | import java.util.List; |
||
31 | |||
32 | 37326 | cordinyana | import org.cresques.ProjectionLibrary; |
33 | |||
34 | 31022 | cordinyana | import org.gvsig.fmap.dal.feature.spi.memory.MemoryResource; |
35 | import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters; |
||
36 | 24496 | jmvivo | import org.gvsig.fmap.dal.resource.ResourceManager; |
37 | 31022 | cordinyana | 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 | 33032 | jjdelcerro | import org.gvsig.fmap.geom.GeometryLibrary; |
41 | import org.gvsig.metadata.MetadataLibrary; |
||
42 | 32880 | jjdelcerro | import org.gvsig.metadata.MetadataLocator; |
43 | import org.gvsig.metadata.MetadataManager; |
||
44 | import org.gvsig.metadata.exceptions.MetadataException; |
||
45 | 37297 | jpiera | import org.gvsig.timesupport.TimeSupportLibrary; |
46 | 33032 | jjdelcerro | import org.gvsig.tools.ToolsLibrary; |
47 | 30633 | cordinyana | import org.gvsig.tools.library.AbstractLibrary; |
48 | 30580 | cordinyana | import org.gvsig.tools.library.LibraryException; |
49 | 23754 | jjdelcerro | import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
50 | |||
51 | 24366 | jiyarza | /**
|
52 | 34708 | jjdelcerro | * Initializes gvSIG's desktop DAL by registering the default implementation for
|
53 | * {@link DataManager} and {@link ResourceManager}.
|
||
54 | *
|
||
55 | 24366 | jiyarza | */
|
56 | 30633 | cordinyana | public class DALLibrary extends AbstractLibrary { |
57 | 23754 | jjdelcerro | |
58 | 35142 | cordinyana | public void doRegistration() { |
59 | registerAsAPI(DALLibrary.class); |
||
60 | 34708 | jjdelcerro | require(ToolsLibrary.class); |
61 | require(MetadataLibrary.class); |
||
62 | 37326 | cordinyana | require(ProjectionLibrary.class); |
63 | require(GeometryLibrary.class); |
||
64 | 37297 | jpiera | require(TimeSupportLibrary.class); |
65 | 34708 | jjdelcerro | } |
66 | 24454 | jmvivo | |
67 | 34708 | jjdelcerro | protected void doInitialize() throws LibraryException { |
68 | // Do nothing
|
||
69 | } |
||
70 | 32880 | jjdelcerro | |
71 | 34708 | jjdelcerro | protected void doPostInitialize() throws LibraryException { |
72 | List exs = new ArrayList(); |
||
73 | 24454 | jmvivo | |
74 | 34708 | jjdelcerro | 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 | 31022 | cordinyana | |
90 | 34708 | jjdelcerro | // 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 | 31022 | cordinyana | |
97 | 34708 | jjdelcerro | ResourceManagerProviderServices resourceManager = |
98 | (ResourceManagerProviderServices) DALLocator.getResourceManager(); |
||
99 | if (resourceManager == null) { |
||
100 | throw new ReferenceNotRegisteredException( |
||
101 | DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance()); |
||
102 | } |
||
103 | 25785 | jmvivo | |
104 | 34708 | jjdelcerro | if (!resourceManager.getResourceProviders().contains(
|
105 | MultiResource.TYPE_NAME)) { |
||
106 | resourceManager.register(MultiResource.TYPE_NAME, |
||
107 | MultiResource.DESCRIPTION, MultiResource.class, |
||
108 | MultiResourceParameters.class); |
||
109 | } |
||
110 | 25785 | jmvivo | |
111 | 34708 | jjdelcerro | if (!resourceManager.getResourceProviders().contains(
|
112 | MemoryResource.NAME)) { |
||
113 | resourceManager.register(MemoryResource.NAME, |
||
114 | MemoryResource.DESCRIPTION, MemoryResource.class, |
||
115 | MemoryResourceParameters.class); |
||
116 | } |
||
117 | 25785 | jmvivo | |
118 | 34708 | jjdelcerro | if (exs.size() > 0) { |
119 | throw new LibraryException(this.getClass(), exs); |
||
120 | } |
||
121 | } |
||
122 | 32880 | jjdelcerro | |
123 | 34708 | jjdelcerro | 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 | } |