mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
un-deprecate TypeConversion.converter plus some improvements
See WW-4906
This commit is contained in:
+7
-8
@@ -82,15 +82,15 @@ import java.lang.annotation.Target;
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>converter</td>
|
||||
* <td>DEPRECATED: either this or value</td>
|
||||
* <td>either this or value</td>
|
||||
* <td> </td>
|
||||
* <td>The class name of the TypeConverter to be used as converter.</td>
|
||||
* <td>The class or bean name of the TypeConverter to be used as converter.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>converterClass</td>
|
||||
* <td>either this or value</td>
|
||||
* <td> </td>
|
||||
* <td>The class of the TypeConverter to be used as converter. XWorkBasicConverter by default.</td>
|
||||
* <td>XWorkBasicConverter</td>
|
||||
* <td>The class of the TypeConverter to be used as converter.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>value</td>
|
||||
@@ -181,14 +181,13 @@ public @interface TypeConversion {
|
||||
ConversionRule rule() default ConversionRule.PROPERTY;
|
||||
|
||||
/**
|
||||
* The class of the TypeConverter to be used as converter.
|
||||
* The class or bean name of the TypeConverter to be used as converter.
|
||||
*
|
||||
* Note: This can not be used with ConversionRule.KEY_PROPERTY!
|
||||
*
|
||||
* @return class of the TypeConverter to be used as converter
|
||||
* @deprecated user {@link #converterClass()} instead
|
||||
* @return class or bean name of the TypeConverter to be used as converter
|
||||
* @see {@link #converterClass()}
|
||||
*/
|
||||
@Deprecated
|
||||
String converter() default "";
|
||||
|
||||
/**
|
||||
|
||||
+11
-6
@@ -26,6 +26,7 @@ import com.opensymphony.xwork2.conversion.annotations.ConversionRule;
|
||||
import com.opensymphony.xwork2.conversion.annotations.ConversionType;
|
||||
import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -80,18 +81,22 @@ public class DefaultConversionAnnotationProcessor implements ConversionAnnotatio
|
||||
else if (tc.rule() == ConversionRule.KEY) {
|
||||
Class<?> converterClass;
|
||||
if (StringUtils.isNoneEmpty(tc.converter())) {
|
||||
converterClass = Thread.currentThread().getContextClassLoader().loadClass(tc.converter());
|
||||
//check if the converter is a type converter if it is one
|
||||
//then just put it in the map as is. Otherwise
|
||||
//put a value in for the type converter of the class
|
||||
converterClass = ClassLoaderUtil.loadClass(tc.converter(), this.getClass());
|
||||
} else {
|
||||
converterClass = tc.converterClass();
|
||||
}
|
||||
|
||||
LOG.debug("Converter class: [{}]", converterClass);
|
||||
|
||||
//check if the converter is a type converter if it is one
|
||||
//then just put it in the map as is. Otherwise
|
||||
//put a value in for the type converter of the class
|
||||
if (converterClass.isAssignableFrom(TypeConverter.class)) {
|
||||
mapping.put(key, converterCreator.createTypeConverter(tc.converter()));
|
||||
if (StringUtils.isNoneEmpty(tc.converter())) {
|
||||
mapping.put(key, converterCreator.createTypeConverter(tc.converter()));
|
||||
} else {
|
||||
mapping.put(key, converterCreator.createTypeConverter(tc.converterClass()));
|
||||
}
|
||||
} else {
|
||||
mapping.put(key, converterClass);
|
||||
LOG.debug("Object placed in mapping for key [{}] is [{}]", key, mapping.get(key));
|
||||
@@ -100,7 +105,7 @@ public class DefaultConversionAnnotationProcessor implements ConversionAnnotatio
|
||||
//elements(values) of maps / lists
|
||||
else {
|
||||
if (StringUtils.isNoneEmpty(tc.converter())) {
|
||||
mapping.put(key, Thread.currentThread().getContextClassLoader().loadClass(tc.converter()));
|
||||
mapping.put(key, ClassLoaderUtil.loadClass(tc.converter(), this.getClass()));
|
||||
} else {
|
||||
mapping.put(key, tc.converterClass());
|
||||
}
|
||||
|
||||
+2
-2
@@ -86,7 +86,7 @@ public class DefaultConversionFileProcessor implements ConversionFileProcessor {
|
||||
//for keys of Maps
|
||||
else if (key.startsWith(DefaultObjectTypeDeterminer.KEY_PREFIX)) {
|
||||
|
||||
Class converterClass = Thread.currentThread().getContextClassLoader().loadClass((String) entry.getValue());
|
||||
Class converterClass = ClassLoaderUtil.loadClass((String) entry.getValue(), this.getClass());
|
||||
|
||||
//check if the converter is a type converter if it is one
|
||||
//then just put it in the map as is. Otherwise
|
||||
@@ -102,7 +102,7 @@ public class DefaultConversionFileProcessor implements ConversionFileProcessor {
|
||||
}
|
||||
//elements(values) of maps / lists
|
||||
else {
|
||||
Class _c = Thread.currentThread().getContextClassLoader().loadClass((String) entry.getValue());
|
||||
Class _c = ClassLoaderUtil.loadClass((String) entry.getValue(), this.getClass());
|
||||
LOG.debug("\t{}:{} [treated as Class {}]", key, entry.getValue(), _c);
|
||||
mapping.put(key, _c);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user