All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.anteros.bean.validation.ElementDescriptorImpl Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
/*******************************************************************************
 * 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 java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import br.com.anteros.bean.validation.model.MetaBean;
import br.com.anteros.bean.validation.model.Validation;
import br.com.anteros.validation.api.metadata.ConstraintDescriptor;
import br.com.anteros.validation.api.metadata.ElementDescriptor;

/**
 * Description: MetaData class
*/ public abstract class ElementDescriptorImpl implements ElementDescriptor { /** * Get a set of {@link ConstraintDescriptor}s from the specified array of * {@link Validation}s. * * @param validations * @return {@link ConstraintDescriptor} set */ protected static Set> getConstraintDescriptors(Validation[] validations) { final Set> result = new HashSet>(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> constraintDescriptors; /** * 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. */ public Class getElementClass() { return elementClass; } /** * {@inheritDoc} */ @SuppressWarnings({"unchecked", "rawtypes"}) public ElementDescriptor.ConstraintFinder findConstraints() { return new ConstraintFinderImpl(metaBean, new HashSet((Set) constraintDescriptors)); } /** * {@inheritDoc} */ public Set> getConstraintDescriptors() { return constraintDescriptors.isEmpty() ? Collections.> emptySet() : Collections .unmodifiableSet(constraintDescriptors); } /** * Get the mutable {@link ConstraintDescriptor} {@link Set}. * * @return Set of {@link ConstraintDescriptor} */ protected Set> getMutableConstraintDescriptors() { return constraintDescriptors; } /** * {@inheritDoc} return true if at least one constraint declaration is * present on the element. */ public boolean hasConstraints() { return !getConstraintDescriptors().isEmpty(); } /** * Set the constraintDescriptors for this element. * * @param constraintDescriptors * to set */ public void setConstraintDescriptors(Set> constraintDescriptors) { this.constraintDescriptors = constraintDescriptors; } /** * Get the model {@link MetaBean} used. * * @return MetaBean */ public MetaBean getMetaBean() { return metaBean; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy