Revision 41770
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/plugins/PluginClassLoader.java | ||
---|---|---|
37 | 37 |
import java.util.ArrayList; |
38 | 38 |
import java.util.Arrays; |
39 | 39 |
import java.util.Enumeration; |
40 |
import java.util.HashSet; |
|
40 | 41 |
import java.util.Hashtable; |
41 | 42 |
import java.util.Iterator; |
42 | 43 |
import java.util.List; |
43 | 44 |
import java.util.Map; |
44 | 45 |
import java.util.Map.Entry; |
46 |
import java.util.Set; |
|
45 | 47 |
import java.util.StringTokenizer; |
46 | 48 |
import java.util.zip.ZipEntry; |
47 | 49 |
import java.util.zip.ZipException; |
... | ... | |
203 | 205 |
|
204 | 206 |
} else { |
205 | 207 |
//Buscamos en los otros plugins |
206 |
logger.debug("Searching in depends pluginLoaders"); |
|
207 |
for (int i = 0; i < pluginLoaders.size(); i++) { |
|
208 |
c = null; |
|
209 |
if (pluginLoaders.get(i) != null) { |
|
210 |
try { |
|
211 |
c = pluginLoaders.get(i).singleLoadClass(name); |
|
212 |
} catch (ClassNotFoundException e) { |
|
213 |
// Si no la encontramos en el primer plugin, capturamos la exceptcion |
|
214 |
// porque es probable que la encontremos en el resto de plugins. |
|
215 |
} |
|
216 |
} |
|
217 |
if (c != null) { |
|
218 |
break; |
|
219 |
} |
|
220 |
} |
|
208 |
Set<String>pluginsVisiteds = new HashSet<String>(); |
|
209 |
c = this.singleLoadClassFromOthersPlugins(pluginsVisiteds, name); |
|
221 | 210 |
} |
222 | 211 |
} else { |
223 | 212 |
String fileName = name.replace('.', '/') + ".class"; |
... | ... | |
395 | 384 |
* @return Resource's URL if it was found, nul otherwise. |
396 | 385 |
*/ |
397 | 386 |
public URL getResource(String res) { |
398 |
URL ret = null;
|
|
387 |
URL ret = null;
|
|
399 | 388 |
// |
400 |
// Primero buscamos en el directorio del plugin.
|
|
401 |
try {
|
|
402 |
logger.debug("Plugin {}. Searching resource '{}'", res, this.getPluginName());
|
|
389 |
// Primero buscamos en el directorio del plugin.
|
|
390 |
try {
|
|
391 |
logger.debug("Plugin {}. Searching resource '{}'", res, this.getPluginName());
|
|
403 | 392 |
List<String> resource = new ArrayList<String>(); |
404 | 393 |
StringTokenizer st = new StringTokenizer(res, "\\/"); |
405 |
while (st.hasMoreTokens()) {
|
|
394 |
while ( st.hasMoreTokens() ) {
|
|
406 | 395 |
String token = st.nextToken(); |
407 | 396 |
resource.add(token); |
408 | 397 |
} |
409 | 398 |
ret = getResource(baseDir, resource); |
410 |
if (ret != null) {
|
|
399 |
if ( ret != null ) {
|
|
411 | 400 |
return ret; |
412 | 401 |
} |
413 | 402 |
} catch (Exception e) { |
414 |
logger.warn("Plugin {}. Error getting resource '{}'.", new Object[] {this.getPluginName(),res}, e);
|
|
403 |
logger.warn("Plugin {}. Error getting resource '{}'.", new Object[]{this.getPluginName(), res}, e);
|
|
415 | 404 |
} |
416 |
|
|
405 |
|
|
417 | 406 |
// |
418 |
// Luego en los plugins de los que depende |
|
419 |
logger.debug("Plugin {}. Searching in depends pluginLoaders", this.getPluginName()); |
|
420 |
for (int i = 0; i < this.pluginLoaders.size(); i++) { |
|
421 |
PluginClassLoader pluginClassLoader = pluginLoaders.get(i); |
|
422 |
if (pluginClassLoader != null) { |
|
423 |
try { |
|
424 |
ret = pluginClassLoader.getResource(res); |
|
425 |
if (ret != null) { |
|
426 |
logger.trace("Plugin {}. Found resource '{}' in plugin '{}'.", |
|
427 |
new Object[] { |
|
428 |
this.getPluginName(),pluginClassLoader.getPluginName(),res |
|
429 |
}); |
|
430 |
return ret; |
|
431 |
} |
|
432 |
} catch (Exception e) { |
|
433 |
// Ignore, try in next classloader |
|
434 |
} |
|
435 |
} |
|
436 |
} |
|
437 |
|
|
407 |
// Luego en los plugins de los que depende |
|
408 |
Set<String>pluginsVisiteds = new HashSet<String>(); |
|
409 |
ret = this.getResourceFromOthersPlugins(pluginsVisiteds, res); |
|
410 |
|
|
438 | 411 |
// |
439 | 412 |
// Por ultimo en el class loader padre, se supone que es el del sistema. |
440 | 413 |
try { |
441 | 414 |
ret = super.getResource(res); |
442 | 415 |
} catch (Exception e) { |
443 |
logger.warn("Plugin {}. Error getting resource '{}' in parent classloader'", new Object[] {this.getPluginName(),res}, e);
|
|
416 |
logger.warn("Plugin {}. Error getting resource '{}' in parent classloader'", new Object[]{this.getPluginName(), res}, e);
|
|
444 | 417 |
} |
445 |
|
|
446 |
|
|
447 |
if( ret == null ) { |
|
448 |
logger.debug("Plugin {}. Resource '{}' not found.", new Object[] {this.getPluginName(),res}); |
|
418 |
|
|
419 |
if ( ret == null ) { |
|
420 |
logger.debug("Plugin {}. Resource '{}' not found.", new Object[]{this.getPluginName(), res}); |
|
449 | 421 |
} |
450 | 422 |
return ret; |
451 | 423 |
} |
... | ... | |
532 | 504 |
this.pluginLoaders.add(pluginClassLoader); |
533 | 505 |
} |
534 | 506 |
} |
507 |
|
|
508 |
private Class singleLoadClassFromOthersPlugins(Set<String> pluginsVisiteds, String name) throws ClassNotFoundException { |
|
509 |
Class<?> c=null; |
|
510 |
|
|
511 |
if ( pluginsVisiteds.contains(this.getPluginName()) ) { |
|
512 |
return null; |
|
513 |
} |
|
514 |
pluginsVisiteds.add(this.getPluginName()); |
|
515 |
|
|
516 |
logger.debug("Searching in depends pluginLoaders"); |
|
517 |
for ( int i = 0; i < pluginLoaders.size(); i++ ) { |
|
518 |
c = null; |
|
519 |
if ( pluginLoaders.get(i) != null ) { |
|
520 |
try { |
|
521 |
c = pluginLoaders.get(i).singleLoadClass(name); |
|
522 |
} catch (ClassNotFoundException e) { |
|
523 |
// Si no la encontramos en el primer plugin, capturamos la exceptcion |
|
524 |
// porque es probable que la encontremos en el resto de plugins. |
|
525 |
} |
|
526 |
} |
|
527 |
if ( c != null ) { |
|
528 |
return c; |
|
529 |
} |
|
530 |
} |
|
531 |
|
|
532 |
return null; |
|
533 |
} |
|
534 |
|
|
535 |
|
|
536 |
private URL getResourceFromOthersPlugins(Set<String>pluginsVisiteds, String res) { |
|
537 |
URL ret = null; |
|
538 |
|
|
539 |
if( pluginsVisiteds.contains(this.getPluginName()) ) { |
|
540 |
return null; |
|
541 |
} |
|
542 |
pluginsVisiteds.add(this.getPluginName()); |
|
543 |
|
|
544 |
logger.debug("Plugin {}. Searching in depends pluginLoaders", this.getPluginName()); |
|
545 |
for ( int i = 0; i < this.pluginLoaders.size(); i++ ) { |
|
546 |
PluginClassLoader pluginClassLoader = pluginLoaders.get(i); |
|
547 |
if ( pluginClassLoader != null ) { |
|
548 |
try { |
|
549 |
pluginsVisiteds.add(pluginClassLoader.getPluginName()); |
|
550 |
ret = pluginClassLoader.getResourceFromOthersPlugins(pluginsVisiteds, res); |
|
551 |
if ( ret != null ) { |
|
552 |
logger.trace("Plugin {}. Found resource '{}' in plugin '{}'.", |
|
553 |
new Object[]{ |
|
554 |
this.getPluginName(), pluginClassLoader.getPluginName(), res |
|
555 |
}); |
|
556 |
return ret; |
|
557 |
} |
|
558 |
} catch (Exception e) { |
|
559 |
// Ignore, try in next classloader |
|
560 |
} |
|
561 |
} |
|
562 |
} |
|
563 |
return null; |
|
564 |
} |
|
535 | 565 |
} |
Also available in: Unified diff