Return-Path: Delivered-To: apmail-incubator-bval-commits-archive@minotaur.apache.org Received: (qmail 92251 invoked from network); 2 Sep 2010 23:04:20 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Sep 2010 23:04:20 -0000 Received: (qmail 48119 invoked by uid 500); 2 Sep 2010 23:04:20 -0000 Delivered-To: apmail-incubator-bval-commits-archive@incubator.apache.org Received: (qmail 48092 invoked by uid 500); 2 Sep 2010 23:04:20 -0000 Mailing-List: contact bval-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: bval-dev@incubator.apache.org Delivered-To: mailing list bval-commits@incubator.apache.org Received: (qmail 48085 invoked by uid 99); 2 Sep 2010 23:04:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Sep 2010 23:04:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Sep 2010 23:04:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AEA9223888EA; Thu, 2 Sep 2010 23:03:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r992148 - in /incubator/bval/sandbox/lang3-work: ./ bval-core/ bval-core/src/main/java/org/apache/bval/ bval-core/src/main/java/org/apache/bval/model/ bval-json/src/main/resources/org/apache/bval/json/ bval-jsr303/ bval-jsr303/src/main/java... Date: Thu, 02 Sep 2010 23:03:55 -0000 To: bval-commits@incubator.apache.org From: mbenson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100902230355.AEA9223888EA@eris.apache.org> Author: mbenson Date: Thu Sep 2 23:03:55 2010 New Revision: 992148 URL: http://svn.apache.org/viewvc?rev=992148&view=rev Log: MetaProperty.type is a type; typeClass still returns a class Modified: incubator/bval/sandbox/lang3-work/ (props changed) incubator/bval/sandbox/lang3-work/bval-core/pom.xml incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/IntrospectorMetaBeanFactory.java incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/model/MetaProperty.java incubator/bval/sandbox/lang3-work/bval-json/src/main/resources/org/apache/bval/json/bean-infos-json.ftl incubator/bval/sandbox/lang3-work/bval-jsr303/pom.xml incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java incubator/bval/sandbox/lang3-work/pom.xml Propchange: incubator/bval/sandbox/lang3-work/ ------------------------------------------------------------------------------ svn:mergeinfo = /incubator/bval/trunk:992143 Modified: incubator/bval/sandbox/lang3-work/bval-core/pom.xml URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-core/pom.xml?rev=992148&r1=992147&r2=992148&view=diff ============================================================================== --- incubator/bval/sandbox/lang3-work/bval-core/pom.xml (original) +++ incubator/bval/sandbox/lang3-work/bval-core/pom.xml Thu Sep 2 23:03:55 2010 @@ -42,6 +42,10 @@ commons-lang + org.apache.commons + commons-lang3 + + commons-logging commons-logging Modified: incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/IntrospectorMetaBeanFactory.java URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/IntrospectorMetaBeanFactory.java?rev=992148&r1=992147&r2=992148&view=diff ============================================================================== --- incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/IntrospectorMetaBeanFactory.java (original) +++ incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/IntrospectorMetaBeanFactory.java Thu Sep 2 23:03:55 2010 @@ -22,6 +22,8 @@ import org.apache.bval.model.MetaPropert import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; +import java.lang.reflect.Type; import java.util.Enumeration; import static org.apache.bval.model.Features.Property.*; @@ -61,7 +63,7 @@ public final class IntrospectorMetaBeanF protected MetaProperty buildMetaProperty(PropertyDescriptor pd) { MetaProperty meta = new MetaProperty(); meta.setName(pd.getName()); - meta.setType(pd.getPropertyType()); + meta.setType(determineGenericPropertyType(pd)); if (pd.isHidden()) meta.putFeature(HIDDEN, Boolean.TRUE); if (pd.isPreferred()) meta.putFeature(PREFERRED, Boolean.TRUE); if (pd.isConstrained()) meta.putFeature(READONLY, Boolean.TRUE); @@ -74,4 +76,16 @@ public final class IntrospectorMetaBeanF } return meta; } + + private Type determineGenericPropertyType(PropertyDescriptor pd) { + Method m = pd.getReadMethod(); + if (m != null) { + return m.getGenericReturnType(); + } + m = pd.getWriteMethod(); + if (m != null && m.getParameterTypes().length == 1) { + return m.getGenericParameterTypes()[0]; + } + return pd.getPropertyType(); + } } Modified: incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/model/MetaProperty.java URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/model/MetaProperty.java?rev=992148&r1=992147&r2=992148&view=diff ============================================================================== --- incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/model/MetaProperty.java (original) +++ incubator/bval/sandbox/lang3-work/bval-core/src/main/java/org/apache/bval/model/MetaProperty.java Thu Sep 2 23:03:55 2010 @@ -16,9 +16,10 @@ */ package org.apache.bval.model; -import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import org.apache.commons.lang3.reflect.TypeUtils; + /** * Description: the meta description of a property of a bean. It supports a map * of features and multiple validations.
@@ -104,20 +105,14 @@ public class MetaProperty extends Featur * @return Class, null if cannot be determined */ public Class getTypeClass() { - return getTypeClass(type); - } - - //TODO can this handle variables? Perhaps move TypeUtils up from bval-jsr303 - private static Class getTypeClass(Type rawType) { - if (rawType instanceof Class) { - return (Class) rawType; - } else if (rawType instanceof ParameterizedType) { - return getTypeClass(((ParameterizedType) rawType).getRawType()); // recursion! - } else if(rawType instanceof DynaType) { - return getTypeClass(((DynaType)rawType).getRawType()); // recursion - } else { - return null; // class cannot be determined! + Type targetType = type instanceof DynaType ? ((DynaType) type) + .getRawType() : type; + if (targetType == null) { + return null; } + Type assigningType = getParentMetaBean() == null ? null + : getParentMetaBean().getBeanClass(); + return TypeUtils.getRawType(targetType, assigningType); } /** @@ -177,4 +172,5 @@ public class MetaProperty extends Featur public String toString() { return "MetaProperty{" + "name='" + name + '\'' + ", type=" + type + '}'; } + } Modified: incubator/bval/sandbox/lang3-work/bval-json/src/main/resources/org/apache/bval/json/bean-infos-json.ftl URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-json/src/main/resources/org/apache/bval/json/bean-infos-json.ftl?rev=992148&r1=992147&r2=992148&view=diff ============================================================================== --- incubator/bval/sandbox/lang3-work/bval-json/src/main/resources/org/apache/bval/json/bean-infos-json.ftl (original) +++ incubator/bval/sandbox/lang3-work/bval-json/src/main/resources/org/apache/bval/json/bean-infos-json.ftl Thu Sep 2 23:03:55 2010 @@ -48,9 +48,10 @@ var metaBean${var} = { <#list metaBean.properties as property> "${property.name}":{ "name" : "${property.name}", - <#if property.type??>"type" : "${property.type.name}", + <#if property.type??>"type" : "${property.type}", + <#if property.typeClass??>"typeClass" : "${property.typeClass.name}", "features" : {<#if property.type?? && - property.type.enum>"enum" : {<#list property.type.enumConstants as enum>"${enum.name()}": "${enum.name()}"<#if enum_has_next>, }<#if property.features?size > 0>,<#list + property.type.enum!false>"enum" : {<#list property.type.enumConstants as enum>"${enum.name()}": "${enum.name()}"<#if enum_has_next>, }<#if property.features?size > 0>,<#list property.features?keys as featureKey> <#assign value = property.features[featureKey]> "${featureKey}" : <#rt/><#if Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/pom.xml URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/pom.xml?rev=992148&r1=992147&r2=992148&view=diff ============================================================================== --- incubator/bval/sandbox/lang3-work/bval-jsr303/pom.xml (original) +++ incubator/bval/sandbox/lang3-work/bval-jsr303/pom.xml Thu Sep 2 23:03:55 2010 @@ -108,6 +108,10 @@ commons-logging + org.apache.commons + commons-lang3 + + junit junit test Modified: incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java?rev=992148&r1=992147&r2=992148&view=diff ============================================================================== --- incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java (original) +++ incubator/bval/sandbox/lang3-work/bval-jsr303/src/main/java/org/apache/bval/jsr303/Jsr303MetaBeanFactory.java Thu Sep 2 23:03:55 2010 @@ -129,7 +129,7 @@ public class Jsr303MetaBeanFactory imple if (!factoryContext.getFactory().getAnnotationIgnores() .isIgnoreAnnotations(field)) { if (metaProperty == null) { - metaProperty = addMetaProperty(metabean, field.getName(), field.getType()); + metaProperty = addMetaProperty(metabean, field.getName(), field.getGenericType()); processAnnotations(metaProperty, beanClass, field, new FieldAccess(field), new AppendValidationToMeta(metaProperty));//) { @@ -154,7 +154,7 @@ public class Jsr303MetaBeanFactory imple // create a property for those methods for which there is not yet a MetaProperty if (metaProperty == null) { metaProperty = - addMetaProperty(metabean, propName, method.getReturnType()); + addMetaProperty(metabean, propName, method.getGenericReturnType()); processAnnotations(metaProperty, beanClass, method, new MethodAccess(propName, method), new AppendValidationToMeta(metaProperty));//) { Modified: incubator/bval/sandbox/lang3-work/pom.xml URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/pom.xml?rev=992148&r1=992147&r2=992148&view=diff ============================================================================== --- incubator/bval/sandbox/lang3-work/pom.xml (original) +++ incubator/bval/sandbox/lang3-work/pom.xml Thu Sep 2 23:03:55 2010 @@ -308,6 +308,11 @@ 2.4 + org.apache.commons + commons-lang3 + 3.0-SNAPSHOT + + commons-logging commons-logging 1.1.1