Revision 42775 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

View differences:

DALLocator.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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.
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 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.
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 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.
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.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
package org.gvsig.fmap.dal;
25 24

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

  
31 31
/**
32 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}.
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}.
35 36
 *
36
 * This locator offers methods for registering as well as for obtaining both managers' unique instances.
37
 * This locator offers methods for registering as well as for obtaining both
38
 * managers' unique instances.
37 39
 *
38 40
 * @see Locator
39 41
 */
40 42
public class DALLocator extends AbstractLocator {
41 43

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

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

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

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

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

  
58
	/**
59
	 * Unique instance.
60
	 */
61
	private static final DALLocator instance = new DALLocator();
60
    /**
61
     * DataManager name used by the locator to access the instance
62
     */
63
    public static final String FEATURETYPE_DEFINITIONS_MANAGER_NAME = "FeatureTypeDefinitionsManager";
62 64

  
63
	/**
64
	 * Return the singleton instance.
65
	 *
66
	 * @return the singleton instance
67
	 */
68
	public static DALLocator getInstance() {
69
		return instance;
70
	}
65
    private static final String FEATURETYPE_DEFINITIONS_MANAGER_DESCRIPTION = "FeatureTypeDefinitionsManager of gvSIG Data Access Library";
71 66

  
72
	/**
73
	 * Returns the Locator name.
74
	 *
75
	 * @return String containing the locator name.
76
	 */
77
	public String getLocatorName() {
78
		return LOCATOR_NAME;
79
	}
67
    /**
68
     * Unique instance.
69
     */
70
    private static final DALLocator instance = new DALLocator();
80 71

  
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
	}
72
    /**
73
     * Return the singleton instance.
74
     *
75
     * @return the singleton instance
76
     */
77
    public static DALLocator getInstance() {
78
        return instance;
79
    }
93 80

  
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
	}
81
    /**
82
     * Returns the Locator name.
83
     *
84
     * @return String containing the locator name.
85
     */
86
    public String getLocatorName() {
87
        return LOCATOR_NAME;
88
    }
104 89

  
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
	}
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
    }
115 101

  
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
	}
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
    }
128 111

  
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
	}
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
    }
139 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

  
140 179
}

Also available in: Unified diff