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