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