public void run() { try { Constructor<?> con = clazz.getConstructor(argclasses); gui = (Component)con.newInstance(args); } catch(Exception e) { throw SUtil.throwUnchecked(e); } } });
/** * Get the init calls. * Cleans the initargs field on return. */ public static List<Tuple2<Class<?>[], Object[]>> getInitCalls(Object obj, Class<?> clazz) { try { Field f = clazz.getDeclaredField("__initargs"); f.setAccessible(true); List<Tuple2<Class<?>[], Object[]>> initcalls = (List<Tuple2<Class<?>[], Object[]>>)f.get(obj); f.set(obj, null); return initcalls; } catch(Exception e) { throw SUtil.throwUnchecked(e); } }
/** * Convert a throwable to an unchecked exception (i.e. error or runtime exception). * Also unpacks InvocationTargeteException and ErrorException. * @param t The throwable. * @return Dummy return value as exception will be thrown inside. Use as <code>throw SUtil.throwUnchecked(t);</code> to avoid compilation errors. */ public static RuntimeException throwUnchecked(Throwable t) throws Error, RuntimeException { if(t instanceof InvocationTargetException) { throw throwUnchecked(((InvocationTargetException)t).getTargetException()); } else if(t instanceof ErrorException) { throw throwUnchecked(((ErrorException)t).getError()); } else if(t instanceof Error) { throw (Error)t; } else if(t instanceof RuntimeException) { throw (RuntimeException)t; } else { throw new RuntimeException(t); } }
/** * Process an object. * @param object The object. * @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader, * e.g. by cloning the object using the class loaded from the target class loader. * @return The processed object. */ public Object process(Object object, Type type, List<ITraverseProcessor> processors, Traverser traverser, Map<Object, Object> traversed, boolean clone, ClassLoader targetcl, Object context) { try { Class<?> clazz = SReflect.getClass(type); Method m = clazz.getMethod("clone", new Class[0]); Object ret = m.invoke(object, new Object[0]); traversed.put(object, ret); return ret; } catch(Exception e) { throw SUtil.throwUnchecked(e); } } }
/** * Encode an object. * @param obj The object. * @throws IOException */ public static byte[] encodeBytes(byte[] val, ClassLoader classloader) { byte[] ret = (byte[])val; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(SUtil.intToBytes(val.length)); GZIPOutputStream gzos = new GZIPOutputStream(baos); gzos.write(val); gzos.close(); ret = baos.toByteArray(); } catch(Exception e) { throw SUtil.throwUnchecked(e); } return ret; }
/** * Add an entry to the init calls. * * @param obj object instance that owns the field __initargs * @param clazz Class definition of the obj object * @param argtypes Signature of the init method * @param args Actual argument values for the init method */ public static void addInitArgs(Object obj, Class<?> clazz, Class<?>[] argtypes, Object[] args) { try { Field f = clazz.getDeclaredField("__initargs"); // System.out.println(f+", "+SUtil.arrayToString(args)); f.setAccessible(true); List<Tuple2<Class<?>[], Object[]>> initcalls = (List<Tuple2<Class<?>[], Object[]>>)f.get(obj); if(initcalls==null) { initcalls = new ArrayList<Tuple2<Class<?>[], Object[]>>(); f.set(obj, initcalls); } initcalls.add(new Tuple2<Class<?>[], Object[]>(argtypes, args)); } catch(Exception e) { throw SUtil.throwUnchecked(e); } }
/** * Add an entry to the init calls. * * @param obj object instance that owns the field __initargs * @param clazz Class definition of the obj object * @param argtypes Signature of the init method * @param args Actual argument values for the init method */ public static void addInitArgs(Object obj, Class<?> clazz, Class<?>[] argtypes, Object[] args) { try { Field f = clazz.getDeclaredField("__initargs"); // System.out.println(f+", "+SUtil.arrayToString(args)); f.setAccessible(true); List<Tuple2<Class<?>[], Object[]>> initcalls = (List<Tuple2<Class<?>[], Object[]>>)f.get(obj); if(initcalls==null) { initcalls = new ArrayList<Tuple2<Class<?>[], Object[]>>(); f.set(obj, initcalls); } initcalls.add(new Tuple2<Class<?>[], Object[]>(argtypes, args)); } catch(Exception e) { throw SUtil.throwUnchecked(e); } }
throw SUtil.throwUnchecked(e);
throw SUtil.throwUnchecked(e);
throw SUtil.throwUnchecked(e); throw SUtil.throwUnchecked(e);
/** * Process an object. * @param object The object. * @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader, * e.g. by cloning the object using the class loaded from the target class loader. * @return The processed object. */ public Object process(Object object, Type type, List<ITraverseProcessor> processors, Traverser traverser, Map<Object, Object> traversed, boolean clone, ClassLoader targetcl, Object context) { // System.out.println("fp: "+object); Class<?> clazz = SReflect.getClass(type); Object ret = getReturnObject(object, clazz, clone, targetcl); traversed.put(object, ret); try { // System.out.println("cloned: "+object.getClass()); // ret = object.getClass().newInstance(); traverseFields(object, traversed, processors, traverser, clone, targetcl, ret, context); } catch(Exception e) { throw SUtil.throwUnchecked(e); } return ret; }
/** * Process an object. * @param object The object. * @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader, * e.g. by cloning the object using the class loaded from the target class loader. * @return The processed object. */ public Object process(Object object, Type type, List<ITraverseProcessor> processors, Traverser traverser, Map<Object, Object> traversed, boolean clone, ClassLoader targetcl, Object context) { // System.out.println("fp: "+object); Class<?> clazz = SReflect.getClass(type); Object ret = getReturnObject(object, clazz, clone, targetcl); traversed.put(object, ret); try { // System.out.println("cloned: "+object.getClass()); // ret = object.getClass().newInstance(); traverseProperties(object, traversed, processors, traverser, clone, targetcl, ret, context); } catch(Exception e) { throw SUtil.throwUnchecked(e); } return ret; }
throw SUtil.throwUnchecked(e);
throw SUtil.throwUnchecked(e);
throw SUtil.throwUnchecked(e);
throw SUtil.throwUnchecked(ex);
throw SUtil.throwUnchecked(e);
throw SUtil.throwUnchecked(e);
throw SUtil.throwUnchecked(e);