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

📄 instructionresourcepermission.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
字号:
/* * InstructionResourcePermission.java * * Created on October 6, 2003, 9:31 AM */package gov.nist.security.permissions;import java.util.*;/** * Permission checking if the amount of bytecode instructions executed has been exceeded * @author  DERUELLE Jean */public class InstructionResourcePermission extends java.security.Permission{    /**maximum memory to allocate in the JVM*/    int numberOfInstructionsAllowed=0;    /**mask of the actions*/    protected int mask;    static private int ALLOWED=0x01;        /** Creates a new instance of InstructionResourcePermission      * @param name - name of the permission          */    public InstructionResourcePermission(String name) {        this(name,"allowed");                try{            numberOfInstructionsAllowed=Integer.parseInt(name);        }        catch(NumberFormatException nfe){            nfe.printStackTrace();        }            }    /** Creates a new instance of InstructionResourcePermission     * @param name - name of the permission          * @param actions - the actions of the permission     */    public InstructionResourcePermission(String name,String actions) {        super(name);                try{            numberOfInstructionsAllowed=Integer.parseInt(name);        }        catch(NumberFormatException nfe){            nfe.printStackTrace();         }                parse(actions);    }        /**     * Look into the actions String to get the actions     * associated with that permission     * @param the actions String     */    private void parse(String actions){        //Look into the action string for        //the words incoming or outgoing or both        StringTokenizer st=new StringTokenizer(actions,",\t");        mask=0;        while(st.hasMoreTokens()){            String tok=st.nextToken();            if(tok.equals("allowed"))                    mask|=ALLOWED;                 else throw new IllegalArgumentException("Unknown action "+ tok);        }                    }    /**     * This method return the actions' String     * @return the actions of the permission     */    public String getActions() {        //This method must return the same String, no matter how        //the action list was passed to the constructor.        if(mask==0)            return "";        else if(mask==ALLOWED)            return "allowed";        else throw new IllegalArgumentException("Unknown mask");    }        /**     * Checks if the specified permission's actions are "implied by" this object's actions.     * @param permission - the permission to check against.     * @return if the specified permission is implied by this object, false if not.      */    public boolean implies(java.security.Permission permission) {        if(!(permission instanceof InstructionResourcePermission))            return false;        InstructionResourcePermission instructionResourcePermission=(InstructionResourcePermission)permission;        //Similarly, the requested actions must macth all match actions        //that we've been constructed with        if((mask & instructionResourcePermission.mask) !=instructionResourcePermission.mask)            return false;                int permissionNumberOfInstructionsCreated=0;        try{            permissionNumberOfInstructionsCreated=Integer.parseInt(instructionResourcePermission.getName());        }                catch(NumberFormatException nfe){            nfe.printStackTrace();            return false;        }        //System.out.println("seuil : "+forkingFactor);        //System.out.println("user : "+permissionForkingFactor);        if(permissionNumberOfInstructionsCreated<=numberOfInstructionsAllowed)            return true;        return false;    }        /**     * @see java.security.Permission#hashCode()     */    public int hashCode(){        //We must always provide the same hashcode for permissions        //because the hashes must match if the permissions compare        // as equals        return getName().hashCode() ^ mask;    }        /**     * @see java.security.Permission#equals(Object obj)     */    public boolean equals(Object o){        if(!(o instanceof InstructionResourcePermission))            return false;        InstructionResourcePermission instructionResourcePermission=(InstructionResourcePermission)o;        //For equality, we check the name and the action mask        return ((instructionResourcePermission.getName().equals(getName())) && (instructionResourcePermission.mask == mask));    }}

⌨️ 快捷键说明

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