List of usage examples for org.springframework.util ReflectionUtils handleReflectionException
public static void handleReflectionException(Exception ex)
From source file:springobjectmapper.ReflectionHelper.java
public static Object[] getValues(List<Field> fields, Object o) { List<Object> results = new ArrayList<Object>(); for (Field field : fields) { try {//from w ww. j a v a 2 s .c om results.add(field.get(o)); } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } } return results.toArray(); }
From source file:edu.wisc.hrs.dao.HrsUtils.java
/** * Utility for creating HRS schema generated wrapper objects that simply have a setValue method */// www . j a v a2s. co m public static <T> T createValue(Class<T> clazz, Object value) { final T instance; try { instance = clazz.newInstance(); } catch (InstantiationException e) { ReflectionUtils.handleReflectionException(e); return null; //This will never run, just used to make compiler's final check happy } catch (IllegalAccessException e) { ReflectionUtils.handleReflectionException(e); return null; //This will never run, just used to make compiler's final check happy } callMethodSafe(instance, "setValue", value); return instance; }
From source file:springobjectmapper.ReflectionHelper.java
public static Field getField(Class<?> c, String name) { do {/*from www . jav a 2 s . c o m*/ try { Field field = c.getDeclaredField(name); field.setAccessible(true); return field; } catch (NoSuchFieldException ex) { } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } c = c.getSuperclass(); } while (c != null); throw new RuntimeException("Field " + name + " was not found!"); }
From source file:springobjectmapper.ReflectionHelper.java
public static Object getFieldValue(Field field, Object o) { try {//w ww . jav a 2 s . c om return field.get(o); } catch (Exception e) { ReflectionUtils.handleReflectionException(e); return null; } }
From source file:org.brushingbits.jnap.validation.constraints.AbstractConstraintValidator.java
/** * This method copies all the annotation properties to fields with the same name. * //from ww w . j av a2 s . co m * @param constraintAnnotation This constraint annotation. * @see PropertyAccessorFactory */ protected void bindParameters(A constraintAnnotation) { Class<?> annotationClass = constraintAnnotation.getClass(); Method[] methods = annotationClass.getDeclaredMethods(); ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(this); try { for (Method method : methods) { String methodName = method.getName(); if (accessor.isWritableProperty(methodName)) { accessor.setPropertyValue(methodName, method.invoke(constraintAnnotation, ArrayUtils.EMPTY_OBJECT_ARRAY)); } } } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } }
From source file:egovframework.rte.bat.core.reflection.EgovReflectionSupport.java
/** * VO ? instance ?//w w w . jav a2 s. com * @param type VO */ private void createObject(Class<?> type) { try { object = type.newInstance(); } catch (InstantiationException e) { ReflectionUtils.handleReflectionException(e); } catch (IllegalAccessException e) { ReflectionUtils.handleReflectionException(e); } }
From source file:org.springmodules.cache.util.Reflections.java
/** * <p>//from w w w. j a v a 2 s .c om * This method uses reflection to build a valid hash code. * </p> * * <p> * It uses <code>AccessibleObject.setAccessible</code> to gain access to * private fields. This means that it will throw a security exception if run * under a security manager, if the permissions are not set up correctly. It * is also not as efficient as testing explicitly. * </p> * * <p> * Transient members will not be used, as they are likely derived fields, * and not part of the value of the <code>Object</code>. * </p> * * <p> * Static fields will not be tested. Superclass fields will be included. * </p> * * @param obj * the object to create a <code>hashCode</code> for * @return the generated hash code, or zero if the given object is * <code>null</code> */ public static int reflectionHashCode(Object obj) { if (obj == null) return 0; Class targetClass = obj.getClass(); if (Objects.isArrayOfPrimitives(obj) || Objects.isPrimitiveOrWrapper(targetClass)) { return Objects.nullSafeHashCode(obj); } if (targetClass.isArray()) { return reflectionHashCode((Object[]) obj); } if (obj instanceof Collection) { return reflectionHashCode((Collection) obj); } if (obj instanceof Map) { return reflectionHashCode((Map) obj); } // determine whether the object's class declares hashCode() or has a // superClass other than java.lang.Object that declares hashCode() Class clazz = (obj instanceof Class) ? (Class) obj : obj.getClass(); Method hashCodeMethod = ReflectionUtils.findMethod(clazz, "hashCode", new Class[0]); if (hashCodeMethod != null) { return obj.hashCode(); } // could not find a hashCode other than the one declared by java.lang.Object int hash = INITIAL_HASH; try { while (targetClass != null) { Field[] fields = targetClass.getDeclaredFields(); AccessibleObject.setAccessible(fields, true); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; int modifiers = field.getModifiers(); if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) { hash = MULTIPLIER * hash + reflectionHashCode(field.get(obj)); } } targetClass = targetClass.getSuperclass(); } } catch (IllegalAccessException exception) { // ///CLOVER:OFF ReflectionUtils.handleReflectionException(exception); // ///CLOVER:ON } return hash; }
From source file:org.brushingbits.jnap.struts2.interceptor.RestWorkflowInterceptor.java
/** * @param invocation//from ww w. j a v a 2s .co m * @param action */ protected String findResultName(ActionInvocation invocation, Object action) { String resultName = Action.INPUT; try { Map<String, Object> session = ActionContext.getContext().getSession(); Method method = action.getClass().getMethod(invocation.getProxy().getMethod(), ArrayUtils.EMPTY_CLASS_ARRAY); if (action instanceof ValidationWorkflowAware) { resultName = ((ValidationWorkflowAware) action).getInputResultName(); } else if (method.isAnnotationPresent(InputConfig.class)) { InputConfig annotation = method.getAnnotation(InputConfig.class); if (StringUtils.isNotBlank(annotation.methodName())) { Method inputMethod = action.getClass().getMethod(annotation.methodName()); resultName = (String) inputMethod.invoke(action); } else { resultName = annotation.resultName(); } } else if (session.containsKey(InputResultInterceptor.INPUT_RESULT_NAME)) { resultName = (String) session.get(InputResultInterceptor.INPUT_RESULT_NAME); } } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } return resultName; }
From source file:lcn.module.batch.core.item.database.support.MethodMapItemPreparedStatementSetter.java
/** * params ? ? sqlType PreparedStatement? ?? *///from w ww . j a v a2s .c o m public void setValues(T item, PreparedStatement ps, String[] params, String[] sqlTypes, Map<String, Method> methodMap) throws SQLException { ReflectionSupport<T> reflector = new ReflectionSupport<T>(); for (int i = 0; i < params.length; i++) { try { if (sqlTypes[i].equals("String")) { ps.setString(i + 1, (String) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("int")) { ps.setInt(i + 1, (Integer) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("double")) { ps.setDouble(i + 1, (Double) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("Date")) { ps.setDate(i + 1, (Date) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("byte")) { ps.setByte(i + 1, (Byte) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("short")) { ps.setShort(i + 1, (Short) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("boolean")) { ps.setBoolean(i + 1, (Boolean) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("long")) { ps.setLong(i + 1, (Long) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("Float")) { ps.setFloat(i + 1, (Float) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("BigDecimal")) { ps.setBigDecimal(i + 1, (BigDecimal) reflector.invokeGettterMethod(item, params[i], methodMap)); } else if (sqlTypes[i].equals("byte[]")) { ps.setBytes(i + 1, (byte[]) reflector.invokeGettterMethod(item, params[i], methodMap)); } else { throw new SQLException(); } } catch (IllegalArgumentException e) { ReflectionUtils.handleReflectionException(e); } } }