You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by mb...@apache.org on 2018/02/25 19:38:23 UTC
[3/6] bval git commit: clean up no-longer-used code from JSR module
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
deleted file mode 100644
index 5ba14ca..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidation.java
+++ /dev/null
@@ -1,605 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.jsr.util.NodeImpl;
-import org.apache.bval.jsr.util.PathImpl;
-import org.apache.bval.model.Validation;
-import org.apache.bval.model.ValidationContext;
-import org.apache.bval.model.ValidationListener;
-import org.apache.bval.util.AccessStrategy;
-import org.apache.bval.util.ObjectUtils;
-import org.apache.bval.util.StringUtils;
-import org.apache.bval.util.reflection.Reflection;
-import org.apache.bval.util.reflection.TypeUtils;
-
-import javax.validation.ConstraintDefinitionException;
-import javax.validation.ConstraintTarget;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.Payload;
-import javax.validation.UnexpectedTypeException;
-import javax.validation.ValidationException;
-import javax.validation.constraintvalidation.SupportedValidationTarget;
-import javax.validation.constraintvalidation.ValidationTarget;
-import javax.validation.metadata.ConstraintDescriptor;
-import javax.validation.metadata.ValidateUnwrappedValue;
-
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
-import java.lang.reflect.GenericArrayType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-/**
- * Description: Adapter between Constraint (JSR303) and Validation (Core)<br/>
- * this instance is immutable!<br/>
- */
-public class ConstraintValidation<T extends Annotation> implements Validation, ConstraintDescriptor<T> {
- private final AccessStrategy access;
- private final boolean reportFromComposite;
- private final Map<String, Object> attributes;
- private T annotation; // for metadata request API
- private volatile ConstraintValidator<T, ?> validator;
-
- private Set<ConstraintValidation<?>> composedConstraints;
-
- private boolean validated = false;
-
- /**
- * the owner is the type where the validation comes from. it is used to
- * support implicit grouping.
- */
- private final Class<?> owner;
- private Set<Class<?>> groups;
- private Set<Class<? extends Payload>> payload;
- private Class<? extends ConstraintValidator<T, ?>>[] validatorClasses;
- private ConstraintTarget validationAppliesTo = null;
-
- public ConstraintValidation(Class<? extends ConstraintValidator<T, ?>>[] validatorClasses, T annotation,
- Class<?> owner, AccessStrategy access, boolean reportFromComposite, ConstraintTarget target) {
- this.attributes = new HashMap<String, Object>();
- this.validatorClasses = validatorClasses != null ? validatorClasses.clone() : null;
- this.annotation = annotation;
- this.owner = owner;
- this.access = access;
- this.reportFromComposite = reportFromComposite;
- this.validationAppliesTo = target;
- }
-
- /**
- * Return a {@link Serializable} {@link ConstraintDescriptor} capturing a
- * snapshot of current state.
- *
- * @return {@link ConstraintDescriptor}
- */
- public ConstraintDescriptor<T> asSerializableDescriptor() {
- return new ConstraintDescriptorImpl<T>(this);
- }
-
- void setGroups(final Set<Class<?>> groups) {
- this.groups = groups;
- ConstraintAnnotationAttributes.GROUPS.put(attributes, groups.toArray(new Class<?>[groups.size()]));
- }
-
- void setGroups(final Class<?>[] groups) {
- this.groups = new HashSet<Class<?>>();
- Collections.addAll(this.groups, groups);
- ConstraintAnnotationAttributes.GROUPS.put(attributes, groups);
- }
-
- void setPayload(Set<Class<? extends Payload>> payload) {
- this.payload = payload;
- ConstraintAnnotationAttributes.PAYLOAD.put(attributes, payload.toArray(new Class[payload.size()]));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isReportAsSingleViolation() {
- return reportFromComposite;
- }
-
- /**
- * Add a composing constraint.
- *
- * @param aConstraintValidation to add
- */
- public void addComposed(ConstraintValidation<?> aConstraintValidation) {
- if (composedConstraints == null) {
- composedConstraints = new HashSet<ConstraintValidation<?>>();
- }
- composedConstraints.add(aConstraintValidation);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public <L extends ValidationListener> void validate(ValidationContext<L> context) {
- validateGroupContext((GroupValidationContext<?>) context);
- }
-
- /**
- * Validate a {@link GroupValidationContext}.
- *
- * @param context root
- */
- public void validateGroupContext(final GroupValidationContext<?> context) {
- if (validator == null) {
- synchronized (this) {
- if (validator == null) {
- try {
- validator = getConstraintValidator(context.getConstraintValidatorFactory(), annotation,
- validatorClasses, owner, access);
- if (validator != null) {
- validator.initialize(annotation);
- }
- } catch (final RuntimeException re) {
- if (ValidationException.class.isInstance(re)) {
- throw re;
- }
- throw new ConstraintDefinitionException(re);
- }
- }
- }
- }
-
- context.setConstraintValidation(this);
- /**
- * execute unless the given validation constraint has already been
- * processed during this validation routine (as part of a previous group
- * match)
- */
- if (!isMemberOf(context.getCurrentGroup().getGroup())) {
- return; // do not validate in the current group
- }
- if (context.getCurrentOwner() != null && !this.owner.equals(context.getCurrentOwner())) {
- return;
- }
- if (validator != null && !context.collectValidated(validator))
- return; // already done
-
- if (context.getMetaProperty() != null && !isReachable(context)) {
- return;
- }
-
- // process composed constraints
- if (isReportAsSingleViolation()) {
- final ConstraintValidationListener<?> listener = context.getListener();
- listener.beginReportAsSingle();
-
- boolean failed = listener.hasViolations();
- try {
- // stop validating when already failed and
- // ReportAsSingleInvalidConstraint = true ?
- for (Iterator<ConstraintValidation<?>> composed = getComposingValidations().iterator(); !failed
- && composed.hasNext();) {
- composed.next().validate(context);
- failed = listener.hasViolations();
- }
- } finally {
- listener.endReportAsSingle();
- // Restore current constraint validation
- context.setConstraintValidation(this);
- }
-
- if (failed) {
- // TODO RSt - how should the composed constraint error report look like?
- addErrors(context, new ConstraintValidatorContextImpl(context, this)); // add defaultErrorMessage only
- return;
- }
- } else {
- for (ConstraintValidation<?> composed : getComposingValidations()) {
- composed.validate(context);
- }
-
- // Restore current constraint validation
- context.setConstraintValidation(this);
- }
-
- if (validator != null) {
- @SuppressWarnings("unchecked")
- final ConstraintValidator<T, Object> objectValidator = (ConstraintValidator<T, Object>) validator;
- final ConstraintValidatorContextImpl jsrContext = new ConstraintValidatorContextImpl(context, this);
- if (!objectValidator.isValid(context.getValidatedValue(), jsrContext)) {
- addErrors(context, jsrContext);
- }
- }
- }
-
- private <A extends Annotation> ConstraintValidator<A, ? super T> getConstraintValidator(
- ConstraintValidatorFactory factory, A annotation,
- Class<? extends ConstraintValidator<A, ?>>[] constraintClasses, Class<?> owner, AccessStrategy access) {
- if (ObjectUtils.isNotEmpty(constraintClasses)) {
- final Type type = determineTargetedType(owner, access);
-
- /**
- * spec says in chapter 3.5.3.: The ConstraintValidator chosen to
- * validate a declared type T is the one where the type supported by
- * the ConstraintValidator is a supertype of T and where there is no
- * other ConstraintValidator whose supported type is a supertype of
- * T and not a supertype of the chosen ConstraintValidator supported
- * type.
- */
- final Map<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>> validatorTypes =
- getValidatorsTypes(constraintClasses);
- reduceTarget(validatorTypes, access);
-
- final List<Type> assignableTypes = new ArrayList<Type>(constraintClasses.length);
- fillAssignableTypes(type, validatorTypes.keySet(), assignableTypes);
- reduceAssignableTypes(assignableTypes);
- checkOneType(assignableTypes, type, owner, annotation, access);
-
- if ((type.equals(Object.class) || type.equals(Object[].class)) && validatorTypes.containsKey(Object.class)
- && validatorTypes.containsKey(Object[].class)) {
- throw new ConstraintDefinitionException(
- "Only a validator for Object or Object[] should be provided for cross-parameter validators");
- }
-
- final Collection<Class<? extends ConstraintValidator<A, ?>>> key =
- validatorTypes.get(assignableTypes.get(0));
- if (key.size() > 1) {
- final String message = "Factory returned " + key.size() + " validators";
- if (ParametersAccess.class.isInstance(access)) { // cross parameter
- throw new ConstraintDefinitionException(message);
- }
- throw new UnexpectedTypeException(message);
- }
-
- @SuppressWarnings("unchecked")
- final ConstraintValidator<A, ? super T> validator =
- (ConstraintValidator<A, ? super T>) factory.getInstance(key.iterator().next());
- if (validator == null) {
- throw new ValidationException("Factory returned null validator for: " + key);
-
- }
- return validator;
- // NOTE: validator initialization deferred until append phase
- }
- return null;
- }
-
- private <A extends Annotation> void reduceTarget(
- final Map<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>> validator,
- final AccessStrategy access) {
- for (final Map.Entry<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>> entry : validator
- .entrySet()) {
- final Collection<Class<? extends ConstraintValidator<A, ?>>> validators = entry.getValue();
- final Iterator<Class<? extends ConstraintValidator<A, ?>>> it = validators.iterator();
- while (it.hasNext()) {
- final Type v = it.next();
- if (!Class.class.isInstance(v)) {
- continue; // TODO: handle this case
- }
-
- final Class<?> clazz = Class.class.cast(v);
- final SupportedValidationTarget target = clazz.getAnnotation(SupportedValidationTarget.class);
- if (target != null) {
- final Collection<ValidationTarget> targets = Arrays.asList(target.value());
- final boolean isParameter =
- ParameterAccess.class.isInstance(access) || ParametersAccess.class.isInstance(access);
- if ((isParameter && !targets.contains(ValidationTarget.PARAMETERS))
- || (!isParameter && !targets.contains(ValidationTarget.ANNOTATED_ELEMENT))) {
- it.remove();
- }
- }
- }
- if (validators.isEmpty()) {
- validator.remove(entry.getKey());
- }
- }
- }
-
- private static void checkOneType(List<Type> types, Type targetType, Class<?> owner, Annotation anno,
- AccessStrategy access) {
-
- if (types.isEmpty()) {
- final String message = "No validator could be found for type " + stringForType(targetType) + ". See: @"
- + anno.annotationType().getSimpleName() + " at " + stringForLocation(owner, access);
- if (Object[].class.equals(targetType)) { // cross parameter
- throw new ConstraintDefinitionException(message);
- }
- throw new UnexpectedTypeException(message);
- }
- if (types.size() > 1) {
- throw new UnexpectedTypeException(String.format(
- "Ambiguous validators for type %s. See: @%s at %s. Validators are: %s",
- stringForType(targetType),
- anno.annotationType().getSimpleName(),
- stringForLocation(owner, access), types.stream()
- .map(Object::toString).collect(Collectors.joining(", "))));
- }
- }
-
- private static String stringForType(Type clazz) {
- if (clazz instanceof Class<?>) {
- return ((Class<?>) clazz).isArray() ? ((Class<?>) clazz).getComponentType().getName() + "[]"
- : ((Class<?>) clazz).getName();
- }
- return clazz.toString();
- }
-
- private static String stringForLocation(Class<?> owner, AccessStrategy access) {
- return access == null ? owner.getName() : access.toString();
- }
-
- private static void fillAssignableTypes(Type type, Set<Type> validatorsTypes, List<Type> suitableTypes) {
- for (final Type validatorType : validatorsTypes) {
- if (TypeUtils.isAssignable(type, validatorType) && !suitableTypes.contains(validatorType)) {
- suitableTypes.add(validatorType);
- }
- }
- }
-
- /**
- * Tries to reduce all assignable classes down to a single class.
- *
- * @param assignableTypes The set of all classes which are assignable to the class of
- * the value to be validated and which are handled by at least
- * one of the validators for the specified constraint.
- */
- private static void reduceAssignableTypes(List<Type> assignableTypes) {
- if (assignableTypes.size() <= 1) {
- return; // no need to reduce
- }
- boolean removed = false;
- do {
- final Type type = assignableTypes.get(0);
- for (int i = 1; i < assignableTypes.size(); i++) {
- final Type nextType = assignableTypes.get(i);
- if (TypeUtils.isAssignable(nextType, type)) {
- assignableTypes.remove(0);
- i--;
- removed = true;
- } else if (TypeUtils.isAssignable(type, nextType)) {
- assignableTypes.remove(i--);
- removed = true;
- }
- }
- } while (removed && assignableTypes.size() > 1);
- }
-
- private static <A extends Annotation> Map<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>> getValidatorsTypes(
- Class<? extends ConstraintValidator<A, ?>>[] constraintValidatorClasses) {
- final Map<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>> validatorsTypes =
- new HashMap<Type, Collection<Class<? extends ConstraintValidator<A, ?>>>>();
- for (Class<? extends ConstraintValidator<A, ?>> validatorType : constraintValidatorClasses) {
- Type validatedType = TypeUtils.getTypeArguments(validatorType, ConstraintValidator.class)
- .get(ConstraintValidator.class.getTypeParameters()[1]);
- if (validatedType == null) {
- throw new ValidationException(String.format("Could not detect validated type for %s", validatorType));
- }
- if (validatedType instanceof GenericArrayType) {
- final Type componentType = TypeUtils.getArrayComponentType(validatedType);
- if (componentType instanceof Class<?>) {
- validatedType = Array.newInstance((Class<?>) componentType, 0).getClass();
- }
- }
- if (!validatorsTypes.containsKey(validatedType)) {
- validatorsTypes.put(validatedType, new ArrayList<Class<? extends ConstraintValidator<A, ?>>>());
- }
- validatorsTypes.get(validatedType).add(validatorType);
- }
- return validatorsTypes;
- }
-
- /**
- * implements spec chapter 3.5.3. ConstraintValidator resolution algorithm.
- */
- private static Type determineTargetedType(Class<?> owner, AccessStrategy access) {
- // if the constraint declaration is hosted on a class or an interface,
- // the targeted type is the class or the interface.
- if (access == null) {
- return owner;
- }
- final Type type = access.getJavaType();
- if (type == null) {
- return Object.class;
- }
- return type instanceof Class<?> ? Reflection.primitiveToWrapper((Class<?>) type) : type;
- }
-
- /**
- * Initialize the validator (if not <code>null</code>) with the stored
- * annotation.
- */
- public void initialize() {
- if (null != validator) {
- try {
- validator.initialize(annotation);
- } catch (RuntimeException e) {
- // Either a "legit" problem initializing the validator or a
- // ClassCastException if the validator associated annotation is
- // not a supertype of the validated annotation.
- throw new ConstraintDefinitionException(
- "Incorrect validator [" + validator.getClass().getCanonicalName() + "] for annotation "
- + annotation.annotationType().getCanonicalName(),
- e);
- }
- }
- }
-
- private boolean isReachable(GroupValidationContext<?> context) {
- final PathImpl path = context.getPropertyPath();
- final NodeImpl node = path.getLeafNode();
- PathImpl beanPath = path.getPathWithoutLeafNode();
- if (beanPath == null) {
- beanPath = PathImpl.create();
- }
- try {
- if (!context.getTraversableResolver().isReachable(context.getBean(), node,
- context.getRootMetaBean().getBeanClass(), beanPath, access.getElementType())) {
- return false;
- }
- } catch (RuntimeException e) {
- throw new ValidationException("Error in TraversableResolver.isReachable() for " + context.getBean(), e);
- }
- return true;
- }
-
- private void addErrors(GroupValidationContext<?> context, ConstraintValidatorContextImpl jsrContext) {
- for (ValidationListener.Error each : jsrContext.getErrorMessages()) {
- context.getListener().addError(each, context);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "ConstraintValidation{" + validator + '}';
- }
-
- /**
- * Get the message template used by this constraint.
- *
- * @return String
- */
- @Override
- public String getMessageTemplate() {
- return ConstraintAnnotationAttributes.MESSAGE.get(attributes);
- }
-
- public ConstraintValidator<T, ?> getValidator() {
- return validator;
- }
-
- protected boolean isMemberOf(Class<?> reqGroup) {
- return groups.contains(reqGroup);
- }
-
- public Class<?> getOwner() {
- return owner;
- }
-
- @Override
- public T getAnnotation() {
- return annotation;
- }
-
- public AccessStrategy getAccess() {
- return access;
- }
-
- public void setAnnotation(T annotation) {
- this.annotation = annotation;
- }
-
- // ///////////////////////// ConstraintDescriptor implementation
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Map<String, Object> getAttributes() {
- return attributes;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public Set<ConstraintDescriptor<?>> getComposingConstraints() {
- if (composedConstraints == null) {
- return Collections.emptySet();
- }
- final Set result = composedConstraints;
- return result;
- }
-
- /**
- * Get the composing {@link ConstraintValidation} objects. This is
- * effectively an implementation-specific analogue to
- * {@link #getComposingConstraints()}.
- *
- * @return {@link Set} of {@link ConstraintValidation}
- */
- Set<ConstraintValidation<?>> getComposingValidations() {
- return composedConstraints == null ? Collections.<ConstraintValidation<?>> emptySet() : composedConstraints;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Set<Class<?>> getGroups() {
- return groups;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Set<Class<? extends Payload>> getPayload() {
- return payload;
- }
-
- @Override
- public ConstraintTarget getValidationAppliesTo() {
- return validationAppliesTo;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<Class<? extends ConstraintValidator<T, ?>>> getConstraintValidatorClasses() {
- return validatorClasses == null ? Collections.<Class<? extends ConstraintValidator<T, ?>>> emptyList()
- : Arrays.asList(validatorClasses);
- }
-
- public void setValidationAppliesTo(final ConstraintTarget validationAppliesTo) {
- this.validationAppliesTo = validationAppliesTo;
- }
-
- public boolean isValidated() {
- return validated;
- }
-
- public void setValidated(final boolean validated) {
- this.validated = validated;
- }
-
- @Override
- public ValidateUnwrappedValue getValueUnwrapping() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public <U> U unwrap(Class<U> arg0) {
- // TODO Auto-generated method stub
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidationListener.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidationListener.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidationListener.java
deleted file mode 100644
index 7d7ec8b..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidationListener.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.jsr.util.PathImpl;
-import org.apache.bval.model.ValidationContext;
-import org.apache.bval.model.ValidationListener;
-
-import javax.validation.ConstraintViolation;
-import javax.validation.ElementKind;
-import javax.validation.MessageInterpolator;
-import javax.validation.Path;
-import javax.validation.metadata.ConstraintDescriptor;
-import java.lang.annotation.ElementType;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * Description: JSR-303 {@link ValidationListener} implementation; provides {@link ConstraintViolation}s.<br/>
- *
- * @version $Rev: 1503686 $ $Date: 2013-07-16 14:38:56 +0200 (mar., 16 juil. 2013) $
- */
-public final class ConstraintValidationListener<T> implements ValidationListener {
- private final Set<ConstraintViolation<T>> constraintViolations = new HashSet<ConstraintViolation<T>>();
- private final T rootBean;
- private final Class<T> rootBeanType;
- // the validation process is single-threaded and it's unlikely to change in the near future (otherwise use AtomicInteger).
- private int compositeDepth = 0;
- private boolean hasCompositeError;
-
- /**
- * Create a new ConstraintValidationListener instance.
- * @param aRootBean
- * @param rootBeanType
- */
- public ConstraintValidationListener(T aRootBean, Class<T> rootBeanType) {
- this.rootBean = aRootBean;
- this.rootBeanType = rootBeanType;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public <VL extends ValidationListener> void addError(String reason, ValidationContext<VL> context) {
- addError(reason, null, context);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public <VL extends ValidationListener> void addError(Error error, ValidationContext<VL> context) {
- if (error.getOwner() instanceof Path) {
- addError(error.getReason(), (Path) error.getOwner(), context);
- } else {
- addError(error.getReason(), null, context);
- }
- }
-
- private void addError(String messageTemplate, Path propPath, ValidationContext<?> context) {
- if (compositeDepth > 0) {
- hasCompositeError |= true;
- return;
- }
- final Object value;
-
- final ConstraintDescriptor<?> descriptor;
- final String message;
- if (context instanceof GroupValidationContext<?>) {
- GroupValidationContext<?> gcontext = (GroupValidationContext<?>) context;
- value = gcontext.getValidatedValue();
- if (gcontext instanceof MessageInterpolator.Context) {
- message =
- gcontext.getMessageResolver().interpolate(messageTemplate, (MessageInterpolator.Context) gcontext);
- } else {
- message = gcontext.getMessageResolver().interpolate(messageTemplate, null);
- }
- descriptor = gcontext.getConstraintValidation().asSerializableDescriptor();
- if (propPath == null)
- propPath = gcontext.getPropertyPath();
- } else {
- if (context.getMetaProperty() == null)
- value = context.getBean();
- else
- value = context.getPropertyValue();
- message = messageTemplate;
- if (propPath == null)
- propPath = PathImpl.createPathFromString(context.getPropertyName());
- descriptor = null;
- }
- ElementType elementType = (context.getAccess() != null) ? context.getAccess().getElementType() : null;
-
- final Object[] parameters;
- Object leaf;
- Object returnValue;
- T rootBean;
- if (GroupValidationContext.class.isInstance(context)) { // TODO: clean up it but it would need to rework completely our context - get rid of it would be the best
- final GroupValidationContext<T> ctx = GroupValidationContext.class.cast(context);
- final ElementKind elementKind = ctx.getElementKind();
- final Iterator<Path.Node> it = propPath.iterator();
- final ElementKind kind = propPath.iterator().next().getKind();
-
- returnValue = ctx.getReturnValue();
-
- if (ElementKind.CONSTRUCTOR.equals(kind)) {
- rootBean = null;
- leaf = context.getBean();
- returnValue = this.rootBean; // switch back return value and rootBean
- } else if (ElementKind.METHOD.equals(kind)) {
- if (ElementKind.RETURN_VALUE.equals(elementKind)) { // switch back return value and rootBean
- rootBean = (T) returnValue;
- if (kindOf(propPath, ElementKind.RETURN_VALUE)) {
- leaf = returnValue;
- returnValue = this.rootBean;
- } else {
- leaf = this.rootBean;
- returnValue = this.rootBean;
- }
- } else {
- rootBean = this.rootBean;
- if (kindOf(propPath, ElementKind.PARAMETER, ElementKind.CROSS_PARAMETER)) {
- leaf = rootBean;
- } else {
- leaf = context.getBean();
- }
- }
- } else {
- rootBean = this.rootBean;
- leaf = context.getBean();
- }
-
- if (ElementKind.CONSTRUCTOR.equals(kind)
- && (ElementKind.CROSS_PARAMETER.equals(elementKind) || ElementKind.PARAMETER.equals(elementKind))
- && (it.hasNext() && it.next() != null && it.hasNext() && it.next() != null && !it.hasNext())) { // means inherited validation use real value
- leaf = null;
- }
-
- parameters = ctx.getParameters();
- } else {
- leaf = context.getBean();
- returnValue = null;
- parameters = null;
- rootBean = this.rootBean;
- }
-
- constraintViolations.add(new ConstraintViolationImpl<T>(messageTemplate, message, rootBean, leaf, propPath,
- value, descriptor, rootBeanType, elementType, returnValue, parameters));
- }
-
- private static boolean kindOf(final Path propPath, final ElementKind... kinds) {
- final Iterator<Path.Node> node = propPath.iterator();
- boolean isParam = false;
- while (node.hasNext()) {
- final ElementKind current = node.next().getKind();
- isParam = false;
- for (final ElementKind k : kinds) {
- if (k.equals(current)) {
- isParam = true;
- break;
- }
- }
- }
- return isParam;
- }
-
- /**
- * Get the {@link ConstraintViolation}s accumulated by this {@link ConstraintValidationListener}.
- * @return {@link Set} of {@link ConstraintViolation}
- */
- public Set<ConstraintViolation<T>> getConstraintViolations() {
- return constraintViolations;
- }
-
- /**
- * Learn whether no violations were found.
- * @return boolean
- */
- public boolean isEmpty() {
- return constraintViolations.isEmpty();
- }
-
- /**
- * Get the root bean.
- * @return T
- */
- public T getRootBean() {
- return rootBean;
- }
-
- /**
- * Get the root bean type of this {@link ConstraintValidationListener}.
- * @return Class<T>
- */
- public Class<T> getRootBeanType() {
- return rootBeanType;
- }
-
- /**
- * Get the count of encountered violations.
- * @return int
- */
- public int violationsSize() {
- return constraintViolations.size();
- }
-
- /**
- * Learn whether there are violations available.
- * If in report-as-single-violation mode, the result is scoped accordingly.
- * Note that this means you must check before exiting report-as-single-violation mode
- * @return boolean
- */
- public boolean hasViolations() {
- return compositeDepth == 0 ? !constraintViolations.isEmpty() : hasCompositeError;
- }
-
- /**
- * Signify the beginning of a report-as-single-violation composite validation.
- * @return <code>true</code> as this call caused the listener to enter report-as-single-violation mode
- */
- public boolean beginReportAsSingle() {
- return ++compositeDepth == 1;
- }
-
- /**
- * Signify the end of a report-as-single-violation composite validation.
- * @return <code>true</code> as this call caused the listener to exit report-as-single-violation mode
- */
- public boolean endReportAsSingle() {
- boolean endOutMostReportAsSingle = (--compositeDepth == 0);
- if (endOutMostReportAsSingle) {
- hasCompositeError = false;
- }
- return endOutMostReportAsSingle;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidatorContextImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidatorContextImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidatorContextImpl.java
deleted file mode 100644
index 74c8685..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidatorContextImpl.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.jsr.util.LeafNodeBuilderCustomizableContextImpl;
-import org.apache.bval.jsr.util.NodeBuilderCustomizableContextImpl;
-import org.apache.bval.jsr.util.NodeBuilderDefinedContextImpl;
-import org.apache.bval.jsr.util.NodeImpl;
-import org.apache.bval.jsr.util.PathImpl;
-import org.apache.bval.model.ValidationListener;
-
-import javax.validation.ClockProvider;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.Path;
-import javax.validation.ValidationException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Description: Short-lived {@link ConstraintValidatorContext} implementation passed by
- * a {@link ConstraintValidation} to its adapted {@link ConstraintValidator}. <br/>
- */
-@Deprecated
-public class ConstraintValidatorContextImpl
- extends org.apache.bval.jsr.job.ConstraintValidatorContextImpl<Object>
- implements ConstraintValidatorContext {
- private final List<ValidationListener.Error> errorMessages = new LinkedList<ValidationListener.Error>();
-
- private final ConstraintValidation<?> constraintDescriptor;
- private final GroupValidationContext<?> validationContext;
-
- private boolean defaultDisabled;
-
- /**
- * Create a new ConstraintValidatorContextImpl instance.
- * @param validationContext
- * @param aConstraintValidation
- */
- public ConstraintValidatorContextImpl(GroupValidationContext<?> validationContext,
- ConstraintValidation<?> aConstraintValidation) {
- super();
- this.validationContext = validationContext;
- this.constraintDescriptor = aConstraintValidation;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void disableDefaultConstraintViolation() {
- defaultDisabled = true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getDefaultConstraintMessageTemplate() {
- return constraintDescriptor.getMessageTemplate();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ConstraintViolationBuilder buildConstraintViolationWithTemplate(String messageTemplate) {
- return new ConstraintViolationBuilderImpl(this, messageTemplate, validationContext.getPropertyPath());
- }
-
- @Override
- public <T> T unwrap(Class<T> type) {
- if (type.isInstance(this)) {
- return type.cast(this);
- }
- throw new ValidationException("Type " + type + " not supported");
- }
-
- private static final class ConstraintViolationBuilderImpl
- implements ConstraintValidatorContext.ConstraintViolationBuilder {
- private final ConstraintValidatorContextImpl parent;
- private final String messageTemplate;
- private final PathImpl propertyPath;
-
- /**
- * Create a new ConstraintViolationBuilderImpl instance.
- * @param contextImpl
- * @param template
- * @param path
- */
- ConstraintViolationBuilderImpl(ConstraintValidatorContextImpl contextImpl, String template, PathImpl path) {
- parent = contextImpl;
- messageTemplate = template;
- propertyPath = path;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public NodeBuilderDefinedContext addNode(String name) {
- PathImpl path;
- if (propertyPath.isRootPath()) {
- path = PathImpl.create();
- path.getLeafNode().setName(name);
- } else {
- path = PathImpl.copy(propertyPath);
- path.addNode(new NodeImpl.PropertyNodeImpl(name));
- }
- return new NodeBuilderDefinedContextImpl(parent, messageTemplate, path);
- }
-
- @Override
- public NodeBuilderCustomizableContext addPropertyNode(String name) {
- return new NodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath, name);
- }
-
- @Override
- public LeafNodeBuilderCustomizableContext addBeanNode() {
- return new LeafNodeBuilderCustomizableContextImpl(parent, messageTemplate, propertyPath);
- }
-
- @Override
- public NodeBuilderDefinedContext addParameterNode(int index) {
- final Method method = parent.validationContext.getMethod();
- final List<String> parameters =
- parent.validationContext.getParameterNameProvider().getParameterNames(method);
- final NodeImpl node = new NodeImpl.ParameterNodeImpl(parameters.get(index), index);
- if (!propertyPath.isRootPath()) {
- propertyPath.removeLeafNode();
- }
- propertyPath.addNode(node);
- return new NodeBuilderDefinedContextImpl(parent, messageTemplate, propertyPath);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ConstraintValidatorContext addConstraintViolation() {
- parent.addError(messageTemplate, propertyPath);
- return parent;
- }
-
- @Override
- public ContainerElementNodeBuilderCustomizableContext addContainerElementNode(
- String arg0, Class<?> arg1, Integer arg2) {
- // TODO Auto-generated method stub
- return null;
- }
- }
-
- /**
- * Get the queued error messages.
- * @return List
- */
- public List<ValidationListener.Error> getErrorMessages() {
- if (defaultDisabled && errorMessages.isEmpty()) {
- throw new ValidationException(
- "At least one custom message must be created if the default error message gets disabled.");
- }
-
- List<ValidationListener.Error> returnedErrorMessages = new ArrayList<ValidationListener.Error>(errorMessages);
- if (!defaultDisabled) {
- returnedErrorMessages.add(new ValidationListener.Error(getDefaultConstraintMessageTemplate(),
- validationContext.getPropertyPath(), null));
- }
- return returnedErrorMessages;
- }
-
- /**
- * Get this {@link ConstraintValidatorContext}'s {@link GroupValidationContext}.
- * @return {@link GroupValidationContext}
- */
- public GroupValidationContext<?> getValidationContext() {
- return validationContext;
- }
-
- /**
- * Add an error message to this {@link ConstraintValidatorContext}.
- * @param messageTemplate
- * @param propertyPath
- */
- public void addError(String messageTemplate, Path propertyPath) {
- errorMessages.add(new ValidationListener.Error(messageTemplate, propertyPath, null));
- }
-
- @Override
- public ClockProvider getClockProvider() {
- // TODO Auto-generated method stub
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidatorIdentity.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidatorIdentity.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidatorIdentity.java
deleted file mode 100644
index 572c39a..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintValidatorIdentity.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import java.util.Objects;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.Path;
-
-/**
- * Class that stores the needed properties to ensure that a validation is not
- * checked more than once.
- * <p>
- * These properties are:
- * <ul>
- * <li>The ref of the bean to which the validation would be applied.</li>
- * <li>The path of the property.</li>
- * <li>The ref of the {@link ConstraintValidator}.</li>
- * </ul>
- *
- * @author Carlos Vara
- */
-final class ConstraintValidatorIdentity {
-
- private final Object bean;
- private final Path path;
- private final ConstraintValidator<?, ?> constraintValidator;
-
- /**
- * Create a new ConstraintValidatorIdentity instance.
- * @param bean
- * @param path
- * @param constraintValidator
- */
- public ConstraintValidatorIdentity(Object bean, Path path, ConstraintValidator<?, ?> constraintValidator) {
- this.bean = bean;
- this.path = path;
- this.constraintValidator = constraintValidator;
- }
-
- /**
- * Get the referenced bean.
- * @return Object
- */
- public Object getBean() {
- return bean;
- }
-
- /**
- * Get the referenced property {@link Path}.
- * @return Path
- */
- public Path getPath() {
- return path;
- }
-
- /**
- * Get the associated {@link ConstraintValidator}.
- * @return {@link ConstraintValidator}
- */
- public ConstraintValidator<?, ?> getConstraintValidator() {
- return constraintValidator;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
-
- if (this == obj) {
- return true;
- }
-
- if (obj == null) {
- return false;
- }
-
- if (!(obj instanceof ConstraintValidatorIdentity)) {
- return false;
- }
-
- ConstraintValidatorIdentity other = (ConstraintValidatorIdentity) obj;
-
- // Bean ref must be the same
- if (this.bean != other.bean) {
- return false;
- }
-
- // ConstraintValidator ref must be the same
- if (this.constraintValidator != other.constraintValidator) {
- return false;
- }
-
- // Path must be equals
- if (!this.path.equals(other.path)) {
- return false;
- }
-
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hash(bean, path, constraintValidator);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintViolationImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintViolationImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintViolationImpl.java
index 91ae20d..15f754d 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintViolationImpl.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/ConstraintViolationImpl.java
@@ -83,7 +83,8 @@ public class ConstraintViolationImpl<T> implements ConstraintViolation<T>, Seria
this.elementType = elementType;
this.returnValue = returnValue;
this.parameters = parameters;
- this.hashCode = computeHashCode();
+ this.hashCode = Arrays.deepHashCode(new Object[] { messageTemplate, message, rootBean, rootBeanClass, leafBean,
+ value, propertyPath, elementType, constraintDescriptor, returnValue, parameters });
}
/**
@@ -208,11 +209,4 @@ public class ConstraintViolationImpl<T> implements ConstraintViolation<T>, Seria
public int hashCode() {
return hashCode;
}
-
- private int computeHashCode() {
- int result = Objects.hash(messageTemplate, message, rootBean, rootBeanClass, leafBean, value, propertyPath,
- elementType, constraintDescriptor, returnValue);
- result = 31 * result + (parameters == null ? 0 : Arrays.hashCode(parameters));
- return result;
- }
}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ConstructorDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstructorDescriptorImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ConstructorDescriptorImpl.java
deleted file mode 100644
index d947a92..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ConstructorDescriptorImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.bval.jsr;
-
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.MetaConstructor;
-import org.apache.bval.model.Validation;
-
-import javax.validation.metadata.ConstructorDescriptor;
-
-/**
- * Description: {@link javax.validation.metadata.ConstructorDescriptor} implementation.<br/>
- */
-public class ConstructorDescriptorImpl extends InvocableElementDescriptor
- implements ConstructorDescriptor, ProcedureDescriptor {
- /**
- * Create a new ConstructorDescriptorImpl instance.
- * @param metaBean
- * @param validations
- */
- protected ConstructorDescriptorImpl(MetaBean metaBean, Validation[] validations) {
- super(metaBean, metaBean.getBeanClass(), validations);
- }
-
- public ConstructorDescriptorImpl(final MetaBean metaBean, final MetaConstructor metaMethod) {
- super(metaBean, metaBean.getBeanClass(), new Validation[0]);
- setCascaded(false);
- }
-
- @Override
- public String getName() {
- return elementClass.getSimpleName();
- }
-
- @Override
- public boolean hasConstraints() {
- return false;
- }
-
- @Override
- public boolean hasConstrainedParameters() {
- return super.hasConstrainedParameters();
- }
-
- @Override
- public boolean hasConstrainedReturnValue() {
- return super.hasConstrainedReturnValue();
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/CrossParameterDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/CrossParameterDescriptorImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/CrossParameterDescriptorImpl.java
deleted file mode 100644
index c14e102..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/CrossParameterDescriptorImpl.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.model.MetaBean;
-
-import javax.validation.metadata.CrossParameterDescriptor;
-import java.util.Collection;
-
-public class CrossParameterDescriptorImpl extends ElementDescriptorImpl implements CrossParameterDescriptor {
- public CrossParameterDescriptorImpl(final MetaBean bean, final Collection<ConstraintValidation<?>> list) {
- super(bean, Object[].class, list.toArray(new ConstraintValidation<?>[list.size()]));
- }
-
- @Override
- public boolean hasConstraints() {
- return !getConstraintDescriptors().isEmpty();
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/ElementDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/ElementDescriptorImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/ElementDescriptorImpl.java
deleted file mode 100644
index cfcf85b..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/ElementDescriptorImpl.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.jsr.groups.Group;
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.Validation;
-
-import javax.validation.ConstraintDeclarationException;
-import javax.validation.metadata.ConstraintDescriptor;
-import javax.validation.metadata.ElementDescriptor;
-import javax.validation.metadata.GroupConversionDescriptor;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * Description: MetaData class<br/>
- */
-public abstract class ElementDescriptorImpl implements ElementDescriptor {
- private final Set<GroupConversionDescriptor> groupConversions =
- new CopyOnWriteArraySet<GroupConversionDescriptor>();
- private boolean cascaded;
- private final Collection<Object> validated = new CopyOnWriteArraySet<Object>();
-
- /**
- * Get a set of {@link ConstraintDescriptor}s from the specified array of
- * {@link Validation}s.
- *
- * @param validations
- * @return {@link ConstraintDescriptor} set
- */
- protected static Set<ConstraintDescriptor<?>> getConstraintDescriptors(final Validation[] validations) {
- final Set<ConstraintDescriptor<?>> result = new HashSet<ConstraintDescriptor<?>>(validations.length);
- for (Validation validation : validations) {
- if (validation instanceof ConstraintValidation<?>) {
- result.add((ConstraintValidation<?>) validation);
- }
- }
- return result;
- }
-
- /** the MetaBean of this element */
- protected final MetaBean metaBean;
-
- /** the raw type of this element */
- protected final Class<?> elementClass;
-
- private Set<ConstraintDescriptor<?>> constraintDescriptors;
-
- private final Map<Group, Group> groupMapping = new HashMap<Group, Group>();
-
- /**
- * Create a new ElementDescriptorImpl instance.
- *
- * @param metaBean
- * @param elementClass
- * @param validations
- */
- protected ElementDescriptorImpl(MetaBean metaBean, Class<?> elementClass, Validation[] validations) {
- this.metaBean = metaBean;
- this.elementClass = elementClass;
- setConstraintDescriptors(getConstraintDescriptors(validations));
- }
-
- /**
- * Create a new ElementDescriptorImpl instance.
- *
- * @param elementClass
- * @param validations
- */
- protected ElementDescriptorImpl(Class<?> elementClass, Validation[] validations) {
- this(null, elementClass, validations);
- }
-
- /**
- * {@inheritDoc}
- *
- * @return Statically defined returned type.
- */
- @Override
- public Class<?> getElementClass() {
- return elementClass;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public ElementDescriptor.ConstraintFinder findConstraints() {
- return new ConstraintFinderImpl(metaBean, new HashSet(constraintDescriptors));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Set<ConstraintDescriptor<?>> getConstraintDescriptors() {
- return constraintDescriptors.isEmpty() ? Collections.<ConstraintDescriptor<?>> emptySet()
- : Collections.unmodifiableSet(constraintDescriptors);
- }
-
- /**
- * Get the mutable {@link ConstraintDescriptor} {@link Set}.
- *
- * @return Set of {@link ConstraintDescriptor}
- */
- public Set<ConstraintDescriptor<?>> getMutableConstraintDescriptors() {
- return constraintDescriptors;
- }
-
- /**
- * {@inheritDoc} return true if at least one constraint declaration is
- * present on the element.
- */
- @Override
- public boolean hasConstraints() {
- return !getConstraintDescriptors().isEmpty();
- }
-
- /**
- * Set the constraintDescriptors for this element.
- *
- * @param constraintDescriptors
- * to set
- */
- public void setConstraintDescriptors(Set<ConstraintDescriptor<?>> constraintDescriptors) {
- this.constraintDescriptors = constraintDescriptors;
- }
-
- /**
- * Get the model {@link MetaBean} used.
- *
- * @return MetaBean
- */
- public MetaBean getMetaBean() {
- return metaBean;
- }
-
- public void addGroupMapping(final Group from, final Group to) {
- groupMapping.put(from, to);
- }
-
- public Group mapGroup(final Group current) {
- final Group mapping = groupMapping.get(current);
- if (mapping != null) {
- return mapping;
- }
- return current;
- }
-
- public Set<GroupConversionDescriptor> getGroupConversions() {
- return groupConversions;
- }
-
- public void addGroupConversion(final GroupConversionDescriptor descriptor) {
- groupConversions.add(descriptor);
- final Group from = new Group(descriptor.getFrom());
- if (mapGroup(from) != from) { // ref == is fine
- throw new ConstraintDeclarationException("You can't map twice from the same group");
- }
- addGroupMapping(from, new Group(descriptor.getTo()));
- }
-
- public boolean isCascaded() {
- return cascaded;
- }
-
- public void setCascaded(final boolean cascaded) {
- this.cascaded = cascaded;
- }
-
- public boolean isValidated(final Object object) {
- return validated.contains(object);
- }
-
- public void setValidated(final Object object) {
- this.validated.add(object);
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/GraphBeanIdentity.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/GraphBeanIdentity.java b/bval-jsr/src/main/java/org/apache/bval/jsr/GraphBeanIdentity.java
deleted file mode 100644
index 26391e6..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/GraphBeanIdentity.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import java.util.Objects;
-
-/**
- * Class that stores the needed properties to avoid circular paths when
- * validating an object graph.
- * <p>
- * These properties are:
- * <ul>
- * <li>The ref of the bean to which the validation would be applied.</li>
- * <li>The current group being validated.</li>
- * </ul>
- *
- * FIXME: Owner is currently not used in identity checking, and probably
- * never will be. So it is likely to be deleted.
- *
- * @author Carlos Vara
- */
-public class GraphBeanIdentity {
-
- private final Object bean;
- private final Class<?> group;
- private final Class<?> owner;
-
- /**
- * Create a new GraphBeanIdentity instance.
- * @param bean
- * @param group
- * @param owner
- */
- public GraphBeanIdentity(Object bean, Class<?> group, Class<?> owner) {
- this.bean = bean;
- this.group = group;
- this.owner = owner;
- }
-
- /**
- * Get the bean.
- * @return Object
- */
- public Object getBean() {
- return bean;
- }
-
- /**
- * Get the group being validated.
- * @return Class
- */
- public Class<?> getGroup() {
- return group;
- }
-
- /**
- * Get the owning class
- * @return
- */
- public Class<?> getOwner() {
- return owner;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof GraphBeanIdentity)) {
- return false;
- }
- GraphBeanIdentity other = (GraphBeanIdentity) obj;
-
- // Bean ref must be the same; Group ref must be the same
- return bean == other.bean && group == other.group;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hash(bean, group);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/GroupValidationContext.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/GroupValidationContext.java b/bval-jsr/src/main/java/org/apache/bval/jsr/GroupValidationContext.java
deleted file mode 100644
index fecfd8d..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/GroupValidationContext.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.jsr.groups.Group;
-import org.apache.bval.jsr.groups.Groups;
-import org.apache.bval.jsr.util.PathImpl;
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.ValidationContext;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.ElementKind;
-import javax.validation.MessageInterpolator;
-import javax.validation.ParameterNameProvider;
-import javax.validation.Path;
-import javax.validation.TraversableResolver;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-
-/**
- * Description: JSR-303 {@link ValidationContext} extension. <br/>
- */
-public interface GroupValidationContext<T> extends ValidationContext<ConstraintValidationListener<T>> {
-
- /**
- * Get the groups of this {@link GroupValidationContext}.
- * @return the groups in their sequence for validation
- */
- Groups getGroups();
-
- void setCurrentGroups(Groups groups);
-
- /**
- * Set the current {@link Group}.
- * @param group to set
- */
- void setCurrentGroup(Group group);
-
- /**
- * Get the current {@link Group}.
- * @return Group
- */
- Group getCurrentGroup();
-
- /**
- * Get the property path.
- * @return {@link PathImpl}
- */
- PathImpl getPropertyPath();
-
- /**
- * Get the root {@link MetaBean}.
- * @return {@link MetaBean}
- */
- MetaBean getRootMetaBean();
-
- /**
- * Set the {@link ConstraintValidation}.
- * @param constraint to set
- */
- void setConstraintValidation(ConstraintValidation<?> constraint);
-
- /**
- * Get the {@link ConstraintValidation}.
- * @return {@link ConstraintValidation}
- */
- ConstraintValidation<?> getConstraintValidation();
-
- /**
- * Get the value being validated.
- * @return Object
- */
- Object getValidatedValue();
-
- /**
- * Set a fixed value for the context.
- * @param value to set
- */
- void setFixedValue(Object value);
-
- /**
- * Get the message resolver.
- * @return {@link MessageInterpolator}
- */
- MessageInterpolator getMessageResolver();
-
- /**
- * Get the {@link TraversableResolver}.
- * @return {@link TraversableResolver}
- */
- TraversableResolver getTraversableResolver();
-
- /**
- * Get the {@link ConstraintValidatorFactory}.
- * @return {@link ConstraintValidatorFactory}
- */
- ConstraintValidatorFactory getConstraintValidatorFactory();
-
- /**
- * Accumulate a validated constraint.
- * @param constraint
- * @return true when the constraint for the object in this path was not
- * already validated in this context
- */
- boolean collectValidated(ConstraintValidator<?, ?> constraint);
-
- /**
- * Get the current owning class.
- * @return Class
- */
- Class<?> getCurrentOwner();
-
- /**
- * Set the current owning class.
- * @param currentOwner to set
- */
- void setCurrentOwner(Class<?> currentOwner);
-
- void setKind(ElementKind type);
-
- ElementKind getElementKind();
-
- Object getReturnValue();
-
- Object[] getParameters();
-
- void setParameters(Object[] parameters);
-
- void setReturnValue(Object returnValue);
-
- ParameterNameProvider getParameterNameProvider();
-
- void setMethod(Method method);
-
- Method getMethod();
-
- void setConstructor(Constructor<?> method);
-
- Constructor<?> getConstructor();
-
- void moveDown(Path.Node node);
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/GroupValidationContextImpl.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/GroupValidationContextImpl.java b/bval-jsr/src/main/java/org/apache/bval/jsr/GroupValidationContextImpl.java
deleted file mode 100644
index 9ca50dc..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/GroupValidationContextImpl.java
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you 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 org.apache.bval.jsr;
-
-import org.apache.bval.BeanValidationContext;
-import org.apache.bval.jsr.groups.Group;
-import org.apache.bval.jsr.groups.Groups;
-import org.apache.bval.jsr.resolver.CachingTraversableResolver;
-import org.apache.bval.jsr.util.NodeImpl;
-import org.apache.bval.jsr.util.PathImpl;
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.MetaProperty;
-import org.apache.bval.util.AccessStrategy;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.ElementKind;
-import javax.validation.MessageInterpolator;
-import javax.validation.ParameterNameProvider;
-import javax.validation.Path;
-import javax.validation.TraversableResolver;
-import javax.validation.ValidationException;
-import javax.validation.metadata.ConstraintDescriptor;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Description: instance per validation process, not thread-safe<br/>
- */
-final class GroupValidationContextImpl<T> extends BeanValidationContext<ConstraintValidationListener<T>>
- implements GroupValidationContext<T>, MessageInterpolator.Context {
-
- private final MessageInterpolator messageResolver;
- private final PathImpl path;
- private final MetaBean rootMetaBean;
- private final ParameterNameProvider parameterNameProvider;
-
- /**
- * the groups in the sequence of validation to take place
- */
- private Groups groups;
- /**
- * the current group during the validation process
- */
- private Group currentGroup;
-
- private Class<?> currentOwner;
-
- /**
- * contains the validation constraints that have already been processed
- * during this validation routine (as part of a previous group match)
- */
- private HashSet<ConstraintValidatorIdentity> validatedConstraints = new HashSet<ConstraintValidatorIdentity>();
-
- private ConstraintValidation<?> constraintValidation;
- private final TraversableResolver traversableResolver;
- private final ConstraintValidatorFactory constraintValidatorFactory;
-
- private Object[] parameters;
- private Object returnValue;
- private Method method;
- private Constructor<?> constructor;
-
- /**
- * Create a new GroupValidationContextImpl instance.
- *
- * @param listener
- * @param aMessageResolver
- * @param traversableResolver
- * @param parameterNameProvider
- * @param rootMetaBean
- */
- public GroupValidationContextImpl(ConstraintValidationListener<T> listener, MessageInterpolator aMessageResolver,
- TraversableResolver traversableResolver, ParameterNameProvider parameterNameProvider,
- ConstraintValidatorFactory constraintValidatorFactory, MetaBean rootMetaBean) {
- super(listener, new HashMap<GraphBeanIdentity, Set<PathImpl>>());
- this.messageResolver = aMessageResolver;
- this.constraintValidatorFactory = constraintValidatorFactory;
- this.traversableResolver = CachingTraversableResolver.cacheFor(traversableResolver);
- this.parameterNameProvider = parameterNameProvider;
- this.rootMetaBean = rootMetaBean;
- this.path = PathImpl.create();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setCurrentIndex(Integer index) {
- NodeImpl leaf = path.getLeafNode();
- if (leaf.getName() == null) {
- leaf.setIndex(index);
- } else {
- path.addNode(NodeImpl.atIndex(index));
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setCurrentKey(Object key) {
- NodeImpl leaf = path.getLeafNode();
- if (leaf.getName() == null) {
- leaf.setKey(key);
- } else {
- path.addNode(NodeImpl.atKey(key));
- }
- }
-
- @Override
- public void setKind(final ElementKind type) {
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void moveDown(MetaProperty prop, AccessStrategy access) {
- moveDown(prop.getName());
- super.moveDown(prop, access);
- }
-
- @Override
- public void moveDown(final String prop) {
- path.addProperty(prop);
- }
-
- @Override
- public void moveDown(final Path.Node node) {
- path.addNode(node);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void moveUp(Object bean, MetaBean metaBean) {
- NodeImpl leaf = path.getLeafNode();
- if (leaf.isInIterable() && leaf.getName() != null) {
- leaf.setName(null);
- } else {
- path.removeLeafNode();
- }
- super.moveUp(bean, metaBean); // call super!
- }
-
- /**
- * {@inheritDoc} Here, state equates to bean identity + group.
- */
- @SuppressWarnings("unchecked")
- @Override
- public boolean collectValidated() {
-
- // Combination of bean+group+owner (owner is currently ignored)
- GraphBeanIdentity gbi = new GraphBeanIdentity(getBean(), getCurrentGroup().getGroup(), getCurrentOwner());
-
- Set<PathImpl> validatedPathsForGBI = (Set<PathImpl>) validatedObjects.get(gbi);
- if (validatedPathsForGBI == null) {
- validatedPathsForGBI = new HashSet<PathImpl>();
- validatedObjects.put(gbi, validatedPathsForGBI);
- }
-
- // If any of the paths is a subpath of the current path, there is a
- // circular dependency, so return false
- for (PathImpl validatedPath : validatedPathsForGBI) {
- if (path.isSubPathOf(validatedPath)) {
- return false;
- }
- }
-
- // Else, add the currentPath to the set of validatedPaths
- validatedPathsForGBI.add(PathImpl.copy(path));
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean collectValidated(ConstraintValidator<?, ?> constraint) {
- ConstraintValidatorIdentity cvi = new ConstraintValidatorIdentity(getBean(), getPropertyPath(), constraint);
- return this.validatedConstraints.add(cvi);
- }
-
- /**
- * Reset the validated constraints.
- */
- public void resetValidatedConstraints() {
- validatedConstraints.clear();
- }
-
- /**
- * {@inheritDoc} If an associated object is validated, add the association
- * field or JavaBeans property name and a dot ('.') as a prefix to the
- * previous rules. uses prop[index] in property path for elements in
- * to-many-relationships.
- *
- * @return the path in dot notation
- */
- @Override
- public PathImpl getPropertyPath() {
- PathImpl currentPath = PathImpl.copy(path);
- if (getMetaProperty() != null) {
- currentPath.addProperty(getMetaProperty().getName());
- }
- return currentPath;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public MetaBean getRootMetaBean() {
- return rootMetaBean;
- }
-
- /**
- * Set the Groups.
- *
- * @param groups
- */
- public void setGroups(Groups groups) {
- this.groups = groups;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Groups getGroups() {
- return groups;
- }
-
- @Override
- public void setCurrentGroups(final Groups g) {
- groups = g;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Group getCurrentGroup() {
- return currentGroup;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setCurrentGroup(Group currentGroup) {
- this.currentGroup = currentGroup;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setConstraintValidation(ConstraintValidation<?> constraint) {
- constraintValidation = constraint;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ConstraintValidation<?> getConstraintValidation() {
- return constraintValidation;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ConstraintDescriptor<?> getConstraintDescriptor() {
- return constraintValidation;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object getValidatedValue() {
- if (getMetaProperty() != null) {
- return getPropertyValue(constraintValidation.getAccess());
- } else {
- return getBean();
- }
- }
-
- @Override
- public <U> U unwrap(Class<U> type) {
- if (type.isInstance(this)) {
- return type.cast(this);
- }
- throw new ValidationException("Type " + type + " not supported");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public MessageInterpolator getMessageResolver() {
- return messageResolver;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public TraversableResolver getTraversableResolver() {
- return traversableResolver;
- }
-
- @Override
- public ConstraintValidatorFactory getConstraintValidatorFactory() {
- return constraintValidatorFactory;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Class<?> getCurrentOwner() {
- return this.currentOwner;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setCurrentOwner(Class<?> currentOwner) {
- this.currentOwner = currentOwner;
- }
-
- @Override
- public ElementKind getElementKind() {
- return path.getLeafNode().getKind();
- }
-
- @Override
- public Object getReturnValue() {
- return returnValue;
- }
-
- @Override
- public Object[] getParameters() {
- return parameters;
- }
-
- @Override
- public void setParameters(final Object[] parameters) {
- this.parameters = parameters;
- }
-
- @Override
- public void setReturnValue(final Object returnValue) {
- this.returnValue = returnValue;
- }
-
- @Override
- public ParameterNameProvider getParameterNameProvider() {
- return parameterNameProvider;
- }
-
- @Override
- public void setMethod(final Method method) {
- this.method = method;
- }
-
- @Override
- public Method getMethod() {
- return method;
- }
-
- @Override
- public Constructor<?> getConstructor() {
- return constructor;
- }
-
- @Override
- public void setConstructor(final Constructor<?> constructor) {
- this.constructor = constructor;
- }
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/IncompatiblePropertyValueException.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/IncompatiblePropertyValueException.java b/bval-jsr/src/main/java/org/apache/bval/jsr/IncompatiblePropertyValueException.java
deleted file mode 100644
index e94a101..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/IncompatiblePropertyValueException.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.bval.jsr;
-
-import javax.validation.ValidationException;
-
-/**
- * Internal exception thrown when trying to validate a value for a property for which it is not assignment-compatible.
- *
- * @version $Rev: 1031833 $ $Date: 2010-11-05 16:53:03 -0500 (Fri, 05 Nov 2010) $
- *
- * @author Matt Benson
- */
-public class IncompatiblePropertyValueException extends ValidationException {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Create a new {@link IncompatiblePropertyValueException} instance.
- *
- * @param message
- */
- public IncompatiblePropertyValueException(String message) {
- super(message);
- }
-
- /**
- * Create a new IncompatiblePropertyValueException instance.
- */
- public IncompatiblePropertyValueException() {
- super();
- }
-
- /**
- * Create a new IncompatiblePropertyValueException instance.
- *
- * @param message
- * @param cause
- */
- public IncompatiblePropertyValueException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Create a new IncompatiblePropertyValueException instance.
- *
- * @param cause
- */
- public IncompatiblePropertyValueException(Throwable cause) {
- super(cause);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/bval/blob/92c64b3c/bval-jsr/src/main/java/org/apache/bval/jsr/InvocableElementDescriptor.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/InvocableElementDescriptor.java b/bval-jsr/src/main/java/org/apache/bval/jsr/InvocableElementDescriptor.java
deleted file mode 100644
index f54b553..0000000
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/InvocableElementDescriptor.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.bval.jsr;
-
-import org.apache.bval.model.MetaBean;
-import org.apache.bval.model.Validation;
-
-import javax.validation.metadata.ConstraintDescriptor;
-import javax.validation.metadata.CrossParameterDescriptor;
-import javax.validation.metadata.ElementDescriptor;
-import javax.validation.metadata.ParameterDescriptor;
-import javax.validation.metadata.ReturnValueDescriptor;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-public class InvocableElementDescriptor extends ElementDescriptorImpl implements ProcedureDescriptor {
- private static final CopyOnWriteArraySet<ConstraintValidation<?>> NO_CONSTRAINTS =
- new CopyOnWriteArraySet<ConstraintValidation<?>>();
-
- private ReturnValueDescriptor returnValueDescriptor;
- private CrossParameterDescriptor crossParameterDescriptor;
- private final List<ParameterDescriptor> parameterDescriptors = new ArrayList<ParameterDescriptor>();
-
- protected InvocableElementDescriptor(final MetaBean metaBean, final Class<?> elementClass,
- final Validation[] validations) {
- super(metaBean, elementClass, validations);
- }
-
- protected InvocableElementDescriptor(final Class<?> elementClass, final Validation[] validations) {
- super(elementClass, validations);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<ParameterDescriptor> getParameterDescriptors() {
- // index aligned
- return parameterDescriptors;
- }
-
- public void setReturnValueDescriptor(final ReturnValueDescriptor returnValueDescriptor) {
- this.returnValueDescriptor = returnValueDescriptor;
- }
-
- public CrossParameterDescriptor getCrossParameterDescriptor() {
- return crossParameterDescriptor;
- }
-
- public void setCrossParameterDescriptor(final CrossParameterDescriptor crossParameterDescriptor) {
- this.crossParameterDescriptor = crossParameterDescriptor;
- }
-
- /**
- * Add the specified validations to this {@link org.apache.bval.jsr.MethodDescriptorImpl}.
- * @param validations
- */
- void addValidations(Collection<ConstraintValidation<?>> validations) {
- getMutableConstraintDescriptors().addAll(validations);
- }
-
- protected boolean hasConstrainedParameters() {
- for (final ParameterDescriptor pd : getParameterDescriptors()) {
- if (pd.isCascaded() || !pd.getConstraintDescriptors().isEmpty()) {
- return true;
- }
- }
- return getCrossParameterDescriptor().hasConstraints();
- }
-
- public ReturnValueDescriptor getReturnValueDescriptor() {
- return returnValueDescriptor;
- }
-
- protected boolean hasConstrainedReturnValue() {
- return getReturnValueDescriptor().isCascaded()
- || !getReturnValueDescriptor().getConstraintDescriptors().isEmpty();
- }
-
- @Override
- public ElementDescriptor.ConstraintFinder findConstraints() {
- return new ConstraintFinderImpl(metaBean, NO_CONSTRAINTS);
- }
-
- @Override
- public Set<ConstraintDescriptor<?>> getConstraintDescriptors() {
- return Set.class.cast(NO_CONSTRAINTS);
- }
-}