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 @ 44340

History | View | Annotate | Download (6.09 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
    public static DataManager getManager() throws LocatorException {
103
        return getDataManager();
104
    }
105
    
106
    /**
107
     * Registers the Class implementing the DataManager interface.
108
     *
109
     * @param clazz implementing the DataManager interface
110
     */
111
    public static void registerDataManager(Class clazz) {
112
        getInstance().register(DATA_MANAGER_NAME, DATA_MANAGER_DESCRIPTION,
113
                clazz);
114
    }
115

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

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

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

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

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

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

    
183
}