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

History | View | Annotate | Download (4.08 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 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 services.
34
 * DAL services are grouped in two managers {@link DataManager} and {@link ResourceManager}.
35
 *
36
 * This locator offers methods for registering as well as for obtaining both managers' unique instances.
37
 *
38
 * @see Locator
39
 */
40
public class DALLocator extends AbstractLocator {
41

    
42
        private static final String LOCATOR_NAME = "DALLocator";
43

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

    
49
        private static final String DATA_MANAGER_DESCRIPTION = "DataManager of gvSIG Data Access Library";
50

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

    
56
        private static final String RESOURCE_MANAGER_DESCRIPTION = "ResourceManager of gvSIG Data Access Library";
57

    
58
        /**
59
         * Unique instance.
60
         */
61
        private static final DALLocator instance = new DALLocator();
62

    
63
        /**
64
         * Return the singleton instance.
65
         *
66
         * @return the singleton instance
67
         */
68
        public static DALLocator getInstance() {
69
                return instance;
70
        }
71

    
72
        /**
73
         * Returns the Locator name.
74
         *
75
         * @return String containing the locator name.
76
         */
77
        public String getLocatorName() {
78
                return LOCATOR_NAME;
79
        }
80

    
81
        /**
82
         * Return a reference to DataManager.
83
         *
84
         * @return a reference to DataManager
85
         * @throws LocatorException
86
         *             if there is no access to the class or the class cannot be
87
         *             instantiated
88
         * @see Locator#get(String)
89
         */
90
        public static DataManager getDataManager() throws LocatorException {
91
                return (DataManager) getInstance().get(DATA_MANAGER_NAME);
92
        }
93

    
94
        /**
95
         * Registers the Class implementing the DataManager interface.
96
         *
97
         * @param clazz
98
         *            implementing the DataManager interface
99
         */
100
        public static void registerDataManager(Class clazz) {
101
                getInstance().register(DATA_MANAGER_NAME, DATA_MANAGER_DESCRIPTION,
102
                                clazz);
103
        }
104

    
105
        /**
106
         * Registers a class as the default DataManager.
107
         *
108
         * @param clazz
109
         *                           implementing the DataManager interface
110
         */
111
        public static void registerDefaultDataManager(Class clazz) {
112
                getInstance().registerDefault(DATA_MANAGER_NAME, DATA_MANAGER_DESCRIPTION,
113
                                clazz);
114
        }
115

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

    
129
        /**
130
         * Registers the Class implementing the MDManager interface.
131
         *
132
         * @param clazz
133
         *            implementing the MDManager interface
134
         */
135
        public static void registerResourceManager(Class clazz) {
136
                getInstance().register(RESOURCE_MANAGER_NAME,
137
                                RESOURCE_MANAGER_DESCRIPTION, clazz);
138
        }
139

    
140
}