environment.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 711 行 · 第 1/2 页

JAVA
711
字号
        ((EnvironmentClassLoader) loader).addDependency(depend);        return;      }    }  }  /**   * Returns the topmost dynamic class loader.   */  public static DynamicClassLoader getDynamicClassLoader()  {    Thread thread = Thread.currentThread();        return getDynamicClassLoader(thread.getContextClassLoader());  }  /**   * Returns the topmost dynamic class loader.   *   * @param loader the context loader   */  public static DynamicClassLoader getDynamicClassLoader(ClassLoader loader)  {    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof DynamicClassLoader) {        return (DynamicClassLoader) loader;      }    }    return null;  }    /**   * Adds a dependency to the current environment.   *   * @param depend the dependency to add   */  public static void addDependency(Path path)  {    addDependency(new Depend(path));  }  /**   * Adds a dependency to the current environment.   *   * @param path the dependency to add   * @param loader the context loader   */  public static void addDependency(Path path, ClassLoader loader)  {    addDependency(new Depend(path), loader);  }  /**   * Gets a local variable for the current environment.   *   * @param name the attribute name   *   * @return the attribute value   */  public static Object getAttribute(String name)  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();    return getAttribute(name, loader);  }  /**   * Returns the current dependency check interval.   */  public static long getDependencyCheckInterval()  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();        for (; loader != null; loader = loader.getParent()) {      if (loader instanceof DynamicClassLoader)        return ((DynamicClassLoader) loader).getDependencyCheckInterval();    }    return DynamicClassLoader.getGlobalDependencyCheckInterval();  }  /**   * Returns the current dependency check interval.   */  public static long getDependencyCheckInterval(ClassLoader loader)  {    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof DynamicClassLoader)        return ((DynamicClassLoader) loader).getDependencyCheckInterval();    }    return DynamicClassLoader.getGlobalDependencyCheckInterval();  }  /**   * Gets a local variable for the current environment.   *   * @param name the attribute name   * @param loader the context loader   *   * @return the attribute value   */  public static Object getAttribute(String name, ClassLoader loader)  {    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {        Object value = ((EnvironmentClassLoader) loader).getAttribute(name);        if (value != null)          return value;      }    }    return null;  }  /**   * Gets a local variable for the current environment.   *   * @param name the attribute name   *   * @return the attribute value   */  public static Object getLevelAttribute(String name)  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();    return getLevelAttribute(name, loader);  }  /**   * Gets a local variable for the current environment.   *   * @param name the attribute name   * @param loader the context loader   *   * @return the attribute value   */  public static Object getLevelAttribute(String name, ClassLoader loader)  {    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {        return ((EnvironmentClassLoader) loader).getAttribute(name);      }    }    return null;  }  /**   * Sets a local variable for the current environment.   *   * @param name the attribute name   * @param value the new attribute value   *   * @return the old attribute value   */  public static Object setAttribute(String name, Object value)  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();    return setAttribute(name, value, loader);  }  /**   * Sets a local variable for the current environment.   *   * @param name the attribute name   * @param value the new attribute value   * @param loader the context loader   *   * @return the old attribute value   */  public static Object setAttribute(String name,                                    Object value,                                    ClassLoader loader)  {    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {        EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader;        Object oldValue = envLoader.getAttribute(name);        envLoader.setAttribute(name, value);                if (oldValue != null)          return oldValue;      }    }    return null;  }  /**   * Adds a permission to the current environment.   *   * @param perm the permission to add.   *   * @return the old attribute value   */  public static void addPermission(Permission perm)  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();        addPermission(perm, loader);  }  /**   * Adds a permission to the current environment.   *   * @param perm the permission to add.   *   * @return the old attribute value   */  public static void addPermission(Permission perm, ClassLoader loader)  {    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {        EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader;	envLoader.addPermission(perm);      }    }  }  /**   * Gets the class loader owner.   */  public static Object getOwner()  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();    return getOwner(loader);  }  /**   * Gets the class loader owner.   */  public static Object getOwner(ClassLoader loader)  {    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {	EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader;	Object owner = envLoader.getOwner();		if (owner != null)	  return owner;      }    }    return null;  }  /**   * Sets a configuration exception.   */  public static void setConfigException(Throwable e)  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();        for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {	EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader;	envLoader.setConfigException(e);	return;      }    }  }  /**   * Returns any configuration exception.   */  public static Throwable getConfigException()  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();        for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {	EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader;	if (envLoader.getConfigException() != null)	  return envLoader.getConfigException();      }    }    return null;  }    /**   * Returns the environment name.   */  public static String getEnvironmentName()  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {	String name = ((EnvironmentClassLoader) loader).getId();	if (name != null)	  return name;	else	  return "";      }    }    return Thread.currentThread().getContextClassLoader().toString();  }  /**   * Returns the classpath for the environment level.   */  public static String getLocalClassPath()  {    ClassLoader loader = Thread.currentThread().getContextClassLoader();        return getLocalClassPath(loader);  }      /**   * Returns the classpath for the environment level.   */  public static String getLocalClassPath(ClassLoader loader)  {    for (; loader != null; loader = loader.getParent()) {      if (loader instanceof EnvironmentClassLoader) {	return ((EnvironmentClassLoader) loader).getLocalClassPath();      }    }    return CauchoSystem.getClassPath();  }  /**   * destroys the current environment.   */  public static void closeGlobal()  {    ArrayList<ClassLoaderListener> listeners;    listeners = new ArrayList<ClassLoaderListener>();    listeners.addAll(_globalLoaderListeners);    _globalLoaderListeners.clear();        for (int i = 0; i < listeners.size(); i++) {      ClassLoaderListener listener = listeners.get(i);      listener.classLoaderDestroy(null);    }  }}

⌨️ 快捷键说明

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