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. 014 package org.apache.tapestry5.beanvalidator; 015 016 import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newSet; 017 018 import java.util.Set; 019 020 import org.apache.tapestry5.json.JSONObject; 021 022 /** 023 * Describes a single client-side constraint. 024 * 025 */ 026 public final class ClientConstraintDescriptor 027 { 028 private final Class annotationClass; 029 private final String validatorName; 030 private final Set<String> attributes; 031 032 /** 033 * Creates a {@link ClientConstraintDescriptor}. 034 * 035 * @param annotationClass Type of the constraint annotation 036 * @param validatorName Name of the client-side validator 037 * @param attributes Attribute names of the constraint annotation to be passed (along with their values) to the JavaScript validator 038 * function as an {@link JSONObject}. 039 */ 040 public ClientConstraintDescriptor(final Class annotationClass, 041 final String validatorName, final String... attributes) 042 { 043 this.annotationClass = annotationClass; 044 this.validatorName = validatorName; 045 this.attributes = newSet(attributes); 046 } 047 048 /** 049 * Returns the annotation describing the constraint declaration. 050 */ 051 public Class getAnnotationClass() 052 { 053 return this.annotationClass; 054 } 055 056 /** 057 * Returns the name of the client-side validator. 058 */ 059 public String getValidatorName() 060 { 061 return this.validatorName; 062 } 063 064 /** 065 * Attribute names of the constraint annotation to be passed (along with their values) to the JavaScript validator 066 * function as an {@link JSONObject}. 067 */ 068 public Set<String> getAttributes() 069 { 070 return this.attributes; 071 } 072 }