Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * Copyright (C) 2012 FoxLabs
   * 
   * 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 org.foxlabs.validation.constraint;
 
 
This class provides Constraint implementation that performs cascade validation on an entity.

 
 public final class CascadeConstraint<V> extends AbstractValidation<V> implements Constraint<V> {
    
    
The type of entity to be validated.
 
     private final EntityMetaData<V> metadata;
    
    
Constructs a new CascadeConstaint with the specified bean type.

Parameters:
type The type of bean to be validated.
Throws:
java.lang.IllegalArgumentException if the specified type is not a bean.
 
     CascadeConstraint(Class<V> type) {
         this(BeanMetaData.<V>getMetaData(type));
     }
    
    
Constructs a new CascadeConstaint with the specified entity metadata.

Parameters:
metadata Entity metadata.
Throws:
java.lang.IllegalArgumentException if the specified metadata is null.
 
     CascadeConstraint(EntityMetaData<V> metadata) {
         this. = Assert.notNull(metadata"metadata");
     }
    
    
Returns the type of entity to be validated.

Returns:
The type of entity to be validated.
 
     @Override
     public Class<?> getType() {
         return .getType();
     }
    
    
CascadeConstaint has no error message.

Parameters:
context Validation context.
Returns:
null.
 
     @Override
     public String getMessageTemplate(ValidationContext<?> context) {
         return null;
     }
    
    
Performs cascade validation on the specified entity.

Parameters:
value Entity to be validated.
context Validation context.
Returns:
Possibly modified entity.
Throws:
ConstraintViolationException if cascade validation fails.
 
     @Override
     public <T> V validate(V valueValidationContext<T> context) {
         try {
             return context.getValidator()
                          .getFactory()
                          .newValidator(context.getValidator())
                          .newContext(context)
                          .validateEntity(value);
        } catch (ValidationException e) {
            throw new ConstraintViolationException(thiscontextvaluee);
        }
    }
    
New to GrepCode? Check out our FAQ X