private <A extends Annotation, T> MetaConstraint<?> createMetaConstraint( ConstraintType constraint, Class<T> beanClass, Member member, String defaultPackage) { @SuppressWarnings("unchecked") Class<A> annotationClass = (Class<A>) getClass(constraint.getAnnotation(), defaultPackage); AnnotationDescriptor<A> annotationDescriptor = new AnnotationDescriptor<A>(annotationClass); if (constraint.getMessage() != null) { annotationDescriptor.setValue(MESSAGE_PARAM, constraint.getMessage()); } annotationDescriptor.setValue(GROUPS_PARAM, getGroups(constraint.getGroups(), defaultPackage)); annotationDescriptor.setValue( PAYLOAD_PARAM, getPayload(constraint.getPayload(), defaultPackage)); for (ElementType elementType : constraint.getElement()) { String name = elementType.getName(); checkNameIsValid(name); Class<?> returnType = getAnnotationParameterType(annotationClass, name); Object elementValue = getElementValue(elementType, returnType); annotationDescriptor.setValue(name, elementValue); } A annotation; try { annotation = AnnotationFactory.create(annotationDescriptor); } catch (RuntimeException e) { throw log.getUnableToCreateAnnotationForConfiguredConstraintException(e); } java.lang.annotation.ElementType type = java.lang.annotation.ElementType.TYPE; if (member instanceof Method) { type = java.lang.annotation.ElementType.METHOD; } else if (member instanceof Field) { type = java.lang.annotation.ElementType.FIELD; } // we set initially ConstraintOrigin.DEFINED_LOCALLY for all xml configured constraints // later we will make copies of this constraint descriptor when needed and adjust the // ConstraintOrigin ConstraintDescriptorImpl<A> constraintDescriptor = new ConstraintDescriptorImpl<A>( annotation, constraintHelper, type, ConstraintOrigin.DEFINED_LOCALLY); return new MetaConstraint<A>( constraintDescriptor, new BeanConstraintLocation(beanClass, member)); }