home *** CD-ROM | disk | FTP | other *** search
/ Australian PC Authority 1999 May / may1999.iso / INTERNET / COMMUNIC / NETCAST.Z / marimb10.jar / netscape / netcast / ApplicationThreadGroup.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-25  |  2.4 KB  |  90 lines

  1. package netscape.netcast;
  2.  
  3. import marimba.persist.PersistentStateClassLoader;
  4. import netscape.applet.CastanetChannelInfo;
  5. import netscape.security.PrivilegeManager;
  6. import netscape.security.Target;
  7.  
  8. final class ApplicationThreadGroup extends ThreadGroup implements PersistentStateClassLoader {
  9.    CastanetChannelInfo loader;
  10.  
  11.    ApplicationThreadGroup(String name) {
  12.       super(name);
  13.    }
  14.  
  15.    public Class loadPersistentClass(String name) throws ClassNotFoundException {
  16.       return this.loader.loadClass(name);
  17.    }
  18.  
  19.    public Class loadScriptClass(String name, byte[] data) {
  20.       if (name == null) {
  21.          name = this.getClassNameFromScript(data);
  22.       }
  23.  
  24.       PrivilegeManager privMgr = PrivilegeManager.getPrivilegeManager();
  25.       if (privMgr != null) {
  26.          Target target = Target.findTarget("MarimbaInternalTarget");
  27.          if (target != null) {
  28.             privMgr.enablePrivilege(target);
  29.          }
  30.       }
  31.  
  32.       return this.loader.classFromBytes(data, name);
  33.    }
  34.  
  35.    public void close() {
  36.       this.loader = null;
  37.       ((ThreadGroup)this).stop();
  38.    }
  39.  
  40.    private String getClassNameFromScript(byte[] clazz) {
  41.       String result = null;
  42.       int cpoolCount = ((clazz[8] & 255) << 8) + (clazz[9] & 255);
  43.  
  44.       try {
  45.          int[] lookup = new int[cpoolCount];
  46.          int i = 10;
  47.  
  48.          for(int count = 1; count < cpoolCount; ++count) {
  49.             switch (clazz[i]) {
  50.                case 1:
  51.                   lookup[count] = i;
  52.                   i += ((clazz[i + 1] & 255) << 8) + (clazz[i + 2] & 255) + 3;
  53.                case 2:
  54.                default:
  55.                   break;
  56.                case 3:
  57.                case 4:
  58.                case 9:
  59.                case 10:
  60.                case 11:
  61.                case 12:
  62.                   i += 5;
  63.                   break;
  64.                case 5:
  65.                case 6:
  66.                   i += 9;
  67.                   ++count;
  68.                   break;
  69.                case 7:
  70.                   lookup[count] = i;
  71.                case 8:
  72.                   i += 3;
  73.             }
  74.          }
  75.  
  76.          i += 2;
  77.          int classIndex = lookup[((clazz[i] & 255) << 8) + (clazz[i + 1] & 255)];
  78.          if (clazz[classIndex] == 7) {
  79.             classIndex = lookup[((clazz[classIndex + 1] & 255) << 8) + (clazz[classIndex + 2] & 255)];
  80.             if (clazz[classIndex] == 1) {
  81.                result = new String(clazz, 0, classIndex + 3, ((clazz[classIndex + 1] & 255) << 8) + (clazz[classIndex + 2] & 255));
  82.             }
  83.          }
  84.       } catch (ArrayIndexOutOfBoundsException var8) {
  85.       }
  86.  
  87.       return result.replace('/', '.');
  88.    }
  89. }
  90.