X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fruntime%2FExpressionClassLoader.java;h=0c134ee5c1130b5e9e730dd9552e01401f367c43;hp=bb2e5efc0a7deb57fc5081c9918a7683f40775c6;hb=a8758de5bc19e5adb3f618d3038743a164f09912;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/ExpressionClassLoader.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/ExpressionClassLoader.java index bb2e5efc0..0c134ee5c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/ExpressionClassLoader.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/runtime/ExpressionClassLoader.java @@ -1,11 +1,11 @@ package org.simantics.scl.compiler.runtime; -import gnu.trove.map.hash.THashMap; - import java.util.Map; import org.simantics.scl.compiler.constants.Constant; +import gnu.trove.map.hash.THashMap; + public class ExpressionClassLoader extends ClassLoader implements MutableClassLoader { public static final boolean VALIDATE_CLASS_NAMES = true; public static final boolean TRACE_CLASS_CREATION = false; @@ -60,6 +60,34 @@ public class ExpressionClassLoader extends ClassLoader implements MutableClassLo return defineClass(name, bytes, 0, bytes.length); } + public byte[] getBytes(String name) { + // Non-SCL classes are not handled here + if(!name.startsWith(SCL_PACKAGE_PREFIX)) + return null; + + // Determine the id of the class loader which is responsible of the class + String requestedModuleName = RuntimeModule.extractClassLoaderId(name); + + // Is class defined locally in this class loader? + if(requestedModuleName.equals(basePackageName)) { + String internalName = name.replace('.', '/'); + byte[] bytes = localClasses.get(internalName); + if(bytes != null) + return bytes; + return localClasses.get(internalName); + } + + // Find suitable class loader that has this class locally + { + RuntimeModule parentModule = runtimeModuleMap.get(requestedModuleName); + if(parentModule == null) + return null; + + // Find the class from the ancestor class loader + return parentModule.classLoader.getBytes(name); + } + } + private Class getClass(String name) throws ClassNotFoundException { //System.out.println("getClass " + name);