public ClassLoader createDynamicClassLoader(ClassLoader parentCl, ClassLoader extraCl) { return new ArchiveFileDynamicClassLoader(this, parentCl, extraCl); }
protected Object getResourceInDependentJarInEAR(String name, int type) { Set visitedArchives = new HashSet(5); visitedArchives.add(getArchive()); return getResourceInDependentJarInEAR(name, visitedArchives, type); }
protected File getFile(String name) { File file = getFileFromArchive(name); if (file == null) { file = getFileFromDependentJar(name); } return file; }
protected Class loadClassInDependentJar(String name) throws ClassNotFoundException { if (inEARFile) { return loadClassInDependentJarInEAR(name); } else if (getExtraClassLoader() != null) { return getExtraClassLoader().loadClass(name); } throw new ClassNotFoundException(name); }
/** * Used for dynamic class loading in dependent jars in ears; the set is used to terminate a * cycle if one exists; the cycle is invalid, but you never know what people might try... */ protected synchronized Class loadClass(String name, Set visitedArchives) throws ClassNotFoundException { if (visitedArchives.contains(getArchive())) throw new ClassNotFoundException(name); visitedArchives.add(getArchive()); try { return super.loadClass(name, false); } catch (ClassNotFoundException ex) { return loadClassInDependentJarInEAR(name, visitedArchives); } }
/** * <p>Loads a specified class. Called only after the parent class loader has had * its chance to load the class, as per the Java2 delegation model.</p> * * <p>When non-null, the receiver's protection * domain is passed in to the call to <code>defineClass</code>.</p> * * @see ClassLoader#defineClass(String, byte[], int) * @see ClassLoader#defineClass(String, byte[], int, ProtectionDomain) */ protected Class findClass(String name) throws ClassNotFoundException { Class result; // Load class bytes from current set of class byte[]'s byte[] bytes = getClassBytesFor(name); if (bytes != null) { if ( protectionDomain == null ) { result = defineClass(name, bytes, 0, bytes.length); } else { result = defineClass(name, bytes, 0, bytes.length, protectionDomain); } if (result == null) { throw new ClassNotFoundException(name); } // endif } else { throw new ClassNotFoundException(name); } // endif return result; }
protected Object getResourceInDependentJarInEAR(String name, Set visitedArchives, int type) { String[] classpath = archive.getManifest().getClassPathTokenized(); for (int i = 0; i < classpath.length; i++) { try { String uri = ArchiveUtil.deriveEARRelativeURI(classpath[i], archive); if (uri == null) continue; File jarFile = getEARFile().getFile(uri); if (jarFile.isArchive()) { Archive dep = (Archive) jarFile; switch (type) { case CLASS_TYPE : try { return ((ArchiveFileDynamicClassLoader) dep.getArchiveClassLoader()).loadClass(name, visitedArchives); } catch (ClassNotFoundException noDice) { continue; } case FILE_TYPE : try { return dep.getFile(name); } catch (FileNotFoundException noDice) { continue; } } } } catch (java.io.FileNotFoundException depJarNotInEAR) { } } return null; }
protected File getFileFromArchive(String name) { try { return getArchive().getFile(name); } catch (FileNotFoundException e) { } return null; }
protected URL findResource(String name) { if (getFile(name) != null) { try { return new URL(null, URL_PROTOCOL + "://" + name, handler); } catch (MalformedURLException e) { e.printStackTrace(); throw new RuntimeException(e); } } return null; }
protected EARFile getEARFile() { return (EARFile) getArchive().getContainer(); }
public InputStream getResourceAsStream(String name) { try { File file = getFile(name); if (null != file) { return file.getInputStream(); } } catch (IOException e) { throw new ArchiveRuntimeException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.io_ex_loading_EXC_, (new Object[]{name})), e); // = "An IO exception occurred loading " } return null; }