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 @ 40766
History | View | Annotate | Download (5.97 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.compat; |
25 |
|
26 |
import org.gvsig.compat.lang.GraphicsUtils; |
27 |
import org.gvsig.compat.lang.MathUtils; |
28 |
import org.gvsig.compat.lang.StringUtils; |
29 |
import org.gvsig.compat.net.Downloader; |
30 |
import org.gvsig.tools.locator.BaseLocator; |
31 |
import org.gvsig.tools.locator.Locator; |
32 |
import org.gvsig.tools.locator.LocatorException; |
33 |
|
34 |
/**
|
35 |
* Locator for the libCompat Library. Returns references to the library's main
|
36 |
* utilities.
|
37 |
*
|
38 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
39 |
*/
|
40 |
public class CompatLocator extends BaseLocator { |
41 |
|
42 |
/**
|
43 |
* The name of the StringUtils reference.
|
44 |
*/
|
45 |
public static final String STRINGUTILS_NAME = "StringUtils"; |
46 |
|
47 |
/**
|
48 |
* The name of the MathUtils reference.
|
49 |
*/
|
50 |
public static final String MATHUTILS_NAME = "MathUtils"; |
51 |
public static final String GRAPHICSUTILS_NAME = "GraphicsUtils"; |
52 |
|
53 |
/**
|
54 |
* The description of the StringUtils reference.
|
55 |
*/
|
56 |
private static final String STRINGUTILS_DESCRIPTION = "Compatible implementation for String Utilities"; |
57 |
|
58 |
/**
|
59 |
* The description of the MathUtils reference.
|
60 |
*/
|
61 |
private static final String MATHUTILS_DESCRIPTION = "Compatible implementation for Math Utilities"; |
62 |
private static final String GRAPHICSUTILS_DESCRIPTION = "Compatible implementation for Graphics Utilities"; |
63 |
|
64 |
/**
|
65 |
* The name and the description for the {@link Downloader} reference.
|
66 |
*/
|
67 |
public static final String DOWNLOADER_NAME = "Downloader"; |
68 |
public static final String DOWNLOADER_DESCRIPTION = "Downloader descripction"; |
69 |
|
70 |
/**
|
71 |
* Unique instance.
|
72 |
*/
|
73 |
private static final CompatLocator instance = new CompatLocator(); |
74 |
|
75 |
/**
|
76 |
* Return the singleton instance.
|
77 |
*
|
78 |
* @return the singleton instance
|
79 |
*/
|
80 |
public static CompatLocator getInstance() { |
81 |
return instance;
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* Return a reference to StringUtils.
|
86 |
*
|
87 |
* @return a reference to StringUtils
|
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 StringUtils getStringUtils() throws LocatorException { |
94 |
return (StringUtils) getInstance().get(STRINGUTILS_NAME);
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* Return a reference to MathUtils.
|
99 |
*
|
100 |
* @return a reference to MathUtils
|
101 |
* @throws LocatorException
|
102 |
* if there is no access to the class or the class cannot be
|
103 |
* instantiated
|
104 |
* @see Locator#get(String)
|
105 |
*/
|
106 |
public static MathUtils getMathUtils() throws LocatorException { |
107 |
return (MathUtils) getInstance().get(MATHUTILS_NAME);
|
108 |
} |
109 |
|
110 |
|
111 |
/**
|
112 |
* Registers the Class implementing the MathUtils interface.
|
113 |
*
|
114 |
* @param clazz
|
115 |
* implementing the MathUtils interface
|
116 |
*/
|
117 |
public static void registerMathUtils(Class clazz) { |
118 |
getInstance() |
119 |
.register(MATHUTILS_NAME, MATHUTILS_DESCRIPTION, clazz); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Registers the Class implementing the StringUtils interface.
|
124 |
*
|
125 |
* @param clazz
|
126 |
* implementing the StringUtils interface
|
127 |
*/
|
128 |
public static void registerStringUtils(Class clazz) { |
129 |
getInstance() |
130 |
.register(STRINGUTILS_NAME, STRINGUTILS_DESCRIPTION, clazz); |
131 |
} |
132 |
|
133 |
// ============================================================
|
134 |
// ============================================================
|
135 |
// ============================================================
|
136 |
|
137 |
/**
|
138 |
* Return a reference to GraphicsUtils.
|
139 |
*
|
140 |
* @return a reference to GraphicsUtils
|
141 |
* @throws LocatorException
|
142 |
* if there is no access to the class or the class cannot be
|
143 |
* instantiated
|
144 |
* @see Locator#get(String)
|
145 |
*/
|
146 |
public static GraphicsUtils getGraphicsUtils() throws LocatorException { |
147 |
return (GraphicsUtils) getInstance().get(GRAPHICSUTILS_NAME);
|
148 |
} |
149 |
|
150 |
|
151 |
/**
|
152 |
* Registers the Class implementing the GraphicsUtils interface.
|
153 |
*
|
154 |
* @param clazz
|
155 |
* implementing the GraphicsUtils interface
|
156 |
*/
|
157 |
public static void registerGraphicsUtils(Class clazz) { |
158 |
getInstance() |
159 |
.register(GRAPHICSUTILS_NAME, GRAPHICSUTILS_DESCRIPTION, clazz); |
160 |
} |
161 |
|
162 |
/**
|
163 |
* Return a reference to GraphicsUtils.
|
164 |
*
|
165 |
* @return a reference to GraphicsUtils
|
166 |
* @throws LocatorException
|
167 |
* if there is no access to the class or the class cannot be
|
168 |
* instantiated
|
169 |
* @see Locator#get(String)
|
170 |
*/
|
171 |
public static Downloader getDownloader() throws LocatorException { |
172 |
return (Downloader) getInstance().get(DOWNLOADER_NAME);
|
173 |
} |
174 |
|
175 |
|
176 |
/**
|
177 |
* Registers the Class implementing the GraphicsUtils interface.
|
178 |
*
|
179 |
* @param clazz
|
180 |
* implementing the GraphicsUtils interface
|
181 |
*/
|
182 |
public static void registerDownloader(Class clazz) { |
183 |
getInstance() |
184 |
.register(DOWNLOADER_NAME, DOWNLOADER_DESCRIPTION, clazz); |
185 |
} |
186 |
|
187 |
|
188 |
} |