Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.compat / org.gvsig.compat.api / src / main / java / org / gvsig / compat / CompatLocator.java @ 40559

History | View | Annotate | Download (6.95 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
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
* 
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
* 
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
* 
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
42
* MA  02110-1301, USA.
43
* 
44
*/
45

    
46
/*
47
 * AUTHORS (In addition to CIT):
48
 * 2008 DiSiD Technologies   Create initial base implementation
49
 */
50
package org.gvsig.compat;
51

    
52
import org.gvsig.compat.lang.GraphicsUtils;
53
import org.gvsig.compat.lang.MathUtils;
54
import org.gvsig.compat.lang.StringUtils;
55
import org.gvsig.compat.net.Downloader;
56
import org.gvsig.tools.locator.BaseLocator;
57
import org.gvsig.tools.locator.Locator;
58
import org.gvsig.tools.locator.LocatorException;
59

    
60
/**
61
 * Locator for the libCompat Library. Returns references to the library's main
62
 * utilities.
63
 * 
64
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
65
 */
66
public class CompatLocator extends BaseLocator {
67
    
68
    /**
69
     * The name of the StringUtils reference.
70
     */
71
    public static final String STRINGUTILS_NAME = "StringUtils";
72
    
73
    /**
74
     * The name of the MathUtils reference.
75
     */
76
    public static final String MATHUTILS_NAME = "MathUtils";
77
    public static final String GRAPHICSUTILS_NAME = "GraphicsUtils";
78

    
79
    /**
80
     * The description of the StringUtils reference.
81
     */
82
    private static final String STRINGUTILS_DESCRIPTION = "Compatible implementation for String Utilities";
83
    
84
    /**
85
     * The description of the MathUtils reference.
86
     */
87
    private static final String MATHUTILS_DESCRIPTION = "Compatible implementation for Math Utilities";
88
    private static final String GRAPHICSUTILS_DESCRIPTION = "Compatible implementation for Graphics Utilities";
89
    
90
    /**
91
     * The name and the description for the {@link Downloader} reference.
92
     */
93
    public static final String DOWNLOADER_NAME = "Downloader";
94
    public static final String DOWNLOADER_DESCRIPTION = "Downloader descripction";
95

    
96
    /**
97
     * Unique instance.
98
     */
99
    private static final CompatLocator instance = new CompatLocator();
100

    
101
    /**
102
     * Return the singleton instance.
103
     * 
104
     * @return the singleton instance
105
     */
106
    public static CompatLocator getInstance() {
107
        return instance;
108
    }
109

    
110
    /**
111
     * Return a reference to StringUtils.
112
     * 
113
     * @return a reference to StringUtils
114
     * @throws LocatorException
115
     *             if there is no access to the class or the class cannot be
116
     *             instantiated
117
     * @see Locator#get(String)
118
     */
119
    public static StringUtils getStringUtils() throws LocatorException {
120
        return (StringUtils) getInstance().get(STRINGUTILS_NAME);
121
    }
122

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

    
136
    
137
    /**
138
     * Registers the Class implementing the MathUtils interface.
139
     * 
140
     * @param clazz
141
     *            implementing the MathUtils interface
142
     */
143
    public static void registerMathUtils(Class clazz) {
144
        getInstance()
145
                .register(MATHUTILS_NAME, MATHUTILS_DESCRIPTION, clazz);
146
    }
147
    
148
    /**
149
     * Registers the Class implementing the StringUtils interface.
150
     * 
151
     * @param clazz
152
     *            implementing the StringUtils interface
153
     */
154
    public static void registerStringUtils(Class clazz) {
155
        getInstance()
156
                .register(STRINGUTILS_NAME, STRINGUTILS_DESCRIPTION, clazz);
157
    }
158
    
159
    // ============================================================
160
    // ============================================================
161
    // ============================================================
162
    
163
    /**
164
     * Return a reference to GraphicsUtils.
165
     * 
166
     * @return a reference to GraphicsUtils
167
     * @throws LocatorException
168
     *             if there is no access to the class or the class cannot be
169
     *             instantiated
170
     * @see Locator#get(String)
171
     */
172
    public static GraphicsUtils getGraphicsUtils() throws LocatorException {
173
        return (GraphicsUtils) getInstance().get(GRAPHICSUTILS_NAME);
174
    }
175

    
176
    
177
    /**
178
     * Registers the Class implementing the GraphicsUtils interface.
179
     * 
180
     * @param clazz
181
     *            implementing the GraphicsUtils interface
182
     */
183
    public static void registerGraphicsUtils(Class clazz) {
184
        getInstance()
185
                .register(GRAPHICSUTILS_NAME, GRAPHICSUTILS_DESCRIPTION, clazz);
186
    }
187
    
188
    /**
189
     * Return a reference to GraphicsUtils.
190
     * 
191
     * @return a reference to GraphicsUtils
192
     * @throws LocatorException
193
     *             if there is no access to the class or the class cannot be
194
     *             instantiated
195
     * @see Locator#get(String)
196
     */
197
    public static Downloader getDownloader() throws LocatorException {
198
        return (Downloader) getInstance().get(DOWNLOADER_NAME);
199
    }
200

    
201
    
202
    /**
203
     * Registers the Class implementing the GraphicsUtils interface.
204
     * 
205
     * @param clazz
206
     *            implementing the GraphicsUtils interface
207
     */
208
    public static void registerDownloader(Class clazz) {
209
        getInstance()
210
                .register(DOWNLOADER_NAME, DOWNLOADER_DESCRIPTION, clazz);
211
    }
212
    
213
    
214
}