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

34
LINES

< > BotCompany Repo | #1019855 // JavaXClassLoaderWithParents - takes certain classes from different parents, in addition to the virtualParent for libraries

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4543L/27K).

static class JavaXClassLoaderWithParents extends JavaXClassLoaderWithParent {
  // keys: full class names or package names
  // (inner classes are automatically included)
  NavigableMap<S, ClassLoader> parentMap = syncTreeMap();
  
  *(S progID, L<File> files, ClassLoader virtualParent) {
    super(progID, files, virtualParent);
  }

  *(S progID, L<File> files) {
    super(progID, files, null);
  }
  
  protected Class<?> findClass(S name) throws ClassNotFoundException {
    ClassLoader parent = findParentForClass(name);
    if (parent != null)
      ret parent.loadClass(name);
    else
      ret super.findClass(name);
  }
    
  ClassLoader findParentForClass(S name) {
    ClassLoader cl = parentMap.get(name);
    if (cl != null) ret cl;
    S s = parentMap.floorKey(name);
    if (startsWithOneOf(name, s + "$", s + "."))
      ret parentMap.get(s);
    null;
  }
  
  void addParent(S name, ClassLoader loader) {
    parentMap.put(name, loader);
  }
}

Author comment

Began life as a copy of #1011216

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019855
Snippet name: JavaXClassLoaderWithParents - takes certain classes from different parents, in addition to the virtualParent for libraries
Eternal ID of this version: #1019855/10
Text MD5: 8098f9b409046db3b3dc9841eb1d4adf
Transpilation MD5: 66a675a26ef91ed9d327eaac8a7966bd
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-02 15:40:56
Source code size: 998 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 349 / 924
Version history: 9 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)