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

📄 wirepermission.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    /**     * Returns a new <tt>PermissionCollection</tt> object for storing     * <tt>WirePermission</tt> objects.     *     * @return A new <tt>PermissionCollection</tt> object suitable for storing     * <tt>WirePermission</tt> objects.     */    public PermissionCollection newPermissionCollection()    {        return new WirePermissionCollection();    }    /**     * Determines the equalty of two <tt>WirePermission</tt> objects.     *     * Checks that specified object has the same name     * and actions as this <tt>WirePermission</tt> object.     *     * @param obj The object to test for equality.     * @return true if <tt>obj</tt> is a <tt>WirePermission</tt>, and has the     * same name and actions as this <tt>WirePermission</tt> object; <tt>false</tt> otherwise.     */    public boolean equals(Object obj)    {        if (obj == this)        {            return true;        }        if (!(obj instanceof WirePermission))        {            return false;        }        WirePermission p = (WirePermission) obj;        return (action_mask == p.action_mask) && getName().equals(p.getName());    }    /**     * Returns the hash code value for this object.     *     * @return Hash code value for this object.     */    public int hashCode()    {        return getName().hashCode() ^ getActions().hashCode();    }    /**     * Returns the current action mask.     * Used by the WirePermissionCollection object.     *     * @return The actions mask.     */    int getMask()    {        return action_mask;    }    /**     * Returns a string describing this <tt>WirePermission</tt>.     * The convention is to specify the class name, the permission name, and     * the actions in the following format:     * '(org.osgi.service.wireadmin.WirePermission &quot;name&quot; &quot;actions&quot;)'.     *     * @return information about this <tt>Permission</tt> object.     */    public String toString()    {        StringBuffer sb = new StringBuffer();        sb.append('(');        sb.append(getClass().getName());        sb.append(" \"");        sb.append(getName());        sb.append("\" \"");        sb.append(getActions());        sb.append("\")");        return sb.toString();    }    /**     * WriteObject is called to save the state of the ServicePermission     * 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));    }}/** * A <tt>WirePermissionCollection</tt> stores a set of <tt>WirePermission</tt> * permissions. */final class WirePermissionCollection extends PermissionCollection{    /**     * Table of permissions.     *     * @serial     */    private Hashtable permissions;    /**     * Boolean saying if "*" is in the collection.     *     * @serial     */    private boolean all_allowed;    /**     * Creates an empty WirePermissionCollection object.     *     */    public WirePermissionCollection()    {        permissions = new Hashtable();        all_allowed = false;    }    /**     * Adds a permission to this PermissionCollection.     *     * @param permission The Permission object to add.     *     * @exception IllegalArgumentException If the permission is not a WirePermission object.     *     * @exception SecurityException If this PermissionCollection has been marked read-only.     */    public void add(Permission permission)    {        if (! (permission instanceof WirePermission))            throw new IllegalArgumentException("invalid permission: "+                                               permission);        if (isReadOnly())            throw new SecurityException("attempt to add a Permission to a " +                    "readonly PermissionCollection");        WirePermission p = (WirePermission) permission;        String name = p.getName();        WirePermission existing =        (WirePermission) permissions.get(name);        if (existing != null)        {            int oldMask = existing.getMask();            int newMask = p.getMask();            if (oldMask != newMask)            {                permissions.put(name,                new WirePermission(name,                            oldMask | newMask));            }        }        else        {            permissions.put(name, permission);        }        if (!all_allowed)        {            if (name.equals("*"))                all_allowed = true;        }    }    /**     * Determines if a set of permissions implies the permissions     * expressed in <tt>permission</tt>.     *     * @param p The Permission object to compare.     *     * @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 WirePermission))            return false;        WirePermission p = (WirePermission) permission;        WirePermission x;        int desired = p.getMask();        int effective = 0;        // short circuit if the "*" Permission was added        if (all_allowed)        {            x = (WirePermission) 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 = p.getName();        x = (WirePermission) 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 = (WirePermission) 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 the Permission objects in the     * container.     *     * @return Enumeration of all the Permission objects.     */    public Enumeration elements()    {        return permissions.elements();    }}

⌨️ 快捷键说明

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