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 @ 47778
History | View | Annotate | Download (4.79 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.fmap.dal; |
||
25 | |||
26 | import java.util.ArrayList; |
||
27 | import java.util.List; |
||
28 | |||
29 | import org.cresques.ProjectionLibrary; |
||
30 | 43987 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorLibrary; |
31 | 44829 | omartinez | import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
32 | 40435 | jjdelcerro | |
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 | 43987 | jjdelcerro | @Override
|
53 | 40435 | jjdelcerro | 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 | 43987 | jjdelcerro | require(ExpressionEvaluatorLibrary.class); |
61 | 40435 | jjdelcerro | } |
62 | |||
63 | 43987 | jjdelcerro | @Override
|
64 | 40435 | jjdelcerro | protected void doInitialize() throws LibraryException { |
65 | // Do nothing
|
||
66 | } |
||
67 | |||
68 | 43987 | jjdelcerro | @Override
|
69 | 40435 | jjdelcerro | 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 | } |