svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / DALLibrary.java @ 45308
History | View | Annotate | Download (4.79 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; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.List; |
28 |
|
29 |
import org.cresques.ProjectionLibrary; |
30 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
31 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
32 |
|
33 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
34 |
import org.gvsig.fmap.geom.GeometryLibrary; |
35 |
import org.gvsig.metadata.MetadataLibrary; |
36 |
import org.gvsig.metadata.MetadataLocator; |
37 |
import org.gvsig.metadata.MetadataManager; |
38 |
import org.gvsig.metadata.exceptions.MetadataException; |
39 |
import org.gvsig.timesupport.TimeSupportLibrary; |
40 |
import org.gvsig.tools.ToolsLibrary; |
41 |
import org.gvsig.tools.library.AbstractLibrary; |
42 |
import org.gvsig.tools.library.LibraryException; |
43 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
44 |
|
45 |
/**
|
46 |
* Initializes gvSIG's desktop DAL by registering the default implementation for
|
47 |
* {@link DataManager} and {@link ResourceManager}.
|
48 |
*
|
49 |
*/
|
50 |
public class DALLibrary extends AbstractLibrary { |
51 |
|
52 |
@Override
|
53 |
public void doRegistration() { |
54 |
registerAsAPI(DALLibrary.class); |
55 |
require(ToolsLibrary.class); |
56 |
require(MetadataLibrary.class); |
57 |
require(ProjectionLibrary.class); |
58 |
require(GeometryLibrary.class); |
59 |
require(TimeSupportLibrary.class); |
60 |
require(ExpressionEvaluatorLibrary.class); |
61 |
} |
62 |
|
63 |
@Override
|
64 |
protected void doInitialize() throws LibraryException { |
65 |
// Do nothing
|
66 |
} |
67 |
|
68 |
@Override
|
69 |
protected void doPostInitialize() throws LibraryException { |
70 |
List exs = new ArrayList(); |
71 |
|
72 |
try {
|
73 |
registerDataStoreMetadataDefinition(); |
74 |
} catch (MetadataException e) {
|
75 |
exs.add(e); |
76 |
} |
77 |
try {
|
78 |
registerSpatialDataStoreMetadataDefinition(); |
79 |
} catch (MetadataException e) {
|
80 |
exs.add(e); |
81 |
} |
82 |
try {
|
83 |
registerFeatureStoreMetadataDefinition(); |
84 |
} catch (MetadataException e) {
|
85 |
exs.add(e); |
86 |
} |
87 |
|
88 |
// Validate there is any implementation registered.
|
89 |
DataManager dataManager = DALLocator.getDataManager(); |
90 |
if (dataManager == null) { |
91 |
throw new ReferenceNotRegisteredException( |
92 |
DALLocator.DATA_MANAGER_NAME, DALLocator.getInstance()); |
93 |
} |
94 |
|
95 |
if (exs.size() > 0) { |
96 |
throw new LibraryException(this.getClass(), exs); |
97 |
} |
98 |
} |
99 |
|
100 |
private void registerDataStoreMetadataDefinition() throws MetadataException { |
101 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
102 |
if (manager.getDefinition(DataStore.METADATA_DEFINITION_NAME) == null) { |
103 |
manager |
104 |
.addDefinition(DataStore.METADATA_DEFINITION_NAME, |
105 |
DALLibrary.class |
106 |
.getResourceAsStream("MetadataDefinitions.xml"),
|
107 |
DALLibrary.class.getClassLoader()); |
108 |
} |
109 |
} |
110 |
|
111 |
private void registerSpatialDataStoreMetadataDefinition() |
112 |
throws MetadataException {
|
113 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
114 |
if (manager.getDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME) == null) { |
115 |
manager |
116 |
.addDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME, |
117 |
DALLibrary.class |
118 |
.getResourceAsStream("MetadataDefinitions.xml"),
|
119 |
DALLibrary.class.getClassLoader()); |
120 |
} |
121 |
} |
122 |
|
123 |
private void registerFeatureStoreMetadataDefinition() |
124 |
throws MetadataException {
|
125 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
126 |
if (manager.getDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME) == null) { |
127 |
manager |
128 |
.addDefinition(DataStore.FEATURE_METADATA_DEFINITION_NAME, |
129 |
DALLibrary.class |
130 |
.getResourceAsStream("MetadataDefinitions.xml"),
|
131 |
DALLibrary.class.getClassLoader()); |
132 |
} |
133 |
} |
134 |
|
135 |
} |