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)

1  
static class JavaXClassLoader extends URLClassLoader {
2  
  S progID;
3  
  L<File> files;
4  
  Set<S> triedToLoad = synchroSet();
5  
  Set<Class> loadedClasses = synchroSet();
6  
  L additionalResolvers; // each is a func(S className) -> InputStream
7  
  bool retired;
8  
  O retiredMarker;
9  
  
10  
  *(S progID, L<File> files) {
11  
    this(progID, files, getSystemClassLoader());
12  
  }
13  
  
14  
  *(S progID, L<File> files, ClassLoader parent) {
15  
    super(new URL[0], parent);
16  
    this.progID = progID;
17  
    this.files = files;
18  
    
19  
    ctex {
20  
      for (File f : files)
21  
        addURL(f.toURI().toURL());
22  
    }
23  
    
24  
    fixACCInClassLoader(this);
25  
  }
26  
  
27  
  protected Class<?> findClass(S name) throws ClassNotFoundException {
28  
    bool triedBefore = !triedToLoad.add(name);
29  
    try {
30  
      Class<?> c = super.findClass(name);
31  
      loadedClasses.add(c);
32  
      if (eq(name, "main"))
33  
        callOpt(javax(), 'registerAMainClass, c);
34  
      ret c;
35  
    } catch (ClassNotFoundException e) {
36  
      throw new ClassNotFoundException("Class " + name + " not found in " + joinWithComma(map(f f2s, files)) + " (progID=" + progID + ")"
37  
        + (triedBefore ? ", tried to load before" : ""), e);
38  
    }
39  
  }
40  
  
41  
  toString {
42  
    ret "JavaXClassLoader[" + systemHashCodeHex(this) + "] - " + progID;
43  
  }
44  
  
45  
  public InputStream getResourceAsStream(String name) {
46  
    fOr (O f : additionalResolvers)
47  
      try object InputStream in = cast callF(f, name);
48  
    ret super.getResourceAsStream(name);
49  
  }
50  
}

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: 96 / 121
Referenced in: [show references]