home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 November / PCO1197.ISO / FilesBBS / WIN95 / NET_COM / N32E403.EXE / nav40l.z / java40.jar / netscape / security / Privilege.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-04  |  2.9 KB  |  138 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 static Privilege[][] itsPrivilegeCache = new Privilege[3][3];
  22.  
  23.    public Privilege() {
  24.    }
  25.  
  26.    private Privilege(int var1, int var2) {
  27.       this.itsPerm = var1;
  28.       this.itsDuration = var2;
  29.    }
  30.  
  31.    public static Privilege findPrivilege(int var0, int var1) {
  32.       return itsPrivilegeCache[var0][var1];
  33.    }
  34.  
  35.    public static int add(int var0, int var1) {
  36.       return var0 < var1 ? var0 : var1;
  37.    }
  38.  
  39.    public static Privilege add(Privilege var0, Privilege var1) {
  40.       return var0.itsPerm < var1.itsPerm ? var0 : var1;
  41.    }
  42.  
  43.    public boolean samePermission(Privilege var1) {
  44.       return var1.itsPerm == this.itsPerm;
  45.    }
  46.  
  47.    public boolean samePermission(int var1) {
  48.       return this.itsPerm == var1;
  49.    }
  50.  
  51.    public boolean sameDuration(Privilege var1) {
  52.       return var1.itsDuration == this.itsDuration;
  53.    }
  54.  
  55.    public boolean sameDuration(int var1) {
  56.       return this.itsDuration == var1;
  57.    }
  58.  
  59.    public boolean isAllowed() {
  60.       return this.itsPerm == 1;
  61.    }
  62.  
  63.    public boolean isForbidden() {
  64.       return this.itsPerm == 0;
  65.    }
  66.  
  67.    public boolean isBlank() {
  68.       return this.itsPerm == 2;
  69.    }
  70.  
  71.    public int getPermission() {
  72.       return this.itsPerm;
  73.    }
  74.  
  75.    public int getDuration() {
  76.       return this.itsDuration;
  77.    }
  78.  
  79.    public String toString() {
  80.       String var1 = null;
  81.       String var2 = null;
  82.       switch (this.itsPerm) {
  83.          case 0:
  84.             var1 = "forbidden";
  85.             break;
  86.          case 1:
  87.             var1 = "allowed";
  88.             break;
  89.          case 2:
  90.             var1 = "blank";
  91.       }
  92.  
  93.       switch (this.itsDuration) {
  94.          case 0:
  95.             var2 = var1 + " in the current scope";
  96.             break;
  97.          case 1:
  98.             var2 = var1 + " in the current browser session";
  99.             break;
  100.          case 2:
  101.             var2 = var1 + " forever";
  102.       }
  103.  
  104.       return var2;
  105.    }
  106.  
  107.    public void describeClassInfo(ClassInfo var1) {
  108.       var1.addClass("Privilege", 1);
  109.       var1.addField("Perm", (byte)8);
  110.       var1.addField("Duration", (byte)8);
  111.    }
  112.  
  113.    public void encode(Encoder var1) throws CodingException {
  114.       var1.encodeInt("Perm", this.itsPerm);
  115.       var1.encodeInt("Duration", this.itsDuration);
  116.    }
  117.  
  118.    public void decode(Decoder var1) throws CodingException {
  119.       PrivilegeManager var2 = PrivilegeManager.getPrivilegeManager();
  120.       if (var2 == null || !var2.isSecurityInited()) {
  121.          this.itsPerm = var1.decodeInt("Perm");
  122.          this.itsDuration = var1.decodeInt("Duration");
  123.       }
  124.    }
  125.  
  126.    public void finishDecoding() throws CodingException {
  127.    }
  128.  
  129.    static {
  130.       for(int var0 = 0; var0 < 3; ++var0) {
  131.          for(int var1 = 0; var1 < 3; ++var1) {
  132.             itsPrivilegeCache[var0][var1] = new Privilege(var0, var1);
  133.          }
  134.       }
  135.  
  136.    }
  137. }
  138.