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