001// Copyright 2009 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014package org.apache.tapestry5.internal.beanvalidator;
015
016import org.apache.tapestry5.beanvalidator.ClientConstraintDescriptor;
017import org.apache.tapestry5.json.JSONObject;
018
019import java.util.Set;
020
021import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newSet;
022
023/**
024 * Describes a single client-side constraint.
025 */
026public abstract class BaseCCD implements ClientConstraintDescriptor
027{
028    private final Class annotationClass;
029
030    private final Set<String> attributes;
031
032    /**
033     * Creates a {@link BaseCCD}.
034     *
035     * @param annotationClass
036     *         Type of the constraint annotation
037     * @param attributes
038     *         Attribute names of the constraint annotation to be passed (along with their values) to the JavaScript validator
039     *         function as an {@link JSONObject}.
040     */
041    public BaseCCD(Class annotationClass, String... attributes)
042    {
043        this.annotationClass = annotationClass;
044        this.attributes = newSet(attributes);
045    }
046
047    /**
048     * Returns the annotation describing the constraint declaration.
049     */
050    @Override
051    public Class getAnnotationClass()
052    {
053        return annotationClass;
054    }
055
056
057    /**
058     * Attribute names of the constraint annotation to be passed (along with their values) to the JavaScript validator
059     * function as an {@link JSONObject}.
060     */
061    @Override
062    public Set<String> getAttributes()
063    {
064        return attributes;
065    }
066}