Statistics
| Revision:

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 / DALLocator.java @ 42775

History | View | Annotate | Download (5.98 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 modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal;
24

    
25
import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager;
26
import org.gvsig.fmap.dal.resource.ResourceManager;
27
import org.gvsig.tools.locator.AbstractLocator;
28
import org.gvsig.tools.locator.Locator;
29
import org.gvsig.tools.locator.LocatorException;
30

    
31
/**
32
 *
33
 * This locator is the entry point of gvSIG's DAL, providing access to all DAL
34
 * services. DAL services are grouped in two managers {@link DataManager} and
35
 * {@link ResourceManager}.
36
 *
37
 * This locator offers methods for registering as well as for obtaining both
38
 * managers' unique instances.
39
 *
40
 * @see Locator
41
 */
42
public class DALLocator extends AbstractLocator {
43

    
44
    private static final String LOCATOR_NAME = "DALLocator";
45

    
46
    /**
47
     * DataManager name used by the locator to access the instance
48
     */
49
    public static final String DATA_MANAGER_NAME = "DataManager";
50

    
51
    private static final String DATA_MANAGER_DESCRIPTION = "DataManager of gvSIG Data Access Library";
52

    
53
    /**
54
     * ResourceManager name used by the locator to access the instance
55
     */
56
    public static final String RESOURCE_MANAGER_NAME = "ResourceManager";
57

    
58
    private static final String RESOURCE_MANAGER_DESCRIPTION = "ResourceManager of gvSIG Data Access Library";
59

    
60
    /**
61
     * DataManager name used by the locator to access the instance
62
     */
63
    public static final String FEATURETYPE_DEFINITIONS_MANAGER_NAME = "FeatureTypeDefinitionsManager";
64

    
65
    private static final String FEATURETYPE_DEFINITIONS_MANAGER_DESCRIPTION = "FeatureTypeDefinitionsManager of gvSIG Data Access Library";
66

    
67
    /**
68
     * Unique instance.
69
     */
70
    private static final DALLocator instance = new DALLocator();
71

    
72
    /**
73
     * Return the singleton instance.
74
     *
75
     * @return the singleton instance
76
     */
77
    public static DALLocator getInstance() {
78
        return instance;
79
    }
80

    
81
    /**
82
     * Returns the Locator name.
83
     *
84
     * @return String containing the locator name.
85
     */
86
    public String getLocatorName() {
87
        return LOCATOR_NAME;
88
    }
89

    
90
    /**
91
     * Return a reference to DataManager.
92
     *
93
     * @return a reference to DataManager
94
     * @throws LocatorException if there is no access to the class or the class
95
     * cannot be instantiated
96
     * @see Locator#get(String)
97
     */
98
    public static DataManager getDataManager() throws LocatorException {
99
        return (DataManager) getInstance().get(DATA_MANAGER_NAME);
100
    }
101

    
102
    /**
103
     * Registers the Class implementing the DataManager interface.
104
     *
105
     * @param clazz implementing the DataManager interface
106
     */
107
    public static void registerDataManager(Class clazz) {
108
        getInstance().register(DATA_MANAGER_NAME, DATA_MANAGER_DESCRIPTION,
109
                clazz);
110
    }
111

    
112
    /**
113
     * Registers a class as the default DataManager.
114
     *
115
     * @param clazz implementing the DataManager interface
116
     */
117
    public static void registerDefaultDataManager(Class clazz) {
118
        getInstance().registerDefault(DATA_MANAGER_NAME, DATA_MANAGER_DESCRIPTION,
119
                clazz);
120
    }
121

    
122
    /**
123
     * Return a reference to ResourceManager.
124
     *
125
     * @return a reference to ResourceManager
126
     * @throws LocatorException if there is no access to the class or the class
127
     * cannot be instantiated
128
     * @see Locator#get(String)
129
     */
130
    public static ResourceManager getResourceManager() throws LocatorException {
131
        return (ResourceManager) getInstance().get(RESOURCE_MANAGER_NAME);
132
    }
133

    
134
    /**
135
     * Registers the Class implementing the MDManager interface.
136
     *
137
     * @param clazz implementing the MDManager interface
138
     */
139
    public static void registerResourceManager(Class clazz) {
140
        getInstance().register(RESOURCE_MANAGER_NAME,
141
                RESOURCE_MANAGER_DESCRIPTION, clazz);
142
    }
143

    
144
    /**
145
     * Return a reference to FeatureTypeDefinitionsManager.
146
     *
147
     * @return a reference to FeatureTypeDefinitionsManager
148
     * @throws LocatorException if there is no access to the class or the class
149
     * cannot be instantiated
150
     * @see Locator#get(String)
151
     */
152
    public static FeatureTypeDefinitionsManager getFeatureTypeDefinitionsManager() throws LocatorException {
153
        return (FeatureTypeDefinitionsManager) getInstance().get(FEATURETYPE_DEFINITIONS_MANAGER_NAME);
154
    }
155

    
156
    /**
157
     * Registers the Class implementing the FeatureTypeDefinitionsManager
158
     * interface.
159
     *
160
     * @param clazz implementing the FeatureTypeDefinitionsManager interface
161
     */
162
    public static void registerFeatureTypeDefinitionsManager(Class clazz) {
163
        getInstance().register(FEATURETYPE_DEFINITIONS_MANAGER_NAME,
164
                FEATURETYPE_DEFINITIONS_MANAGER_DESCRIPTION,
165
                clazz);
166
    }
167

    
168
    /**
169
     * Registers a class as the default FeatureTypeDefinitionsManager.
170
     *
171
     * @param clazz implementing the FeatureTypeDefinitionsManager interface
172
     */
173
    public static void registerDefaultFeatureTypeDefinitionsManager(Class clazz) {
174
        getInstance().registerDefault(FEATURETYPE_DEFINITIONS_MANAGER_NAME,
175
                FEATURETYPE_DEFINITIONS_MANAGER_DESCRIPTION,
176
                clazz);
177
    }
178

    
179
}