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

History | View | Annotate | Download (4.1 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 IVER T.I. S.A.   {{Task}}
26
 */
27
package org.gvsig.fmap.dal;
28

    
29
import org.gvsig.fmap.dal.resource.ResourceManager;
30
import org.gvsig.tools.locator.AbstractLocator;
31
import org.gvsig.tools.locator.Locator;
32
import org.gvsig.tools.locator.LocatorException;
33

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

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

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

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

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

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

    
61
        /**
62
         * Unique instance.
63
         */
64
        private static final DALLocator instance = new DALLocator();
65

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

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

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

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

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

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

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

    
143
}