/** Fetch the classloader for the given ApplicationID. */ static URLClassLoader getUrlClassLoader(ApplicationID appId, Map input) { NCube cpCube = getCube(appId, CLASSPATH_CUBE); if (cpCube == null) { // No sys.classpath cube exists, just create regular GroovyClassLoader with no // URLs set into it. // Scope the GroovyClassLoader per ApplicationID return getLocalClassloader(appId); } final String envLevel = SystemUtilities.getExternalVariable("ENV_LEVEL"); if (!input.containsKey("env") && StringUtilities.hasContent( envLevel)) { // Add in the 'ENV_LEVEL" environment variable when looking up sys.* cubes, // if there was not already an entry for it. input.put("env", envLevel); } if (!input.containsKey("username")) { // same as ENV_LEVEL, add it in if not already there. input.put("username", System.getProperty("user.name")); } Object urlCpLoader = cpCube.getCell(input); if (urlCpLoader instanceof URLClassLoader) { return (URLClassLoader) urlCpLoader; } throw new IllegalStateException( "If the sys.classpath cube exists it must return a URLClassLoader."); }
/** * Fetch an n-cube by name from the given ApplicationID. If no n-cubes are loaded, then a * loadCubes() call is performed and then the internal cache is checked again. If the cube is not * found, null is returned. */ public static NCube getCube(ApplicationID appId, String name) { validateAppId(appId); NCube.validateCubeName(name); Map<String, Object> cubes = getCacheForApp(appId); final String lowerCubeName = name.toLowerCase(); if (cubes.containsKey(lowerCubeName)) { // pull from cache final Object cube = cubes.get(lowerCubeName); return Boolean.FALSE == cube ? null : ensureLoaded(cube); } // now even items with metaProperties(cache = 'false') can be retrieved // and normal app processing doesn't do two queries anymore. // used to do getCubeInfoRecords() -> dto // and then dto -> loadCube(id) NCube ncube = getPersister().loadCube(appId, name); if (ncube == null) { cubes.put(lowerCubeName, Boolean.FALSE); return null; } return prepareCube(ncube); }