Compiles a generated code to a Class.
@param cl the ClassLoader used to load the class
@param name  the class name
@param code  the generated code
@param <T>   the class type
@return  the compiled class
518255
public static <T> Class<T> compile(ClassLoader cl, String name, String code) {
		Tuple2<ClassLoader, String> cacheKey = Tuple2.of(cl, name);
		Class<?> clazz = COMPILED_CACHE.getIfPresent(cacheKey);
		if (clazz == null) {
			clazz = doCompile(cl, name, code);
			COMPILED_CACHE.put(cacheKey, clazz);
		}
		//noinspection unchecked
		return (Class<T>) clazz;
	}
359537
public final static Class<?> getCompiledClass(String className, boolean useCache) throws CompilationException, ClassLoadException {
        try {
            if (! useCache) {
                
                /*String compilationResult = compileClass(className);
                System.out.println("************ compilationResult   " + compilationResult);
                if (compilationResult.contains("cannot read")) {
                    throw new ClassLoadException(compilationResult);
                }
                if (compilationResult.contains("error")) {
                    throw new CompilationException(compilationResult);
                }*/

                DynamicClassLoader dynamicClassLoader = new DynamicClassLoader(DynamicClassFactory.class.getClassLoader());
                return dynamicClassLoader.loadClass(className);
            } else {
                return CACHED_CONTROLLERS.computeIfAbsent(className, WRAP_FORNAME);
            }
        } catch (CompilationException e) {
            throw e; // so the exception doesn't get caught by the more general catch(Exception)
        } catch (Exception e) {
            throw new ClassLoadException(e);
        }
    }
1072175
@SuppressWarnings("rawtypes")
	public static Class loadClass(Class loadClass, String name)
			throws ClassNotFoundException {
		return loadClass(loadClass, name, false);
	}
800257
public static Class classForName(String name) throws ClassNotFoundException {
		try {
			return Thread.currentThread().getContextClassLoader().loadClass(name);
		}
		catch (Exception e) {
			return Class.forName(name);
		}
	}
1037801
@SuppressWarnings("unchecked")
  public static <T> T populate(Class<T> clazz, String name) {
    EntityType type = null;
    if (clazz.isInterface()) {
      type = Model.getType(clazz.getName());
    } else {
      type = Model.getType(clazz);
    }
    return (T) populate(type.newInstance(), type.getEntityName(), name);
  }
765414
public static Class<?> classFind(String name) {
        try {
            return Class.forName(name);
        } catch (ClassNotFoundException e) {
            return findType(name).type;
        }
    }
813555
public static void dynamicCodeGenerate(OutputStream os, Class cls, Charset charset, ICodeGenerator codeGenerator)
            throws IOException {
        if (cls == null) {
            throw new NullPointerException("Parameter 'cls' is null");
        }
        if (os == null) {
            throw new NullPointerException("Parameter 'os' is null");
        }
        if (charset == null) {
            charset = Charset.defaultCharset();
        }
        String code = codeGenerator.getCode();

        os.write(code.getBytes(charset));
    }
281887
private Set<String> getClasses(String name, ClassLoader cl)
   {
      Set<String> result = new HashSet<String>();
      
      try
      {
         Class<?> clz = Class.forName(name, true, cl);
         while (!Object.class.equals(clz))
         {
            result.add(clz.getName());
            clz = clz.getSuperclass();
         }
      }
      catch (Throwable t)
      {
         log.debugf("Couldn't load: %s", name);
      }

      return result;
   }
211705
private static Class<?> name2class(ClassLoader cl, String name)
			throws ClassNotFoundException {
		int c = 0, index = name.indexOf('[');
		if (index > 0) {
			c = (name.length() - index) / 2;
			name = name.substring(0, index);
		}
		if (c > 0) {
			StringBuilder sb = new StringBuilder();
			while (c-- > 0)
				sb.append("[");

			if ("void".equals(name))
				sb.append(JVM_VOID);
			else if ("boolean".equals(name))
				sb.append(JVM_BOOLEAN);
			else if ("byte".equals(name))
				sb.append(JVM_BYTE);
			else if ("char".equals(name))
				sb.append(JVM_CHAR);
			else if ("double".equals(name))
				sb.append(JVM_DOUBLE);
			else if ("float".equals(name))
				sb.append(JVM_FLOAT);
			else if ("int".equals(name))
				sb.append(JVM_INT);
			else if ("long".equals(name))
				sb.append(JVM_LONG);
			else if ("short".equals(name))
				sb.append(JVM_SHORT);
			else
				sb.append('L').append(name).append(';'); // "java.lang.Object"
															// ==>
															// "Ljava.lang.Object;"
			name = sb.toString();
		} else {
			if ("void".equals(name))
				return void.class;
			else if ("boolean".equals(name))
				return boolean.class;
			else if ("byte".equals(name))
				return byte.class;
			else if ("char".equals(name))
				return char.class;
			else if ("double".equals(name))
				return double.class;
			else if ("float".equals(name))
				return float.class;
			else if ("int".equals(name))
				return int.class;
			else if ("long".equals(name))
				return long.class;
			else if ("short".equals(name))
				return short.class;
		}

		if (cl == null)
			cl = getClassLoader();
		Class<?> clazz = NAME_CLASS_CACHE.get(name);
		if (clazz == null) {
			clazz = Class.forName(name, true, cl);
			NAME_CLASS_CACHE.put(name, clazz);
		}
		return clazz;
	}
754174
public String code(String classificationName, String elementName) {
        assertArgumentNotNull("classificationName", classificationName);
        assertArgumentNotNull("elementName", elementName);
        final ClassificationMeta meta = findClassificationMeta((String) classificationName, () -> {
            return "code('" + classificationName + "', '" + elementName + "')";
        });
        final Classification cls = meta.nameOf(elementName);
        assertClassificationByNameExists(classificationName, elementName, cls);
        return cls.code();
    }
991984
private Class loadClass(final String name) {

		ClassLoader loader = NodeExtender.getClassLoader();
		Class loadedClass  = null;

		if (loader == null) {
			loader = getClass().getClassLoader();
		}

		try {

			loadedClass = Class.forName(name, true, loader);

		} catch (Throwable ignore) {}

		if (loadedClass == null) {

			try {

				loadedClass = Class.forName(name);

			} catch (Throwable ignore) {}
		}

		return loadedClass;
	}
914667
public Class<?> getClassByNameOrNull(String name) {
		Map<String, WeakReference<Class<?>>> map;

		synchronized (CACHE_CLASSES) {
			map = CACHE_CLASSES.get(classLoader);
			if (map == null) {
				map = Collections.synchronizedMap(
						new WeakHashMap<String, WeakReference<Class<?>>>());
				CACHE_CLASSES.put(classLoader, map);
			}
		}

		Class<?> clazz = null;
		WeakReference<Class<?>> ref = map.get(name);
		if (ref != null) {
			clazz = ref.get();
		}

		if (clazz == null) {
			try {
				clazz = Class.forName(name, true, classLoader);
			} catch (ClassNotFoundException e) {
				// Leave a marker that the class isn't found
				map.put(name, new WeakReference<Class<?>>(NEGATIVE_CACHE_SENTINEL));
				return null;
			}
			// two putters can race here, but they'll put the same class
			map.put(name, new WeakReference<Class<?>>(clazz));
			return clazz;
		} else if (clazz == NEGATIVE_CACHE_SENTINEL) {
			return null; // not found
		} else {
			// cache hit
			return clazz;
		}
	}
1223504
public static <T> Class<T> getType(String name) {
        Class<T> type;
        try {
            type = (Class<T>) Class.forName(name);
        } catch (ClassNotFoundException e) {
            throw new XOException("Cannot find class with name '" + name + "'", e);
        }
        return type;
    }
1306250
public Class<?> internalLoadClass(String name, boolean resolve) throws ClassNotFoundException {
        if (CACHE_NON_EXISTING_CLASSES && nonExistingClasses.contains(name)) {
            throw dummyCFNE;
        }

        if (droolsClassLoader != null) {
            try {
                return Class.forName(name, resolve, droolsClassLoader);
            } catch (ClassNotFoundException e) { }
        }
        try {
            return super.loadClass(name, resolve);
        } catch (ClassNotFoundException e) {
            return Class.forName(name, resolve, getParent());
        }
    }
900900
public Class loadClass(final String name, boolean lookupScriptFiles, boolean preferClassOverScript)
            throws ClassNotFoundException, CompilationFailedException {
        return loadClass(name, lookupScriptFiles, preferClassOverScript, false);
    }
463732
public static Class loadClass(ClassLoader cl, String className) throws ClassException {

	Set<Throwable> exceptions = new HashSet<Throwable>();
	Class clazz = loadClass(cl, className, null, exceptions);

	if (clazz != null) return clazz;

	String msg = "cannot load class through its string name, because no definition for the class with the specified name [" + className + "] could be found";

	if (!exceptions.isEmpty()) {

	    StringBuilder detail = new StringBuilder();
	    Iterator<Throwable> it = exceptions.iterator();
	    Throwable t;
	    while (it.hasNext()) {
		t = it.next();
		detail.append(t.getClass().getName()).append(':').append(t.getMessage()).append(';');
	    }
	    throw new ClassException(msg + " caused by (" + detail.toString() + ")");
	}
	throw new ClassException(msg);
    }
1262752
protected Class loadClass(String className) {
        try {
            return getClass().getClassLoader().loadClass(className);
        } catch (Exception e) {
            //ignore and fallback to TCCL
        }

        try {
            if (Thread.currentThread().getContextClassLoader() != null)
            return Thread.currentThread().getContextClassLoader().loadClass(className);
        } catch (Exception e) {
            //ignore and fallback to TCCL
        }
        throw new IllegalStateException("Failed to load class: ["+className+"].");
    }