svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / impl / DALDefaultImplLibrary.java @ 40435
History | View | Annotate | Download (9.66 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 |
package org.gvsig.fmap.dal.impl; |
23 |
|
24 |
import java.io.IOException; |
25 |
import java.util.ArrayList; |
26 |
import java.util.List; |
27 |
import java.util.Map; |
28 |
|
29 |
import org.gvsig.fmap.dal.DALLibrary; |
30 |
import org.gvsig.fmap.dal.DALLocator; |
31 |
import org.gvsig.fmap.dal.DataManager; |
32 |
import org.gvsig.fmap.dal.DataTypes; |
33 |
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform; |
34 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureQuery; |
35 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReference; |
36 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection; |
37 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection; |
38 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
39 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStoreTransforms; |
40 |
import org.gvsig.fmap.dal.feature.impl.MemorySpatialIndexProvider; |
41 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.DayToAbsoluteInstantFeatureAttributeGetter; |
42 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.DayToRelativeInstantFeatureAttributeGetter; |
43 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.HourToAbsoluteInstantFeatureAttributeGetter; |
44 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.HourToRelativeInstantFeatureAttributeGetter; |
45 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.MilliToAbsoluteInstantFeatureAttributeGetter; |
46 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.MilliToRelativeInstantFeatureAttributeGetter; |
47 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.MinuteToAbsoluteInstantFeatureAttributeGetter; |
48 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.MinuteToRelativeInstantFeatureAttributeGetter; |
49 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.MonthToAbsoluteInstantFeatureAttributeGetter; |
50 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.SecondToAbsoluteInstantFeatureAttributeGetter; |
51 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.SecondToRelativeInstantFeatureAttributeGetter; |
52 |
import org.gvsig.fmap.dal.feature.impl.attributegetter.YearToAbsoluteInstantFeatureAttributeGetter; |
53 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResource; |
54 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters; |
55 |
import org.gvsig.fmap.dal.resource.impl.DefaultResourceManager; |
56 |
import org.gvsig.fmap.dal.resource.spi.MultiResource; |
57 |
import org.gvsig.fmap.dal.resource.spi.MultiResourceParameters; |
58 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
59 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
60 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
61 |
import org.gvsig.i18n.Messages; |
62 |
import org.gvsig.metadata.exceptions.MetadataException; |
63 |
import org.gvsig.tools.ToolsLocator; |
64 |
import org.gvsig.tools.dynobject.DynClass; |
65 |
import org.gvsig.tools.dynobject.DynObjectManager; |
66 |
import org.gvsig.tools.library.AbstractLibrary; |
67 |
import org.gvsig.tools.library.LibraryException; |
68 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
69 |
import org.xmlpull.v1.XmlPullParserException; |
70 |
|
71 |
/**
|
72 |
* Initialize the implementation of DAL.
|
73 |
*
|
74 |
* @author gvSIG Team
|
75 |
* @version $Id$
|
76 |
*
|
77 |
*/
|
78 |
public class DALDefaultImplLibrary extends AbstractLibrary { |
79 |
|
80 |
public void doRegistration() { |
81 |
registerAsImplementationOf(DALLibrary.class); |
82 |
} |
83 |
|
84 |
protected void doInitialize() throws LibraryException { |
85 |
DALLocator.registerDefaultDataManager(DefaultDataManager.class); |
86 |
DALLocator.registerResourceManager(DefaultResourceManager.class); |
87 |
} |
88 |
|
89 |
protected void doPostInitialize() throws LibraryException { |
90 |
List exs = new ArrayList(); |
91 |
|
92 |
Messages.addResourceFamily("org.gvsig.fmap.dal.i18n.text",
|
93 |
DALDefaultImplLibrary.class.getClassLoader(), |
94 |
DALDefaultImplLibrary.class.getClass().getName()); |
95 |
|
96 |
try {
|
97 |
registerBaseNewProvidersParametersDefinition(); |
98 |
} catch (XmlPullParserException e) {
|
99 |
exs.add(e); |
100 |
} catch (IOException e) { |
101 |
exs.add(e); |
102 |
} |
103 |
|
104 |
DefaultFeatureQuery.registerPersistent(); |
105 |
DefaultFeatureReference.registerPersistent(); |
106 |
DefaultFeatureStoreTransforms.registerPersistent(); |
107 |
AbstractFeatureStoreTransform.registerPersistent(); |
108 |
DefaultFeatureReferenceSelection.registerPersistent(); |
109 |
DefaultFeatureSelection.registerPersistent(); |
110 |
// DefaultCoverageStore.registerPersistent();
|
111 |
|
112 |
DefaultFeatureStore.registerPersistenceDefinition(); |
113 |
try {
|
114 |
DefaultFeatureStore.registerMetadataDefinition(); |
115 |
} catch (MetadataException e) {
|
116 |
exs.add(e); |
117 |
} |
118 |
|
119 |
// DefaultFeatureAttributeDescriptor.registerPersistent();
|
120 |
|
121 |
//Register the FeatureAttributeTransform
|
122 |
DataManager dataManager = DALLocator.getDataManager(); |
123 |
if (dataManager == null) { |
124 |
throw new ReferenceNotRegisteredException( |
125 |
DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance()); |
126 |
} |
127 |
dataManager.registerFeatureAttributeGetter("milliToRelativeInstant", MilliToRelativeInstantFeatureAttributeGetter.class);
|
128 |
dataManager.registerFeatureAttributeGetter("milliToAbsoluteInstant", MilliToAbsoluteInstantFeatureAttributeGetter.class);
|
129 |
dataManager.registerFeatureAttributeGetter("secondToRelativeInstant", SecondToRelativeInstantFeatureAttributeGetter.class);
|
130 |
dataManager.registerFeatureAttributeGetter("secondToAbsoluteInstant",SecondToAbsoluteInstantFeatureAttributeGetter.class);
|
131 |
dataManager.registerFeatureAttributeGetter("minuteToRelativeInstant",MinuteToRelativeInstantFeatureAttributeGetter.class);
|
132 |
dataManager.registerFeatureAttributeGetter("minuteToAbsoluteInstant", MinuteToAbsoluteInstantFeatureAttributeGetter.class);
|
133 |
dataManager.registerFeatureAttributeGetter("hourToRelativeInstant", HourToRelativeInstantFeatureAttributeGetter.class);
|
134 |
dataManager.registerFeatureAttributeGetter("hourToAbsoluteInstant", HourToAbsoluteInstantFeatureAttributeGetter.class);
|
135 |
dataManager.registerFeatureAttributeGetter("dayToAbsoluteInstant", DayToAbsoluteInstantFeatureAttributeGetter.class);
|
136 |
dataManager.registerFeatureAttributeGetter("dayToRelativeInstant", DayToRelativeInstantFeatureAttributeGetter.class);
|
137 |
dataManager.registerFeatureAttributeGetter("monthToAbsoluteInstant", MonthToAbsoluteInstantFeatureAttributeGetter.class);
|
138 |
dataManager.registerFeatureAttributeGetter("yearToAbsoluteInstant", YearToAbsoluteInstantFeatureAttributeGetter.class);
|
139 |
|
140 |
// Register a default spatial index based in the default memory spatial index of geom library
|
141 |
if (!dataManager.getFeatureIndexProviders().contains(MemorySpatialIndexProvider.NAME)) {
|
142 |
((DataManagerProviderServices)dataManager).registerFeatureIndexProvider(MemorySpatialIndexProvider.NAME, "Default Spatial index",
|
143 |
MemorySpatialIndexProvider.class, DataTypes.GEOMETRY); |
144 |
dataManager.setDefaultFeatureIndexProviderName(DataTypes.GEOMETRY, MemorySpatialIndexProvider.NAME); |
145 |
} |
146 |
|
147 |
ResourceManagerProviderServices resourceManager = |
148 |
(ResourceManagerProviderServices) DALLocator.getResourceManager(); |
149 |
if (resourceManager == null) { |
150 |
throw new ReferenceNotRegisteredException( |
151 |
DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance()); |
152 |
} |
153 |
|
154 |
if (!resourceManager.getResourceProviders().contains(
|
155 |
MultiResource.TYPE_NAME)) { |
156 |
resourceManager.register(MultiResource.TYPE_NAME, |
157 |
MultiResource.DESCRIPTION, MultiResource.class, |
158 |
MultiResourceParameters.class); |
159 |
} |
160 |
|
161 |
if (!resourceManager.getResourceProviders().contains(
|
162 |
MemoryResource.NAME)) { |
163 |
resourceManager.register(MemoryResource.NAME, |
164 |
MemoryResource.DESCRIPTION, MemoryResource.class, |
165 |
MemoryResourceParameters.class); |
166 |
} |
167 |
|
168 |
if (exs.size() > 0) { |
169 |
throw new LibraryException(this.getClass(), exs); |
170 |
} |
171 |
} |
172 |
|
173 |
private void registerBaseNewProvidersParametersDefinition() |
174 |
throws XmlPullParserException, IOException { |
175 |
DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
176 |
if (manager
|
177 |
.get( |
178 |
"DAL",
|
179 |
DataStoreProviderServices.BASE_NEWPARAMETERS_PROVIDER_DEFINITION_NAME) == null) {
|
180 |
Map definitions =
|
181 |
manager |
182 |
.importDynClassDefinitions( |
183 |
DataStoreProviderServices.class |
184 |
.getResourceAsStream("ProviderParametersDefinition.xml"),
|
185 |
DataStoreProviderServices.class.getClassLoader()); |
186 |
manager |
187 |
.add((DynClass) definitions |
188 |
.get(DataStoreProviderServices.BASE_NEWPARAMETERS_PROVIDER_DEFINITION_FULLNAME)); |
189 |
manager |
190 |
.add((DynClass) definitions |
191 |
.get(DataStoreProviderServices.BASE_PARAMETERS_PROVIDER_DEFINITION_FULLNAME)); |
192 |
} |
193 |
} |
194 |
|
195 |
} |