home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / NETSCAP4.06 / CP32E406.EXE / nav40.z / java40.jar / netscape / security / Privilege.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-08-13  |  3.2 KB  |  140 lines

  1. package netscape.security;
  2.  
  3. import netscape.util.ClassInfo;
  4. import netscape.util.Codable;
  5. import netscape.util.CodingException;
  6. import netscape.util.Decoder;
  7. import netscape.util.Encoder;
  8.  
  9. public final class Privilege implements Codable {
  10.    static final int VERSION = 1;
  11.    public static final int N_PERMISSIONS = 3;
  12.    public static final int FORBIDDEN = 0;
  13.    public static final int ALLOWED = 1;
  14.    public static final int BLANK = 2;
  15.    private int itsPerm;
  16.    public static final int N_DURATIONS = 3;
  17.    public static final int SCOPE = 0;
  18.    public static final int SESSION = 1;
  19.    public static final int FOREVER = 2;
  20.    private int itsDuration;
  21.    private boolean itsInited = false;
  22.    private static Privilege[][] itsPrivilegeCache = new Privilege[3][3];
  23.  
  24.    public Privilege() {
  25.    }
  26.  
  27.    private Privilege(int var1, int var2) {
  28.       this.itsPerm = var1;
  29.       this.itsDuration = var2;
  30.       this.itsInited = true;
  31.    }
  32.  
  33.    public static Privilege findPrivilege(int var0, int var1) {
  34.       return itsPrivilegeCache[var0][var1];
  35.    }
  36.  
  37.    public static int add(int var0, int var1) {
  38.       return var0 < var1 ? var0 : var1;
  39.    }
  40.  
  41.    public static Privilege add(Privilege var0, Privilege var1) {
  42.       return var0.itsPerm < var1.itsPerm ? var0 : var1;
  43.    }
  44.  
  45.    public boolean samePermission(Privilege var1) {
  46.       return var1.itsPerm == this.itsPerm;
  47.    }
  48.  
  49.    public boolean samePermission(int var1) {
  50.       return this.itsPerm == var1;
  51.    }
  52.  
  53.    public boolean sameDuration(Privilege var1) {
  54.       return var1.itsDuration == this.itsDuration;
  55.    }
  56.  
  57.    public boolean sameDuration(int var1) {
  58.       return this.itsDuration == var1;
  59.    }
  60.  
  61.    public boolean isAllowed() {
  62.       return this.itsPerm == 1;
  63.    }
  64.  
  65.    public boolean isForbidden() {
  66.       return this.itsPerm == 0;
  67.    }
  68.  
  69.    public boolean isBlank() {
  70.       return this.itsPerm == 2;
  71.    }
  72.  
  73.    public int getPermission() {
  74.       return this.itsPerm;
  75.    }
  76.  
  77.    public int getDuration() {
  78.       return this.itsDuration;
  79.    }
  80.  
  81.    public String toString() {
  82.       String var1 = null;
  83.       String var2 = null;
  84.       switch (this.itsPerm) {
  85.          case 0:
  86.             var1 = "forbidden";
  87.             break;
  88.          case 1:
  89.             var1 = "allowed";
  90.             break;
  91.          case 2:
  92.             var1 = "blank";
  93.       }
  94.  
  95.       switch (this.itsDuration) {
  96.          case 0:
  97.             var2 = var1 + " in the current scope";
  98.             break;
  99.          case 1:
  100.             var2 = var1 + " in the current browser session";
  101.             break;
  102.          case 2:
  103.             var2 = var1 + " forever";
  104.       }
  105.  
  106.       return var2;
  107.    }
  108.  
  109.    public void describeClassInfo(ClassInfo var1) {
  110.       var1.addClass("Privilege", 1);
  111.       var1.addField("Perm", (byte)8);
  112.       var1.addField("Duration", (byte)8);
  113.    }
  114.  
  115.    public void encode(Encoder var1) throws CodingException {
  116.       var1.encodeInt("Perm", this.itsPerm);
  117.       var1.encodeInt("Duration", this.itsDuration);
  118.    }
  119.  
  120.    public void decode(Decoder var1) throws CodingException {
  121.       if (!this.itsInited) {
  122.          this.itsInited = true;
  123.          this.itsPerm = var1.decodeInt("Perm");
  124.          this.itsDuration = var1.decodeInt("Duration");
  125.       }
  126.    }
  127.  
  128.    public void finishDecoding() throws CodingException {
  129.    }
  130.  
  131.    static {
  132.       for(int var0 = 0; var0 < 3; ++var0) {
  133.          for(int var1 = 0; var1 < 3; ++var1) {
  134.             itsPrivilegeCache[var0][var1] = new Privilege(var0, var1);
  135.          }
  136.       }
  137.  
  138.    }
  139. }
  140.