de.smartics.properties.spi.core.constraint.jsr303
Class GenericPropertyConstraint<A extends Annotation,T>

Package class diagram package GenericPropertyConstraint
java.lang.Object
  extended by de.smartics.properties.spi.core.constraint.AbstractPropertyConstraint<T>
      extended by de.smartics.properties.spi.core.constraint.jsr303.GenericPropertyConstraint<A,T>
Type Parameters:
A - the constraint annotation.
T - the type of the property that is validated.
All Implemented Interfaces:
PropertyConstraint<T>, Serializable

public class GenericPropertyConstraint<A extends Annotation,T>
     
     
extends AbstractPropertyConstraint<T>

Generic wrapper for JSR-303 constraints.

See Also:
Serialized Form

Constructor Summary
GenericPropertyConstraint(A constraintAnnotation, Class<?> propertyType)
          Convenience constructor if the validator can be derived from the constraintAnnotation.
GenericPropertyConstraint(javax.validation.ConstraintValidator<A,T> validator, A constraintAnnotation)
          Default constructor.
 
Method Summary
 String getDescription(Locale locale)
          Returns a localized description of the defined constraints.
 String getViolationMessage(Locale locale, Object actualValue)
          Returns a localized description of the violation message adding the actual value.
 boolean isMandatoryConstraint()
          Determines if the constraint is a check that evaluates if a property is present or not and fails if a value is not present.
 boolean isValid(T value, Class<?> group)
          Checks if the given value is valid only if the constraint is in the given group.
 
Methods inherited from class de.smartics.properties.spi.core.constraint.AbstractPropertyConstraint
getDescription, isValid, toString, validate, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GenericPropertyConstraint

public GenericPropertyConstraint(A constraintAnnotation,
                                 Class<?> propertyType)
                          throws de.smartics.util.lang.NullArgumentException
Convenience constructor if the validator can be derived from the constraintAnnotation.

Parameters:
constraintAnnotation - the JSR-303 constraint annotation.
propertyType - the type of the property selects the validator if more than on validator is referenced by the constraint annotation.
Throws:
de.smartics.util.lang.NullArgumentException - if constraintAnnotation is null.

GenericPropertyConstraint

public GenericPropertyConstraint(javax.validation.ConstraintValidator<A,T> validator,
                                 A constraintAnnotation)
                          throws de.smartics.util.lang.NullArgumentException
Default constructor.

Parameters:
validator - the validator to validate values.
constraintAnnotation - the JSR-303 constraint annotation.
Throws:
de.smartics.util.lang.NullArgumentException - if either validator or constraintAnnotation is null.
Method Detail

getDescription

public String getDescription(Locale locale)
Returns a localized description of the defined constraints.

Override to provide more specific information the the string representation of the constraint annotation.

Parameters:
locale - the locale to use to fetch a localized description.
See Also:
PropertyConstraint.getDescription(java.util.Locale)
Returns:
a localized description of the defined constraints.

getViolationMessage

public String getViolationMessage(Locale locale,
                                  Object actualValue)
Description copied from interface: PropertyConstraint
Returns a localized description of the violation message adding the actual value.

Specified by:
getViolationMessage in interface PropertyConstraint<T>
Overrides:
getViolationMessage in class AbstractPropertyConstraint<T>
Parameters:
locale - the locale to use for the message.
actualValue - the value that has violated the constraint.
Returns:
a localized description of violation message.

isValid

public final boolean isValid(T value,
                             Class<?> group)
Description copied from interface: PropertyConstraint
Checks if the given value is valid only if the constraint is in the given group.

Parameters:
value - the value to be checked.
group - the validation only takes place if this constraint is in this group or the argument is null.
Returns:
true if the value is valid, false otherwise.

isMandatoryConstraint

public final boolean isMandatoryConstraint()
Description copied from interface: PropertyConstraint
Determines if the constraint is a check that evaluates if a property is present or not and fails if a value is not present.

Specified by:
isMandatoryConstraint in interface PropertyConstraint<T>
Overrides:
isMandatoryConstraint in class AbstractPropertyConstraint<T>
Returns:
true if the constraint is a check for value presence, false if it is any regular constraint.


Copyright © 2012-2013 Kronseder & Reiner GmbH - smartics. All Rights Reserved.