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