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 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
+<groupId>org.apache.commons</groupId>
+<artifactId>commons-lang3</artifactId>
+</dependency>
+<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
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.<br/>
@@ -104,20 +105,14 @@ public class MetaProperty extends Featur
* @return Class,<code>null</code> 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>
+<#if property.type??>"type" : "${property.type}",</#if>
+<#if property.typeClass??>"typeClass" : "${property.typeClass.name}",</#if>
"features" : {<#if property.type??&&
- property.type.enum>"enum" : {<#list property.type.enumConstants as enum>"${enum.name()}": "${enum.name()}"<#if
enum_has_next>,</#if></#list>}<#if property.features?size> 0>,</#if></#if><#list
+ property.type.enum!false>"enum" : {<#list property.type.enumConstants as enum>"${enum.name()}":
"${enum.name()}"<#if enum_has_next>,</#if></#list>}<#if property.features?size> 0>,</#if></#if><#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 @@
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
+<groupId>org.apache.commons</groupId>
+<artifactId>commons-lang3</artifactId>
+</dependency>
+<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
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 @@
<version>2.4</version>
</dependency>
<dependency>
+<groupId>org.apache.commons</groupId>
+<artifactId>commons-lang3</artifactId>
+<version>3.0-SNAPSHOT</version>
+</dependency>
+<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>