You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by dw...@apache.org on 2010/05/20 20:56:29 UTC
svn commit: r946757 - in
/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303:
Jsr303MetaBeanFactory.java xml/ValidationMappingParser.java
xml/ValidationParser.java
Author: dwoods
Date: Thu May 20 18:56:29 2010
New Revision: 946757
URL: http://svn.apache.org/viewvc?rev=946757&view=rev
Log:
BVAL-53 Several fixes for XML metadata processing impl. Contributed by Carlos Vara.
Modified:
incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java
incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java?rev=946757&r1=946756&r2=946757&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java Thu May 20 18:56:29 2010
@@ -106,60 +106,62 @@ public class Jsr303MetaBeanFactory imple
*/
private void processClass(Class<?> beanClass, MetaBean metabean)
throws IllegalAccessException, InvocationTargetException {
+
+ // if NOT ignore class level annotations
if (!factoryContext.getFactory().getAnnotationIgnores()
- .isIgnoreAnnotations(beanClass)) { // ignore on class level
-
+ .isIgnoreAnnotations(beanClass)) {
processAnnotations(null, beanClass, beanClass, null,
new AppendValidationToMeta(metabean));
+ }
+
+ Field[] fields = beanClass.getDeclaredFields();
+ for (Field field : fields) {
+ MetaProperty metaProperty = metabean.getProperty(field.getName());
+ // create a property for those fields for which there is not yet a MetaProperty
+ if (!factoryContext.getFactory().getAnnotationIgnores()
+ .isIgnoreAnnotations(field)) {
+ if (metaProperty == null) {
+ metaProperty = addMetaProperty(metabean, field.getName(), field.getType());
+ processAnnotations(metaProperty, beanClass, field,
+ new FieldAccess(field),
+ new AppendValidationToMeta(metaProperty));//) {
+ } else {
+ processAnnotations(metaProperty, beanClass, field,
+ new FieldAccess(field),
+ new AppendValidationToMeta(metaProperty));
+ }
+ }
+ }
+ Method[] methods = beanClass.getDeclaredMethods();
+ for (Method method : methods) {
- Field[] fields = beanClass.getDeclaredFields();
- for (Field field : fields) {
- MetaProperty metaProperty = metabean.getProperty(field.getName());
- // create a property for those fields for which there is not yet a MetaProperty
+ String propName = null;
+ if (method.getParameterTypes().length == 0) {
+ propName = MethodAccess.getPropertyName(method);
+ }
+ if (propName != null) {
if (!factoryContext.getFactory().getAnnotationIgnores()
- .isIgnoreAnnotations(field)) {
+ .isIgnoreAnnotations(method)) {
+ MetaProperty metaProperty = metabean.getProperty(propName);
+ // create a property for those methods for which there is not yet a MetaProperty
if (metaProperty == null) {
- metaProperty = addMetaProperty(metabean, field.getName(), field.getType());
- processAnnotations(metaProperty, beanClass, field,
- new FieldAccess(field),
+ metaProperty =
+ addMetaProperty(metabean, propName, method.getReturnType());
+ processAnnotations(metaProperty, beanClass, method,
+ new MethodAccess(propName, method),
new AppendValidationToMeta(metaProperty));//) {
} else {
- processAnnotations(metaProperty, beanClass, field,
- new FieldAccess(field),
+ processAnnotations(metaProperty, beanClass, method,
+ new MethodAccess(propName, method),
new AppendValidationToMeta(metaProperty));
}
}
}
- Method[] methods = beanClass.getDeclaredMethods();
- for (Method method : methods) {
-
- String propName = null;
- if (method.getParameterTypes().length == 0) {
- propName = MethodAccess.getPropertyName(method);
- }
- if (propName != null) {
- if (!factoryContext.getFactory().getAnnotationIgnores()
- .isIgnoreAnnotations(method)) {
- MetaProperty metaProperty = metabean.getProperty(propName);
- // create a property for those methods for which there is not yet a MetaProperty
- if (metaProperty == null) {
- metaProperty =
- addMetaProperty(metabean, propName, method.getReturnType());
- processAnnotations(metaProperty, beanClass, method,
- new MethodAccess(propName, method),
- new AppendValidationToMeta(metaProperty));//) {
- } else {
- processAnnotations(metaProperty, beanClass, method,
- new MethodAccess(propName, method),
- new AppendValidationToMeta(metaProperty));
- }
- }
- }
- else if ( hasValidationConstraintsDefined(method) ) {
- throw new ValidationException("Property " + method.getName() + " does not follow javabean conventions.");
- }
+ else if ( hasValidationConstraintsDefined(method) ) {
+ throw new ValidationException("Property " + method.getName() + " does not follow javabean conventions.");
}
}
+
addXmlConstraints(beanClass, metabean);
}
Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java?rev=946757&r1=946756&r2=946757&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationMappingParser.java Thu May 20 18:56:29 2010
@@ -268,8 +268,8 @@ public class ValidationMappingParser {
if (converter == null && returnType.isEnum()) {
converter = EnumerationConverter.getInstance();
}
-
- return ConvertUtils.convert(value, returnType);
+
+ return converter.convert(returnType, value);
}
private <A extends Annotation> Annotation createAnnotation(AnnotationType annotationType,
Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java?rev=946757&r1=946756&r2=946757&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java Thu May 20 18:56:29 2010
@@ -168,38 +168,44 @@ public class ValidationParser {
private void applyMessageInterpolator(ValidationConfigType xmlConfig,
ConfigurationImpl target) {
String messageInterpolatorClass = xmlConfig.getMessageInterpolator();
- if (messageInterpolatorClass != null) {
- Class<MessageInterpolator> clazz = (Class<MessageInterpolator>) SecureActions
- .loadClass(messageInterpolatorClass, this.getClass());
- target.messageInterpolator(SecureActions.newInstance(clazz));
- if (log.isInfoEnabled())
- log.info("Using " + messageInterpolatorClass + " as message interpolator.");
-
+ if ( target.getMessageInterpolator() == null ) {
+ if (messageInterpolatorClass != null) {
+ Class<MessageInterpolator> clazz = (Class<MessageInterpolator>) SecureActions
+ .loadClass(messageInterpolatorClass, this.getClass());
+ target.messageInterpolator(SecureActions.newInstance(clazz));
+ if (log.isInfoEnabled())
+ log.info("Using " + messageInterpolatorClass + " as message interpolator.");
+
+ }
}
}
private void applyTraversableResolver(ValidationConfigType xmlConfig,
ConfigurationImpl target) {
String traversableResolverClass = xmlConfig.getTraversableResolver();
- if (traversableResolverClass != null) {
- Class<TraversableResolver> clazz = (Class<TraversableResolver>) SecureActions
- .loadClass(traversableResolverClass, this.getClass());
- target.traversableResolver(SecureActions.newInstance(clazz));
- if (log.isInfoEnabled())
- log.info("Using " + traversableResolverClass + " as traversable resolver.");
+ if ( target.getTraversableResolver() == null ) {
+ if (traversableResolverClass != null) {
+ Class<TraversableResolver> clazz = (Class<TraversableResolver>) SecureActions
+ .loadClass(traversableResolverClass, this.getClass());
+ target.traversableResolver(SecureActions.newInstance(clazz));
+ if (log.isInfoEnabled())
+ log.info("Using " + traversableResolverClass + " as traversable resolver.");
+ }
}
}
private void applyConstraintFactory(ValidationConfigType xmlConfig,
ConfigurationImpl target) {
String constraintFactoryClass = xmlConfig.getConstraintValidatorFactory();
- if (constraintFactoryClass != null) {
- Class<ConstraintValidatorFactory> clazz =
- (Class<ConstraintValidatorFactory>) SecureActions
- .loadClass(constraintFactoryClass, this.getClass());
- target.constraintValidatorFactory(SecureActions.newInstance(clazz));
- if (log.isInfoEnabled())
- log.info("Using " + constraintFactoryClass + " as constraint factory.");
+ if ( target.getConstraintValidatorFactory() == null ) {
+ if (constraintFactoryClass != null) {
+ Class<ConstraintValidatorFactory> clazz =
+ (Class<ConstraintValidatorFactory>) SecureActions
+ .loadClass(constraintFactoryClass, this.getClass());
+ target.constraintValidatorFactory(SecureActions.newInstance(clazz));
+ if (log.isInfoEnabled())
+ log.info("Using " + constraintFactoryClass + " as constraint factory.");
+ }
}
}