List of usage examples for org.springframework.util ReflectionUtils handleReflectionException
public static void handleReflectionException(Exception ex)
From source file:egovframework.rte.bat.core.item.database.support.EgovMethodMapItemPreparedStatementSetter.java
/** * params ? ? sqlType PreparedStatement? ?? *//* w ww .j a v a 2 s . c o m*/ public void setValues(T item, PreparedStatement ps, String[] params, String[] sqlTypes, Map<String, Method> methodMap) throws SQLException { EgovReflectionSupport<T> reflector = new EgovReflectionSupport<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); } } }
From source file:egovframework.rte.bat.core.reflection.EgovReflectionSupport.java
/** * VO? Setter method // w w w . ja va 2 s .c o m * @param tokens VO? set ? value * @param names VO? field */ private void invokeSetterMethod(List<String> tokens, String[] names) { Method method; for (int i = 0; i < names.length; i++) { method = methodMap.get(names[i]); try { method.invoke(object, parsingFromString(tokens.get(i).trim(), fieldType[i])); } catch (IllegalAccessException e) { ReflectionUtils.handleReflectionException(e); } catch (InvocationTargetException e) { ReflectionUtils.handleReflectionException(e); } catch (SecurityException e) { ReflectionUtils.handleReflectionException(e); } } }
From source file:egovframework.rte.bat.core.reflection.EgovReflectionSupport.java
/** * item? field getter invoke/*from w w w. j a v a 2 s.com*/ * @param item VO * @param names VO? field name * @return getValue field get return */ public Object invokeGettterMethod(T item, String names) { Object value = null; try { value = methodMap.get(names).invoke(item); } catch (IllegalArgumentException e) { ReflectionUtils.handleReflectionException(e); } catch (IllegalAccessException e) { ReflectionUtils.handleReflectionException(e); } catch (InvocationTargetException e) { ReflectionUtils.handleReflectionException(e); } return value; }
From source file:com.javaetmoi.core.spring.vfs.Vfs2Utils.java
protected static Object invokeVfsMethod(Method method, Object target, Object... args) throws IOException { try {//from ww w .ja v a2s . c om return method.invoke(target, args); } catch (InvocationTargetException ex) { Throwable targetEx = ex.getTargetException(); if (targetEx instanceof IOException) { throw (IOException) targetEx; } ReflectionUtils.handleInvocationTargetException(ex); } catch (Exception ex) { ReflectionUtils.handleReflectionException(ex); } throw new IllegalStateException("Invalid code path reached"); }
From source file:com.siberhus.tdfl.mapping.BeanWrapLineMapper.java
@SuppressWarnings("unchecked") private T getBean() { if (name != null) { return (T) beanFactory.getBean(name); }//from ww w .j a v a2 s .co m try { return type.newInstance(); } catch (InstantiationException e) { ReflectionUtils.handleReflectionException(e); } catch (IllegalAccessException e) { ReflectionUtils.handleReflectionException(e); } // should not happen throw new IllegalStateException("Internal error: could not create bean instance for mapping."); }
From source file:org.jboss.spring.vfs.VFSUtil.java
public static <T, E extends Exception> T invokeMethodWithExpectedExceptionType(Method method, Object target, Class<E> expectedExceptionType, Object... args) throws E { try {/* w ww . j av a 2 s .c om*/ return (T) method.invoke(target, args); } catch (IllegalAccessException ex) { ReflectionUtils.handleReflectionException(ex); } catch (InvocationTargetException ex) { if (expectedExceptionType.isAssignableFrom(ex.getTargetException().getClass())) { throw (E) ex.getTargetException(); } ReflectionUtils.handleInvocationTargetException(ex); } throw new IllegalStateException("Should never get here"); }
From source file:org.grails.datastore.mapping.redis.util.JedisTemplate.java
private void disconnect() { // hack in to get the private client since disconnect() isn't in the interface Field field = ReflectionUtils.findField(pipeline.getClass(), "client"); field.setAccessible(true);//ww w.jav a 2 s . c o m try { Client client = (Client) field.get(pipeline); client.disconnect(); } catch (Exception e) { ReflectionUtils.handleReflectionException(e); } }
From source file:egovframework.rte.bat.core.reflection.EgovReflectionSupport.java
/** * item? field getter invoke/*from w w w . j a v a 2s .co m*/ * @param item item VO * @param param * @param mapMethod VO? getter Map * @return field get return */ public Object invokeGettterMethod(T item, String param, Map<String, Method> mapMethod) { Object value = null; try { value = mapMethod.get(param).invoke(item); } catch (IllegalArgumentException e) { ReflectionUtils.handleReflectionException(e); } catch (IllegalAccessException e) { ReflectionUtils.handleReflectionException(e); } catch (InvocationTargetException e) { ReflectionUtils.handleReflectionException(e); } return value; }
From source file:egovframework.rte.bat.core.reflection.EgovReflectionSupport.java
/** * VO? field? get/*from w ww.ja v a2s . c o m*/ * @param type VO? * @param names VO field names */ public void getFieldType(Class<?> type, String[] names) { fieldType = new Type[names.length]; for (int i = 0; i < names.length; i++) { try { fieldType[i] = type.newInstance().getClass().getDeclaredField(names[i]).getType(); } catch (SecurityException e) { ReflectionUtils.handleReflectionException(e); } catch (NoSuchFieldException e) { ReflectionUtils.handleReflectionException(e); } catch (InstantiationException e) { ReflectionUtils.handleReflectionException(e); } catch (IllegalAccessException e) { ReflectionUtils.handleReflectionException(e); } } }
From source file:com.eu.evaluation.server.dao.AbstractDAO.java
public boolean isUnique(T entity, String... propertys) { if (propertys == null || propertys.length == 0) { return true; }/*from w ww .ja v a2 s.c o m*/ try { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = cb.createQuery(entityClass); Root<T> root = criteriaQuery.from(entityClass); Predicate predicate = null; for (String property : propertys) { if (predicate == null) { predicate = cb.equal(root.get(property), PropertyUtils.getProperty(entity, property)); } else { predicate = cb.and(predicate, cb.equal(root.get(property), PropertyUtils.getProperty(entity, property))); } } if (!StringUtils.isBlank(entity.getId())) { predicate = cb.and(predicate, cb.notEqual(root.get("id"), entity.getId())); } criteriaQuery.where(predicate); TypedQuery<T> typedQuery = entityManager.createQuery(criteriaQuery); List<T> result = typedQuery.getResultList(); return result.isEmpty(); } catch (Exception e) { e.printStackTrace(); ReflectionUtils.handleReflectionException(e); } return false; }