dynamicclassloader.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,097 行 · 第 1/4 页
JAVA
2,097 行
return null; } /** * Adds the URL to the URLClassLoader. */ @Override public void addURL(URL url) { addURL(_urls.length, url); } /** * Adds the URL to the URLClassLoader. */ public void addURL(int index, URL url) { super.addURL(url); for (int i = 0; i < _urls.length; i++) { if (_urls[i].equals(url)) return; } URL []newURLs = new URL[_urls.length + 1]; for (int i = 0; i < index; i++) newURLs[i] = _urls[i]; newURLs[index] = url; for (int i = index + 1; i < newURLs.length; i++) newURLs[i] = _urls[i - 1]; _urls = newURLs; } /** * Adds a class loader for instrumentation (jdk 1.6). */ public void appendToClassPathForInstrumentation(String path) { addRoot(com.caucho.vfs.Vfs.lookup(path)); } /** * Returns the URLs. */ @Override public URL []getURLs() { return _urls; } /** * Returns true if the loader contains the url. */ private boolean containsURL(URL url) { if (_urls != null) { for (URL testURL : _urls) { if (url.equals(testURL)) return true; } } ClassLoader parent = getParent(); if (parent instanceof DynamicClassLoader) { DynamicClassLoader dynParent = (DynamicClassLoader) parent; return dynParent.containsURL(url); } return false; } /** * Sets the dependency check interval. */ public void setDependencyCheckInterval(long interval) { _dependencies.setCheckInterval(interval); } /** * Gets the dependency check interval. */ public long getDependencyCheckInterval() { if (_dependencies != null) return _dependencies.getCheckInterval(); else return 0; } /** * Enables the dependency checking. */ public void setEnableDependencyCheck(boolean enable) { _isEnableDependencyCheck = enable; } /** * Adds a dependency. */ public void addDependency(Dependency dependency) { _dependencies.add(dependency); } public void addPermission(String path, String actions) { addPermission(new FilePermission(path, actions)); } /** * Adds a permission to the loader. */ public void addPermission(Permission permission) { if (_permissions == null) _permissions = new ArrayList<Permission>(); _permissions.add(permission); } public ArrayList<Permission> getPermissions() { return _permissions; } public void addPermissions(ArrayList<Permission> perms) { if (perms == null) return; if (_permissions == null) _permissions = new ArrayList<Permission>(); _permissions.addAll(perms); } /** * Returns the security manager. */ public SecurityManager getSecurityManager() { return _securityManager; } /** * Set true if the loader should use the servlet spec's hack. */ public void setServletHack(boolean servletHack) { _useServletHack = servletHack; if (_parentPriorityPackages == null) _parentPriorityPackages = new String[0]; } /** * Adds a listener to detect class loader changes. */ public final void addListener(ClassLoaderListener listener) { if (_lifecycle.isDestroyed()) { IllegalStateException e = new IllegalStateException(L().l("attempted to add listener to a closed classloader {0}", this)); log().log(Level.WARNING, e.toString(), e); return; } ArrayList<ClassLoaderListener> listeners; WeakCloseListener closeListener = null; synchronized (this) { if (_listeners == null) { _listeners = new ArrayList<ClassLoaderListener>(); closeListener = new WeakCloseListener(this); //_closeListener = closeListener; } listeners = _listeners; } if (closeListener != null) { for (ClassLoader parent = getParent(); parent != null; parent = parent.getParent()) { if (parent instanceof DynamicClassLoader) { ((DynamicClassLoader) parent).addListener(closeListener); break; } } } synchronized (listeners) { for (int i = listeners.size() - 1; i >= 0; i--) { ClassLoaderListener oldListener = listeners.get(i); if (listener == oldListener) { return; } else if (oldListener == null) listeners.remove(i); } listeners.add(listener); } if (_lifecycle.isActive()) listener.classLoaderInit(this); } /** * Adds a listener to detect class loader changes. */ public final void removeListener(ClassLoaderListener listener) { ArrayList<ClassLoaderListener> listeners = _listeners; if (listeners == null) return; synchronized (listeners) { for (int i = listeners.size() - 1; i >= 0; i--) { ClassLoaderListener oldListener = listeners.get(i); if (listener == oldListener) { listeners.remove(i); return; } else if (oldListener == null) listeners.remove(i); } } } /** * Returns the listeners. */ protected ArrayList<ClassLoaderListener> getListeners() { ArrayList<ClassLoaderListener> listeners; listeners = new ArrayList<ClassLoaderListener>(); ArrayList<ClassLoaderListener> listenerList; listenerList = _listeners; if (listenerList != null) { synchronized (listenerList) { for (int i = 0; i < listenerList.size(); i++) { ClassLoaderListener listener = listenerList.get(i); if (listener != null) listeners.add(listener); else { listenerList.remove(i); i--; } } } } return listeners; } /** * Adds a listener to detect class loader changes. */ protected final void sendAddLoaderEvent() { if (_hasNewLoader) { _hasNewLoader = false; scan(); configureEnhancerEvent(); } } /** * Sends an event to notify than an event has changed. */ protected void configureEnhancerEvent() { } /** * Add to the list of packages that don't use the hack. */ public void addParentPriorityPackages(String []pkg) { for (int i = 0; pkg != null && i < pkg.length; i++) { addParentPriorityPackage(pkg[i]); } } /** * Add to the list of packages that don't use the {@link #setServletHack(boolean)}. */ public void addParentPriorityPackage(String pkg) { if (_parentPriorityPackages == null) _parentPriorityPackages = new String[0]; int oldLength = _parentPriorityPackages.length; String []newPkgs = new String[oldLength + 1]; System.arraycopy(_parentPriorityPackages, 0, newPkgs, 0, oldLength); if (! pkg.endsWith(".")) pkg = pkg + '.'; newPkgs[oldLength] = pkg; _parentPriorityPackages = newPkgs; } /** * Add to the list of packages that take priority over the parent */ public void addPriorityPackage(String pkg) { if (_priorityPackages == null) _priorityPackages = new String[0]; int oldLength = _priorityPackages.length; String []newPkgs = new String[oldLength + 1]; System.arraycopy(_priorityPackages, 0, newPkgs, 0, oldLength); if (! pkg.endsWith(".")) pkg = pkg + '.'; newPkgs[oldLength] = pkg; _priorityPackages = newPkgs; } /** * Returns the permission collection for the given code source. */ @Override protected PermissionCollection getPermissions(CodeSource codeSource) { PermissionCollection perms = super.getPermissions(codeSource); ArrayList<Permission> permissions = _permissions; for (int i = 0; permissions != null && i < permissions.size(); i++) { Permission permission = permissions.get(i); perms.add(permission); } return perms; } protected void addCodeBasePath(String path) { } /** * Sets any enhancer. */ public void addTransformer(ClassFileTransformer transformer) { if (_classFileTransformerList == null) _classFileTransformerList = new ArrayList<ClassFileTransformer>(); _classFileTransformerList.add(transformer); } protected ArrayList<ClassFileTransformer> getTransformerList() { return _classFileTransformerList; } /** * Fill data for the class path. fillClassPath() will add all * .jar and .zip files in the directory list. */ public final String getClassPath() { StringBuilder head = new StringBuilder(); buildClassPath(head); return head.toString(); } /** * Fill data for the class path. fillClassPath() will add all * .jar and .zip files in the directory list. */ protected final void buildClassPath(StringBuilder head) { ClassLoader parent = getParent(); if (parent instanceof DynamicClassLoader) ((DynamicClassLoader) parent).buildClassPath(head); else { head.append(CauchoSystem.getClassPath()); for (; parent != null; parent = parent.getParent()) { // XXX: should be reverse order if (parent instanceof URLClassLoader) { URLClassLoader urlLoader = (URLClassLoader) parent; for (URL url : urlLoader.getURLs()) { if (head.length() > 0) head.append(CauchoSystem.getPathSeparatorChar()); String urlString = url.toString(); if (urlString.startsWith("file:")) urlString = urlString.substring("file:".length()); head.append(urlString); } } } } ArrayList<Loader> loaders = getLoaders(); if (loaders != null) { for (int i = 0; i < loaders.size(); i++) { Loader loader = loaders.get(i); loader.buildClassPath(head); } } } /** * Fill data for the class path. fillClassPath() will add all * .jar and .zip files in the directory list. */ public final String getLocalClassPath() { StringBuilder head = new StringBuilder(); ArrayList<Loader> loaders = getLoaders(); for (int i = 0; i < loaders.size(); i++) { Loader loader = loaders.get(i); buildClassPath(head); } return head.toString(); } /** * Returns the source path. The source path is used for looking up * resources. */ public final String getSourcePath() { StringBuilder head = new StringBuilder(); buildSourcePath(head); return head.toString(); } /** * Fill data for the class path. fillSourcePath() will add all * .jar and .zip files in the directory list. */ protected final void buildSourcePath(StringBuilder head) { ClassLoader parent = getParent(); if (parent instanceof DynamicClassLoader) ((DynamicClassLoader) parent).buildSourcePath(head); else head.append(CauchoSystem.getClassPath()); ArrayList<Loader> loaders = getLoaders(); for (int i = 0; i < loaders.size(); i++) { Loader loader = loaders.get(i); loader.buildSourcePath(head); } } /** * Returns the resource path with most specific first. */ public final String getResourcePathSpecificFirst() { ArrayList<String> pathList = new ArrayList<String>(); buildResourcePathSpecificFirst(pathList); StringBuilder sb = new StringBuilder(); char sep = CauchoSystem.getPathSeparatorChar(); if (pathList.size() == 0) return ""; sb.append(pathList.get(0)); for (int i = 1; i < pathList.size(); i++) { sb.append(sep); sb.append(pathList.get(i)); } return sb.toString(); } /** * Returns the resource path with most specific first. */ protected final void buildResourcePathSpecificFirst(ArrayList<String> pathList) { ClassLoader parent = getParent(); ArrayList<Loader> loaders = getLoaders(); int size = loaders != null ? loaders.size() : 0; for (int i = 0; i < size; i++) { Loader loader = loaders.get(i); loader.buildSourcePath(pathList);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?