Revision 40403 branches/v2_0_0_prep/frameworks/_fwAndami/src/org/gvsig/andami/Launcher.java
Launcher.java | ||
---|---|---|
128 | 128 |
import org.gvsig.andami.plugins.PluginClassLoader; |
129 | 129 |
import org.gvsig.andami.plugins.config.generate.Action; |
130 | 130 |
import org.gvsig.andami.plugins.config.generate.ActionTool; |
131 |
import org.gvsig.andami.plugins.config.generate.AlternativeNames; |
|
131 | 132 |
import org.gvsig.andami.plugins.config.generate.ComboButton; |
132 | 133 |
import org.gvsig.andami.plugins.config.generate.ComboButtonElement; |
133 | 134 |
import org.gvsig.andami.plugins.config.generate.ComboScale; |
... | ... | |
195 | 196 |
*/ |
196 | 197 |
public class Launcher { |
197 | 198 |
|
199 |
public static abstract class MapWithAlias<Item> extends HashMap<String, Item> { |
|
200 |
private HashMap<String, String> aliases = new HashMap<String, String>(); |
|
201 |
|
|
202 |
protected abstract String[] getAliases(Item item); |
|
203 |
|
|
204 |
public Item get(Object key) { |
|
205 |
Item item = super.get(key); |
|
206 |
if( item != null ) { |
|
207 |
return item; |
|
208 |
} |
|
209 |
String alias = aliases.get(key); |
|
210 |
if( alias != null ) { |
|
211 |
return super.get(alias); |
|
212 |
} |
|
213 |
return null; |
|
214 |
} |
|
215 |
|
|
216 |
public boolean containsKey(Object key) { |
|
217 |
boolean contains = super.containsKey(key); |
|
218 |
if( contains ) { |
|
219 |
return true; |
|
220 |
} |
|
221 |
String alias = aliases.get(key); |
|
222 |
return super.containsKey(alias); |
|
223 |
} |
|
224 |
|
|
225 |
public Item put(String key, Item value) { |
|
226 |
super.put(key, value); |
|
227 |
String[] aliases = getAliases(value); |
|
228 |
if( aliases==null ) { |
|
229 |
return value; |
|
230 |
} |
|
231 |
for( int n=0; n<aliases.length; n++ ) { |
|
232 |
this.aliases.put(aliases[n].trim(), key); |
|
233 |
} |
|
234 |
return value; |
|
235 |
} |
|
236 |
|
|
237 |
public void putAll(Map<? extends String, ? extends Item> m) { |
|
238 |
Iterator<?> it = m.entrySet().iterator(); |
|
239 |
while( it.hasNext() ) { |
|
240 |
Map.Entry<String, Item> x = (Map.Entry<String, Item>) it.next(); |
|
241 |
this.put(x.getKey(), x.getValue()); |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
public Item remove(Object key) { |
|
246 |
Item item = super.get(key); |
|
247 |
if( item == null ) { |
|
248 |
String alias = aliases.get(key); |
|
249 |
if( alias == null ) { |
|
250 |
return null; |
|
251 |
} |
|
252 |
item = super.get(alias); |
|
253 |
super.remove(alias); |
|
254 |
} else { |
|
255 |
super.remove(key); |
|
256 |
} |
|
257 |
String[] aliases = getAliases(item); |
|
258 |
if( aliases==null ) { |
|
259 |
return item; |
|
260 |
} |
|
261 |
for( int n=0; n<aliases.length; n++ ) { |
|
262 |
this.aliases.remove(aliases[n].trim()); |
|
263 |
} |
|
264 |
return item; |
|
265 |
} |
|
266 |
|
|
267 |
} |
|
268 |
|
|
269 |
public static class PluginsConfig extends MapWithAlias<org.gvsig.andami.plugins.config.generate.PluginConfig> { |
|
270 |
|
|
271 |
protected String[] getAliases( |
|
272 |
org.gvsig.andami.plugins.config.generate.PluginConfig item) { |
|
273 |
return getAlternativeNames(item); |
|
274 |
} |
|
275 |
|
|
276 |
static String[] getAlternativeNames(org.gvsig.andami.plugins.config.generate.PluginConfig item) { |
|
277 |
AlternativeNames[] x = item.getAlternativeNames(); |
|
278 |
if( x == null ) { |
|
279 |
return null; |
|
280 |
} |
|
281 |
String[] r = new String[x.length]; |
|
282 |
for( int i=0; i<x.length; i++) { |
|
283 |
r[i] = x[i].getName(); |
|
284 |
} |
|
285 |
return r; |
|
286 |
} |
|
287 |
|
|
288 |
} |
|
289 |
|
|
290 |
public static class PluginsServices extends MapWithAlias<org.gvsig.andami.PluginServices> { |
|
291 |
|
|
292 |
protected String[] getAliases(org.gvsig.andami.PluginServices item) { |
|
293 |
return item.getAlternativeNames(); |
|
294 |
} |
|
295 |
} |
|
296 |
|
|
198 | 297 |
protected static Logger logger = LoggerFactory.getLogger(Launcher.class |
199 | 298 |
.getName()); |
200 | 299 |
protected static Preferences prefs = Preferences.userRoot().node( |
... | ... | |
203 | 302 |
protected static MultiSplashWindow splashWindow; |
204 | 303 |
protected static String appName; |
205 | 304 |
protected static Locale locale; |
206 |
protected static HashMap<String, PluginConfig> pluginsConfig = new HashMap<String, PluginConfig>();
|
|
207 |
protected static HashMap<String, PluginServices> pluginsServices = new HashMap<String, PluginServices>();
|
|
305 |
protected static PluginsConfig pluginsConfig = new PluginsConfig();
|
|
306 |
protected static PluginsServices pluginsServices = new PluginsServices();
|
|
208 | 307 |
protected static MDIFrame frame; |
209 | 308 |
protected static HashMap<Class<? extends IExtension>, ExtensionDecorator> classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>(); |
210 | 309 |
protected static String andamiConfigPath; |
... | ... | |
2051 | 2150 |
+ File.separator + pluginName, Launcher.class |
2052 | 2151 |
.getClassLoader(), loaders); |
2053 | 2152 |
|
2054 |
PluginServices ps = new PluginServices(loader); |
|
2153 |
PluginServices ps = new PluginServices(loader, PluginsConfig.getAlternativeNames(config));
|
|
2055 | 2154 |
|
2056 | 2155 |
pluginsServices.put(ps.getPluginName(), ps); |
2057 | 2156 |
|
Also available in: Unified diff