Reloading classes means creating a new classloader and using it whenever we are asked for classes in the appropriate space. For this we use a DiscreteFilesClassLoader
( String [] classNames )
| 356 | For this we use a DiscreteFilesClassLoader |
| 357 | */ |
| 358 | @Override |
| 359 | public void reloadClasses( String [] classNames ) |
| 360 | throws ClassPathException |
| 361 | { |
| 362 | // validate that it is a class here? |
| 363 | |
| 364 | // init base class loader if there is none... |
| 365 | if ( baseLoader == null ) |
| 366 | initBaseLoader(); |
| 367 | |
| 368 | DiscreteFilesClassLoader.ClassSourceMap map = |
| 369 | new DiscreteFilesClassLoader.ClassSourceMap(); |
| 370 | |
| 371 | for (int i=0; i< classNames.length; i++) { |
| 372 | String name = classNames[i]; |
| 373 | |
| 374 | // look in baseLoader class path |
| 375 | ClassSource classSource = baseClassPath.getClassSource( name ); |
| 376 | |
| 377 | // look in user class path |
| 378 | if ( classSource == null ) { |
| 379 | BshClassPath.getUserClassPath().insureInitialized(); |
| 380 | classSource = BshClassPath.getUserClassPath().getClassSource( |
| 381 | name ); |
| 382 | } |
| 383 | |
| 384 | // No point in checking boot class path, can't reload those. |
| 385 | // else we could have used fullClassPath above. |
| 386 | |
| 387 | if ( classSource == null ) |
| 388 | throw new ClassPathException("Nothing known about class: " |
| 389 | +name ); |
| 390 | |
| 391 | // JarClassSource is not working... just need to implement it's |
| 392 | // getCode() method or, if we decide to, allow the BshClassManager |
| 393 | // to handle it... since it is a URLClassLoader and can handle JARs |
| 394 | if ( classSource instanceof JarClassSource ) |
| 395 | throw new ClassPathException("Cannot reload class: "+name+ |
| 396 | " from source: "+ classSource ); |
| 397 | |
| 398 | map.put( name, classSource ); |
| 399 | } |
| 400 | |
| 401 | // Create classloader for the set of classes |
| 402 | ClassLoader cl = new DiscreteFilesClassLoader( this, map ); |
| 403 | |
| 404 | // map those classes the loader in the overlay map |
| 405 | Iterator it = map.keySet().iterator(); |
| 406 | while ( it.hasNext() ) |
| 407 | loaderMap.put( (String)it.next(), cl ); |
| 408 | |
| 409 | classLoaderChanged(); |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | Reload all classes in the specified package: e.g. "com.sun.tools" |
no test coverage detected