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

📄 packagepermission.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                sb.append(EXPORT);                comma = true;            }            if ((action_mask & ACTION_IMPORT) == ACTION_IMPORT)            {                if (comma) sb.append(',');                sb.append(IMPORT);            }            actions = sb.toString();        }        return(actions);    }    /**     * Returns a new <tt>PermissionCollection</tt> object suitable for storing     * <tt>PackagePermission</tt> objects.     *     * @return A new <tt>PermissionCollection</tt> object.     */    public PermissionCollection newPermissionCollection()    {        return(new PackagePermissionCollection());    }    /**     * Determines the equality of two <tt>PackagePermission</tt> objects.     *     * This method checks that specified package has the same package name     * and <tt>PackagePermission</tt> actions as this <tt>PackagePermission</tt> object.     *     * @param obj The object to test for equality with this <tt>PackagePermission</tt> object.     * @return <tt>true</tt> if <tt>obj</tt> is a <tt>PackagePermission</tt>, and has the     * same package name and actions as this <tt>PackagePermission</tt> object; <tt>false</tt> otherwise.     */    public boolean equals(Object obj)    {        if (obj == this)        {            return(true);        }        if (!(obj instanceof PackagePermission))        {            return(false);        }        PackagePermission p = (PackagePermission) obj;        return((action_mask == p.action_mask) &&               getName().equals(p.getName()));    }    /**     * Returns the hash code value for this object.     *     * @return A hash code value for this object.     */    public int hashCode()    {        return(getName().hashCode() ^ getActions().hashCode());    }    /**     * Returns the current action mask.     * <p>Used by the PackagePermissionCollection class.     *     * @return Current action mask.     */    int getMask()    {        return(action_mask);    }    /**     * WriteObject is called to save the state of the <tt>ServicePermission</tt>     * object to a stream. The actions are serialized, and the superclass     * takes care of the name.     */    private synchronized void writeObject(java.io.ObjectOutputStream s)    throws IOException    {        // Write out the actions. The superclass takes care of the name        // call getActions to make sure actions field is initialized        if (actions == null)            getActions();        s.defaultWriteObject();    }    /**     * readObject is called to restore the state of the ServicePermission from     * a stream.     */    private synchronized void readObject(java.io.ObjectInputStream s)    throws IOException, ClassNotFoundException    {        // Read in the action, then initialize the rest        s.defaultReadObject();        init(getMask(actions));    }}/** * Stores a set of <tt>PackagePermission</tt> permissions. * * @see java.security.Permission * @see java.security.Permissions * @see java.security.PermissionCollection */final class PackagePermissionCollection extends PermissionCollection{    /**     * Table of permissions.     *     * @serial     */    private Hashtable permissions;    /**     * Boolean saying if "*" is in the collection.     *     * @serial     */    private boolean all_allowed;    /**     * Create an empty PackagePermissions object.     *     */    public PackagePermissionCollection()    {        permissions = new Hashtable();        all_allowed = false;    }    /**     * Adds a permission to the <tt>PackagePermission</tt> objects. The key for the hash is     * the name.     *     * @param permission The <tt>PackagePermission</tt> object to add.     *     * @exception IllegalArgumentException If the permission is not a     * <tt>PackagePermission</tt> instance.     *     * @exception SecurityException If this <tt>PackagePermissionCollection</tt>     * object has been marked read-only.     */    public void add(Permission permission)    {        if (! (permission instanceof PackagePermission))            throw new IllegalArgumentException("invalid permission: "+                                               permission);        if (isReadOnly())            throw new SecurityException("attempt to add a Permission to a " +                                        "readonly PermissionCollection");        PackagePermission pp = (PackagePermission) permission;        String name = pp.getName();        PackagePermission existing =        (PackagePermission) permissions.get(name);        if (existing != null)        {            int oldMask = existing.getMask();            int newMask = pp.getMask();            if (oldMask != newMask)            {                permissions.put(name,                                new PackagePermission(name,                                                      oldMask | newMask));            }        }        else        {            permissions.put(name, permission);        }        if (!all_allowed)        {            if (name.equals("*"))                all_allowed = true;        }    }    /**     * Determines if the specified permissions implies the permissions     * expressed in <tt>permission</tt>.     *     * @param p The Permission object to compare with this <tt>PackagePermission</tt> object.     *     * @return <tt>true</tt> if <tt>permission</tt> is a proper subset of a permission in     * the set; <tt>false</tt> otherwise.     */    public boolean implies(Permission permission)    {        if (!(permission instanceof PackagePermission))            return(false);        PackagePermission pp = (PackagePermission) permission;        PackagePermission x;        int desired = pp.getMask();        int effective = 0;        // short circuit if the "*" Permission was added        if (all_allowed)        {            x = (PackagePermission) permissions.get("*");            if (x != null)            {                effective |= x.getMask();                if ((effective & desired) == desired)                    return(true);            }        }        // strategy:        // Check for full match first. Then work our way up the        // name looking for matches on a.b.*        String name = pp.getName();        x = (PackagePermission) permissions.get(name);        if (x != null)        {            // we have a direct hit!            effective |= x.getMask();            if ((effective & desired) == desired)                return(true);        }        // work our way up the tree...        int last, offset;        offset = name.length()-1;        while ((last = name.lastIndexOf(".", offset)) != -1)        {            name = name.substring(0, last+1) + "*";            x = (PackagePermission) permissions.get(name);            if (x != null)            {                effective |= x.getMask();                if ((effective & desired) == desired)                    return(true);            }            offset = last -1;        }        // we don't have to check for "*" as it was already checked        // at the top (all_allowed), so we just return false        return(false);    }    /**     * Returns an enumeration of all <tt>PackagePermission</tt> objects in the     * container.     *     * @return Enumeration of all <tt>PackagePermission</tt> objects.     */    public Enumeration elements()    {        return(permissions.elements());    }}

⌨️ 快捷键说明

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