- public static Object construct(Constructor<? extends Object> constructor, ArrayList<Object> objects) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- Object[] initargs = objects.toArray(new Object[]{});
- return constructor.newInstance(initargs);
+ public static Object construct(Constructor<? extends Object> constructor, List<Object> objects)
+ throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ Object[] initargs = objects.toArray(new Object[] {});
+ return constructor.newInstance(initargs);
+ }
+
+ public static Class<?> loadClassWithTCCL(String name) throws ClassNotFoundException {
+ if ("byte[]".equals(name)) {
+ return byte[].class;
+ }
+ try {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ } catch (ClassNotFoundException e) {
+ String[] components = name.split("\\.");
+ String potentialOuter;
+ int length = components.length;
+ if (length > 2 && (potentialOuter = components[length - 2]) != null && Character.isUpperCase(potentialOuter.charAt(0))) {
+
+ String outerName = Joiner.on(".").join(Arrays.asList(components).subList(0, length - 1));
+ String innerName = outerName + "$" + components[length-1];
+ return Thread.currentThread().getContextClassLoader().loadClass(innerName);
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ public static Class<?> tryToLoadClassWithTCCL(String fullyQualifiedName) {
+ try {
+ return loadClassWithTCCL(fullyQualifiedName);
+ } catch (ClassNotFoundException e) {
+
+ }
+ return null;