home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / io / FilePermission.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.5 KB  |  208 lines

  1. package java.io;
  2.  
  3. import java.security.AccessController;
  4. import java.security.Permission;
  5. import java.security.PermissionCollection;
  6. import sun.security.action.GetPropertyAction;
  7.  
  8. public final class FilePermission extends Permission implements Serializable {
  9.    private static final int EXECUTE = 1;
  10.    private static final int WRITE = 2;
  11.    private static final int READ = 4;
  12.    private static final int DELETE = 8;
  13.    private static final int ALL = 15;
  14.    private static final int NONE = 0;
  15.    private transient int mask;
  16.    private transient boolean directory;
  17.    private transient boolean recursive;
  18.    private String actions;
  19.    private transient String cpath;
  20.    private static final String RECURSIVE = "-";
  21.    private static final String WILD = "*";
  22.    private static final String SEP_RECURSIVE;
  23.    private static final String SEP_WILD;
  24.    private static final long serialVersionUID = 7930732926638008763L;
  25.  
  26.    private void init(int var1) {
  27.       if ((var1 & 15) != var1) {
  28.          throw new IllegalArgumentException("invalid actions mask");
  29.       } else if (var1 == 0) {
  30.          throw new IllegalArgumentException("invalid actions mask");
  31.       } else if (((Permission)this).getName() == null) {
  32.          throw new NullPointerException("name can't be null");
  33.       } else {
  34.          this.mask = var1;
  35.          this.cpath = ((Permission)this).getName();
  36.          if (this.cpath.equals("<<ALL FILES>>")) {
  37.             this.directory = true;
  38.             this.recursive = true;
  39.             this.cpath = "";
  40.          } else {
  41.             if (!this.cpath.endsWith(SEP_RECURSIVE) && !this.cpath.equals("-")) {
  42.                if (this.cpath.endsWith(SEP_WILD) || this.cpath.equals("*")) {
  43.                   this.directory = true;
  44.                   this.cpath = this.cpath.substring(0, this.cpath.length() - 1);
  45.                }
  46.             } else {
  47.                this.directory = true;
  48.                this.recursive = true;
  49.                this.cpath = this.cpath.substring(0, this.cpath.length() - 1);
  50.             }
  51.  
  52.             if (this.cpath.equals("")) {
  53.                this.cpath = (String)AccessController.doPrivileged(new GetPropertyAction("user.dir"));
  54.             }
  55.  
  56.             this.cpath = (String)AccessController.doPrivileged(new 1(this));
  57.          }
  58.       }
  59.    }
  60.  
  61.    public FilePermission(String var1, String var2) {
  62.       super(var1);
  63.       this.init(getMask(var2));
  64.    }
  65.  
  66.    FilePermission(String var1, int var2) {
  67.       super(var1);
  68.       this.init(var2);
  69.    }
  70.  
  71.    public boolean implies(Permission var1) {
  72.       if (!(var1 instanceof FilePermission)) {
  73.          return false;
  74.       } else {
  75.          FilePermission var2 = (FilePermission)var1;
  76.          return (this.mask & var2.mask) == var2.mask && this.impliesIgnoreMask(var2);
  77.       }
  78.    }
  79.  
  80.    boolean impliesIgnoreMask(FilePermission var1) {
  81.       if (this.directory) {
  82.          if (!this.recursive) {
  83.             if (var1.directory) {
  84.                return var1.recursive ? false : this.cpath.equals(var1.cpath);
  85.             } else {
  86.                int var2 = var1.cpath.lastIndexOf(File.separatorChar);
  87.                if (var2 == -1) {
  88.                   return false;
  89.                } else {
  90.                   String var3 = var1.cpath.substring(0, var2 + 1);
  91.                   return this.cpath.equals(var3);
  92.                }
  93.             }
  94.          } else if (var1.directory) {
  95.             return var1.cpath.length() >= this.cpath.length() && var1.cpath.startsWith(this.cpath);
  96.          } else {
  97.             return var1.cpath.length() > this.cpath.length() && var1.cpath.startsWith(this.cpath);
  98.          }
  99.       } else {
  100.          return this.cpath.equals(var1.cpath);
  101.       }
  102.    }
  103.  
  104.    public boolean equals(Object var1) {
  105.       if (var1 == this) {
  106.          return true;
  107.       } else if (!(var1 instanceof FilePermission)) {
  108.          return false;
  109.       } else {
  110.          FilePermission var2 = (FilePermission)var1;
  111.          return this.mask == var2.mask && this.cpath.equals(var2.cpath) && this.directory == var2.directory && this.recursive == var2.recursive;
  112.       }
  113.    }
  114.  
  115.    public int hashCode() {
  116.       return this.cpath.hashCode();
  117.    }
  118.  
  119.    private static int getMask(String param0) {
  120.       // $FF: Couldn't be decompiled
  121.    }
  122.  
  123.    int getMask() {
  124.       return this.mask;
  125.    }
  126.  
  127.    private static String getActions(int var0) {
  128.       StringBuffer var1 = new StringBuffer();
  129.       boolean var2 = false;
  130.       if ((var0 & 4) == 4) {
  131.          var2 = true;
  132.          var1.append("read");
  133.       }
  134.  
  135.       if ((var0 & 2) == 2) {
  136.          if (var2) {
  137.             var1.append(',');
  138.          } else {
  139.             var2 = true;
  140.          }
  141.  
  142.          var1.append("write");
  143.       }
  144.  
  145.       if ((var0 & 1) == 1) {
  146.          if (var2) {
  147.             var1.append(',');
  148.          } else {
  149.             var2 = true;
  150.          }
  151.  
  152.          var1.append("execute");
  153.       }
  154.  
  155.       if ((var0 & 8) == 8) {
  156.          if (var2) {
  157.             var1.append(',');
  158.          } else {
  159.             var2 = true;
  160.          }
  161.  
  162.          var1.append("delete");
  163.       }
  164.  
  165.       return var1.toString();
  166.    }
  167.  
  168.    public String getActions() {
  169.       if (this.actions == null) {
  170.          this.actions = getActions(this.mask);
  171.       }
  172.  
  173.       return this.actions;
  174.    }
  175.  
  176.    public PermissionCollection newPermissionCollection() {
  177.       return new FilePermissionCollection();
  178.    }
  179.  
  180.    private synchronized void writeObject(ObjectOutputStream var1) throws IOException {
  181.       if (this.actions == null) {
  182.          this.getActions();
  183.       }
  184.  
  185.       var1.defaultWriteObject();
  186.    }
  187.  
  188.    private synchronized void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  189.       var1.defaultReadObject();
  190.       this.init(getMask(this.actions));
  191.    }
  192.  
  193.    // $FF: synthetic method
  194.    static String access$000(FilePermission var0) {
  195.       return var0.cpath;
  196.    }
  197.  
  198.    // $FF: synthetic method
  199.    static boolean access$100(FilePermission var0) {
  200.       return var0.directory;
  201.    }
  202.  
  203.    static {
  204.       SEP_RECURSIVE = File.separator + "-";
  205.       SEP_WILD = File.separator + "*";
  206.    }
  207. }
  208.