br.com.anteros.bean.validation.AppendValidationToBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Anteros-Bean-Validation Show documentation
Show all versions of Anteros-Bean-Validation Show documentation
Anteros Bean Validation for Java.
/*******************************************************************************
* Copyright 2012 Anteros Tecnologia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package br.com.anteros.bean.validation;
import br.com.anteros.bean.validation.xml.AnnotationProxyBuilder;
import br.com.anteros.validation.api.Payload;
import java.lang.annotation.Annotation;
import java.util.Set;
/**
* Description: Adapt {@link AnnotationConstraintBuilder} to the {@link AppendValidation} interface.
*/
public class AppendValidationToBuilder extends BaseAppendValidation {
private final AnnotationConstraintBuilder> builder;
/**
* Create a new AppendValidationToBuilder instance.
* @param builder
*/
public AppendValidationToBuilder(AnnotationConstraintBuilder> builder) {
this.builder = builder;
}
/**
* {@inheritDoc}
*/
public void preProcessValidation(ConstraintValidation validation) {
// JSR-303 2.3:
// Groups from the main constraint annotation are inherited by the composing annotations.
// Any groups definition on a composing annotation is ignored.
Set> inheritedGroups = builder.getConstraintValidation().getGroups();
validation.setGroups(inheritedGroups);
// JSR-303 2.3 p:
// Payloads are also inherited
Set> inheritedPayload = builder.getConstraintValidation().getPayload();
validation.setPayload(inheritedPayload);
// Inherited groups and payload values must also be replicated in the
// annotation, so it has to be substituted with a new proxy.
T originalAnnot = validation.getAnnotation();
AnnotationProxyBuilder apb = new AnnotationProxyBuilder(originalAnnot);
apb.putValue(ConstraintAnnotationAttributes.GROUPS.getAttributeName(),
inheritedGroups.toArray(new Class[inheritedGroups.size()]));
apb.putValue(ConstraintAnnotationAttributes.PAYLOAD.getAttributeName(),
inheritedPayload.toArray(new Class[inheritedPayload.size()]));
T newAnnot = apb.createAnnotation();
validation.setAnnotation(newAnnot);
}
/**
* {@inheritDoc}
*/
public void performAppend(ConstraintValidation validation) {
builder.addComposed(validation);
}
/**
* Get inherited groups.
* @return The set of groups from the parent constraint.
*/
public Set> getInheritedGroups() {
return builder.getConstraintValidation().getGroups();
}
/**
* Get inherited payload.
* @return The set of payloads from the parent constraint.
*/
public Set> getInheritedPayload() {
return builder.getConstraintValidation().getPayload();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy