Author: hardy.ferentschik
Date: 2010-05-25 16:30:50 -0400 (Tue, 25 May 2010)
New Revision: 19608
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefAccessor.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDef.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintMapping.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java
Log:
HV-274 added an additional indirection in order to only have configuration methods in the
XYZDef classes
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDef.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDef.java 2010-05-25
19:07:43 UTC (rev 19607)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDef.java 2010-05-25
20:30:50 UTC (rev 19608)
@@ -30,14 +30,18 @@
* @author Hardy Ferentschik
*/
public class ConstraintDef<A extends Annotation> {
- private final Class<A> constraintType;
- private final Map<String, Object> parameters;
- private final Class<?> beanType;
- private final ElementType elementType;
- private final String property;
- private final ConstraintMapping mapping;
+ protected final Class<A> constraintType;
+ protected final Map<String, Object> parameters;
+ protected final Class<?> beanType;
+ protected final ElementType elementType;
+ protected final String property;
+ protected final ConstraintMapping mapping;
public ConstraintDef(Class<?> beanType, Class<A> constraintType, String
property, ElementType elementType, ConstraintMapping mapping) {
+ this( beanType, constraintType, property, elementType, new HashMap<String,
Object>(), mapping );
+ }
+
+ protected ConstraintDef(Class<?> beanType, Class<A> constraintType, String
property, ElementType elementType, Map<String, Object> parameters, ConstraintMapping
mapping) {
if ( beanType == null ) {
throw new ValidationException( "Null is not a valid bean type" );
}
@@ -65,7 +69,7 @@
this.beanType = beanType;
this.constraintType = constraintType;
- this.parameters = new HashMap<String, Object>();
+ this.parameters = parameters;
this.property = property;
this.elementType = elementType;
this.mapping = mapping;
@@ -77,7 +81,6 @@
}
public <A extends Annotation, T extends ConstraintDef<A>> T
constraint(Class<T> definition) {
-
final Constructor<T> constructor = ReflectionHelper.getConstructor(
definition, Class.class, String.class, ElementType.class, ConstraintMapping.class
);
@@ -103,30 +106,10 @@
return new ConstraintsForType( beanType, mapping );
}
- public Class<A> getConstraintType() {
- return constraintType;
- }
-
- public Map<String, Object> getParameters() {
- return parameters;
- }
-
- public ElementType getElementType() {
- return elementType;
- }
-
- public Class<?> getBeanType() {
- return beanType;
- }
-
- public String getProperty() {
- return property;
- }
-
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
- sb.append( "ConstraintDefinition" );
+ sb.append( this.getClass().getName() );
sb.append( "{beanType=" ).append( beanType );
sb.append( ", constraintType=" ).append( constraintType );
sb.append( ", parameters=" ).append( parameters );
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefAccessor.java
(from rev 19606,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDef.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefAccessor.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefAccessor.java 2010-05-25
20:30:50 UTC (rev 19608)
@@ -0,0 +1,52 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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 org.hibernate.validator.cfg;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.util.Map;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConstraintDefAccessor<A extends Annotation> extends
ConstraintDef<A> {
+
+ public ConstraintDefAccessor(Class<?> beanType, Class<A> constraintType,
String property, ElementType elementType, Map<String, Object> parameters,
ConstraintMapping mapping) {
+ super( beanType, constraintType, property, elementType, parameters, mapping );
+ }
+
+ public Class<A> getConstraintType() {
+ return constraintType;
+ }
+
+ public Map<String, Object> getParameters() {
+ return this.parameters;
+ }
+
+ public ElementType getElementType() {
+ return elementType;
+ }
+
+ public Class<?> getBeanType() {
+ return beanType;
+ }
+
+ public String getProperty() {
+ return property;
+ }
+}
\ No newline at end of file
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintDefAccessor.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintMapping.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintMapping.java 2010-05-25
19:07:43 UTC (rev 19607)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/ConstraintMapping.java 2010-05-25
20:30:50 UTC (rev 19608)
@@ -17,6 +17,7 @@
*/
package org.hibernate.validator.cfg;
+import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -32,13 +33,13 @@
* @author Hardy Ferentschik
*/
public class ConstraintMapping {
- private final Map<Class<?>, List<ConstraintDef<?>>>
constraintConfig;
+ private final Map<Class<?>, List<ConstraintDefAccessor<?>>>
constraintConfig;
private final Map<Class<?>, List<CascadeDef>> cascadeConfig;
private final Set<Class<?>> configuredClasses;
private final Map<Class<?>, List<Class<?>>>
defaultGroupSequences;
public ConstraintMapping() {
- this.constraintConfig = new HashMap<Class<?>,
List<ConstraintDef<?>>>();
+ this.constraintConfig = new HashMap<Class<?>,
List<ConstraintDefAccessor<?>>>();
this.cascadeConfig = new HashMap<Class<?>, List<CascadeDef>>();
this.configuredClasses = new HashSet<Class<?>>();
this.defaultGroupSequences = new HashMap<Class<?>,
List<Class<?>>>();
@@ -48,15 +49,24 @@
return new ConstraintsForType( beanClass, this );
}
- protected void addConstraintConfig(ConstraintDef<?> definition) {
- Class<?> beanClass = definition.getBeanType();
+ protected <A extends Annotation> void addConstraintConfig(ConstraintDef<?>
definition) {
+ Class<?> beanClass = definition.beanType;
+ ConstraintDefAccessor<A> defAccessor = new ConstraintDefAccessor<A>(
+ beanClass,
+ ( Class<A> ) definition.constraintType,
+ definition.property,
+ definition.elementType,
+ definition.parameters,
+ this
+ );
+
configuredClasses.add( beanClass );
if ( constraintConfig.containsKey( beanClass ) ) {
- constraintConfig.get( beanClass ).add( definition );
+ constraintConfig.get( beanClass ).add( defAccessor );
}
else {
- List<ConstraintDef<?>> definitionList = new
ArrayList<ConstraintDef<?>>();
- definitionList.add( definition );
+ List<ConstraintDefAccessor<?>> definitionList = new
ArrayList<ConstraintDefAccessor<?>>();
+ definitionList.add( defAccessor );
constraintConfig.put( beanClass, definitionList );
}
}
@@ -78,7 +88,7 @@
defaultGroupSequences.put( beanClass, defaultGroupSequence );
}
- public Map<Class<?>, List<ConstraintDef<?>>>
getConstraintConfig() {
+ public Map<Class<?>, List<ConstraintDefAccessor<?>>>
getConstraintConfig() {
return constraintConfig;
}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java 2010-05-25
19:07:43 UTC (rev 19607)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ValidatorFactoryImpl.java 2010-05-25
20:30:50 UTC (rev 19608)
@@ -35,7 +35,7 @@
import javax.validation.spi.ConfigurationState;
import org.hibernate.validator.cfg.CascadeDef;
-import org.hibernate.validator.cfg.ConstraintDef;
+import org.hibernate.validator.cfg.ConstraintDefAccessor;
import org.hibernate.validator.cfg.ConstraintMapping;
import org.hibernate.validator.metadata.AnnotationIgnores;
import org.hibernate.validator.metadata.BeanMetaDataCache;
@@ -228,10 +228,10 @@
}
@SuppressWarnings("unchecked")
- private <T, A extends Annotation> void
addProgrammaticConfiguredConstraints(List<ConstraintDef<?>> definitions,
+ private <T, A extends Annotation> void
addProgrammaticConfiguredConstraints(List<ConstraintDefAccessor<?>>
definitions,
Class<T> rootClass, Class<?> hierarchyClass,
Map<Class<?>, List<MetaConstraint<T, ?>>>
constraints) {
- for ( ConstraintDef<?> config : definitions ) {
+ for ( ConstraintDefAccessor<?> config : definitions ) {
A annotation = ( A ) createAnnotationProxy( config );
ConstraintOrigin definedIn = definedIn( rootClass, hierarchyClass );
ConstraintDescriptorImpl<A> constraintDescriptor = new
ConstraintDescriptorImpl<A>(
@@ -299,7 +299,7 @@
}
@SuppressWarnings("unchecked")
- private <A extends Annotation> Annotation
createAnnotationProxy(ConstraintDef<?> config) {
+ private <A extends Annotation> Annotation
createAnnotationProxy(ConstraintDefAccessor<?> config) {
Class<A> constraintType = ( Class<A> ) config.getConstraintType();
AnnotationDescriptor<A> annotationDescriptor = new AnnotationDescriptor<A>(
constraintType );
for ( Map.Entry<String, Object> parameter : config.getParameters().entrySet() )
{