⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 repositoryclassloader.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }        return null;    }    /**     * Returns an Enumeration of URLs representing all of the resources     * on the search path having the specified name.     *     * @param name the resource name     *     * @return an <code>Enumeration</code> of <code>URL</code>s. This is an     *      empty enumeration if no resources are found by this class loader     *      or if this class loader has already been destroyed.     */    public Enumeration findResources(String name) {        if (isDestroyed()) {            log.warn("Destroyed class loader cannot find resources");            return new Enumeration() {                public boolean hasMoreElements() {                    return false;                }                public Object nextElement() {                    throw new NoSuchElementException("No Entries");                }            };        }        log.debug("findResources: Try to find resources for {}", name);        List list = new LinkedList();        for (int i=0; i < repository.length; i++) {            final ClassPathEntry cp = repository[i];            log.debug("findResources: Trying {}", cp);            ClassLoaderResource res = cp.getResource(name);            if (res != null) {                log.debug("findResources: Adding resource from {}, created {}",                    res, new Date(res.getLastModificationTime()));                URL url = res.getURL();                if (url != null) {                    list.add(url);                }            }        }        // return the enumeration on the list        return Collections.enumeration(list);    }    /**     * Returns the search path of URLs for loading classes and resources.     * This includes the original list of URLs specified to the constructor,     * along with any URLs subsequently appended by the {@link #addURL(URL)}     * and {@link #addHandle(String)} methods.     *     * @return the search path of URLs for loading classes and resources. The     *      list is empty, if this class loader has already been destroyed.     */    public URL[] getURLs() {        if (isDestroyed()) {            log.warn("Destroyed class loader has no URLs any more");            return new URL[0];        }        List urls = new ArrayList();        for (int i=0; i < repository.length; i++) {            URL url = repository[i].toURL();            if (url != null) {                urls.add(url);            }        }        return (URL[]) urls.toArray(new URL[urls.size()]);    }    /**     * Appends the specified URL to the list of URLs to search for     * classes and resources. Only Repository URLs with the protocol set to     * <code>JCR</code> are considered for addition. The system will find out     * whether the URL points to a directory or a jar archive.     * <p>     * URLs added using this method will be preserved through reconfiguration     * and reinstantiation.     * <p>     * If this class loader has already been destroyed this method has no     * effect.     *     * @param url the <code>JCR</code> URL to be added to the search path of     *      URLs.     */    protected void addURL(URL url) {        if (isDestroyed()) {            log.warn("Cannot add URL to destroyed class loader");        } else if (checkURL(url)) {            // Repository URL            log.debug("addURL: Adding URL {}", url);            try {                JCRURLConnection conn = (JCRURLConnection) url.openConnection();                ClassPathEntry cp = ClassPathEntry.getInstance(                    conn.getSession(), conn.getPath());                addClassPathEntry(cp);            } catch (IOException ioe) {                log.warn("addURL: Cannot add URL " + url, ioe);            }        } else {            log.warn("addURL: {} is not a Repository URL, ignored", url);        }    }    /**     * Appends the specified path to the list of handles to search for classes     * and resources. The system will find out whether the path points to a     * directory or a JAR or ZIP archive. The path is added as is, provided it     * is valid to be used in the class path and therefore must not contain any     * globbing characters.     * <p>     * If this class loader has already been destroyed, this method has no     * effect.     *     * @param path The path to be added to the search path.     */    public void addHandle(String path) {        if (isDestroyed()) {            log.warn("Cannot add handle to destroyed class loader");            return;        }        log.debug("addURL: Adding Handle {}", path);        ClassPathEntry cp = ClassPathEntry.getInstance(session, path);        if (cp != null) {            addClassPathEntry(cp);        } else {            log.debug("addHandle: Cannot get a ClassPathEntry for {}", path);        }    }    //---------- Property access ----------------------------------------------    /**     * Sets the {@link PatternPath} list to be used as the initial search     * path of this class loader. This new list replaces the path pattern list     * set in the constructor or in a previous call to this method.     * <p>     * After setting the list, this class loader's class path has to be rebuilt     * by calling the {@link #buildRepository()} method.     *     * @param handles The {@link PatternPath} to set on this class loader.     */    /* package */ void setHandles(PatternPath handles) {        this.handles = handles;    }    /**     * Returns the current {@link PatternPath} from which the search path     * of this class loader is configured.     */    /* package */ PatternPath getHandles() {        return handles;    }    /**     * Returns the named {@link ClassLoaderResource} if it is contained in the     * cache. If the resource does not exist in the cache or has not been found     * in the class path at an earlier point in time, <code>null</code> is     * returned.     *     * @param name The name of the resource to retrieve from the cache.     *     * @return The named <code>ClassLoaderResource</code> or <code>null</code>     *      if not loaded.     *     * @throws NullPointerException If this class loader has already been     *      destroyed.     */    /* package */ ClassLoaderResource getCachedResource(String name) {        Object res = cache.get(name);        if (res == null || res == NOT_FOUND_RESOURCE) {            log.debug("Resource {} not cached", name);            return null;        }        return (ClassLoaderResource) res;    }    /**     * Returns an <code>Iterator</code> on all resources in the cache. This     * iterator may also contain {@link #NOT_FOUND_RESOURCE sentinel} entries     * for resources, which failed to load. Callers of this method should take     * care to filter out such resources before acting on it.     *     * @throws NullPointerException If this class loader has already been     *      destroyed.     */    /* package */ Iterator getCachedResources() {        return cache.values().iterator();    }    /**     * Removes all entries from the cache of loaded resources, which mark     * resources, which have not been found as of yet.     *     * @throws NullPointerException If this class loader has already been     *      destroyed.     */    protected void cleanCache() {        for (Iterator ci=cache.values().iterator(); ci.hasNext(); ) {            if (ci.next() == NOT_FOUND_RESOURCE) {                ci.remove();            }        }    }    /**     * Returns <code>true</code>, if the cache is not empty. If the     * {@link #cleanCache()} method is not called before calling this method, a     * false positive result may be returned.     *     * @throws NullPointerException If this class loader has already been     *      destroyed.     */    protected boolean hasLoadedResources() {        return cache.isEmpty();    }    /**     * Returns the session used by this class loader to access the repository.     * If this class loader has already been destroyed, this <code>null</code>     * is returned.     */    protected Session getSession() {        return session;    }    /**     * Sets the current active class path to the list of class path entries.     */    protected void setRepository(ClassPathEntry[] classPath) {        this.repository = classPath;    }    /**     * Returns the current active class path entries list or <code>null</code>     * if this class loader has already been destroyed.     */    protected ClassPathEntry[] getRepository() {        return repository;    }    /**     * Adds the class path entry to the current class path list. If the class     * loader has already been destroyed, this method creates a single entry     * class path list with the new class path entry.     */    protected void addClassPathEntry(ClassPathEntry cpe) {        log.debug("addHandle: Adding path {}", cpe.getPath());        // append the entry to the current class path        ClassPathEntry[] oldClassPath = getRepository();        ClassPathEntry[] newClassPath = addClassPathEntry(oldClassPath, cpe);        setRepository(newClassPath);    }    /**     * Helper method for class path handling to a new entry to an existing     * list and return the new list.     * <p>     * If <code>list</code> is <code>null</code> a new array is returned with     * a single element <code>newEntry</code>. Otherwise the array returned     * contains all elements of <code>list</code> and <code>newEntry</code>     * at the last position.     *     * @param list The array of class path entries, to which a new entry is     *      to be appended. This may be <code>null</code>.     * @param newEntry The new entry to append to the class path list.     *     * @return The extended class path list.     */    protected ClassPathEntry[] addClassPathEntry(ClassPathEntry[] list,            ClassPathEntry newEntry) {        // quickly define single entry array for the first entry        if (list == null) {            return new ClassPathEntry[]{ newEntry };        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -