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