Author: epbernard
Date: 2008-10-31 15:01:01 -0400 (Fri, 31 Oct 2008)
New Revision: 15477
Added:
validator/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java
validator/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProvider.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ElementDescriptorImpl.java
validator/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java
validator/trunk/validation-api/src/main/java/javax/validation/Validator.java
Log:
BVAL-46 split Elementdescriptor into BeanDescriptor and PropertyDescriptor
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProvider.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProvider.java 2008-10-31
18:13:28 UTC (rev 15476)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProvider.java 2008-10-31
19:01:01 UTC (rev 15477)
@@ -23,6 +23,8 @@
import java.util.List;
import java.util.Map;
import javax.validation.ElementDescriptor;
+import javax.validation.BeanDescriptor;
+import javax.validation.PropertyDescriptor;
/**
* Interface defining the meta data about the constraints defined in a given bean.
@@ -39,7 +41,7 @@
/**
* @return an instance of <code>ElementDescriptor</code> describing the bean
this meta data applies for.
*/
- ElementDescriptor getBeanDescriptor();
+ BeanDescriptor getBeanDescriptor();
/**
* @return A list of all cascaded fields (fields annotated with @Valid).
@@ -73,7 +75,7 @@
* @todo Maybe needs to be removed since this data structure is ambigious. There could
be conflicts between field and
* methods.
*/
- Map<String, ElementDescriptor> getPropertyDescriptors();
+ Map<String, PropertyDescriptor> getPropertyDescriptors();
ElementDescriptor getPropertyDescriptors(String property);
}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java 2008-10-31
18:13:28 UTC (rev 15476)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaDataProviderImpl.java 2008-10-31
19:01:01 UTC (rev 15477)
@@ -26,12 +26,13 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.validation.BeanDescriptor;
import javax.validation.Constraint;
import javax.validation.ConstraintFactory;
import javax.validation.ConstraintValidator;
-import javax.validation.ElementDescriptor;
import javax.validation.GroupSequence;
import javax.validation.GroupSequences;
+import javax.validation.PropertyDescriptor;
import javax.validation.Valid;
import javax.validation.ValidationException;
@@ -84,7 +85,7 @@
* Maps field and method names to their <code>ElementDescriptorImpl</code>.
* FIXME This model is problematic as you can have conflicting names for fields and
methods
*/
- private Map<String, ElementDescriptor> propertyDescriptors = new
HashMap<String, ElementDescriptor>();
+ private Map<String, PropertyDescriptor> propertyDescriptors = new
HashMap<String, PropertyDescriptor>();
/**
* Factory to create acutal constraint instances from the annotated
fields/method/class.
@@ -392,7 +393,7 @@
return beanClass;
}
- public ElementDescriptor getBeanDescriptor() {
+ public BeanDescriptor getBeanDescriptor() {
return beanDescriptor;
}
@@ -419,11 +420,11 @@
return metaConstraintList;
}
- public Map<String, ElementDescriptor> getPropertyDescriptors() {
+ public Map<String, PropertyDescriptor> getPropertyDescriptors() {
return propertyDescriptors;
}
- public ElementDescriptor getPropertyDescriptors(String property) {
+ public PropertyDescriptor getPropertyDescriptors(String property) {
return propertyDescriptors.get( property );
}
}
\ No newline at end of file
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2008-10-31
18:13:28 UTC (rev 15476)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java 2008-10-31
19:01:01 UTC (rev 15477)
@@ -34,6 +34,8 @@
import javax.validation.ConstraintViolation;
import javax.validation.MessageResolver;
import javax.validation.Validator;
+import javax.validation.PropertyDescriptor;
+import javax.validation.BeanDescriptor;
import org.hibernate.validation.Version;
import org.hibernate.validation.ValidatorConstants;
@@ -505,18 +507,17 @@
return metaDataProvider.getConstraintMetaDataList().size() > 0;
}
- public ElementDescriptor getConstraintsForBean() {
+ public BeanDescriptor getConstraintsForBean() {
return metaDataProvider.getBeanDescriptor();
}
- public ElementDescriptor getConstraintsForProperty(String propertyName) {
+ public PropertyDescriptor getConstraintsForProperty(String propertyName) {
return metaDataProvider.getPropertyDescriptors().get( propertyName );
}
- public String[] getValidatedProperties() {
- return metaDataProvider.getPropertyDescriptors()
- .keySet()
- .toArray( new String[metaDataProvider.getPropertyDescriptors().size()] );
+ public Set<String> getValidatedProperties() {
+ return Collections.unmodifiableSet( metaDataProvider.getPropertyDescriptors()
+ .keySet() );
}
public MetaDataProvider<T> getMetaDataProvider() {
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ElementDescriptorImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ElementDescriptorImpl.java 2008-10-31
18:13:28 UTC (rev 15476)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ElementDescriptorImpl.java 2008-10-31
19:01:01 UTC (rev 15477)
@@ -23,6 +23,8 @@
import java.util.List;
import javax.validation.ConstraintDescriptor;
import javax.validation.ElementDescriptor;
+import javax.validation.BeanDescriptor;
+import javax.validation.PropertyDescriptor;
/**
* Describe a validated element (class, field or property).
@@ -32,7 +34,8 @@
* @todo Should returnType be renamed to type?
* @todo Handle problem in descirbing cyclic dependecies for propertyPath
*/
-public class ElementDescriptorImpl implements ElementDescriptor {
+//FIXME I implement both interfaces on the same object as a quick hack, we need to fix
that.
+public class ElementDescriptorImpl implements PropertyDescriptor, BeanDescriptor {
private final Class returnType;
private final boolean cascaded;
private final List<ConstraintDescriptor> constraintDescriptors = new
ArrayList<ConstraintDescriptor>();
@@ -75,7 +78,7 @@
/**
* {@inheritDoc}
*/
- public String getPropertyPath() {
+ public String getPropertyName() {
return propertyPath;
}
}
Added: validator/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java
(rev 0)
+++
validator/trunk/validation-api/src/main/java/javax/validation/BeanDescriptor.java 2008-10-31
19:01:01 UTC (rev 15477)
@@ -0,0 +1,9 @@
+package javax.validation;
+
+/**
+ * Describe a constrained Java Bean and the constraints associated to it.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface BeanDescriptor extends ElementDescriptor {
+}
Modified:
validator/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java 2008-10-31
18:13:28 UTC (rev 15476)
+++
validator/trunk/validation-api/src/main/java/javax/validation/ElementDescriptor.java 2008-10-31
19:01:01 UTC (rev 15477)
@@ -33,23 +33,11 @@
*
* @todo should it be Type or even completly removed
*/
- Class getType();
+ Class<?> getType();
/**
- * @return Returns <code>true</code> if the association is cascaded,
<code>false</code> otherwise.
- */
- boolean isCascaded();
-
- /**
* @return All the constraint descriptors for this element.
*/
List<ConstraintDescriptor> getConstraintDescriptors();
- /**
- * @return Property path from the root entity validated.
- *
- * @todo there is a problem in describing cyclic dependencies
- */
- String getPropertyPath();
-
}
Added:
validator/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java
(rev 0)
+++
validator/trunk/validation-api/src/main/java/javax/validation/PropertyDescriptor.java 2008-10-31
19:01:01 UTC (rev 15477)
@@ -0,0 +1,23 @@
+package javax.validation;
+
+/**
+ * Describes a Java Bean property hosting validation constraints.
+ *
+ * Constraints placed on the attribute and the getter for a given property
+ * are all referenced by this object.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface PropertyDescriptor extends ElementDescriptor {
+ /**
+ * Is the property marked by the <code>@Valid</code> annotation.
+ * @return true if the annotation is present
+ */
+ boolean isCascaded();
+
+ /**
+ * Name of the property acording to the Java Bean specification.
+ * @return property name
+ */
+ String getPropertyName();
+}
\ No newline at end of file
Modified: validator/trunk/validation-api/src/main/java/javax/validation/Validator.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/Validator.java 2008-10-31
18:13:28 UTC (rev 15476)
+++
validator/trunk/validation-api/src/main/java/javax/validation/Validator.java 2008-10-31
19:01:01 UTC (rev 15477)
@@ -76,17 +76,17 @@
/**
* return the class level constraints
*/
- ElementDescriptor getConstraintsForBean();
+ BeanDescriptor getConstraintsForBean();
/**
* return the property level constraints for a given propertyName
* or null if either the property does not exist or has no constraint
*/
- ElementDescriptor getConstraintsForProperty(String propertyName);
+ PropertyDescriptor getConstraintsForProperty(String propertyName);
/**
* return the property names having at least a constraint defined
*/
- String[] getValidatedProperties();
+ Set<String> getValidatedProperties();
}