/** * Get the named value from the specified {@link Annotation}. * @param annotation * @param name * @return Object value * @throws IllegalAccessException * @throws InvocationTargetException */ public static Object getAnnotationValue(final Annotation annotation, final String name) throws IllegalAccessException, InvocationTargetException { final Method valueMethod; try { valueMethod = annotation.annotationType().getDeclaredMethod(name); } catch (final NoSuchMethodException ex) { // do nothing return null; } final boolean mustUnset = setAccessible(valueMethod, true); try { return valueMethod.invoke(annotation); } finally { if (mustUnset) { setAccessible(valueMethod, false); } } }
/** * Get the named value from the specified {@link Annotation}. * @param annotation * @param name * @return Object value * @throws IllegalAccessException * @throws InvocationTargetException */ public static Object getAnnotationValue(final Annotation annotation, final String name) throws IllegalAccessException, InvocationTargetException { final Method valueMethod; try { valueMethod = annotation.annotationType().getDeclaredMethod(name); } catch (final NoSuchMethodException ex) { // do nothing return null; } final boolean mustUnset = setAccessible(valueMethod, true); try { return valueMethod.invoke(annotation); } finally { if (mustUnset) { setAccessible(valueMethod, false); } } }
/** * Get the named value from the specified {@link Annotation}. * @param annotation * @param name * @return Object value * @throws IllegalAccessException * @throws InvocationTargetException */ public static Object getAnnotationValue(final Annotation annotation, final String name) throws IllegalAccessException, InvocationTargetException { final Method valueMethod; try { valueMethod = annotation.annotationType().getDeclaredMethod(name); } catch (final NoSuchMethodException ex) { // do nothing return null; } final boolean mustUnset = setAccessible(valueMethod, true); try { return valueMethod.invoke(annotation); } finally { if (mustUnset) { setAccessible(valueMethod, false); } } }
@Override public Object getValue(Object parent) throws Exception { final boolean mustUnset = Reflection.setAccessible(getTarget(), true); try { return getTarget().get(parent); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } finally { if (mustUnset) { Reflection.setAccessible(getTarget(), false); } } } }
@Override public Object getValue(Object parent) throws Exception { final boolean mustUnset = Reflection.setAccessible(getTarget(), true); try { return getTarget().invoke(parent); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalArgumentException(e); } finally { if (mustUnset) { Reflection.setAccessible(getTarget(), false); } } } }
@Override public Object getValue(Object parent) throws Exception { final boolean mustUnset = Reflection.setAccessible(getTarget(), true); try { return getTarget().invoke(parent); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalArgumentException(e); } finally { if (mustUnset) { Reflection.setAccessible(getTarget(), false); } } } }
@Override public Object getValue(Object parent) throws Exception { final boolean mustUnset = Reflection.setAccessible(getTarget(), true); try { return getTarget().get(parent); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } finally { if (mustUnset) { Reflection.setAccessible(getTarget(), false); } } } }
private <T> T newInstance(final Class<T> cls) { final Constructor<T> cons = Reflection.getDeclaredConstructor(cls, ApacheFactoryContext.class); if (cons == null) { throw new ValidationException("Cannot instantiate " + cls); } final boolean mustUnset = Reflection.setAccessible(cons, true); try { return cons.newInstance(validatorContext); } catch (final Exception ex) { throw new ValidationException("Cannot instantiate " + cls, ex); } finally { if (mustUnset) { Reflection.setAccessible(cons, false); } } } }
private <T> T newInstance(final Class<T> cls) { final Constructor<T> cons = Reflection.getDeclaredConstructor(cls, ApacheFactoryContext.class); if (cons == null) { throw new ValidationException("Cannot instantiate " + cls); } final boolean mustUnset = Reflection.setAccessible(cons, true); try { return cons.newInstance(validatorContext); } catch (final Exception ex) { throw new ValidationException("Cannot instantiate " + cls, ex); } finally { if (mustUnset) { Reflection.setAccessible(cons, false); } } } }