1 /*
2  * Hibernate Validator, declare and validate application constraints
3  *
4  * License: Apache License, Version 2.0
5  * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
6  */

7 package org.hibernate.validator.internal.metadata.descriptor;
8
9 import java.lang.reflect.Type;
10 import java.util.List;
11 import java.util.Set;
12
13 import javax.validation.metadata.ContainerElementTypeDescriptor;
14 import javax.validation.metadata.GroupConversionDescriptor;
15 import javax.validation.metadata.PropertyDescriptor;
16
17 import org.hibernate.validator.internal.util.CollectionHelper;
18 import org.hibernate.validator.internal.util.stereotypes.Immutable;
19
20 /**
21  * Describes a validated property.
22  *
23  * @author Emmanuel Bernard
24  * @author Hardy Ferentschik
25  * @author Guillaume Smet
26  */

27 public class PropertyDescriptorImpl extends ElementDescriptorImpl implements PropertyDescriptor {
28
29     private final String propertyName;
30
31     @Immutable
32     private final Set<ContainerElementTypeDescriptor> constrainedContainerElementTypes;
33
34     private final boolean cascaded;
35
36     @Immutable
37     private final Set<GroupConversionDescriptor> groupConversions;
38
39     public PropertyDescriptorImpl(Type returnType,
40                                   String propertyName,
41                                   Set<ConstraintDescriptorImpl<?>> constraints,
42                                   Set<ContainerElementTypeDescriptor> constrainedContainerElementTypes,
43                                   boolean cascaded,
44                                   boolean defaultGroupSequenceRedefined,
45                                   List<Class<?>> defaultGroupSequence,
46                                   Set<GroupConversionDescriptor> groupConversions) {
47         super( returnType, constraints, defaultGroupSequenceRedefined, defaultGroupSequence );
48
49         this.propertyName = propertyName;
50         this.constrainedContainerElementTypes = CollectionHelper.toImmutableSet( constrainedContainerElementTypes );
51         this.cascaded = cascaded;
52         this.groupConversions = CollectionHelper.toImmutableSet( groupConversions );
53     }
54
55     @Override
56     public String getPropertyName() {
57         return propertyName;
58     }
59
60     @Override
61     public Set<ContainerElementTypeDescriptor> getConstrainedContainerElementTypes() {
62         return constrainedContainerElementTypes;
63     }
64
65     @Override
66     public boolean isCascaded() {
67         return cascaded;
68     }
69
70     @Override
71     public Set<GroupConversionDescriptor> getGroupConversions() {
72         return groupConversions;
73     }
74
75     @Override
76     public String toString() {
77         final StringBuilder sb = new StringBuilder();
78         sb.append( "PropertyDescriptorImpl" );
79         sb.append( "{propertyName=" ).append( propertyName );
80         sb.append( ", cascaded=" ).append( cascaded );
81         sb.append( '}' );
82         return sb.toString();
83     }
84 }
85