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