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 @ 43521
History | View | Annotate | Download (10.3 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.JSIRSpatialIndexProviderFactory; |
44 |
import org.gvsig.fmap.dal.feature.impl.MemorySpatialIndexProvider; |
45 |
import org.gvsig.fmap.dal.feature.impl.MemorySpatialIndexProviderFactory; |
46 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.ComputeAvailableValuesFromTable; |
47 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DumbFeatureTypeDefinitionsManager; |
48 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.relations.DALLink_getRelatedFeature; |
49 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.relations.DALLink_getRelatedFeatures; |
50 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResource; |
51 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters; |
52 |
import org.gvsig.fmap.dal.resource.impl.DefaultResourceManager; |
53 |
import org.gvsig.fmap.dal.resource.spi.MultiResource; |
54 |
import org.gvsig.fmap.dal.resource.spi.MultiResourceParameters; |
55 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
56 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
57 |
import org.gvsig.i18n.Messages; |
58 |
import org.gvsig.metadata.exceptions.MetadataException; |
59 |
import org.gvsig.tools.ToolsLocator; |
60 |
import org.gvsig.tools.dynobject.DynClass; |
61 |
import org.gvsig.tools.dynobject.DynObjectManager; |
62 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
63 |
import org.gvsig.tools.library.AbstractLibrary; |
64 |
import org.gvsig.tools.library.LibraryException; |
65 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
66 |
import org.xmlpull.v1.XmlPullParserException; |
67 |
|
68 |
/**
|
69 |
* Initialize the implementation of DAL.
|
70 |
*
|
71 |
* @author gvSIG Team
|
72 |
* @version $Id$
|
73 |
*
|
74 |
*/
|
75 |
public class DALDefaultImplLibrary extends AbstractLibrary { |
76 |
|
77 |
@Override
|
78 |
public void doRegistration() { |
79 |
registerAsImplementationOf(DALLibrary.class); |
80 |
} |
81 |
|
82 |
@Override
|
83 |
protected void doInitialize() throws LibraryException { |
84 |
DALLocator.registerDefaultDataManager(DefaultDataManager.class); |
85 |
DALLocator.registerResourceManager(DefaultResourceManager.class); |
86 |
DALLocator.registerDefaultFeatureTypeDefinitionsManager(DumbFeatureTypeDefinitionsManager.class); |
87 |
} |
88 |
|
89 |
@Override
|
90 |
protected void doPostInitialize() throws LibraryException { |
91 |
List exs = new ArrayList(); |
92 |
|
93 |
Messages.addResourceFamily("org.gvsig.fmap.dal.i18n.text",
|
94 |
DALDefaultImplLibrary.class.getClassLoader(), |
95 |
DALDefaultImplLibrary.class.getClass().getName()); |
96 |
|
97 |
try {
|
98 |
registerBaseNewProvidersParametersDefinition(); |
99 |
} catch (XmlPullParserException e) {
|
100 |
exs.add(e); |
101 |
} catch (IOException e) { |
102 |
exs.add(e); |
103 |
} |
104 |
|
105 |
SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager(); |
106 |
identityManager.registerAction(DataManager.CREATE_STORE_AUTHORIZATION); |
107 |
identityManager.registerAction(DataManager.READ_STORE_AUTHORIZATION); |
108 |
identityManager.registerAction(DataManager.WRITE_STORE_AUTHORIZATION); |
109 |
|
110 |
|
111 |
DefaultFeatureQuery.registerPersistent(); |
112 |
DefaultFeatureReference.registerPersistent(); |
113 |
DefaultFeatureStoreTransforms.registerPersistent(); |
114 |
AbstractFeatureStoreTransform.registerPersistent(); |
115 |
DefaultFeatureReferenceSelection.registerPersistent(); |
116 |
DefaultFeatureSelection.registerPersistent(); |
117 |
// DefaultCoverageStore.registerPersistent();
|
118 |
|
119 |
DefaultFeatureStore.registerPersistenceDefinition(); |
120 |
DefaultDataServerExplorerPool.registerPersistenceDefinition(); |
121 |
DefaultDataServerExplorerPoolEntry.registerPersistenceDefinition(); |
122 |
try {
|
123 |
DefaultFeatureStore.registerMetadataDefinition(); |
124 |
} catch (MetadataException e) {
|
125 |
exs.add(e); |
126 |
} |
127 |
|
128 |
// DefaultFeatureAttributeDescriptor.registerPersistent();
|
129 |
|
130 |
//Register the FeatureAttributeTransform
|
131 |
DefaultDataManager dataManager = (DefaultDataManager) DALLocator.getDataManager(); |
132 |
if (dataManager == null) { |
133 |
throw new ReferenceNotRegisteredException( |
134 |
DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance()); |
135 |
} |
136 |
// dataManager.registerFeatureAttributeGetter("milliToRelativeInstant", MilliToRelativeInstantFeatureAttributeGetter.class);
|
137 |
// dataManager.registerFeatureAttributeGetter("milliToAbsoluteInstant", MilliToAbsoluteInstantFeatureAttributeGetter.class);
|
138 |
// dataManager.registerFeatureAttributeGetter("secondToRelativeInstant", SecondToRelativeInstantFeatureAttributeGetter.class);
|
139 |
// dataManager.registerFeatureAttributeGetter("secondToAbsoluteInstant",SecondToAbsoluteInstantFeatureAttributeGetter.class);
|
140 |
// dataManager.registerFeatureAttributeGetter("minuteToRelativeInstant",MinuteToRelativeInstantFeatureAttributeGetter.class);
|
141 |
// dataManager.registerFeatureAttributeGetter("minuteToAbsoluteInstant", MinuteToAbsoluteInstantFeatureAttributeGetter.class);
|
142 |
// dataManager.registerFeatureAttributeGetter("hourToRelativeInstant", HourToRelativeInstantFeatureAttributeGetter.class);
|
143 |
// dataManager.registerFeatureAttributeGetter("hourToAbsoluteInstant", HourToAbsoluteInstantFeatureAttributeGetter.class);
|
144 |
// dataManager.registerFeatureAttributeGetter("dayToAbsoluteInstant", DayToAbsoluteInstantFeatureAttributeGetter.class);
|
145 |
// dataManager.registerFeatureAttributeGetter("dayToRelativeInstant", DayToRelativeInstantFeatureAttributeGetter.class);
|
146 |
// dataManager.registerFeatureAttributeGetter("monthToAbsoluteInstant", MonthToAbsoluteInstantFeatureAttributeGetter.class);
|
147 |
// dataManager.registerFeatureAttributeGetter("yearToAbsoluteInstant", YearToAbsoluteInstantFeatureAttributeGetter.class);
|
148 |
|
149 |
// Register a default spatial index based in the default memory spatial index of geom library
|
150 |
if( !dataManager.getFeatureIndexRegister().exits(MemorySpatialIndexProvider.NAME) ) {
|
151 |
dataManager.getFeatureIndexRegister().register(new MemorySpatialIndexProviderFactory());
|
152 |
} |
153 |
if( !dataManager.getFeatureIndexRegister().exits(JSIRSpatialIndexProvider.NAME) ) {
|
154 |
dataManager.getFeatureIndexRegister().register(new JSIRSpatialIndexProviderFactory());
|
155 |
dataManager.setDefaultFeatureIndexProviderName( |
156 |
DataTypes.GEOMETRY, |
157 |
JSIRSpatialIndexProvider.NAME |
158 |
); |
159 |
} |
160 |
|
161 |
ResourceManagerProviderServices resourceManager = |
162 |
(ResourceManagerProviderServices) DALLocator.getResourceManager(); |
163 |
if (resourceManager == null) { |
164 |
throw new ReferenceNotRegisteredException( |
165 |
DALLocator.RESOURCE_MANAGER_NAME, DALLocator.getInstance()); |
166 |
} |
167 |
|
168 |
if (!resourceManager.getResourceProviders().contains(
|
169 |
MultiResource.TYPE_NAME)) { |
170 |
resourceManager.register(MultiResource.TYPE_NAME, |
171 |
MultiResource.DESCRIPTION, MultiResource.class, |
172 |
MultiResourceParameters.class); |
173 |
} |
174 |
|
175 |
if (!resourceManager.getResourceProviders().contains(
|
176 |
MemoryResource.NAME)) { |
177 |
resourceManager.register(MemoryResource.NAME, |
178 |
MemoryResource.DESCRIPTION, MemoryResource.class, |
179 |
MemoryResourceParameters.class); |
180 |
} |
181 |
|
182 |
DynObjectManager dynObjectmanager = ToolsLocator.getDynObjectManager(); |
183 |
dynObjectmanager.registerDynMethod(new DALLink_getRelatedFeatures());
|
184 |
dynObjectmanager.registerDynMethod(new DALLink_getRelatedFeature());
|
185 |
dynObjectmanager.registerDynMethod(new ComputeAvailableValuesFromTable("getAvailableValuesFromTable", "Retrieve available values from the elements of a table.")); |
186 |
|
187 |
if (exs.size() > 0) { |
188 |
throw new LibraryException(this.getClass(), exs); |
189 |
} |
190 |
} |
191 |
|
192 |
private void registerBaseNewProvidersParametersDefinition() |
193 |
throws XmlPullParserException, IOException { |
194 |
DynObjectManager manager = ToolsLocator.getDynObjectManager(); |
195 |
if (manager
|
196 |
.get( |
197 |
"DAL",
|
198 |
DataStoreProviderServices.BASE_NEWPARAMETERS_PROVIDER_DEFINITION_NAME) == null) {
|
199 |
Map definitions =
|
200 |
manager |
201 |
.importDynClassDefinitions( |
202 |
DataStoreProviderServices.class |
203 |
.getResourceAsStream("ProviderParametersDefinition.xml"),
|
204 |
DataStoreProviderServices.class.getClassLoader()); |
205 |
manager |
206 |
.add((DynClass) definitions |
207 |
.get(DataStoreProviderServices.BASE_NEWPARAMETERS_PROVIDER_DEFINITION_FULLNAME)); |
208 |
manager |
209 |
.add((DynClass) definitions |
210 |
.get(DataStoreProviderServices.BASE_PARAMETERS_PROVIDER_DEFINITION_FULLNAME)); |
211 |
} |
212 |
} |
213 |
|
214 |
} |