public static <A extends Annotation> When sandboxedValidation(A proxy, TypeQualifierValidator<A> v, @CheckForNull Object constantValue) { if (performingValidation.get()) throw new IllegalStateException("recursive validation"); try { performingValidation.set(Boolean.TRUE); if (TypeQualifierValue.DEBUG_CLASSLOADING) System.out.println("Performing validation in thread " + Thread.currentThread().getName()); try { When result = v.forConstantValue(proxy, constantValue); if (!performingValidation.get()) throw new IllegalStateException("performingValidation not set when validation completes"); return result; } catch (ClassCastException e) { Class<? extends Annotation> c = proxy.getClass(); System.out.println(c.getName() + " extends " + c.getSuperclass().getName()); for(Class<?> i : c.getInterfaces()) System.out.println(" " + i.getName()); throw e; } } finally { performingValidation.set(Boolean.FALSE); if (TypeQualifierValue.DEBUG_CLASSLOADING) System.out.println("Validation finished in thread " + Thread.currentThread().getName()); } }
private boolean inValidation() { for (Class<?> c : getClassContext()) { if (TypeQualifierValidator.class.isAssignableFrom(c) || c.getClassLoader() == ValidatorClassLoader.INSTANCE) return true; } return false; }
private static <A extends Annotation> TypeQualifierValidator<A> getValidator( Class<? extends TypeQualifierValidator<A>> checkerClass) throws InstantiationException, IllegalAccessException { return checkerClass.newInstance(); }
/** * @param checkerClass * @return * @throws InstantiationException * @throws IllegalAccessException */ @SuppressWarnings("unchecked") private TypeQualifierValidator<A> getValidator(Class<? extends TypeQualifierValidator> checkerClass) throws InstantiationException, IllegalAccessException { return checkerClass.newInstance(); }