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

📄 resourcemanagerfactory.java

📁 aglet的部分源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ibm.aglets.tahiti;import com.ibm.aglet.MessageManager;import com.ibm.aglets.AgletRuntime;import com.ibm.aglets.AgletThread;import com.ibm.aglets.ResourceManager;import com.ibm.aglets.security.PolicyImpl;import com.ibm.awb.misc.*;import com.ibm.maf.ClassName;import com.ibm.maf.MAFAgentSystem;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;/* *  @(#)ResourceManagerFactory.java * *  IBM Confidential-Restricted * *  OCO Source Materials * *  03L7246 (c) Copyright IBM Corp. 1996, 1998 * *  The source code for this program is not published or otherwise *  divested of its trade secrets, irrespective of what has been *  deposited with the U.S. Copyright Office. */import java.net.URL;import java.security.AccessController;//import java.security.Identity;import java.security.CodeSource;import java.security.Policy;import java.security.PrivilegedAction;import java.security.PrivilegedActionException;import java.security.PrivilegedExceptionAction;import java.security.cert.Certificate;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;import org.aglets.log.*;/** * @author     Mitsuru Oshima * @version    1.10 $Date: 2002/02/20 22:17:18 $ */final class ResourceManagerFactory         implements com.ibm.aglets.ResourceManagerFactory {    static Class exportedClass[];    static String[] exportedClassName = {            "com.ibm.aglets.AgletProxyImpl", "com.ibm.aglets.DeactivationInfo",            "com.ibm.aglets.MessageImpl", "com.ibm.aglets.MessageManagerImpl",            "com.ibm.aglets.SystemMessage", "com.ibm.aglets.AgletImageData",            "com.ibm.aglets.AgletAudioClip",            "com.ibm.aglets.ByteArrayImageSource", "com.ibm.awb.misc.Resource",            "com.ibm.awb.weakref.VirtualRef",            };    private static String _agletsClassPath[];    private static Hashtable _manifests;    private static String _publicRoot;    private static String _localAddr;    private final static LogCategory log             = LogInitializer.getCategory(ResourceManagerFactory.class.getName());    private ResourceManager _appResourceManager;    private Hashtable _map = new Hashtable();    static {        Resource res = Resource.getResourceFor("aglets");        _agletsClassPath = res.getStringArray("aglets.class.path",                File.pathSeparator);        _publicRoot = res.getString("aglets.public.root", null);        if (_publicRoot != null) {            try {                _publicRoot = getCanonicalDirectory(_publicRoot);            } catch (IOException ex) {                ex.printStackTrace();            }        }        _localAddr = MAFAgentSystem.getLocalMAFAgentSystem().getAddress();        Policy pol = Policy.getPolicy();        if (pol instanceof PolicyImpl) {            PolicyImpl policy = (PolicyImpl) pol;            policy.setSystemCodeBase(_localAddr);            policy.setPublicRoot(_publicRoot);        }        //        // Search jar/zip files.        //        _manifests = new Hashtable();        for (int i = 0; i < _agletsClassPath.length; i++) {            lookupJarFiles(_agletsClassPath[i], true);            if (log.isDebugEnabled()) {                log.debug("Aglet CP: " + _agletsClassPath[i]);            }        }        ClassLoader loader = ResourceManagerFactory.class.getClassLoader();        exportedClass = new Class[exportedClassName.length];        for (int i = 0; i < exportedClassName.length; i++) {            try {                if (loader == null) {                    exportedClass[i] = Class.forName(exportedClassName[i]);                } else {                    exportedClass[i] = loader.loadClass(exportedClassName[i]);                }            } catch (ClassNotFoundException ex) {                ex.printStackTrace();            }        }    }    /**     *  Constructor for the ResourceManagerFactory object     */    public ResourceManagerFactory() {        // - 	ClassLoader loader = this.getClass().getClassLoader();        // tentative        // ClassLoader loader = SecureClassLoader.getSecureClassLoader();        _appResourceManager = new AppResourceManager();    }    /**     *  Gets the canonicalDirectory attribute of the ResourceManagerFactory     *  class     *     * @param  path             Description of Parameter     * @return                  The canonicalDirectory value     * @exception  IOException  Description of Exception     */    private static String getCanonicalDirectory(String path)             throws IOException {        final File file = new File(path);        try {            return (String) AccessController.doPrivileged(                new PrivilegedExceptionAction() {                    public Object run() throws IOException {                        String cp = file.getCanonicalPath();                        if (!(file.isAbsolute())) {                            // due to the URL formatting bugs                            cp = File.separatorChar + cp;                        }                        if (cp.charAt(cp.length() - 1) != File.separatorChar) {                            cp = cp + File.separatorChar;                        }                        return cp;                    }                });        } catch (PrivilegedActionException ex) {            throw (IOException) ex.getException();        }    }    /**     *  Gets the jarFile attribute of the ResourceManagerFactory class     *     * @param  p  Description of Parameter     * @return    The jarFile value     */    private static boolean isJarFile(String p) {        return p.endsWith(".jar");    }    /**     *  Description of the Method     *     * @param  name             Description of Parameter     * @param  pathList         Description of Parameter     * @return                  Description of the Returned Value     * @exception  IOException  Description of Exception     */    private static String lookupCodeBaseFrom(final String name, String[] pathList)             throws IOException {        final String[] pl = pathList;        final String classFileName = name.replace('.', File.separatorChar)                 + ".class";        log.debug("lookupCodeBaseFrom()++");        try {            return (String) AccessController.doPrivileged(                new PrivilegedExceptionAction() {                    public Object run() throws IOException {                        for (int i = 0; i < pl.length; i++) {                            final File f = new File(pl[i] + File.separator                                     + classFileName);                            if (f.exists()) {                                log.debug("Found ["+name+"] in "+getCanonicalDirectory(pl[i]));                                return getCanonicalDirectory(pl[i]);                                // REMIND:                                // file URL automatically adds local address to URL.                                // return new URL(new URL("file", "", absolute).toExternalForm());                            }                        }                        return null;                    }                });        } catch (PrivilegedActionException ex) {            log.error("PrivilegedAction error",ex);            throw (IOException) ex.getException();        }    }    /**     *  Description of the Method     *     * @param  name             Description of Parameter     * @return                  Description of the Returned Value     * @exception  IOException  Description of Exception     */    private static String lookupCodeBaseInManifest(String name)             throws IOException {                         log.debug("lookupCodeBaseInManifest() : ["+name+"]");        Enumeration e = _manifests.keys();        while (e.hasMoreElements()) {            Manifest m = (Manifest) e.nextElement();            if (m.contains(name.replace('.', '/') + ".class")) {                log.debug("Found in manifest.");                return (String) _manifests.get(m);            }        }        return null;    }    /**     *  Description of the Method     *     * @param  path       Description of Parameter     * @param  recursive  Description of Parameter     */    private static void lookupJarFiles(String path, boolean recursive) {        final File f = new File(path);        Boolean b =                (Boolean) AccessController.doPrivileged(            new PrivilegedAction() {                public Object run() {                    return new Boolean(f.isDirectory());                }            });        boolean isDir = b.booleanValue();        if (isDir && recursive) {            AccessController.doPrivileged(                new PrivilegedAction() {                    public Object run() {                        String[] list = f.list();                        String front = f.getPath() + File.separator;                        for (int i = 0; i < list.length; i++) {                            lookupJarFiles(front + list[i], false);                        }                        return null;                    }                });        } else if (isJarFile(path)) {            readManifest(path);        }    }    /**     *  Description of the Method     *     * @param  path  Description of Parameter     */    private static void readManifest(String path) {        try {            path = new File(path).getCanonicalPath();        } catch (IOException ex) {            ex.printStackTrace();        }        log.debug("Reading manifest .. " + path);        try {            JarArchive j = new JarArchive(path);            Manifest m = j.getManifest();            _manifests.put(m, path);        } catch (IOException ex) {            ex.printStackTrace();        }    }    //    /**     *  Gets the currentResourceManager attribute of the ResourceManagerFactory     *  object     *     * @return    The currentResourceManager value     */    public ResourceManager getCurrentResourceManager() {        ResourceManager rm = ResourceManagerImpl.getResourceManagerContext();                        if (rm == null) {            SecurityManager sm = System.getSecurityManager();            if (sm != null && sm instanceof AgletsSecurityManager) {                AgletsSecurityManager asm = (AgletsSecurityManager) sm;                ClassLoader loader = asm.getCurrentNonSecureClassLoader();                if (loader instanceof AgletClassLoader) {                    rm = ((AgletClassLoader) loader);                } else {                    log.debug("Using appResourceManager???");                    // then, that's secure class loader.                    rm = _appResourceManager;                }            }        }        log.debug("getCurrentResourceManager() : "+ rm );        return rm;    }    /**     */    public synchronized void clearCache() {        _map = new Hashtable();    }    /**     * @param  codebase  Description of Parameter     * @param  owner     Description of Parameter     */    public synchronized void clearCache(URL codebase, Certificate owner) {        if (codebase == null) {            clearCache();        } else {            CodeSource cs = new CodeSource(codebase, new Certificate[]{                    owner

⌨️ 快捷键说明

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