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

javax.validation.metadata.ElementDescriptor Maven / Gradle / Ivy

There is a newer version: 2.0.1.Final
Show newest version
// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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 javax.validation.metadata;

import java.util.Set;
import java.lang.annotation.ElementType;

/**
 * Describes a validated element (class, property, method etc.).
 *
 * @author Emmanuel Bernard
 * @author Hardy Ferentschik
 * @author Gunnar Morling
 */
public interface ElementDescriptor {

	/**
	 * The kind of an {@link ElementDescriptor}.
	 *
	 * @author Gunnar Morling
	 */
	public enum Kind {

		/**
		 * A Java Bean.
		 */
		BEAN,

		/**
		 * A property of a Java Bean.
		 */
		PROPERTY,

		/**
		 * A method.
		 */
		METHOD,

		/**
		 * A constructor.
		 */
		CONSTRUCTOR,

		/**
		 * A parameter of a method or constructor.
		 */
		PARAMETER,

		/**
		 * The return value of a method or constructor.
		 */
		RETURN_VALUE;
	}

    /**
     * @return Return {@code true} if at least one constraint declaration is present
     * for this element in the class hierarchy, {@code false} otherwise.
     */
    boolean hasConstraints();

    /**
     * @return Statically defined returned type.
     */
    Class getElementClass();

    /**
     * Return all constraint descriptors for this element in the class hierarchy
     * or an empty Set if none are present.
     *
     * @return Set of constraint descriptors for this element
     */
    Set> getConstraintDescriptors();

    /**
     * Find constraints and potentially restricts them to certain criteria.
     *
     * @return ConstraintFinder object.
     */
    ConstraintFinder findConstraints();

    /**
     * Returns the kind of this descriptor.
     * @return The kind of this descriptor.
     */
    Kind getKind();

    /**
     * Narrows the type of this descriptor down to the given type. The type
     * should be checked before by calling {@link ElementDescriptor#getKind()}.
     *
     * @param 
     *            The type to narrow down to.
     * @param descriptorType
     *            Class object representing the descriptor type to narrow down
     *            to.
     *
     * @return This descriptor narrowed down to the given type.
     *
     * @throws ClassCastException
     *             If this descriptor is not assignable to the type
     *             T.
     */
     T as(Class descriptorType);

    /**
     * Declare restrictions on retrieved constraints.
     * Restrictions are cumulative.
     *
     * A ConstraintFinder is not thread-safe. The set of matching
     * ConstraintDescriptor is.
     */
    interface ConstraintFinder {
        /**
         * Restrict to the constraints matching a given set of groups for this element
         *
         * This method respects group sequences and group inheritance (including
         * class-level Default group overriding) but does not return
         * ConstraintDescriptors in any particular order.
         * Specifically, ordering of the group sequence is not respected.
         *
         * @param groups groups targeted
         *
         * @return this following the chaining method pattern
         */
        ConstraintFinder unorderedAndMatchingGroups(Class... groups);

        /**
         * Restrict to the constraints matching the provided scope for this element.
         *
         * Defaults to Scope.HIERARCHY
         *
         * @param scope expected scope
         * @return this following the chaining method pattern
         */
        ConstraintFinder lookingAt(Scope scope);

        /**
         * Restrict to the constraints hosted on the listed types
         * for a given element.
         *
         * Default to all possible types of the element.
         *
         * Typically used to restrict to fields (FIELD)
         * or getters (METHOD)
         *
         * @param types targeted types
         * @return this following the chaining method pattern
         */
        ConstraintFinder declaredOn(ElementType... types);

        /**
         * Retrieve the constraint descriptors following the defined
         * restrictions and hosted on the element described by
         * ElementDescriptor
         *
         * @return matching constraint descriptors
         */
        Set> getConstraintDescriptors();

        /**
         * Returns true if at least one constraint declaration
         * matching the restrictions is present on the element,
         * false otherwise.
         *
         * @return is there any constraint
         */
        boolean hasConstraints();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy