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

History | View | Annotate | Download (4.15 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 org.gvsig.fmap.dal.resource.ResourceManager;
31
import org.gvsig.tools.locator.AbstractLocator;
32
import org.gvsig.tools.locator.Locator;
33
import org.gvsig.tools.locator.LocatorException;
34

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

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

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

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

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

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

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

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

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

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

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

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

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

    
133
        /**
134
         * Registers the Class implementing the MDManager interface.
135
         *
136
         * @param clazz
137
         *            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
}