Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

50
LINES

< > BotCompany Repo | #1027595 // JavaXClassLoader with additionalResolvers [abandoned, doesn't work, they're never used]]

JavaX fragment (include)

static class JavaXClassLoader extends URLClassLoader {
  S progID;
  L<File> files;
  Set<S> triedToLoad = synchroSet();
  Set<Class> loadedClasses = synchroSet();
  L additionalResolvers; // each is a func(S className) -> InputStream
  bool retired;
  O retiredMarker;
  
  *(S progID, L<File> files) {
    this(progID, files, getSystemClassLoader());
  }
  
  *(S progID, L<File> files, ClassLoader parent) {
    super(new URL[0], parent);
    this.progID = progID;
    this.files = files;
    
    ctex {
      for (File f : files)
        addURL(f.toURI().toURL());
    }
    
    fixACCInClassLoader(this);
  }
  
  protected Class<?> findClass(S name) throws ClassNotFoundException {
    bool triedBefore = !triedToLoad.add(name);
    try {
      Class<?> c = super.findClass(name);
      loadedClasses.add(c);
      if (eq(name, "main"))
        callOpt(javax(), 'registerAMainClass, c);
      ret c;
    } catch (ClassNotFoundException e) {
      throw new ClassNotFoundException("Class " + name + " not found in " + joinWithComma(map(f f2s, files)) + " (progID=" + progID + ")"
        + (triedBefore ? ", tried to load before" : ""), e);
    }
  }
  
  toString {
    ret "JavaXClassLoader[" + systemHashCodeHex(this) + "] - " + progID;
  }
  
  public InputStream getResourceAsStream(String name) {
    fOr (O f : additionalResolvers)
      try object InputStream in = cast callF(f, name);
    ret super.getResourceAsStream(name);
  }
}

Author comment

Began life as a copy of #1004665

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

-
Snippet ID: #1027595
Snippet name: JavaXClassLoader with additionalResolvers [abandoned, doesn't work, they're never used]]
Eternal ID of this version: #1027595/1
Text MD5: 230a8cc910ee81f3ad2ed6d8bcd1104f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-25 14:16:38
Source code size: 1496 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 150 / 179
Referenced in: