public static Object getAndWrap(Field field, Object target) { try { return get(field, target); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IllegalArgumentException("exception setting: " + field.getName(), e); } }
public static Object invokeAndWrap(Method method, Object target, Object... args) { try { return invoke(method, target, args); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException("exception invoking: " + method.getName(), e); } }
/** * Return's true if the class can be loaded using Reflections.classForName() */ public static boolean isClassAvailable(String name) { try { classForName(name); } catch (ClassNotFoundException e) { return false; } return true; }
public Object getVersion(Object entity) { if (versionGetter != null) return Reflections.invokeAndWrap(versionGetter, entity); else if (versionField != null) return Reflections.getAndWrap(versionField, entity); return null; }
break; Method getter = org.granite.util.Reflections.getGetterMethod(value.getClass(), path[i]); value = Reflections.invoke(getter, value); if (i < path.length-1) bean = value; Method setter = Reflections.getSetterMethod(bean.getClass(), path[path.length-1]); Type type = setter.getParameterTypes()[0]; value = ((ConvertersConfig)GraniteContext.getCurrentInstance().getGraniteConfig()).getConverters().convert(update.getValue(), type); Reflections.invoke(setter, bean, value);
break; try { Method getter = Reflections.getGetterMethod(value.getClass(), path[i]); value = Reflections.invoke(getter, value);
public static Object get(Field field, Object target) throws Exception { try { return field.get(target); } catch (IllegalArgumentException iae) { String message = "Could not get field value by reflection: " + toString(field) + " on: " + target.getClass().getName(); throw new IllegalArgumentException(message, iae); } }
public static void setAndWrap(Field field, Object target, Object value) { try { set(field, target, value); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IllegalArgumentException("exception setting: " + field.getName(), e); } }
Method getter = null; try { getter = Reflections.getGetterMethod(invocation.getTarget().getClass(), propName);
public Object getIdentifier(Object entity) { if (identifierGetter != null) return Reflections.invokeAndWrap(identifierGetter, entity); else if (identifierField != null) return Reflections.getAndWrap(identifierField, entity); else throw new IllegalStateException("@Id attribute not found for entity class: " + entity.getClass().getName()); }
public static Object get(Field field, Object target) throws Exception { try { return field.get(target); } catch (IllegalArgumentException iae) { String message = "Could not get field value by reflection: " + toString(field) + " on: " + target.getClass().getName(); throw new IllegalArgumentException(message, iae); } }
public static void setAndWrap(Field field, Object target, Object value) { try { set(field, target, value); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IllegalArgumentException("exception setting: " + field.getName(), e); } }
String[] pnames = propertyNames[i].split("\\."); for (int j = 0; j < pnames.length; j++) initializedObj = Reflections.getGetterMethod(initializedObj.getClass(), pnames[j]).invoke(initializedObj);
for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(Version.class)) { return Reflections.invokeAndWrap(method, entity); if (!field.isAccessible()) field.setAccessible(true); return Reflections.getAndWrap(field, entity); return Reflections.invokeAndWrap(versionGetter, entity); if (!field.isAccessible()) field.setAccessible(true); return Reflections.getAndWrap(field, entity);
public static Object getAndWrap(Field field, Object target) { try { return get(field, target); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IllegalArgumentException("exception setting: " + field.getName(), e); } }
public static void set(Field field, Object target, Object value) throws Exception { try { field.set(target, value); } catch (IllegalArgumentException iae) { // target may be null if field is static so use field.getDeclaringClass() instead String message = "Could not set field value by reflection: " + toString(field) + " on: " + field.getDeclaringClass().getName(); if (value==null) { message += " with null value"; } else { message += " with value: " + value.getClass(); } throw new IllegalArgumentException(message, iae); } }
public static Object invokeAndWrap(Method method, Object target, Object... args) { try { return invoke(method, target, args); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException("exception invoking: " + method.getName(), e); } }
/** * Return's true if the class can be loaded using Reflections.classForName() */ public static boolean isClassAvailable(String name) { try { classForName(name); } catch (ClassNotFoundException e) { return false; } return true; }
List<Object[]> updated = new ArrayList<Object[]>(); List<?> queuedOperations = get(newColl, "operationQueue", List.class); for (Object op : queuedOperations) { added.add(new Object[] { get(op, "index"), get(op, "value") }); added.add(new Object[] { null, get(op, "value") }); added.add(new Object[] { get(op, "index"), get(op, "value") }); removed.add(new Object[] { get(op, "index"), get(op, "old") }); removed.add(new Object[] { null, get(op, "value") }); updated.add(new Object[] { get(op, "index"), get(op, "value") }); if (value != null && value.getClass().isAnnotationPresent(Entity.class)) { org.granite.util.Entity e = new org.granite.util.Entity(value); value = new ChangeRef(e.getName(), (String)get(value, "uid"), (Serializable)e.getIdentifier());
public static void set(Field field, Object target, Object value) throws Exception { try { field.set(target, value); } catch (IllegalArgumentException iae) { // target may be null if field is static so use field.getDeclaringClass() instead String message = "Could not set field value by reflection: " + toString(field) + " on: " + field.getDeclaringClass().getName(); if (value==null) { message += " with null value"; } else { message += " with value: " + value.getClass(); } throw new IllegalArgumentException(message, iae); } }