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

📄 wrapperservicepermission.java

📁 java程序写系统的服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {
                first = false;
            }
            sb.append( ACTION_INTERROGATE );
        }
        if ( ( m_actionMask & MASK_USER_CODE ) != 0 )
        {
            if ( first )
            {
                sb.append( ',' );
            }
            else
            {
                first = false;
            }
            sb.append( ACTION_USER_CODE );
        }
        
        return sb.toString();
    }

    /**
     * Checks if this WrapperServicePermission object "implies" the
     *  specified permission.
     * <P>
     * More specifically, this method returns true if:<p>
     * <ul>
     *  <li><i>p2</i> is an instanceof FilePermission,<p>
     *  <li><i>p2</i>'s actions are a proper subset of this object's actions,
     *      and<p>
     *  <li><i>p2</i>'s service name is implied by this object's service name.
     *      For example, "MyApp*" implies "MyApp".
     * </ul>
     *
     * @param p2 the permission to check against.
     *
     * @return true if the specified permission is implied by this object,
     */
    public boolean implies( Permission p2 )
    {
        if ( !( p2 instanceof WrapperServicePermission ) )
        {
            return false;
        }
        
        WrapperServicePermission wsp = (WrapperServicePermission)p2;
        
        // we get the effective mask. i.e., the "and" of this and that.
        // They must be equal to that.mask for implies to return true.
        
        return ( ( m_actionMask & wsp.m_actionMask ) == wsp.m_actionMask ) &&
            impliesIgnoreActionMask( wsp );
    }
    
    /**
     * Returns an custom WSCollection implementation of a PermissionCollection.
     */
    public PermissionCollection newPermissionCollection()
    {
        return new WSCollection();
    }

    /**
     * Returns the hash code value for this object.
     * 
     * @return A hash code value for this object.
     */
    public int hashCode()
    {
        return getName().hashCode();
    }
    
    /*---------------------------------------------------------------
     * Methods
     *-------------------------------------------------------------*/
    /**
     * Returns the action mask of the Permission.
     */
    int getActionMask()
    {
        return m_actionMask;
    }
    
    /**
     * Tests whether this permissions implies another without taking the
     *  action mask into account.
     */
    boolean impliesIgnoreActionMask( WrapperServicePermission p2 )
    {
        if ( getName().equals( p2.getName() ) )
        {
            return true;
        }
        
        if ( p2.getName().endsWith( "*" ) )
        {
            if ( getName().startsWith( p2.getName().substring( 0, p2.getName().length() - 1 ) ) )
            {
                return true;
            }
        }
        return false;
    }
    
    /**
     * Builds an action mask given a comma separated list of actions.
     */
    private int buildActionMask( String actions )
    {
        // Check for the constants first as they are used internally.
        if ( actions == ACTION_START )
        {
            return MASK_START;
        }
        else if ( actions == ACTION_STOP )
        {
            return MASK_STOP;
        }
        else if ( actions == ACTION_PAUSE )
        {
            return MASK_PAUSE;
        }
        else if ( actions == ACTION_CONTINUE )
        {
            return MASK_CONTINUE;
        }
        else if ( actions == ACTION_INTERROGATE )
        {
            return MASK_INTERROGATE;
        }
        else if ( actions == ACTION_USER_CODE )
        {
            return MASK_USER_CODE;
        }
        else if ( actions.equals( "*" ) )
        {
            return MASK_ALL;
        }
        
        int mask = 0;
        StringTokenizer st = new StringTokenizer( actions, "," );
        while ( st.hasMoreTokens() )
        {
            String action = st.nextToken();
            if ( action.equals( ACTION_START ) )
            {
                mask |= MASK_START;
            }
            else if ( action.equals( ACTION_STOP ) )
            {
                mask |= MASK_STOP;
            }
            else if ( action.equals( ACTION_PAUSE ) )
            {
                mask |= MASK_PAUSE;
            }
            else if ( action.equals( ACTION_CONTINUE ) )
            {
                mask |= MASK_CONTINUE;
            }
            else if ( action.equals( ACTION_INTERROGATE ) )
            {
                mask |= MASK_INTERROGATE;
            }
            else if ( action.equals( ACTION_USER_CODE ) )
            {
                mask |= MASK_USER_CODE;
            }
            else
            {
                throw new IllegalArgumentException(
                    "Invalid permission action: \"" + action + "\"" );
            }
        }
        
        return mask;
    }
}
        
final class WSCollection
    extends PermissionCollection
{
    private Vector m_permissions = new Vector();
    
    /*---------------------------------------------------------------
     * Constructors
     *-------------------------------------------------------------*/
    /**
     * Creates an empty WSCollection.
     */
    public WSCollection()
    {
    }
    
    /*---------------------------------------------------------------
     * Methods
     *-------------------------------------------------------------*/
    /**
     * Adds a permission to the FilePermissions. The key for the hash is
     * permission.path.
     *
     * @param permission the Permission object to add.
     *
     * @exception IllegalArgumentException - if the permission is not a
     *                                       FilePermission 
     *
     * @exception SecurityException - if this FilePermissionCollection object
     *                                has been marked readonly
     */
    public void add( Permission permission )
    {
        if ( !( permission instanceof WrapperServicePermission ) )
        {
            throw new IllegalArgumentException( "invalid permission: " + permission );
        }
        
        if ( isReadOnly() )
        {
            throw new SecurityException( "Collection is read-only.");
        }
        
        m_permissions.add( permission );
    }
    
    /**
     * Check and see if this set of permissions implies the permissions 
     * expressed in "permission".
     *
     * @param permission the Permission object to compare
     *
     * @return true if "permission" is a proper subset of a permission in 
     * the set, false if not.
     */
    public boolean implies( Permission permission ) 
    {
        if ( !( permission instanceof WrapperServicePermission ) )
        {
            return false;
        }

        WrapperServicePermission wsp = (WrapperServicePermission)permission;
        
        int desiredMask = wsp.getActionMask();
        int pendingMask = desiredMask;
        int foundMask = 0;
        
        for ( Enumeration en = m_permissions.elements(); en.hasMoreElements(); )
        {
            WrapperServicePermission p2 =
                (WrapperServicePermission)en.nextElement();
            if ( ( pendingMask & p2.getActionMask() ) != 0 )
            {
                // This permission has one or more actions that we need.
                if ( wsp.impliesIgnoreActionMask( p2 ) )
                {
                    foundMask |= desiredMask & p2.getActionMask();
                    if ( foundMask == desiredMask )
                    {
                        return true;
                    }
                    pendingMask = desiredMask ^ foundMask;
                }
            }
        }
        
        return false;
    }

    /**
     * Returns an enumeration of all the WrapperServicePermission
     *  objects in the container.
     *
     * @return An enumeration of all the WrapperServicePermission
     *         objects.
     */
    public Enumeration elements()
    {
        return m_permissions.elements();
    }
}

⌨️ 快捷键说明

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