private void processGroupSequence(Class<?> beanClass, MetaBean metabean, String key) { GroupSequence annotation = beanClass.getAnnotation(GroupSequence.class); List<Group> groupSeq = metabean.getFeature(key); if (groupSeq == null) { groupSeq = new ArrayList<Group>(annotation == null ? 1 : annotation.value().length);
/** * {@inheritDoc} Return the descriptor object describing bean constraints. The returned object (and associated * objects including <code>ConstraintDescriptor<code>s) are immutable. * * @param clazz class or interface type evaluated * @return the bean descriptor for the specified class. * @throws IllegalArgumentException if clazz is null * @throws ValidationException if a non recoverable error happens during the metadata * discovery or if some constraints are invalid. */ // @Override - not allowed in 1.5 for Interface methods public BeanDescriptor getConstraintsForClass(Class<?> clazz) { if (clazz == null) { throw new IllegalArgumentException("Class cannot be null"); } try { MetaBean metaBean = getMetaBeanFinder().findForClass(clazz); BeanDescriptorImpl edesc = metaBean.getFeature(Jsr303Features.Bean.BEAN_DESCRIPTOR); if (edesc == null) { edesc = createBeanDescriptor(metaBean); metaBean.putFeature(Jsr303Features.Bean.BEAN_DESCRIPTOR, edesc); } return edesc; } catch (RuntimeException ex) { throw new ValidationException("error retrieving constraints for " + clazz, ex); } }
/** * {@inheritDoc} */ public ElementDescriptor.ConstraintFinder unorderedAndMatchingGroups(Class<?>... groups) { Set<ConstraintValidation<?>> matchingDescriptors = new HashSet<ConstraintValidation<?>>(constraintDescriptors.size()); Groups groupChain = new GroupsComputer().computeGroups(groups); for (Group group : groupChain.getGroups()) { if (group.isDefault()) { // If group is default, check if it gets redefined List<Group> expandedDefaultGroup = metaBean.getFeature(Jsr303Features.Bean.GROUP_SEQUENCE); for (Group defaultGroupMember : expandedDefaultGroup) { for (ConstraintValidation<?> descriptor : constraintDescriptors) { if (isInScope(descriptor) && isInGroup(descriptor, defaultGroupMember)) { matchingDescriptors.add(descriptor); } } } } else { for (ConstraintValidation<?> descriptor : constraintDescriptors) { if (isInScope(descriptor) && isInGroup(descriptor, group)) { matchingDescriptors.add(descriptor); } } } } return thisWith(matchingDescriptors); }
/** * in case of a default group return the list of groups for a redefined default GroupSequence * * @return null when no in default group or default group sequence not redefined */ private List<Group> expandDefaultGroup(GroupValidationContext<?> context) { if (context.getCurrentGroup().isDefault()) { // mention if metaBean redefines the default group List<Group> groupSeq = context.getMetaBean().getFeature(Jsr303Features.Bean.GROUP_SEQUENCE); if (groupSeq != null) { context.getGroups().assertDefaultGroupSequenceIsExpandable(groupSeq); } return groupSeq; } else { return null; } }
context.getMetaBean().getFeature("{GroupSequence:" + owner.getCanonicalName() + "}"); for (Group each : ownerDefaultGroups) { context.setCurrentGroup(each);