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

  1. package netscape.softupdate;
  2.  
  3. import java.util.Enumeration;
  4. import netscape.security.Principal;
  5. import netscape.security.PrivilegeManager;
  6.  
  7. public final class Registry implements RegistryErrors {
  8.    protected static final int ROOTKEY_USERS = 1;
  9.    protected static final int ROOTKEY_COMMON = 2;
  10.    protected static final int ROOTKEY_CURRENT_USER = 3;
  11.    protected static final int ROOTKEY_PRIVATE = 4;
  12.    protected static final int ROOTKEY = 32;
  13.    protected static final int ROOTKEY_VERSIONS = 33;
  14.    protected static final int PRIVATE_KEY_COMMON = -2;
  15.    protected static final int PRIVATE_KEY_USER = -3;
  16.    protected static final int ENUM_NORMAL = 0;
  17.    protected static final int ENUM_DESCEND = 1;
  18.    public static final int TYPE_STRING = 17;
  19.    public static final int TYPE_INT_ARRAY = 18;
  20.    public static final int TYPE_BYTES = 19;
  21.    private static final String PRIVATE = "PrivateRegistryAccess";
  22.    private static final String STANDARD = "StandardRegistryAccess";
  23.    private static final String ADMIN = "AdministratorRegistryAccess";
  24.    private int hReg;
  25.    private String regName;
  26.    private String username;
  27.  
  28.    public Registry() throws RegistryException {
  29.       this("");
  30.    }
  31.  
  32.    private Registry(String var1) throws RegistryException {
  33.       this.regName = var1;
  34.       PrivilegeManager.checkPrivilegeEnabled("PrivateRegistryAccess");
  35.       int var2 = this.nOpen();
  36.       if (var2 != 0) {
  37.          throw new RegistryException(var2);
  38.       }
  39.    }
  40.  
  41.    public RegistryNode addNode(RegistryNode var1, String var2) throws RegistryException {
  42.       int var3;
  43.       String var4;
  44.       if (var1 == null) {
  45.          var4 = "AdministratorRegistryAccess";
  46.          var3 = 32;
  47.       } else {
  48.          var4 = var1.getTarget();
  49.          var3 = var1.getKey();
  50.       }
  51.  
  52.       PrivilegeManager.checkPrivilegeEnabled(var4);
  53.       int var5 = this.nAddKey(var3, var2);
  54.       if (var5 != 0) {
  55.          throw new RegistryException(var5);
  56.       } else {
  57.          return this.nGetKey(var3, var2, var4);
  58.       }
  59.    }
  60.  
  61.    public void deleteNode(RegistryNode var1, String var2) throws RegistryException {
  62.       int var3;
  63.       String var4;
  64.       if (var1 == null) {
  65.          var4 = "AdministratorRegistryAccess";
  66.          var3 = 32;
  67.       } else {
  68.          var4 = var1.getTarget();
  69.          var3 = var1.getKey();
  70.       }
  71.  
  72.       PrivilegeManager.checkPrivilegeEnabled(var4);
  73.       int var5 = this.nDeleteKey(var3, var2);
  74.       if (var5 != 0) {
  75.          throw new RegistryException(var5);
  76.       }
  77.    }
  78.  
  79.    public RegistryNode getNode(RegistryNode var1, String var2) throws RegistryException {
  80.       int var3;
  81.       String var4;
  82.       if (var1 == null) {
  83.          var4 = "AdministratorRegistryAccess";
  84.          var3 = 32;
  85.       } else {
  86.          var4 = var1.getTarget();
  87.          var3 = var1.getKey();
  88.       }
  89.  
  90.       PrivilegeManager.checkPrivilegeEnabled(var4);
  91.       return this.nGetKey(var3, var2, var4);
  92.    }
  93.  
  94.    public Enumeration children(RegistryNode var1, String var2) throws RegistryException {
  95.       RegistryNode var3 = this.getNode(var1, var2);
  96.       return new RegKeyEnumerator(this, var3.getKey(), 0, var3.getTarget());
  97.    }
  98.  
  99.    public Enumeration subtree(RegistryNode var1, String var2) throws RegistryException {
  100.       RegistryNode var3 = this.getNode(var1, var2);
  101.       return new RegKeyEnumerator(this, var3.getKey(), 1, var3.getTarget());
  102.    }
  103.  
  104.    public RegistryNode getSharedNode() throws RegistryException {
  105.       PrivilegeManager.checkPrivilegeEnabled("StandardRegistryAccess");
  106.       return this.nGetKey(2, "", "StandardRegistryAccess");
  107.    }
  108.  
  109.    public RegistryNode getSharedUserNode() throws RegistryException {
  110.       PrivilegeManager.checkPrivilegeEnabled("StandardRegistryAccess");
  111.       return this.nGetKey(3, "", "StandardRegistryAccess");
  112.    }
  113.  
  114.    public RegistryNode getPrivateNode() throws RegistryException {
  115.       PrivilegeManager.checkPrivilegeEnabled("PrivateRegistryAccess");
  116.       Principal[] var1 = PrivilegeManager.getPrivilegeManager().getClassPrincipalsFromStack(1);
  117.       if (var1 == null) {
  118.          System.out.println("Registry called without principals");
  119.          throw new NullPointerException("Registry called without principals");
  120.       } else {
  121.          String var2 = "/" + var1[0].getFingerPrint() + "/Common";
  122.          int var3 = this.nAddKey(4, var2);
  123.          if (var3 != 0) {
  124.             throw new RegistryException(var3);
  125.          } else {
  126.             return this.nGetKey(4, var2, "PrivateRegistryAccess");
  127.          }
  128.       }
  129.    }
  130.  
  131.    public RegistryNode getPrivateUserNode() throws RegistryException {
  132.       PrivilegeManager.checkPrivilegeEnabled("PrivateRegistryAccess");
  133.       Principal[] var1 = PrivilegeManager.getPrivilegeManager().getClassPrincipalsFromStack(1);
  134.       if (var1 == null) {
  135.          System.out.println("Registry called without principals");
  136.          throw new NullPointerException("Registry called without principals");
  137.       } else {
  138.          String var2 = "/" + var1[0].getFingerPrint() + "/Users/" + this.userName();
  139.          int var3 = this.nAddKey(4, var2);
  140.          if (var3 != 0) {
  141.             throw new RegistryException(var3);
  142.          } else {
  143.             return this.nGetKey(4, var2, "PrivateRegistryAccess");
  144.          }
  145.       }
  146.    }
  147.  
  148.    protected void finalize() throws Throwable {
  149.       if (this.hReg != 0) {
  150.          this.nClose();
  151.       }
  152.  
  153.    }
  154.  
  155.    private String userName() {
  156.       if (this.username == null) {
  157.          this.username = this.nUserName();
  158.       }
  159.  
  160.       return this.username;
  161.    }
  162.  
  163.    private native int nOpen();
  164.  
  165.    private native int nClose();
  166.  
  167.    private native int nAddKey(int var1, String var2);
  168.  
  169.    private native int nDeleteKey(int var1, String var2);
  170.  
  171.    private native RegistryNode nGetKey(int var1, String var2, String var3);
  172.  
  173.    private native String nUserName();
  174. }
  175.