@Test public void testResources() throws IllegalArgumentException, IOException { LoadedLibrary lib = LoadedJarLibrary .createFromJar("export/jars/i5.las2peer.classLoaders.testPackage1-1.0.jar"); ServiceClassLoader testee = new ServiceClassLoader(lib, null, new DefaultPolicy()); Properties properties = new Properties(); properties.load(testee.getResourceAsStream("i5/las2peer/classLoaders/testPackage1/test.properties")); assertEquals("123", properties.getProperty("integer")); assertEquals("value", properties.getProperty("attribute")); URL test = testee.getResource("does/not/exist"); assertNull(test); }
URL getResource(String resourceName, boolean lookUp) { Logger.logGetResource(this, resourceName, null, lookUp); URL res; try { res = library.getResourceAsUrl(resourceName); } catch (ResourceNotFoundException e) { if (lookUp && parent != null) { URL result = parent.getResource(resourceName); if (result != null) { return result; } else { Logger.logGetResource(this, resourceName, false, null); return null; } } else { Logger.logGetResource(this, resourceName, false, null); return null; } } if (res != null) { Logger.logGetResource(this, resourceName, true, null); return res; } else { return null; } }
ServiceClassLoader extends ClassLoader { URL getResource(String resourceName, boolean lookUp) { Logger.logGetResource(this, resourceName, null, lookUp); URL res; try { res = library.getResourceAsUrl(resourceName); } catch (ResourceNotFoundException e) { if (lookUp && parent != null) { URL result = parent.getResource(resourceName); if (result != null) { return result; } else { Logger.logGetResource(this, resourceName, false, null); return null; } } else { Logger.logGetResource(this, resourceName, false, null); return null; } } if (res != null) { Logger.logGetResource(this, resourceName, true, null); return res; } else { return null; } } }
ServiceClassLoader extends ClassLoader { URL getResource(String resourceName, boolean lookUp) { Logger.logGetResource(this, resourceName, null, lookUp); URL res; try { res = library.getResourceAsUrl(resourceName); } catch (ResourceNotFoundException e) { if (lookUp && parent != null) { URL result = parent.getResource(resourceName); if (result != null) { return result; } else { Logger.logGetResource(this, resourceName, false, null); return null; } } else { Logger.logGetResource(this, resourceName, false, null); return null; } } if (res != null) { Logger.logGetResource(this, resourceName, true, null); return res; } else { return null; } } ServiceClassLoader(LoadedLibrary lib, ClassLoader parent, ClassLoaderPolicy policy); }
ServiceClassLoader extends ClassLoader { URL getResource(String resourceName, boolean lookUp) { Logger.logGetResource(this, resourceName, null, lookUp); URL res; try { res = library.getResourceAsUrl(resourceName); } catch (ResourceNotFoundException e) { if (lookUp && parent != null) { URL result = parent.getResource(resourceName); if (result != null) { return result; } else { Logger.logGetResource(this, resourceName, false, null); return null; } } else { Logger.logGetResource(this, resourceName, false, null); return null; } } if (res != null) { Logger.logGetResource(this, resourceName, true, null); return res; } else { return null; } } ServiceClassLoader(LoadedLibrary lib, ClassLoader parent, ClassLoaderPolicy policy); LoadedLibrary getLibrary(); @Override URL getResource(String resourceName); }
ServiceClassLoader extends ClassLoader { URL getResource(String resourceName, boolean lookUp) { Logger.logGetResource(this, resourceName, null, lookUp); URL res; try { res = library.getResourceAsUrl(resourceName); } catch (ResourceNotFoundException e) { if (lookUp && parent != null) { URL result = parent.getResource(resourceName); if (result != null) { return result; } else { Logger.logGetResource(this, resourceName, false, null); return null; } } else { Logger.logGetResource(this, resourceName, false, null); return null; } } if (res != null) { Logger.logGetResource(this, resourceName, true, null); return res; } else { return null; } } ServiceClassLoader(LoadedLibrary lib, ClassLoader parent, ClassLoaderPolicy policy); LoadedLibrary getLibrary(); @Override URL getResource(String resourceName);  }