Example usage for org.springframework.util ReflectionUtils handleInvocationTargetException

List of usage examples for org.springframework.util ReflectionUtils handleInvocationTargetException

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils handleInvocationTargetException.

Prototype

public static void handleInvocationTargetException(InvocationTargetException ex) 

Source Link

Document

Handle the given invocation target exception.

Usage

From source file:com.javaetmoi.core.spring.vfs.Vfs2Utils.java

protected static Object invokeVfsMethod(Method method, Object target, Object... args) throws IOException {
    try {//  ww w. j  av  a  2 s  .  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: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 {//  www  .  j av a 2s  . c  o m
        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:grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition.java

protected Closure<?> newInstance(final Class<?> closureClass) {
    try {/*from w  w  w.ja va  2 s  . c  o m*/
        Constructor<?> constructor = closureClass.getConstructor(Object.class, Object.class);
        ReflectionUtils.makeAccessible(constructor);
        return (Closure<?>) constructor.newInstance(this, this);
    } catch (NoSuchMethodException e) {
        ReflectionUtils.handleReflectionException(e);
    } catch (InstantiationException e) {
        ReflectionUtils.handleReflectionException(e);
    } catch (IllegalAccessException e) {
        ReflectionUtils.handleReflectionException(e);
    } catch (InvocationTargetException e) {
        ReflectionUtils.handleInvocationTargetException(e);
    }
    return null;
}

From source file:org.codehaus.groovy.grails.orm.hibernate.GrailsSessionContext.java

protected Object create(Constructor<?> constructor, Object... args) {
    try {/*from w  w w.  j  a v  a2s.c  om*/
        return constructor.newInstance(args);
    } catch (InstantiationException e) {
        ReflectionUtils.handleReflectionException(e);
    } catch (IllegalAccessException e) {
        ReflectionUtils.handleReflectionException(e);
    } catch (IllegalArgumentException e) {
        ReflectionUtils.handleReflectionException(e);
    } catch (InvocationTargetException e) {
        ReflectionUtils.handleInvocationTargetException(e);
    }
    return null;
}

From source file:org.openengsb.core.util.BeanUtilsExtended.java

/**
 * Analyzes the bean and returns a map containing the property-values. Works similar to
 * {@link BeanUtils#describe(Object)} but does not convert everything to strings.
 * //  w ww  .j a  v  a 2 s .  c o  m
 * @throws IllegalArgumentException if the bean cannot be analyzed properly. Probably because some getter throw an
 *         Exception
 */
public static Map<String, Object> buildObjectAttributeMap(Object bean) throws IllegalArgumentException {
    BeanInfo beanInfo;
    try {
        beanInfo = Introspector.getBeanInfo(bean.getClass(), Object.class);
    } catch (IntrospectionException e1) {
        throw new IllegalArgumentException(e1);
    }
    Map<String, Object> result;
    result = Maps.newHashMap();
    for (PropertyDescriptor pDesc : beanInfo.getPropertyDescriptors()) {
        String name = pDesc.getName();
        Object propertyValue;
        try {
            propertyValue = pDesc.getReadMethod().invoke(bean);
        } catch (IllegalAccessException e) {
            // this should never happen since the Introspector only returns accessible read-methods
            LOGGER.error("WTF: got property descriptor with inaccessible read-method");
            throw new IllegalStateException(e);
        } catch (InvocationTargetException e) {
            ReflectionUtils.handleInvocationTargetException(e);
            throw new IllegalStateException("Should never get here");
        }
        if (propertyValue != null) {
            result.put(name, propertyValue);
        }
    }
    return result;
}

From source file:org.springframework.scheduling.quartz.SchedulerFactoryBean.java

/**
 * Add the given calendar to the Scheduler, checking for the
 * corresponding Quartz 1.4 or Quartz 1.3 method
 * (which differ in 1.4's additional "updateTriggers" flag).
 * @param calendarName the name of the calendar
 * @param calendar the Calendar object/*from   ww  w .  java2 s . c o  m*/
 * @see org.quartz.Scheduler#addCalendar
 */
private void addCalendarToScheduler(String calendarName, Calendar calendar) throws SchedulerException {
    try {
        try {
            // Try Quartz 1.4 (with "updateTriggers" flag).
            Method addCalendarMethod = this.scheduler.getClass().getMethod("addCalendar",
                    new Class[] { String.class, Calendar.class, boolean.class, boolean.class });
            addCalendarMethod.invoke(this.scheduler,
                    new Object[] { calendarName, calendar, Boolean.TRUE, Boolean.TRUE });
        } catch (NoSuchMethodException ex) {
            // Try Quartz 1.3 (without "updateTriggers" flag).
            Method addCalendarMethod = this.scheduler.getClass().getMethod("addCalendar",
                    new Class[] { String.class, Calendar.class, boolean.class });
            addCalendarMethod.invoke(this.scheduler, new Object[] { calendarName, calendar, Boolean.TRUE });
        }
    } catch (InvocationTargetException ex) {
        if (ex.getTargetException() instanceof SchedulerException) {
            throw (SchedulerException) ex.getTargetException();
        }
        ReflectionUtils.handleInvocationTargetException(ex);
    } catch (Exception ex) {
        ReflectionUtils.handleReflectionException(ex);
    }
}