1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -223,7 +223,7 @@ public final Object getWrappedInstance() {
223
223
return this .object ;
224
224
}
225
225
226
- public final Class getWrappedClass () {
226
+ public final Class <?> getWrappedClass () {
227
227
return (this .object != null ? this .object .getClass () : null );
228
228
}
229
229
@@ -246,7 +246,7 @@ public final Object getRootInstance() {
246
246
* Return the class of the root object at the top of the path of this BeanWrapper.
247
247
* @see #getNestedPath
248
248
*/
249
- public final Class getRootClass () {
249
+ public final Class <?> getRootClass () {
250
250
return (this .rootObject != null ? this .rootObject .getClass () : null );
251
251
}
252
252
@@ -304,7 +304,7 @@ public AccessControlContext getSecurityContext() {
304
304
* Needs to be called when the target object changes.
305
305
* @param clazz the class to introspect
306
306
*/
307
- protected void setIntrospectionClass (Class clazz ) {
307
+ protected void setIntrospectionClass (Class <?> clazz ) {
308
308
if (this .cachedIntrospectionResults != null &&
309
309
!clazz .equals (this .cachedIntrospectionResults .getBeanClass ())) {
310
310
this .cachedIntrospectionResults = null ;
@@ -352,7 +352,7 @@ protected PropertyDescriptor getPropertyDescriptorInternal(String propertyName)
352
352
}
353
353
354
354
@ Override
355
- public Class getPropertyType (String propertyName ) throws BeansException {
355
+ public Class <?> getPropertyType (String propertyName ) throws BeansException {
356
356
try {
357
357
PropertyDescriptor pd = getPropertyDescriptorInternal (propertyName );
358
358
if (pd != null ) {
@@ -366,7 +366,7 @@ public Class getPropertyType(String propertyName) throws BeansException {
366
366
}
367
367
// Check to see if there is a custom editor,
368
368
// which might give an indication on the desired target type.
369
- Class editorType = guessPropertyTypeFromEditors (propertyName );
369
+ Class <?> editorType = guessPropertyTypeFromEditors (propertyName );
370
370
if (editorType != null ) {
371
371
return editorType ;
372
372
}
@@ -485,13 +485,13 @@ public Object convertForProperty(Object value, String propertyName) throws TypeM
485
485
throw new InvalidPropertyException (getRootClass (), this .nestedPath + propertyName ,
486
486
"No property '" + propertyName + "' found" );
487
487
}
488
- return convertForProperty (propertyName , null , value , pd );
488
+ return convertForProperty (propertyName , null , value , new TypeDescriptor ( property ( pd )) );
489
489
}
490
490
491
- private Object convertForProperty (String propertyName , Object oldValue , Object newValue , PropertyDescriptor pd )
491
+ private Object convertForProperty (String propertyName , Object oldValue , Object newValue , TypeDescriptor td )
492
492
throws TypeMismatchException {
493
493
494
- return convertIfNecessary (propertyName , oldValue , newValue , pd . getPropertyType (), new TypeDescriptor ( property ( pd )) );
494
+ return convertIfNecessary (propertyName , oldValue , newValue , td . getType (), td );
495
495
}
496
496
497
497
private Property property (PropertyDescriptor pd ) {
@@ -699,7 +699,8 @@ public Object getPropertyValue(String propertyName) throws BeansException {
699
699
return nestedBw .getPropertyValue (tokens );
700
700
}
701
701
702
- private Object getPropertyValue (PropertyTokenHolder tokens ) throws BeansException {
702
+ @ SuppressWarnings ("unchecked" )
703
+ private Object getPropertyValue (PropertyTokenHolder tokens ) throws BeansException {
703
704
String propertyName = tokens .canonicalName ;
704
705
String actualName = tokens .actualName ;
705
706
PropertyDescriptor pd = getCachedIntrospectionResults ().getPropertyDescriptor (actualName );
@@ -766,20 +767,20 @@ else if (value.getClass().isArray()) {
766
767
}
767
768
else if (value instanceof List ) {
768
769
int index = Integer .parseInt (key );
769
- List list = (List ) value ;
770
+ List < Object > list = (List < Object > ) value ;
770
771
growCollectionIfNecessary (list , index , indexedPropertyName , pd , i + 1 );
771
772
value = list .get (index );
772
773
}
773
774
else if (value instanceof Set ) {
774
775
// Apply index to Iterator in case of a Set.
775
- Set set = (Set ) value ;
776
+ Set < Object > set = (Set < Object > ) value ;
776
777
int index = Integer .parseInt (key );
777
778
if (index < 0 || index >= set .size ()) {
778
779
throw new InvalidPropertyException (getRootClass (), this .nestedPath + propertyName ,
779
780
"Cannot get element with index " + index + " from Set of size " +
780
781
set .size () + ", accessed using property path '" + propertyName + "'" );
781
782
}
782
- Iterator it = set .iterator ();
783
+ Iterator < Object > it = set .iterator ();
783
784
for (int j = 0 ; it .hasNext (); j ++) {
784
785
Object elem = it .next ();
785
786
if (j == index ) {
@@ -789,11 +790,12 @@ else if (value instanceof Set) {
789
790
}
790
791
}
791
792
else if (value instanceof Map ) {
792
- Map map = (Map ) value ;
793
+ Map < Object , Object > map = (Map < Object , Object > ) value ;
793
794
Class <?> mapKeyType = GenericCollectionTypeResolver .getMapKeyReturnType (pd .getReadMethod (), i + 1 );
794
795
// IMPORTANT: Do not pass full property name in here - property editors
795
796
// must not kick in for map keys but rather only for map values.
796
- TypeDescriptor typeDescriptor = mapKeyType != null ? TypeDescriptor .valueOf (mapKeyType ) : TypeDescriptor .valueOf (Object .class );
797
+ TypeDescriptor typeDescriptor = (mapKeyType != null ?
798
+ TypeDescriptor .valueOf (mapKeyType ) : TypeDescriptor .valueOf (Object .class ));
797
799
Object convertedMapKey = convertIfNecessary (null , null , key , mapKeyType , typeDescriptor );
798
800
value = map .get (convertedMapKey );
799
801
}
@@ -850,16 +852,15 @@ private Object growArrayIfNecessary(Object array, int index, String name) {
850
852
}
851
853
}
852
854
853
- @ SuppressWarnings ("unchecked" )
854
- private void growCollectionIfNecessary (
855
- Collection collection , int index , String name , PropertyDescriptor pd , int nestingLevel ) {
855
+ private void growCollectionIfNecessary (Collection <Object > collection , int index , String name ,
856
+ PropertyDescriptor pd , int nestingLevel ) {
856
857
857
858
if (!this .autoGrowNestedPaths ) {
858
859
return ;
859
860
}
860
861
int size = collection .size ();
861
862
if (index >= size && index < this .autoGrowCollectionLimit ) {
862
- Class elementType = GenericCollectionTypeResolver .getCollectionReturnType (pd .getReadMethod (), nestingLevel );
863
+ Class <?> elementType = GenericCollectionTypeResolver .getCollectionReturnType (pd .getReadMethod (), nestingLevel );
863
864
if (elementType != null ) {
864
865
for (int i = collection .size (); i < index + 1 ; i ++) {
865
866
collection .add (newValue (elementType , name ));
@@ -945,7 +946,7 @@ private void setPropertyValue(PropertyTokenHolder tokens, PropertyValue pv) thro
945
946
}
946
947
if (propValue .getClass ().isArray ()) {
947
948
PropertyDescriptor pd = getCachedIntrospectionResults ().getPropertyDescriptor (actualName );
948
- Class requiredType = propValue .getClass ().getComponentType ();
949
+ Class <?> requiredType = propValue .getClass ().getComponentType ();
949
950
int arrayIndex = Integer .parseInt (key );
950
951
Object oldValue = null ;
951
952
try {
@@ -963,9 +964,9 @@ private void setPropertyValue(PropertyTokenHolder tokens, PropertyValue pv) thro
963
964
}
964
965
else if (propValue instanceof List ) {
965
966
PropertyDescriptor pd = getCachedIntrospectionResults ().getPropertyDescriptor (actualName );
966
- Class requiredType = GenericCollectionTypeResolver .getCollectionReturnType (
967
+ Class <?> requiredType = GenericCollectionTypeResolver .getCollectionReturnType (
967
968
pd .getReadMethod (), tokens .keys .length );
968
- List list = (List ) propValue ;
969
+ List < Object > list = (List < Object > ) propValue ;
969
970
int index = Integer .parseInt (key );
970
971
Object oldValue = null ;
971
972
if (isExtractOldValueForEditor () && index < list .size ()) {
@@ -1000,11 +1001,11 @@ else if (propValue instanceof List) {
1000
1001
}
1001
1002
else if (propValue instanceof Map ) {
1002
1003
PropertyDescriptor pd = getCachedIntrospectionResults ().getPropertyDescriptor (actualName );
1003
- Class mapKeyType = GenericCollectionTypeResolver .getMapKeyReturnType (
1004
+ Class <?> mapKeyType = GenericCollectionTypeResolver .getMapKeyReturnType (
1004
1005
pd .getReadMethod (), tokens .keys .length );
1005
- Class mapValueType = GenericCollectionTypeResolver .getMapValueReturnType (
1006
+ Class <?> mapValueType = GenericCollectionTypeResolver .getMapValueReturnType (
1006
1007
pd .getReadMethod (), tokens .keys .length );
1007
- Map map = (Map ) propValue ;
1008
+ Map < Object , Object > map = (Map < Object , Object > ) propValue ;
1008
1009
// IMPORTANT: Do not pass full property name in here - property editors
1009
1010
// must not kick in for map keys but rather only for map values.
1010
1011
TypeDescriptor typeDescriptor = (mapKeyType != null ?
@@ -1094,7 +1095,8 @@ public Object run() throws Exception {
1094
1095
}
1095
1096
}
1096
1097
}
1097
- valueToApply = convertForProperty (propertyName , oldValue , originalValue , pd );
1098
+ valueToApply = convertForProperty (
1099
+ propertyName , oldValue , originalValue , new TypeDescriptor (property (pd )));
1098
1100
}
1099
1101
pv .getOriginalPropertyValue ().conversionNecessary = (valueToApply != originalValue );
1100
1102
}
0 commit comments