List of utility methods to do Class Load
Stack | getClassHierarchyFrom(Class> clazz) get Class Hierarchy From Stack<Class<?>> result = new Stack<Class<?>>(); Class<?> target = clazz; while (target.getSuperclass() != null) { result.add(target); target = target.getSuperclass(); for (Class<?> iface : clazz.getInterfaces()) { result.add(iface); ... |
Class> | getClassHierarchyLeaf(Collection get Class Hierarchy Leaf Class<?> hierarchyLeaf = null; for (Class<?> clazz : classes) { if (hierarchyLeaf == null) { hierarchyLeaf = clazz; } else if (clazz != null) { if (hierarchyLeaf.isAssignableFrom(clazz)) { hierarchyLeaf = clazz; return hierarchyLeaf; |
String | getClassName(String logicalName, String trailingName) Returns the class name for the given logical name and trailing name. if (isBlank(logicalName)) { throw new IllegalArgumentException("Argument [logicalName] cannot be null or blank"); String className = logicalName.substring(0, 1).toUpperCase(Locale.ENGLISH) + logicalName.substring(1); if (trailingName != null) { className = className + trailingName; return className; ... |
String | getClassNameRepresentation(String name) Returns the class name representation of the given name String className; StringBuffer buf = new StringBuffer(); if (name != null && name.length() > 0) { String[] tokens = name.split("[^\\w\\d]"); for (int i = 0; i < tokens.length; i++) { String token = tokens[i].trim(); buf.append(token.substring(0, 1).toUpperCase(Locale.ENGLISH)).append(token.substring(1)); className = buf.toString(); return className; |
List | getClassNames(StackTraceElement[] currentStack) get Class Names ArrayList<String> list = new ArrayList<String>(); for (StackTraceElement element : currentStack) { list.add(element.getClassName()); return list; |
Class> | loadClass(Class context, String... names) Attempt to load a class for one ore more supplied class names, returning the first one found. for (String name : names) { try { Class<?> clazz = Class.forName(name, true, context.getClassLoader()); return clazz; } catch (ClassNotFoundException cnfe) { return null; ... |
Class | loadClass(Class sourceClass, final String className) load Class try { ClassLoader loader = sourceClass.getClassLoader(); if (loader != null) { return loader.loadClass(className); } else { return (Class) Class.forName(className); } catch (ClassNotFoundException e) { ... |
Class | loadClass(Class> base, String name) load Class return loadClass(base.getClassLoader(), name);
|
void | loadClass(Class> clazz) load Class loadClass(clazz.getName()); |
Class> | loadClass(Class> contextClass, String className) Loads a class using the class loader. Class<?> clazz = null; if (contextClass.getClassLoader() != null) { clazz = silentLoadClass(className, contextClass.getClassLoader()); if (clazz == null && Thread.currentThread().getContextClassLoader() != null) { clazz = silentLoadClass(className, Thread.currentThread().getContextClassLoader()); return clazz; ... |