Refactor code to use Java 5 features
- Apply and use Generics - Remove JdkVersion.isAtLeastJava15() conditionals - Replace iterator loops with foreach syntax - Switch on warning in eclipse Issues: SWF-1532
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#Wed Jun 09 09:16:13 BST 2010
|
||||
#Tue Jan 17 17:40:54 PST 2012
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
|
||||
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
|
||||
@@ -19,6 +19,8 @@ org.eclipse.jdt.core.compiler.doc.comment.support=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deadCode=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||
@@ -26,11 +28,13 @@ org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
|
||||
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
@@ -42,6 +46,7 @@ org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
|
||||
@@ -49,7 +54,9 @@ org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
@@ -57,12 +64,20 @@ org.eclipse.jdt.core.compiler.problem.nullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
|
||||
@@ -70,14 +85,19 @@ org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class CompositeIterator implements Iterator {
|
||||
public class CompositeIterator<E> implements Iterator<E> {
|
||||
|
||||
private List iterators = new LinkedList();
|
||||
private List<Iterator<E>> iterators = new LinkedList<Iterator<E>>();
|
||||
|
||||
private boolean inUse = false;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CompositeIterator implements Iterator {
|
||||
/**
|
||||
* Add given iterator to this composite.
|
||||
*/
|
||||
public void add(Iterator iterator) {
|
||||
public void add(Iterator<E> iterator) {
|
||||
Assert.state(!inUse, "You can no longer add iterator to a composite iterator that's already in use");
|
||||
if (iterators.contains(iterator)) {
|
||||
throw new IllegalArgumentException("You cannot add the same iterator twice");
|
||||
@@ -53,18 +53,17 @@ public class CompositeIterator implements Iterator {
|
||||
|
||||
public boolean hasNext() {
|
||||
inUse = true;
|
||||
for (Iterator it = iterators.iterator(); it.hasNext();) {
|
||||
if (((Iterator) it.next()).hasNext()) {
|
||||
for (Iterator<E> iterator : iterators) {
|
||||
if (iterator.hasNext()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
public E next() {
|
||||
inUse = true;
|
||||
for (Iterator it = iterators.iterator(); it.hasNext();) {
|
||||
Iterator iterator = (Iterator) it.next();
|
||||
for (Iterator<E> iterator : iterators) {
|
||||
if (iterator.hasNext()) {
|
||||
return iterator.next();
|
||||
}
|
||||
|
||||
@@ -26,25 +26,25 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class MapAccessor implements MapAdaptable {
|
||||
public class MapAccessor<K, V> implements MapAdaptable<K, V> {
|
||||
|
||||
/**
|
||||
* The target map.
|
||||
*/
|
||||
private Map map;
|
||||
private Map<K, V> map;
|
||||
|
||||
/**
|
||||
* Creates a new attribute map accessor.
|
||||
* @param map the map
|
||||
*/
|
||||
public MapAccessor(Map map) {
|
||||
public MapAccessor(Map<K, V> map) {
|
||||
Assert.notNull(map, "The map to decorate is required");
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
// implementing MapAdaptable
|
||||
|
||||
public Map asMap() {
|
||||
public Map<K, V> asMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @param key the key
|
||||
* @return the value
|
||||
*/
|
||||
public Object get(Object key) {
|
||||
public V get(Object key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @param defaultValue the default
|
||||
* @return the attribute value
|
||||
*/
|
||||
public Object get(Object key, Object defaultValue) {
|
||||
public V get(Object key, V defaultValue) {
|
||||
if (!map.containsKey(key)) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @return the value
|
||||
* @throws IllegalArgumentException if the key is present but the value is not of the required type
|
||||
*/
|
||||
public Object get(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public <T extends V> T get(Object key, Class<T> requiredType) throws IllegalArgumentException {
|
||||
return get(key, requiredType, null);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @return the attribute value
|
||||
* @throws IllegalArgumentException if the key is present but the value is not of the required type
|
||||
*/
|
||||
public Object get(Object key, Class requiredType, Object defaultValue) {
|
||||
public <T extends V> T get(Object key, Class<T> requiredType, T defaultValue) {
|
||||
if (!map.containsKey(key)) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @param key the key
|
||||
* @return the value
|
||||
*/
|
||||
public Object getRequired(Object key) throws IllegalArgumentException {
|
||||
public V getRequired(Object key) throws IllegalArgumentException {
|
||||
assertContainsKey(key);
|
||||
return map.get(key);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @param requiredType the required type
|
||||
* @return the value
|
||||
*/
|
||||
public Object getRequired(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public <T extends V> T getRequired(Object key, Class<T> requiredType) throws IllegalArgumentException {
|
||||
assertContainsKey(key);
|
||||
return assertKeyValueOfType(key, requiredType);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
if (!map.containsKey(key)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return (String) assertKeyValueOfType(key, String.class);
|
||||
return assertKeyValueOfType(key, String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +150,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
*/
|
||||
public String getRequiredString(Object key) throws IllegalArgumentException {
|
||||
assertContainsKey(key);
|
||||
return (String) assertKeyValueOfType(key, String.class);
|
||||
return assertKeyValueOfType(key, String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,11 +159,12 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @return the collection value
|
||||
* @throws IllegalArgumentException if the key is present but the value is not a collection
|
||||
*/
|
||||
public Collection getCollection(Object key) throws IllegalArgumentException {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<V> getCollection(Object key) throws IllegalArgumentException {
|
||||
if (!map.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
return (Collection) assertKeyValueOfType(key, Collection.class);
|
||||
return assertKeyValueOfType(key, Collection.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,12 +174,12 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @return the collection value
|
||||
* @throws IllegalArgumentException if the key is present but the value is not a collection
|
||||
*/
|
||||
public Collection getCollection(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public <T extends Collection<V>> T getCollection(Object key, Class<T> requiredType) throws IllegalArgumentException {
|
||||
if (!map.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
assertAssignableTo(Collection.class, requiredType);
|
||||
return (Collection) assertKeyValueOfType(key, requiredType);
|
||||
return assertKeyValueOfType(key, requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,9 +188,10 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @return the collection value
|
||||
* @throws IllegalArgumentException if the key is not present or present but the value is not a collection
|
||||
*/
|
||||
public Collection getRequiredCollection(Object key) throws IllegalArgumentException {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<V> getRequiredCollection(Object key) throws IllegalArgumentException {
|
||||
assertContainsKey(key);
|
||||
return (Collection) assertKeyValueOfType(key, Collection.class);
|
||||
return assertKeyValueOfType(key, Collection.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,10 +202,11 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @throws IllegalArgumentException if the key is not present or present but the value is not a collection of the
|
||||
* required type
|
||||
*/
|
||||
public Collection getRequiredCollection(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public <T extends Collection<V>> T getRequiredCollection(Object key, Class<T> requiredType)
|
||||
throws IllegalArgumentException {
|
||||
assertContainsKey(key);
|
||||
assertAssignableTo(Collection.class, requiredType);
|
||||
return (Collection) assertKeyValueOfType(key, requiredType);
|
||||
return assertKeyValueOfType(key, requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,12 +216,12 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @return the array value
|
||||
* @throws IllegalArgumentException if the key is present but the value is not an array of the required type
|
||||
*/
|
||||
public Object[] getArray(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public <T extends V> T[] getArray(Object key, Class<? extends T[]> requiredType) throws IllegalArgumentException {
|
||||
assertAssignableTo(Object[].class, requiredType);
|
||||
if (!map.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
return (Object[]) assertKeyValueOfType(key, requiredType);
|
||||
return assertKeyValueOfType(key, requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,10 +232,11 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @throws IllegalArgumentException if the key is not present or present but the value is not a array of the
|
||||
* required type
|
||||
*/
|
||||
public Object[] getRequiredArray(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public <T extends V> T[] getRequiredArray(Object key, Class<? extends T[]> requiredType)
|
||||
throws IllegalArgumentException {
|
||||
assertContainsKey(key);
|
||||
assertAssignableTo(Object[].class, requiredType);
|
||||
return (Object[]) assertKeyValueOfType(key, requiredType);
|
||||
return assertKeyValueOfType(key, requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,10 +244,10 @@ public class MapAccessor implements MapAdaptable {
|
||||
* found.
|
||||
* @param key the key
|
||||
* @param requiredType the required number type
|
||||
* @return the numbervalue
|
||||
* @return the number value
|
||||
* @throws IllegalArgumentException if the key is present but the value is not a number of the required type
|
||||
*/
|
||||
public Number getNumber(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public <T extends Number> T getNumber(Object key, Class<T> requiredType) throws IllegalArgumentException {
|
||||
return getNumber(key, requiredType, null);
|
||||
}
|
||||
|
||||
@@ -255,12 +259,13 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @param defaultValue the default
|
||||
* @throws IllegalArgumentException if the key is present but the value is not a number of the required type
|
||||
*/
|
||||
public Number getNumber(Object key, Class requiredType, Number defaultValue) throws IllegalArgumentException {
|
||||
public <T extends Number> T getNumber(Object key, Class<T> requiredType, T defaultValue)
|
||||
throws IllegalArgumentException {
|
||||
if (!map.containsKey(key)) {
|
||||
return defaultValue;
|
||||
}
|
||||
assertAssignableTo(Number.class, requiredType);
|
||||
return (Number) assertKeyValueOfType(key, requiredType);
|
||||
return assertKeyValueOfType(key, requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,9 +275,9 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @throws IllegalArgumentException if the key is not present or present but the value is not a number of the
|
||||
* required type
|
||||
*/
|
||||
public Number getRequiredNumber(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public <T extends Number> T getRequiredNumber(Object key, Class<T> requiredType) throws IllegalArgumentException {
|
||||
assertContainsKey(key);
|
||||
return (Number) assertKeyValueOfType(key, requiredType);
|
||||
return assertKeyValueOfType(key, requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,7 +298,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @throws IllegalArgumentException if the key is present but the value is not an integer
|
||||
*/
|
||||
public Integer getInteger(Object key, Integer defaultValue) throws IllegalArgumentException {
|
||||
return (Integer) getNumber(key, Integer.class, defaultValue);
|
||||
return getNumber(key, Integer.class, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +308,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @throws IllegalArgumentException if the key is not present or present but the value is not an integer
|
||||
*/
|
||||
public Integer getRequiredInteger(Object key) throws IllegalArgumentException {
|
||||
return (Integer) getRequiredNumber(key, Integer.class);
|
||||
return getRequiredNumber(key, Integer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,7 +329,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @throws IllegalArgumentException if the key is present but the value is not a long
|
||||
*/
|
||||
public Long getLong(Object key, Long defaultValue) throws IllegalArgumentException {
|
||||
return (Long) getNumber(key, Long.class, defaultValue);
|
||||
return getNumber(key, Long.class, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,7 +339,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @throws IllegalArgumentException if the key is not present or present but the value is not a long
|
||||
*/
|
||||
public Long getRequiredLong(Object key) throws IllegalArgumentException {
|
||||
return (Long) getRequiredNumber(key, Long.class);
|
||||
return getRequiredNumber(key, Long.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -358,7 +363,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
if (!map.containsKey(key)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return (Boolean) assertKeyValueOfType(key, Boolean.class);
|
||||
return assertKeyValueOfType(key, Boolean.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,7 +374,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
*/
|
||||
public Boolean getRequiredBoolean(Object key) throws IllegalArgumentException {
|
||||
assertContainsKey(key);
|
||||
return (Boolean) assertKeyValueOfType(key, Boolean.class);
|
||||
return assertKeyValueOfType(key, Boolean.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -389,7 +394,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @param key the attribute name
|
||||
* @return true if present and of the required type, false if not present.
|
||||
*/
|
||||
public boolean containsKey(Object key, Class requiredType) throws IllegalArgumentException {
|
||||
public boolean containsKey(Object key, Class<?> requiredType) throws IllegalArgumentException {
|
||||
if (map.containsKey(key)) {
|
||||
assertKeyValueOfType(key, requiredType);
|
||||
return true;
|
||||
@@ -404,7 +409,7 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @param requiredType the required attribute value type
|
||||
* @return the attribute value
|
||||
*/
|
||||
public Object assertKeyValueOfType(Object key, Class requiredType) {
|
||||
public <T> T assertKeyValueOfType(Object key, Class<T> requiredType) {
|
||||
return assertKeyValueInstanceOf(key, map.get(key), requiredType);
|
||||
}
|
||||
|
||||
@@ -415,17 +420,18 @@ public class MapAccessor implements MapAdaptable {
|
||||
* @param requiredType the required type
|
||||
* @return the value
|
||||
*/
|
||||
public Object assertKeyValueInstanceOf(Object key, Object value, Class requiredType) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T assertKeyValueInstanceOf(Object key, Object value, Class<T> requiredType) {
|
||||
Assert.notNull(requiredType, "The required type to assert is required");
|
||||
if (value != null && !requiredType.isInstance(value)) {
|
||||
throw new IllegalArgumentException("Map key '" + key + "' has value [" + value
|
||||
+ "] that is not of expected type [" + requiredType + "], instead it is of type ["
|
||||
+ value.getClass().getName() + "]");
|
||||
}
|
||||
return value;
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
private void assertAssignableTo(Class clazz, Class requiredType) {
|
||||
private void assertAssignableTo(Class<?> clazz, Class<?> requiredType) {
|
||||
Assert.isTrue(clazz.isAssignableFrom(requiredType), "The provided required type must be assignable to ["
|
||||
+ clazz + "]");
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.springframework.binding.collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An object whose contents are capable of being exposed as an unmodifiable map.
|
||||
* An object whose contents are capable of being exposed as a map.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public interface MapAdaptable {
|
||||
public interface MapAdaptable<K, V> {
|
||||
|
||||
/**
|
||||
* Returns this object's contents as a {@link Map}. The returned map may or may not be modifiable depending on this
|
||||
@@ -32,6 +32,6 @@ public interface MapAdaptable {
|
||||
* calculated) be cached as appropriate.
|
||||
* @return the object's contents as a map
|
||||
*/
|
||||
public Map asMap();
|
||||
public Map<K, V> asMap();
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public interface SharedMap extends Map {
|
||||
public interface SharedMap<K, V> extends Map<K, V> {
|
||||
|
||||
/**
|
||||
* Returns the shared mutex that may be synchronized on using a synchronized block. The returned mutex is guaranteed
|
||||
|
||||
@@ -28,18 +28,18 @@ import org.springframework.core.style.ToStringCreator;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class SharedMapDecorator implements SharedMap, Serializable {
|
||||
public class SharedMapDecorator<K, V> implements SharedMap<K, V>, Serializable {
|
||||
|
||||
/**
|
||||
* The wrapped, target map.
|
||||
*/
|
||||
private Map map;
|
||||
private Map<K, V> map;
|
||||
|
||||
/**
|
||||
* Creates a new shared map decorator.
|
||||
* @param map the map that is shared by multiple threads, to be synced
|
||||
*/
|
||||
public SharedMapDecorator(Map map) {
|
||||
public SharedMapDecorator(Map<K, V> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@@ -57,11 +57,11 @@ public class SharedMapDecorator implements SharedMap, Serializable {
|
||||
return map.containsValue(value);
|
||||
}
|
||||
|
||||
public Set entrySet() {
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
return map.entrySet();
|
||||
}
|
||||
|
||||
public Object get(Object key) {
|
||||
public V get(Object key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@@ -69,19 +69,19 @@ public class SharedMapDecorator implements SharedMap, Serializable {
|
||||
return map.isEmpty();
|
||||
}
|
||||
|
||||
public Set keySet() {
|
||||
public Set<K> keySet() {
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
public Object put(Object key, Object value) {
|
||||
public V put(K key, V value) {
|
||||
return map.put(key, value);
|
||||
}
|
||||
|
||||
public void putAll(Map map) {
|
||||
public void putAll(Map<? extends K, ? extends V> map) {
|
||||
this.map.putAll(map);
|
||||
}
|
||||
|
||||
public Object remove(Object key) {
|
||||
public V remove(Object key) {
|
||||
return map.remove(key);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class SharedMapDecorator implements SharedMap, Serializable {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
public Collection values() {
|
||||
public Collection<V> values() {
|
||||
return map.values();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,19 +27,19 @@ import java.util.Set;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public abstract class StringKeyedMapAdapter implements Map {
|
||||
public abstract class StringKeyedMapAdapter<V> implements Map<String, V> {
|
||||
|
||||
private Set keySet;
|
||||
private Set<String> keySet;
|
||||
|
||||
private Collection values;
|
||||
private Collection<V> values;
|
||||
|
||||
private Set entrySet;
|
||||
private Set<Entry<String, V>> entrySet;
|
||||
|
||||
// implementing Map
|
||||
|
||||
public void clear() {
|
||||
for (Iterator it = getAttributeNames(); it.hasNext();) {
|
||||
removeAttribute((String) it.next());
|
||||
for (Iterator<String> it = getAttributeNames(); it.hasNext();) {
|
||||
removeAttribute(it.next());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
for (Iterator it = getAttributeNames(); it.hasNext();) {
|
||||
Object aValue = getAttribute((String) it.next());
|
||||
for (Iterator<String> it = getAttributeNames(); it.hasNext();) {
|
||||
Object aValue = getAttribute(it.next());
|
||||
if (value.equals(aValue)) {
|
||||
return true;
|
||||
}
|
||||
@@ -60,11 +60,11 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set entrySet() {
|
||||
public Set<Entry<String, V>> entrySet() {
|
||||
return (entrySet != null) ? entrySet : (entrySet = new EntrySet());
|
||||
}
|
||||
|
||||
public Object get(Object key) {
|
||||
public V get(Object key) {
|
||||
return getAttribute(key.toString());
|
||||
}
|
||||
|
||||
@@ -72,41 +72,40 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
return !getAttributeNames().hasNext();
|
||||
}
|
||||
|
||||
public Set keySet() {
|
||||
public Set<String> keySet() {
|
||||
return (keySet != null) ? keySet : (keySet = new KeySet());
|
||||
}
|
||||
|
||||
public Object put(Object key, Object value) {
|
||||
public V put(String key, V value) {
|
||||
String stringKey = String.valueOf(key);
|
||||
Object previousValue = getAttribute(stringKey);
|
||||
V previousValue = getAttribute(stringKey);
|
||||
setAttribute(stringKey, value);
|
||||
return previousValue;
|
||||
}
|
||||
|
||||
public void putAll(Map map) {
|
||||
for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
setAttribute(entry.getKey().toString(), entry.getValue());
|
||||
public void putAll(Map<? extends String, ? extends V> map) {
|
||||
for (Entry<? extends String, ? extends V> entry : map.entrySet()) {
|
||||
setAttribute(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public Object remove(Object key) {
|
||||
public V remove(Object key) {
|
||||
String stringKey = key.toString();
|
||||
Object retval = getAttribute(stringKey);
|
||||
V retval = getAttribute(stringKey);
|
||||
removeAttribute(stringKey);
|
||||
return retval;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (Iterator it = getAttributeNames(); it.hasNext();) {
|
||||
for (Iterator<String> it = getAttributeNames(); it.hasNext();) {
|
||||
size++;
|
||||
it.next();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public Collection values() {
|
||||
public Collection<V> values() {
|
||||
return (values != null) ? values : (values = new Values());
|
||||
}
|
||||
|
||||
@@ -117,7 +116,7 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
* @param key the key to lookup
|
||||
* @return the associated value, or null if none
|
||||
*/
|
||||
protected abstract Object getAttribute(String key);
|
||||
protected abstract V getAttribute(String key);
|
||||
|
||||
/**
|
||||
* Hook method that needs to be implemented by concrete subclasses. Puts a key-value pair in the map, overwriting
|
||||
@@ -125,7 +124,7 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
* @param key the key to associate the value with
|
||||
* @param value the value to associate with the key
|
||||
*/
|
||||
protected abstract void setAttribute(String key, Object value);
|
||||
protected abstract void setAttribute(String key, V value);
|
||||
|
||||
/**
|
||||
* Hook method that needs to be implemented by concrete subclasses. Removes a key and its associated value from the
|
||||
@@ -139,11 +138,11 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
* the map.
|
||||
* @return the key enumeration
|
||||
*/
|
||||
protected abstract Iterator getAttributeNames();
|
||||
protected abstract Iterator<String> getAttributeNames();
|
||||
|
||||
// internal helper classes
|
||||
|
||||
private abstract class AbstractSet extends java.util.AbstractSet {
|
||||
private abstract class AbstractSet<T> extends java.util.AbstractSet<T> {
|
||||
public boolean isEmpty() {
|
||||
return StringKeyedMapAdapter.this.isEmpty();
|
||||
}
|
||||
@@ -157,8 +156,8 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
}
|
||||
}
|
||||
|
||||
private class KeySet extends AbstractSet {
|
||||
public Iterator iterator() {
|
||||
private class KeySet extends AbstractSet<String> {
|
||||
public Iterator<String> iterator() {
|
||||
return new KeyIterator();
|
||||
}
|
||||
|
||||
@@ -171,10 +170,10 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
}
|
||||
}
|
||||
|
||||
private class KeyIterator implements Iterator {
|
||||
protected final Iterator it = getAttributeNames();
|
||||
private abstract class AbstractKeyIterator {
|
||||
private final Iterator<String> it = getAttributeNames();
|
||||
|
||||
protected Object currentKey;
|
||||
private String currentKey;
|
||||
|
||||
public void remove() {
|
||||
if (currentKey == null) {
|
||||
@@ -187,13 +186,19 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
protected String nextKey() {
|
||||
return currentKey = it.next();
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractSet {
|
||||
public Iterator iterator() {
|
||||
private class KeyIterator extends AbstractKeyIterator implements Iterator<String> {
|
||||
public String next() {
|
||||
return nextKey();
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends AbstractSet<V> {
|
||||
public Iterator<V> iterator() {
|
||||
return new ValuesIterator();
|
||||
}
|
||||
|
||||
@@ -205,7 +210,7 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
for (Iterator it = iterator(); it.hasNext();) {
|
||||
for (Iterator<V> it = iterator(); it.hasNext();) {
|
||||
if (o.equals(it.next())) {
|
||||
it.remove();
|
||||
return true;
|
||||
@@ -215,68 +220,69 @@ public abstract class StringKeyedMapAdapter implements Map {
|
||||
}
|
||||
}
|
||||
|
||||
private class ValuesIterator extends KeyIterator {
|
||||
public Object next() {
|
||||
super.next();
|
||||
return StringKeyedMapAdapter.this.get(currentKey);
|
||||
private class ValuesIterator extends AbstractKeyIterator implements Iterator<V> {
|
||||
public V next() {
|
||||
return StringKeyedMapAdapter.this.get(nextKey());
|
||||
}
|
||||
}
|
||||
|
||||
private class EntrySet extends AbstractSet {
|
||||
public Iterator iterator() {
|
||||
private class EntrySet extends AbstractSet<Entry<String, V>> {
|
||||
public Iterator<Entry<String, V>> iterator() {
|
||||
return new EntryIterator();
|
||||
}
|
||||
|
||||
public boolean contains(Object o) {
|
||||
if (!(o instanceof Entry)) {
|
||||
Entry<String, V> entry = getAsEntry(o);
|
||||
if (entry == null || entry.getKey() == null || entry.getValue() == null) {
|
||||
return false;
|
||||
}
|
||||
Entry entry = (Entry) o;
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (key == null || value == null) {
|
||||
return false;
|
||||
}
|
||||
return value.equals(StringKeyedMapAdapter.this.get(key));
|
||||
V valueFromThisMap = StringKeyedMapAdapter.this.get(entry.getKey());
|
||||
return entry.getValue().equals(valueFromThisMap);
|
||||
}
|
||||
|
||||
public boolean remove(Object o) {
|
||||
if (!(o instanceof Entry)) {
|
||||
Entry<String, V> entry = getAsEntry(o);
|
||||
if (entry == null || entry.getKey() == null || entry.getValue() == null) {
|
||||
return false;
|
||||
}
|
||||
Entry entry = (Entry) o;
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (key == null || value == null || !value.equals(StringKeyedMapAdapter.this.get(key))) {
|
||||
V valueFromThisMap = StringKeyedMapAdapter.this.get(entry.getKey());
|
||||
if (!entry.getValue().equals(valueFromThisMap)) {
|
||||
return false;
|
||||
}
|
||||
return StringKeyedMapAdapter.this.remove(((Entry) o).getKey()) != null;
|
||||
return StringKeyedMapAdapter.this.remove(entry.getKey()) != null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Entry<String, V> getAsEntry(Object o) {
|
||||
if (o instanceof Entry) {
|
||||
return (Entry<String, V>) o;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class EntryIterator extends KeyIterator {
|
||||
public Object next() {
|
||||
super.next();
|
||||
return new EntrySetEntry(currentKey);
|
||||
private class EntryIterator extends AbstractKeyIterator implements Iterator<Entry<String, V>> {
|
||||
public Entry<String, V> next() {
|
||||
return new EntrySetEntry(nextKey());
|
||||
}
|
||||
}
|
||||
|
||||
private class EntrySetEntry implements Entry {
|
||||
private final Object currentKey;
|
||||
private class EntrySetEntry implements Entry<String, V> {
|
||||
private final String currentKey;
|
||||
|
||||
public EntrySetEntry(Object currentKey) {
|
||||
public EntrySetEntry(String currentKey) {
|
||||
this.currentKey = currentKey;
|
||||
}
|
||||
|
||||
public Object getKey() {
|
||||
public String getKey() {
|
||||
return currentKey;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
public V getValue() {
|
||||
return StringKeyedMapAdapter.this.get(currentKey);
|
||||
}
|
||||
|
||||
public Object setValue(Object value) {
|
||||
public V setValue(V value) {
|
||||
return StringKeyedMapAdapter.this.put(currentKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ public class ConversionExecutionException extends ConversionException {
|
||||
/**
|
||||
* The source type we tried to convert the value from.
|
||||
*/
|
||||
private Class sourceClass;
|
||||
private Class<?> sourceClass;
|
||||
|
||||
/**
|
||||
* The target type we tried to convert the value to.
|
||||
*/
|
||||
private Class targetClass;
|
||||
private Class<?> targetClass;
|
||||
|
||||
/**
|
||||
* Creates a new conversion exception.
|
||||
@@ -46,7 +46,7 @@ public class ConversionExecutionException extends ConversionException {
|
||||
* @param targetClass the value's target type
|
||||
* @param cause the cause of the conversion failure
|
||||
*/
|
||||
public ConversionExecutionException(Object value, Class sourceClass, Class targetClass, Throwable cause) {
|
||||
public ConversionExecutionException(Object value, Class<?> sourceClass, Class<?> targetClass, Throwable cause) {
|
||||
super(defaultMessage(value, sourceClass, targetClass, cause), cause);
|
||||
this.value = value;
|
||||
this.sourceClass = sourceClass;
|
||||
@@ -60,7 +60,7 @@ public class ConversionExecutionException extends ConversionException {
|
||||
* @param targetClass the value's target type
|
||||
* @param message a descriptive message of what went wrong.
|
||||
*/
|
||||
public ConversionExecutionException(Object value, Class sourceClass, Class targetClass, String message) {
|
||||
public ConversionExecutionException(Object value, Class<?> sourceClass, Class<?> targetClass, String message) {
|
||||
super(message);
|
||||
this.value = value;
|
||||
this.sourceClass = sourceClass;
|
||||
@@ -77,18 +77,18 @@ public class ConversionExecutionException extends ConversionException {
|
||||
/**
|
||||
* Returns the source type we tried to convert the value from.
|
||||
*/
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return sourceClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target type we tried to convert the value to.
|
||||
*/
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
private static String defaultMessage(Object value, Class sourceClass, Class targetClass, Throwable cause) {
|
||||
private static String defaultMessage(Object value, Class<?> sourceClass, Class<?> targetClass, Throwable cause) {
|
||||
return "Unable to convert value " + StylerUtils.style(value) + " from type '" + sourceClass.getName()
|
||||
+ "' to type '" + targetClass.getName() + "'; reason = '" + cause.getMessage() + "'";
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ public interface ConversionExecutor {
|
||||
* Returns the source class of conversions performed by this executor.
|
||||
* @return the source class
|
||||
*/
|
||||
public Class getSourceClass();
|
||||
public Class<?> getSourceClass();
|
||||
|
||||
/**
|
||||
* Returns the target class of conversions performed by this executor.
|
||||
* @return the target class
|
||||
*/
|
||||
public Class getTargetClass();
|
||||
public Class<?> getTargetClass();
|
||||
|
||||
/**
|
||||
* Execute the conversion for the provided source object.
|
||||
|
||||
@@ -23,9 +23,9 @@ package org.springframework.binding.convert;
|
||||
*/
|
||||
public class ConversionExecutorNotFoundException extends ConversionException {
|
||||
|
||||
private Class sourceClass;
|
||||
private Class<?> sourceClass;
|
||||
|
||||
private Class targetClass;
|
||||
private Class<?> targetClass;
|
||||
|
||||
/**
|
||||
* Creates a new conversion executor not found exception.
|
||||
@@ -33,7 +33,7 @@ public class ConversionExecutorNotFoundException extends ConversionException {
|
||||
* @param targetClass the target type requested to convert to
|
||||
* @param message a descriptive message
|
||||
*/
|
||||
public ConversionExecutorNotFoundException(Class sourceClass, Class targetClass, String message) {
|
||||
public ConversionExecutorNotFoundException(Class<?> sourceClass, Class<?> targetClass, String message) {
|
||||
super(message);
|
||||
this.sourceClass = sourceClass;
|
||||
this.targetClass = targetClass;
|
||||
@@ -42,14 +42,14 @@ public class ConversionExecutorNotFoundException extends ConversionException {
|
||||
/**
|
||||
* Returns the source type requested to convert from.
|
||||
*/
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return sourceClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target type requested to convert to.
|
||||
*/
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.binding.convert;
|
||||
|
||||
|
||||
/**
|
||||
* A service interface for retrieving type conversion executors. The returned command objects are thread-safe and may be
|
||||
* safely cached for use by client code.
|
||||
@@ -33,7 +32,7 @@ public interface ConversionService {
|
||||
* @return the converted object, an instance of the <code>targetClass</code>
|
||||
* @throws ConversionException if an exception occurred during the conversion process
|
||||
*/
|
||||
public Object executeConversion(Object source, Class targetClass) throws ConversionException;
|
||||
public Object executeConversion(Object source, Class<?> targetClass) throws ConversionException;
|
||||
|
||||
/**
|
||||
* Execute a conversion using the custom converter with the provided id.
|
||||
@@ -44,7 +43,7 @@ public interface ConversionService {
|
||||
* @return the converted object, an instance of the <code>targetClass</code>
|
||||
* @throws ConversionException if an exception occurred during the conversion process
|
||||
*/
|
||||
public Object executeConversion(String converterId, Object source, Class targetClass);
|
||||
public Object executeConversion(String converterId, Object source, Class<?> targetClass);
|
||||
|
||||
/**
|
||||
* Return the default conversion executor capable of converting source objects of the specified
|
||||
@@ -56,7 +55,7 @@ public interface ConversionService {
|
||||
* @return the executor that can execute instance type conversion, never null
|
||||
* @throws ConversionExecutorNotFoundException when no suitable conversion executor could be found
|
||||
*/
|
||||
public ConversionExecutor getConversionExecutor(Class sourceClass, Class targetClass)
|
||||
public ConversionExecutor getConversionExecutor(Class<?> sourceClass, Class<?> targetClass)
|
||||
throws ConversionExecutorNotFoundException;
|
||||
|
||||
/**
|
||||
@@ -70,7 +69,7 @@ public interface ConversionService {
|
||||
* @return the executor that can execute instance type conversion, never null
|
||||
* @throws ConversionExecutorNotFoundException when no suitable conversion executor could be found
|
||||
*/
|
||||
public ConversionExecutor getConversionExecutor(String id, Class sourceClass, Class targetClass)
|
||||
public ConversionExecutor getConversionExecutor(String id, Class<?> sourceClass, Class<?> targetClass)
|
||||
throws ConversionExecutorNotFoundException;
|
||||
|
||||
/**
|
||||
@@ -78,7 +77,7 @@ public interface ConversionService {
|
||||
* @param alias the class alias
|
||||
* @return the class, or <code>null</code> if no alias exists
|
||||
*/
|
||||
public Class getClassForAlias(String alias);
|
||||
public Class<?> getClassForAlias(String alias);
|
||||
|
||||
/**
|
||||
* Return the underlying Spring ConversionService.
|
||||
|
||||
@@ -51,20 +51,20 @@ public class ArrayToArray implements Converter {
|
||||
this.elementConverter = elementConverter;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return Object[].class;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return Object[].class;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
Class sourceComponentType = source.getClass().getComponentType();
|
||||
Class targetComponentType = targetClass.getComponentType();
|
||||
Class<?> sourceComponentType = source.getClass().getComponentType();
|
||||
Class<?> targetComponentType = targetClass.getComponentType();
|
||||
int length = Array.getLength(source);
|
||||
Object targetArray = Array.newInstance(targetComponentType, length);
|
||||
ConversionExecutor converter = getElementConverter(sourceComponentType, targetComponentType);
|
||||
@@ -75,7 +75,7 @@ public class ArrayToArray implements Converter {
|
||||
return targetArray;
|
||||
}
|
||||
|
||||
private ConversionExecutor getElementConverter(Class sourceComponentType, Class targetComponentType) {
|
||||
private ConversionExecutor getElementConverter(Class<?> sourceComponentType, Class<?> targetComponentType) {
|
||||
if (elementConverter != null) {
|
||||
return elementConverter;
|
||||
} else {
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.TreeSet;
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
import org.springframework.binding.convert.ConversionService;
|
||||
import org.springframework.core.GenericCollectionTypeResolver;
|
||||
import org.springframework.core.JdkVersion;
|
||||
|
||||
/**
|
||||
* Special converter that converts from a source array to a target collection. Supports the selection of an
|
||||
@@ -67,21 +66,22 @@ public class ArrayToCollection implements TwoWayConverter {
|
||||
this.elementConverter = elementConverter;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return Object[].class;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return Collection.class;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
Class collectionImplClass = getCollectionImplClass(targetClass);
|
||||
Constructor constructor = collectionImplClass.getConstructor(null);
|
||||
Collection collection = (Collection) constructor.newInstance(null);
|
||||
Class<?> collectionImplClass = getCollectionImplClass(targetClass);
|
||||
Constructor<?> constructor = collectionImplClass.getConstructor();
|
||||
Collection<Object> collection = (Collection<Object>) constructor.newInstance();
|
||||
ConversionExecutor converter = getArrayElementConverter(source, targetClass);
|
||||
int length = Array.getLength(source);
|
||||
for (int i = 0; i < length; i++) {
|
||||
@@ -94,22 +94,22 @@ public class ArrayToCollection implements TwoWayConverter {
|
||||
return collection;
|
||||
}
|
||||
|
||||
public Object convertTargetToSourceClass(Object target, Class sourceClass) throws Exception {
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception {
|
||||
if (target == null) {
|
||||
return null;
|
||||
}
|
||||
Collection collection = (Collection) target;
|
||||
Collection<?> collection = (Collection<?>) target;
|
||||
Object array = Array.newInstance(sourceClass.getComponentType(), collection.size());
|
||||
int i = 0;
|
||||
for (Iterator it = collection.iterator(); it.hasNext(); i++) {
|
||||
for (Iterator<?> it = collection.iterator(); it.hasNext(); i++) {
|
||||
Object value = it.next();
|
||||
if (value != null) {
|
||||
ConversionExecutor converter;
|
||||
if (elementConverter != null) {
|
||||
converter = elementConverter;
|
||||
} else {
|
||||
converter = conversionService.getConversionExecutor(value.getClass(), sourceClass
|
||||
.getComponentType());
|
||||
converter = conversionService.getConversionExecutor(value.getClass(),
|
||||
sourceClass.getComponentType());
|
||||
}
|
||||
value = converter.execute(value);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class ArrayToCollection implements TwoWayConverter {
|
||||
return array;
|
||||
}
|
||||
|
||||
private Class getCollectionImplClass(Class targetClass) {
|
||||
private Class<?> getCollectionImplClass(Class<?> targetClass) {
|
||||
if (targetClass.isInterface()) {
|
||||
if (List.class.equals(targetClass)) {
|
||||
return ArrayList.class;
|
||||
@@ -134,16 +134,16 @@ public class ArrayToCollection implements TwoWayConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private ConversionExecutor getArrayElementConverter(Object source, Class targetClass) {
|
||||
@SuppressWarnings("unchecked")
|
||||
private ConversionExecutor getArrayElementConverter(Object source, Class<?> targetClass) {
|
||||
if (elementConverter != null) {
|
||||
return elementConverter;
|
||||
} else {
|
||||
if (JdkVersion.isAtLeastJava15()) {
|
||||
Class elementType = GenericCollectionTypeResolver.getCollectionType(targetClass);
|
||||
if (elementType != null) {
|
||||
Class componentType = source.getClass().getComponentType();
|
||||
return conversionService.getConversionExecutor(componentType, elementType);
|
||||
}
|
||||
Class<?> elementType = GenericCollectionTypeResolver
|
||||
.getCollectionType((Class<? extends Collection<?>>) targetClass);
|
||||
if (elementType != null) {
|
||||
Class<?> componentType = source.getClass().getComponentType();
|
||||
return conversionService.getConversionExecutor(componentType, elementType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package org.springframework.binding.convert.converters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
import org.springframework.binding.convert.ConversionService;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.GenericCollectionTypeResolver;
|
||||
import org.springframework.core.JdkVersion;
|
||||
|
||||
/**
|
||||
* A converter that can convert from one collection type to another.
|
||||
@@ -21,6 +15,8 @@ import org.springframework.core.JdkVersion;
|
||||
*/
|
||||
public class CollectionToCollection implements Converter {
|
||||
|
||||
private static final int DEFAULT_INITIAL_SIZE = 16;
|
||||
|
||||
private ConversionService conversionService;
|
||||
|
||||
private ConversionExecutor elementConverter;
|
||||
@@ -42,21 +38,21 @@ public class CollectionToCollection implements Converter {
|
||||
this.elementConverter = elementConverter;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return Collection.class;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return Collection.class;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
Class targetCollectionImpl = getCollectionImplClass(targetClass);
|
||||
Collection targetCollection = (Collection) targetCollectionImpl.getConstructor(null).newInstance(null);
|
||||
ConversionExecutor elementConverter = getElementConverter(source, targetClass);
|
||||
Collection targetCollection = CollectionFactory.createCollection(targetClass, DEFAULT_INITIAL_SIZE);
|
||||
ConversionExecutor elementConverter = getElementConverter(source, (Class<? extends Collection<?>>) targetClass);
|
||||
Collection sourceCollection = (Collection) source;
|
||||
Iterator it = sourceCollection.iterator();
|
||||
while (it.hasNext()) {
|
||||
@@ -69,33 +65,14 @@ public class CollectionToCollection implements Converter {
|
||||
return targetCollection;
|
||||
}
|
||||
|
||||
// this code is duplicated in ArrayToCollection.java and ObjectToCollection too
|
||||
private Class getCollectionImplClass(Class targetClass) {
|
||||
if (targetClass.isInterface()) {
|
||||
if (List.class.equals(targetClass)) {
|
||||
return ArrayList.class;
|
||||
} else if (Set.class.equals(targetClass)) {
|
||||
return LinkedHashSet.class;
|
||||
} else if (SortedSet.class.equals(targetClass)) {
|
||||
return TreeSet.class;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported collection interface [" + targetClass.getName() + "]");
|
||||
}
|
||||
} else {
|
||||
return targetClass;
|
||||
}
|
||||
}
|
||||
|
||||
private ConversionExecutor getElementConverter(Object source, Class targetClass) {
|
||||
private ConversionExecutor getElementConverter(Object source, Class<? extends Collection<?>> targetClass) {
|
||||
if (elementConverter != null) {
|
||||
return elementConverter;
|
||||
} else {
|
||||
if (JdkVersion.isAtLeastJava15()) {
|
||||
Class elementType = GenericCollectionTypeResolver.getCollectionType(targetClass);
|
||||
if (elementType != null) {
|
||||
Class componentType = source.getClass().getComponentType();
|
||||
return conversionService.getConversionExecutor(componentType, elementType);
|
||||
}
|
||||
Class<?> elementType = GenericCollectionTypeResolver.getCollectionType(targetClass);
|
||||
if (elementType != null) {
|
||||
Class<?> componentType = source.getClass().getComponentType();
|
||||
return conversionService.getConversionExecutor(componentType, elementType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ package org.springframework.binding.convert.converters;
|
||||
|
||||
/**
|
||||
* A converter is capable of converting a source object of type {@link #getSourceClass()} to a target type of type
|
||||
* {@link #getTargetClass()}. If the converter is a {@link TwoWayConverter}, it can also convert from the target back
|
||||
* to the source.
|
||||
* {@link #getTargetClass()}. If the converter is a {@link TwoWayConverter}, it can also convert from the target back to
|
||||
* the source.
|
||||
* <p>
|
||||
* Implementations of this interface are thread-safe and can be shared.
|
||||
* </p>
|
||||
@@ -31,14 +31,14 @@ public interface Converter {
|
||||
* convert specific subclasses as well.
|
||||
* @return the source type
|
||||
*/
|
||||
public Class getSourceClass();
|
||||
public Class<?> getSourceClass();
|
||||
|
||||
/**
|
||||
* The target class this converter can convert to. May be an interface or abstract type to allow this converter to
|
||||
* convert specific subclasses as well.
|
||||
* @return the target type
|
||||
*/
|
||||
public Class getTargetClass();
|
||||
public Class<?> getTargetClass();
|
||||
|
||||
/**
|
||||
* Convert the provided source object argument to an instance of the specified target class.
|
||||
@@ -48,6 +48,6 @@ public interface Converter {
|
||||
* @return the converted object, which must be an instance of the <code>targetClass</code>
|
||||
* @throws Exception an exception occurred performing the conversion
|
||||
*/
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception;
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception;
|
||||
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class FormattedStringToNumber extends StringToObject {
|
||||
super(Number.class);
|
||||
}
|
||||
|
||||
public FormattedStringToNumber(Class numberClass) {
|
||||
public FormattedStringToNumber(Class<? extends Number> numberClass) {
|
||||
super(numberClass);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,8 @@ public class FormattedStringToNumber extends StringToObject {
|
||||
this.lenient = lenient;
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class targetClass) throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
ParsePosition parsePosition = new ParsePosition(0);
|
||||
NumberFormat format = numberFormatFactory.getNumberFormat();
|
||||
Number number = format.parse(string, parsePosition);
|
||||
@@ -98,7 +99,7 @@ public class FormattedStringToNumber extends StringToObject {
|
||||
throw new InvalidFormatException(string, getPattern(format));
|
||||
}
|
||||
}
|
||||
return convertToNumberClass(number, targetClass);
|
||||
return convertToNumberClass(number, (Class<? extends Number>) targetClass);
|
||||
}
|
||||
|
||||
protected String toString(Object object) throws Exception {
|
||||
@@ -112,7 +113,8 @@ public class FormattedStringToNumber extends StringToObject {
|
||||
* @return the coersed number
|
||||
* @throws IllegalArgumentException when an overflow condition occurs during coersion
|
||||
*/
|
||||
protected Number convertToNumberClass(Number number, Class numberClass) throws IllegalArgumentException {
|
||||
protected Number convertToNumberClass(Number number, Class<? extends Number> numberClass)
|
||||
throws IllegalArgumentException {
|
||||
return NumberUtils.convertNumberToTargetClass(number, numberClass);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,16 +22,16 @@ import org.springframework.util.NumberUtils;
|
||||
*/
|
||||
public class NumberToNumber implements Converter {
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return Number.class;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return Number.class;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
return NumberUtils.convertNumberToTargetClass((Number) source, targetClass);
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
return NumberUtils.convertNumberToTargetClass((Number) source, (Class<? extends Number>) targetClass);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,19 +49,19 @@ public class ObjectToArray implements Converter {
|
||||
this.elementConverter = elementConverter;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return Object[].class;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
Class componentType = targetClass.getComponentType();
|
||||
Class<?> componentType = targetClass.getComponentType();
|
||||
Object array = Array.newInstance(componentType, 1);
|
||||
ConversionExecutor converter;
|
||||
if (elementConverter != null) {
|
||||
|
||||
@@ -15,19 +15,12 @@
|
||||
*/
|
||||
package org.springframework.binding.convert.converters;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
import org.springframework.binding.convert.ConversionService;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.GenericCollectionTypeResolver;
|
||||
import org.springframework.core.JdkVersion;
|
||||
|
||||
/**
|
||||
* Special two-way converter that converts an object to an single-element collection. Supports type conversion of the
|
||||
@@ -37,6 +30,8 @@ import org.springframework.core.JdkVersion;
|
||||
*/
|
||||
public class ObjectToCollection implements Converter {
|
||||
|
||||
private static final int DEFAULT_INITIAL_CAPACITY = 16;
|
||||
|
||||
private ConversionService conversionService;
|
||||
|
||||
private ConversionExecutor elementConverter;
|
||||
@@ -58,22 +53,21 @@ public class ObjectToCollection implements Converter {
|
||||
this.elementConverter = elementConverter;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return Collection.class;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
Class collectionImplClass = getCollectionImplClass(targetClass);
|
||||
Constructor constructor = collectionImplClass.getConstructor(null);
|
||||
Collection collection = (Collection) constructor.newInstance(null);
|
||||
ConversionExecutor converter = getElementConverter(source, targetClass);
|
||||
Collection collection = CollectionFactory.createCollection(targetClass, DEFAULT_INITIAL_CAPACITY);
|
||||
ConversionExecutor converter = getElementConverter(source, (Class<? extends Collection<?>>) targetClass);
|
||||
Object value;
|
||||
if (converter != null) {
|
||||
value = converter.execute(source);
|
||||
@@ -84,33 +78,14 @@ public class ObjectToCollection implements Converter {
|
||||
return collection;
|
||||
}
|
||||
|
||||
// this code is duplicated in ArrayToCollection and CollectionToCollection
|
||||
private Class getCollectionImplClass(Class targetClass) {
|
||||
if (targetClass.isInterface()) {
|
||||
if (List.class.equals(targetClass)) {
|
||||
return ArrayList.class;
|
||||
} else if (Set.class.equals(targetClass)) {
|
||||
return LinkedHashSet.class;
|
||||
} else if (SortedSet.class.equals(targetClass)) {
|
||||
return TreeSet.class;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported collection interface [" + targetClass.getName() + "]");
|
||||
}
|
||||
} else {
|
||||
return targetClass;
|
||||
}
|
||||
}
|
||||
|
||||
private ConversionExecutor getElementConverter(Object source, Class targetClass) {
|
||||
private ConversionExecutor getElementConverter(Object source, Class<? extends Collection<?>> targetClass) {
|
||||
if (elementConverter != null) {
|
||||
return elementConverter;
|
||||
} else {
|
||||
if (JdkVersion.isAtLeastJava15()) {
|
||||
Class elementType = GenericCollectionTypeResolver.getCollectionType(targetClass);
|
||||
if (elementType != null) {
|
||||
Class componentType = source.getClass().getComponentType();
|
||||
return conversionService.getConversionExecutor(componentType, elementType);
|
||||
}
|
||||
Class<?> elementType = GenericCollectionTypeResolver.getCollectionType(targetClass);
|
||||
if (elementType != null) {
|
||||
Class<?> componentType = source.getClass().getComponentType();
|
||||
return conversionService.getConversionExecutor(componentType, elementType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ public class PropertyEditorConverter extends StringToObject {
|
||||
* @param propertyEditor the property editor to adapt
|
||||
* @param targetClass the {@link PropertyEditor#getValue() value class} this property editor converts to from string
|
||||
*/
|
||||
public PropertyEditorConverter(PropertyEditor propertyEditor, Class targetClass) {
|
||||
public PropertyEditorConverter(PropertyEditor propertyEditor, Class<?> targetClass) {
|
||||
super(targetClass);
|
||||
this.propertyEditor = propertyEditor;
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
synchronized (propertyEditor) {
|
||||
propertyEditor.setAsText(string);
|
||||
return propertyEditor.getValue();
|
||||
|
||||
@@ -30,15 +30,15 @@ public class ReverseConverter implements Converter {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return converter.getTargetClass();
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return converter.getSourceClass();
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
return converter.convertTargetToSourceClass(source, targetClass);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,19 +28,20 @@ public class SpringConvertingConverterAdapter implements Converter {
|
||||
/**
|
||||
* The source value type to convert from.
|
||||
*/
|
||||
private final Class sourceClass;
|
||||
private final Class<?> sourceClass;
|
||||
|
||||
/**
|
||||
* The target value type to convert to.
|
||||
*/
|
||||
private final Class targetClass;
|
||||
private final Class<?> targetClass;
|
||||
|
||||
/**
|
||||
* The ConversionService that will perform the conversion.
|
||||
*/
|
||||
private ConversionService conversionService;
|
||||
|
||||
public SpringConvertingConverterAdapter(Class sourceClass, Class targetClass, ConversionService conversionService) {
|
||||
public SpringConvertingConverterAdapter(Class<?> sourceClass, Class<?> targetClass,
|
||||
ConversionService conversionService) {
|
||||
Assert.notNull(sourceClass, "The source class to convert from is required.");
|
||||
Assert.notNull(targetClass, "The target class to convert to is required.");
|
||||
Assert.notNull(conversionService, "A Spring ConversionService is required.");
|
||||
@@ -49,15 +50,15 @@ public class SpringConvertingConverterAdapter implements Converter {
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
return conversionService.convert(source, targetClass);
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return sourceClass;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class StringToBigDecimal extends StringToObject {
|
||||
super(BigDecimal.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return new BigDecimal(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class StringToBigInteger extends StringToObject {
|
||||
super(BigInteger.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return new BigInteger(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class StringToBoolean extends StringToObject {
|
||||
this.falseString = falseString;
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
if (trueString != null && string.equals(trueString)) {
|
||||
return Boolean.TRUE;
|
||||
} else if (falseString != null && string.equals(falseString)) {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class StringToByte extends StringToObject {
|
||||
super(Byte.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return Byte.valueOf(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class StringToCharacter extends StringToObject {
|
||||
super(Character.class);
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
return new Character(string.charAt(0));
|
||||
}
|
||||
|
||||
|
||||
@@ -31,12 +31,12 @@ public class StringToClass extends StringToObject {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return ClassUtils.forName(string, classLoader);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
Class clazz = (Class) object;
|
||||
Class<?> clazz = (Class<?>) object;
|
||||
return clazz.getName();
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class StringToDate extends StringToObject {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class targetClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
if (!StringUtils.hasText(string)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class StringToDouble extends StringToObject {
|
||||
super(Double.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return Double.valueOf(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,9 @@ public class StringToEnum extends StringToObject {
|
||||
super(Enum.class);
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class targetClass) throws Exception {
|
||||
return Enum.valueOf(targetClass, string);
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
return Enum.valueOf((Class) targetClass, string);
|
||||
}
|
||||
|
||||
protected String toString(Object object) throws Exception {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class StringToFloat extends StringToObject {
|
||||
super(Float.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return Float.valueOf(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class StringToInteger extends StringToObject {
|
||||
super(Integer.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return Integer.valueOf(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.core.enums.StaticLabeledEnumResolver;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
@Deprecated
|
||||
public class StringToLabeledEnum extends StringToObject {
|
||||
|
||||
private LabeledEnumResolver labeledEnumResolver = StaticLabeledEnumResolver.instance();
|
||||
@@ -32,7 +33,7 @@ public class StringToLabeledEnum extends StringToObject {
|
||||
super(LabeledEnum.class);
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
return labeledEnumResolver.getLabeledEnumByLabel(targetClass, string);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class StringToLocale extends StringToObject {
|
||||
super(Locale.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return StringUtils.parseLocaleString(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class StringToLong extends StringToObject {
|
||||
super(Long.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return Long.valueOf(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,21 +17,21 @@ package org.springframework.binding.convert.converters;
|
||||
|
||||
public abstract class StringToObject implements TwoWayConverter {
|
||||
|
||||
private Class objectClass;
|
||||
private Class<?> objectClass;
|
||||
|
||||
public StringToObject(Class objectClass) {
|
||||
public StringToObject(Class<?> objectClass) {
|
||||
this.objectClass = objectClass;
|
||||
}
|
||||
|
||||
public final Class getSourceClass() {
|
||||
public final Class<?> getSourceClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public final Class getTargetClass() {
|
||||
public final Class<?> getTargetClass() {
|
||||
return objectClass;
|
||||
}
|
||||
|
||||
public final Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
public final Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
String string = (String) source;
|
||||
if (string != null && string.length() > 0) {
|
||||
return toObject(string, targetClass);
|
||||
@@ -40,7 +40,7 @@ public abstract class StringToObject implements TwoWayConverter {
|
||||
}
|
||||
}
|
||||
|
||||
public final Object convertTargetToSourceClass(Object target, Class sourceClass) throws Exception {
|
||||
public final Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception {
|
||||
if (target != null) {
|
||||
return toString(target);
|
||||
} else {
|
||||
@@ -48,7 +48,7 @@ public abstract class StringToObject implements TwoWayConverter {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Object toObject(String string, Class targetClass) throws Exception;
|
||||
protected abstract Object toObject(String string, Class<?> targetClass) throws Exception;
|
||||
|
||||
protected abstract String toString(Object object) throws Exception;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class StringToShort extends StringToObject {
|
||||
super(Short.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
return Short.valueOf(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,6 @@ public interface TwoWayConverter extends Converter {
|
||||
* @return the converted object, which must be an instance of the <code>sourceClass</code>
|
||||
* @throws Exception an exception occurred performing the conversion
|
||||
*/
|
||||
public Object convertTargetToSourceClass(Object target, Class sourceClass) throws Exception;
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception;
|
||||
|
||||
}
|
||||
@@ -53,12 +53,12 @@ public class GenericConversionService implements ConversionService {
|
||||
* A map of custom converters. Custom converters are assigned a unique identifier that can be used to lookup the
|
||||
* converter. This allows multiple converters for the same source->target class to be registered.
|
||||
*/
|
||||
private final Map customConverters = new HashMap();
|
||||
private final Map<String, Converter> customConverters = new HashMap<String, Converter>();
|
||||
|
||||
/**
|
||||
* Indexes classes by well-known aliases.
|
||||
*/
|
||||
private final Map aliasMap = new HashMap();
|
||||
private final Map<String, Class<?>> aliasMap = new HashMap<String, Class<?>>();
|
||||
|
||||
/**
|
||||
* An optional parent conversion service.
|
||||
@@ -143,11 +143,11 @@ public class GenericConversionService implements ConversionService {
|
||||
/**
|
||||
* Add an alias for given target type.
|
||||
*/
|
||||
public void addAlias(String alias, Class targetType) {
|
||||
public void addAlias(String alias, Class<?> targetType) {
|
||||
aliasMap.put(alias, targetType);
|
||||
}
|
||||
|
||||
public ConversionExecutor getConversionExecutor(Class sourceClass, Class targetClass)
|
||||
public ConversionExecutor getConversionExecutor(Class<?> sourceClass, Class<?> targetClass)
|
||||
throws ConversionExecutorNotFoundException {
|
||||
Assert.notNull(sourceClass, "The source class to convert from is required");
|
||||
Assert.notNull(targetClass, "The target class to convert to is required");
|
||||
@@ -168,12 +168,12 @@ public class GenericConversionService implements ConversionService {
|
||||
}
|
||||
}
|
||||
|
||||
public ConversionExecutor getConversionExecutor(String id, Class sourceClass, Class targetClass)
|
||||
public ConversionExecutor getConversionExecutor(String id, Class<?> sourceClass, Class<?> targetClass)
|
||||
throws ConversionExecutorNotFoundException {
|
||||
Assert.hasText(id, "The id of the custom converter is required");
|
||||
Assert.notNull(sourceClass, "The source class to convert from is required");
|
||||
Assert.notNull(targetClass, "The target class to convert to is required");
|
||||
Converter converter = (Converter) customConverters.get(id);
|
||||
Converter converter = customConverters.get(id);
|
||||
if (converter == null) {
|
||||
if (parent != null) {
|
||||
return parent.getConversionExecutor(id, sourceClass, targetClass);
|
||||
@@ -186,9 +186,9 @@ public class GenericConversionService implements ConversionService {
|
||||
sourceClass = convertToWrapperClassIfNecessary(sourceClass);
|
||||
targetClass = convertToWrapperClassIfNecessary(targetClass);
|
||||
if (sourceClass.isArray()) {
|
||||
Class sourceComponentType = sourceClass.getComponentType();
|
||||
Class<?> sourceComponentType = sourceClass.getComponentType();
|
||||
if (targetClass.isArray()) {
|
||||
Class targetComponentType = targetClass.getComponentType();
|
||||
Class<?> targetComponentType = targetClass.getComponentType();
|
||||
if (converter.getSourceClass().isAssignableFrom(sourceComponentType)) {
|
||||
if (!converter.getTargetClass().isAssignableFrom(targetComponentType)) {
|
||||
throw new ConversionExecutorNotFoundException(sourceClass, targetClass,
|
||||
@@ -221,15 +221,15 @@ public class GenericConversionService implements ConversionService {
|
||||
}
|
||||
if (converter.getSourceClass().isAssignableFrom(sourceComponentType)) {
|
||||
// type erasure has prevented us from getting the concrete type, this is best we can do for now
|
||||
ConversionExecutor elementConverter = new StaticConversionExecutor(sourceComponentType, converter
|
||||
.getTargetClass(), converter);
|
||||
ConversionExecutor elementConverter = new StaticConversionExecutor(sourceComponentType,
|
||||
converter.getTargetClass(), converter);
|
||||
return new StaticConversionExecutor(sourceClass, targetClass, new ArrayToCollection(
|
||||
elementConverter));
|
||||
} else if (converter.getTargetClass().isAssignableFrom(sourceComponentType)
|
||||
&& converter instanceof TwoWayConverter) {
|
||||
TwoWayConverter twoWay = (TwoWayConverter) converter;
|
||||
ConversionExecutor elementConverter = new StaticConversionExecutor(sourceComponentType, converter
|
||||
.getSourceClass(), new ReverseConverter(twoWay));
|
||||
ConversionExecutor elementConverter = new StaticConversionExecutor(sourceComponentType,
|
||||
converter.getSourceClass(), new ReverseConverter(twoWay));
|
||||
return new StaticConversionExecutor(sourceClass, targetClass, new ArrayToCollection(
|
||||
elementConverter));
|
||||
} else {
|
||||
@@ -242,7 +242,7 @@ public class GenericConversionService implements ConversionService {
|
||||
}
|
||||
}
|
||||
if (targetClass.isArray()) {
|
||||
Class targetComponentType = targetClass.getComponentType();
|
||||
Class<?> targetComponentType = targetClass.getComponentType();
|
||||
if (Collection.class.isAssignableFrom(sourceClass)) {
|
||||
// type erasure limits us here as well
|
||||
if (converter.getTargetClass().isAssignableFrom(targetComponentType)) {
|
||||
@@ -294,11 +294,11 @@ public class GenericConversionService implements ConversionService {
|
||||
ConversionExecutor elementConverter;
|
||||
// type erasure forces us to do runtime checks of list elements
|
||||
if (converter instanceof TwoWayConverter) {
|
||||
elementConverter = new TwoWayCapableConversionExecutor(converter.getSourceClass(), converter
|
||||
.getTargetClass(), (TwoWayConverter) converter);
|
||||
elementConverter = new TwoWayCapableConversionExecutor(converter.getSourceClass(),
|
||||
converter.getTargetClass(), (TwoWayConverter) converter);
|
||||
} else {
|
||||
elementConverter = new StaticConversionExecutor(converter.getSourceClass(), converter
|
||||
.getTargetClass(), converter);
|
||||
elementConverter = new StaticConversionExecutor(converter.getSourceClass(),
|
||||
converter.getTargetClass(), converter);
|
||||
}
|
||||
return new StaticConversionExecutor(sourceClass, targetClass, new CollectionToCollection(
|
||||
elementConverter));
|
||||
@@ -340,7 +340,7 @@ public class GenericConversionService implements ConversionService {
|
||||
}
|
||||
}
|
||||
|
||||
public Object executeConversion(Object source, Class targetClass) throws ConversionException {
|
||||
public Object executeConversion(Object source, Class<?> targetClass) throws ConversionException {
|
||||
if (source != null) {
|
||||
ConversionExecutor conversionExecutor = getConversionExecutor(source.getClass(), targetClass);
|
||||
return conversionExecutor.execute(source);
|
||||
@@ -349,7 +349,7 @@ public class GenericConversionService implements ConversionService {
|
||||
}
|
||||
}
|
||||
|
||||
public Object executeConversion(String converterId, Object source, Class targetClass) throws ConversionException {
|
||||
public Object executeConversion(String converterId, Object source, Class<?> targetClass) throws ConversionException {
|
||||
if (source != null) {
|
||||
ConversionExecutor conversionExecutor = getConversionExecutor(converterId, source.getClass(), targetClass);
|
||||
return conversionExecutor.execute(source);
|
||||
@@ -358,8 +358,8 @@ public class GenericConversionService implements ConversionService {
|
||||
}
|
||||
}
|
||||
|
||||
public Class getClassForAlias(String name) throws IllegalArgumentException {
|
||||
Class clazz = (Class) aliasMap.get(name);
|
||||
public Class<?> getClassForAlias(String name) throws IllegalArgumentException {
|
||||
Class<?> clazz = aliasMap.get(name);
|
||||
if (clazz != null) {
|
||||
return clazz;
|
||||
} else {
|
||||
@@ -373,7 +373,7 @@ public class GenericConversionService implements ConversionService {
|
||||
|
||||
// internal helpers
|
||||
|
||||
private Class convertToWrapperClassIfNecessary(Class targetType) {
|
||||
private Class<?> convertToWrapperClassIfNecessary(Class<?> targetType) {
|
||||
if (targetType.isPrimitive()) {
|
||||
if (targetType.equals(int.class)) {
|
||||
return Integer.class;
|
||||
|
||||
@@ -24,27 +24,27 @@ import org.springframework.binding.convert.converters.Converter;
|
||||
*/
|
||||
class NoOpConverter implements Converter {
|
||||
|
||||
private Class sourceClass;
|
||||
private Class<?> sourceClass;
|
||||
|
||||
private Class targetClass;
|
||||
private Class<?> targetClass;
|
||||
|
||||
/**
|
||||
* Create a "no op" converter from given source to given target class.
|
||||
*/
|
||||
public NoOpConverter(Class sourceClass, Class targetClass) {
|
||||
public NoOpConverter(Class<?> sourceClass, Class<?> targetClass) {
|
||||
this.sourceClass = sourceClass;
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return sourceClass;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class NoOpConverter implements Converter {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object convertTargetToSourceClass(Object target, Class sourceClass) throws Exception,
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception,
|
||||
UnsupportedOperationException {
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class RuntimeBindingConversionExecutor implements ConversionExecutor {
|
||||
|
||||
private Class targetClass;
|
||||
private Class<?> targetClass;
|
||||
|
||||
private ConversionService conversionService;
|
||||
|
||||
@@ -35,18 +35,18 @@ public class RuntimeBindingConversionExecutor implements ConversionExecutor {
|
||||
* @param targetClass the target type to convert to
|
||||
* @param conversionService the conversion service to get converters from
|
||||
*/
|
||||
public RuntimeBindingConversionExecutor(Class targetClass, ConversionService conversionService) {
|
||||
public RuntimeBindingConversionExecutor(Class<?> targetClass, ConversionService conversionService) {
|
||||
Assert.notNull(targetClass, "The target class of the conversion is required");
|
||||
Assert.notNull(conversionService, "The conversion service is required");
|
||||
this.targetClass = targetClass;
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SpringBindingConverterAdapter implements GenericConverter {
|
||||
}
|
||||
}
|
||||
|
||||
public Set getConvertibleTypes() {
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
return Collections.singleton(new ConvertiblePair(converter.getSourceClass(), converter.getTargetClass()));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,12 @@ public class StaticConversionExecutor implements ConversionExecutor {
|
||||
/**
|
||||
* The source value type this executor will attempt to convert from.
|
||||
*/
|
||||
private final Class sourceClass;
|
||||
private final Class<?> sourceClass;
|
||||
|
||||
/**
|
||||
* The target value type this executor will attempt to convert to.
|
||||
*/
|
||||
private final Class targetClass;
|
||||
private final Class<?> targetClass;
|
||||
|
||||
/**
|
||||
* The converter that will perform the conversion.
|
||||
@@ -53,7 +53,7 @@ public class StaticConversionExecutor implements ConversionExecutor {
|
||||
* @param targetClass the target type that the converter will convert to
|
||||
* @param converter the converter that will perform the conversion
|
||||
*/
|
||||
public StaticConversionExecutor(Class sourceClass, Class targetClass, Converter converter) {
|
||||
public StaticConversionExecutor(Class<?> sourceClass, Class<?> targetClass, Converter converter) {
|
||||
Assert.notNull(sourceClass, "The source class is required");
|
||||
Assert.notNull(targetClass, "The target class is required");
|
||||
Assert.notNull(converter, "The converter is required");
|
||||
@@ -66,7 +66,7 @@ public class StaticConversionExecutor implements ConversionExecutor {
|
||||
* Returns the source class of conversions performed by this executor.
|
||||
* @return the source class
|
||||
*/
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return sourceClass;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class StaticConversionExecutor implements ConversionExecutor {
|
||||
* Returns the target class of conversions performed by this executor.
|
||||
* @return the target class
|
||||
*/
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ import org.springframework.binding.convert.converters.TwoWayConverter;
|
||||
*/
|
||||
class TwoWayCapableConversionExecutor implements ConversionExecutor {
|
||||
|
||||
private Class sourceClass;
|
||||
private Class<?> sourceClass;
|
||||
|
||||
private Class targetClass;
|
||||
private Class<?> targetClass;
|
||||
|
||||
private TwoWayConverter converter;
|
||||
|
||||
@@ -39,17 +39,17 @@ class TwoWayCapableConversionExecutor implements ConversionExecutor {
|
||||
* @param targetClass the target class to convert from (or to)
|
||||
* @param converter the two way converter
|
||||
*/
|
||||
public TwoWayCapableConversionExecutor(Class sourceClass, Class targetClass, TwoWayConverter converter) {
|
||||
public TwoWayCapableConversionExecutor(Class<?> sourceClass, Class<?> targetClass, TwoWayConverter converter) {
|
||||
this.sourceClass = sourceClass;
|
||||
this.targetClass = targetClass;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return sourceClass;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package org.springframework.binding.expression;
|
||||
*/
|
||||
public class EvaluationException extends RuntimeException {
|
||||
|
||||
private Class contextClass;
|
||||
private Class<?> contextClass;
|
||||
|
||||
private String expressionString;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class EvaluationException extends RuntimeException {
|
||||
* @param expressionString the string form of the expression that failed to evaluate
|
||||
* @param message the exception message
|
||||
*/
|
||||
public EvaluationException(Class contextClass, String expressionString, String message) {
|
||||
public EvaluationException(Class<?> contextClass, String expressionString, String message) {
|
||||
this(contextClass, expressionString, message, null);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class EvaluationException extends RuntimeException {
|
||||
* @param message the exception message
|
||||
* @param cause the underlying cause of this evaluation exception
|
||||
*/
|
||||
public EvaluationException(Class contextClass, String expressionString, String message, Throwable cause) {
|
||||
public EvaluationException(Class<?> contextClass, String expressionString, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class EvaluationException extends RuntimeException {
|
||||
* The class of object upon which evaluation was attempted and failed.
|
||||
* @return the context class
|
||||
*/
|
||||
public Class getContextClass() {
|
||||
public Class<?> getContextClass() {
|
||||
return contextClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public interface Expression {
|
||||
* information cannot be determined
|
||||
* @throws EvaluationException an exception occurred during expression evaluation
|
||||
*/
|
||||
public Class getValueType(Object context) throws EvaluationException;
|
||||
public Class<?> getValueType(Object context) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Returns the original string used to create this expression, unmodified.
|
||||
|
||||
@@ -26,14 +26,14 @@ public interface ParserContext {
|
||||
* value to install custom variable resolves for that particular type of context.
|
||||
* @return the evaluation context type
|
||||
*/
|
||||
public Class getEvaluationContextType();
|
||||
public Class<?> getEvaluationContextType();
|
||||
|
||||
/**
|
||||
* Returns the expected type of object returned from evaluating the parsed expression. An expression parser may use
|
||||
* this value to coerce an raw evaluation result before it is returned.
|
||||
* @return the expected evaluation result type
|
||||
*/
|
||||
public Class getExpectedEvaluationResultType();
|
||||
public Class<?> getExpectedEvaluationResultType();
|
||||
|
||||
/**
|
||||
* Returns additional expression variables or aliases that can be referenced during expression evaluation. An
|
||||
|
||||
@@ -28,7 +28,7 @@ public class PropertyNotFoundException extends EvaluationException {
|
||||
* @param property the property that could not be found
|
||||
* @param cause root cause of the failure
|
||||
*/
|
||||
public PropertyNotFoundException(Class contextClass, String property, Throwable cause) {
|
||||
public PropertyNotFoundException(Class<?> contextClass, String property, Throwable cause) {
|
||||
super(contextClass, property, "Property not found", cause);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ValueCoercionException extends EvaluationException {
|
||||
|
||||
private transient Object value;
|
||||
|
||||
private Class targetClass;
|
||||
private Class<?> targetClass;
|
||||
|
||||
/**
|
||||
* Creates a new property not found exception
|
||||
@@ -33,7 +33,7 @@ public class ValueCoercionException extends EvaluationException {
|
||||
* @param value the value that could not be coerced
|
||||
* @param targetClass the class the value could not be coerced to
|
||||
*/
|
||||
public ValueCoercionException(Class contextClass, String property, Object value, Class targetClass) {
|
||||
public ValueCoercionException(Class<?> contextClass, String property, Object value, Class<?> targetClass) {
|
||||
this(contextClass, property, value, targetClass, null);
|
||||
this.value = value;
|
||||
this.targetClass = targetClass;
|
||||
@@ -47,7 +47,8 @@ public class ValueCoercionException extends EvaluationException {
|
||||
* @param targetClass the class the value could not be coerced to
|
||||
* @param cause root cause of the failure
|
||||
*/
|
||||
public ValueCoercionException(Class contextClass, String property, Object value, Class targetClass, Throwable cause) {
|
||||
public ValueCoercionException(Class<?> contextClass, String property, Object value, Class<?> targetClass,
|
||||
Throwable cause) {
|
||||
super(contextClass, property,
|
||||
"Value could not be converted to target class; is a suitable type converter registered?", cause);
|
||||
this.value = value;
|
||||
@@ -64,7 +65,7 @@ public class ValueCoercionException extends EvaluationException {
|
||||
/**
|
||||
* @return the class the value could not be coerced to
|
||||
*/
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class BeanWrapperExpression implements Expression {
|
||||
}
|
||||
}
|
||||
|
||||
public Class getValueType(Object context) {
|
||||
public Class<?> getValueType(Object context) {
|
||||
try {
|
||||
BeanWrapperImpl beanWrapper = new BeanWrapperImpl(context);
|
||||
return beanWrapper.getPropertyType(expression);
|
||||
|
||||
@@ -25,13 +25,13 @@ class BindingValueExpression extends ValueExpression {
|
||||
|
||||
private ValueExpression targetExpression;
|
||||
|
||||
private Class expectedType;
|
||||
private Class<?> expectedType;
|
||||
|
||||
private ConversionService conversionService;
|
||||
|
||||
private boolean template;
|
||||
|
||||
public BindingValueExpression(ValueExpression targetExpression, Class expectedType,
|
||||
public BindingValueExpression(ValueExpression targetExpression, Class<?> expectedType,
|
||||
ConversionService conversionService, boolean template) {
|
||||
Assert.notNull(expectedType, "The expectedType Class is required");
|
||||
Assert.notNull(conversionService, "The ConversionService to perform type coersions is required");
|
||||
@@ -41,11 +41,11 @@ class BindingValueExpression extends ValueExpression {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public Class getExpectedType() {
|
||||
public Class<?> getExpectedType() {
|
||||
return targetExpression.getExpectedType();
|
||||
}
|
||||
|
||||
public Class getType(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException {
|
||||
public Class<?> getType(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException {
|
||||
return targetExpression.getType(context);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class BindingValueExpression extends ValueExpression {
|
||||
return targetExpression.hashCode();
|
||||
}
|
||||
|
||||
private Object convertValueIfNecessary(Object value, Class expectedType, Object context)
|
||||
private Object convertValueIfNecessary(Object value, Class<?> expectedType, Object context)
|
||||
throws ValueCoercionException {
|
||||
if (expectedType == null) {
|
||||
return value;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DefaultELResolver extends CompositeELResolver {
|
||||
* that the base object has already been resolved by the time this resolver runs.
|
||||
* @param customResolvers the custom resolvers to apply before this resolver
|
||||
*/
|
||||
public DefaultELResolver(List customResolvers) {
|
||||
public DefaultELResolver(List<? extends ELResolver> customResolvers) {
|
||||
this(null, customResolvers);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class DefaultELResolver extends CompositeELResolver {
|
||||
* @param target the target, or "root", object of the expression
|
||||
* @param customResolvers the custom resolvers to apply before this resolver
|
||||
*/
|
||||
public DefaultELResolver(Object target, List customResolvers) {
|
||||
public DefaultELResolver(Object target, List<? extends ELResolver> customResolvers) {
|
||||
this.target = target;
|
||||
configureResolvers(customResolvers);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class DefaultELResolver extends CompositeELResolver {
|
||||
return target;
|
||||
}
|
||||
|
||||
public Class getType(ELContext context, Object base, Object property) {
|
||||
public Class<?> getType(ELContext context, Object base, Object property) {
|
||||
if (base == null) {
|
||||
return super.getType(context, target, property);
|
||||
} else {
|
||||
@@ -89,11 +89,11 @@ public class DefaultELResolver extends CompositeELResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private void configureResolvers(List customResolvers) {
|
||||
private void configureResolvers(List<? extends ELResolver> customResolvers) {
|
||||
if (customResolvers != null) {
|
||||
Iterator i = customResolvers.iterator();
|
||||
Iterator<? extends ELResolver> i = customResolvers.iterator();
|
||||
while (i.hasNext()) {
|
||||
ELResolver resolver = (ELResolver) i.next();
|
||||
ELResolver resolver = i.next();
|
||||
add(resolver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ELExpression implements Expression {
|
||||
}
|
||||
}
|
||||
|
||||
public Class getValueType(Object context) {
|
||||
public Class<?> getValueType(Object context) {
|
||||
ELContext ctx = elContextFactory.getELContext(context);
|
||||
try {
|
||||
return valueExpression.getType(ctx);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ELExpressionParser implements ExpressionParser {
|
||||
|
||||
private ExpressionFactory expressionFactory;
|
||||
|
||||
private Map contextFactories = new HashMap();
|
||||
private Map<Class<?>, ELContextFactory> contextFactories = new HashMap<Class<?>, ELContextFactory>();
|
||||
|
||||
private ConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ELExpressionParser implements ExpressionParser {
|
||||
* @param contextType the expression context class
|
||||
* @param contextFactory the context factory to use for expressions that evaluate those types of contexts
|
||||
*/
|
||||
public void putContextFactory(Class contextType, ELContextFactory contextFactory) {
|
||||
public void putContextFactory(Class<?> contextType, ELContextFactory contextFactory) {
|
||||
Assert.notNull(contextFactory, "The EL context factory cannot be null");
|
||||
contextFactories.put(contextType, contextFactory);
|
||||
}
|
||||
@@ -117,16 +117,16 @@ public class ELExpressionParser implements ExpressionParser {
|
||||
return new BindingValueExpression(expression, getExpectedType(context), conversionService, context.isTemplate());
|
||||
}
|
||||
|
||||
private Class getExpectedType(ParserContext context) {
|
||||
Class expectedType = context.getExpectedEvaluationResultType();
|
||||
private Class<?> getExpectedType(ParserContext context) {
|
||||
Class<?> expectedType = context.getExpectedEvaluationResultType();
|
||||
return expectedType != null ? expectedType : Object.class;
|
||||
}
|
||||
|
||||
private ELContextFactory getContextFactory(Class expressionTargetType, String expressionString) {
|
||||
private ELContextFactory getContextFactory(Class<?> expressionTargetType, String expressionString) {
|
||||
if (contextFactories.containsKey(expressionTargetType)) {
|
||||
return (ELContextFactory) contextFactories.get(expressionTargetType);
|
||||
return contextFactories.get(expressionTargetType);
|
||||
} else {
|
||||
return (ELContextFactory) contextFactories.get(Object.class);
|
||||
return contextFactories.get(Object.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,8 +172,7 @@ public class ELExpressionParser implements ExpressionParser {
|
||||
public void mapVariables(ExpressionVariable[] variables, ExpressionFactory expressionFactory) {
|
||||
if (variables != null && variables.length > 0) {
|
||||
variableMapper = new VariableMapperImpl();
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
ExpressionVariable var = variables[i];
|
||||
for (ExpressionVariable var : variables) {
|
||||
ParserContext context = var.getParserContext() != null ? var.getParserContext()
|
||||
: NullParserContext.INSTANCE;
|
||||
ValueExpression expr;
|
||||
@@ -191,14 +190,14 @@ public class ELExpressionParser implements ExpressionParser {
|
||||
}
|
||||
|
||||
private static class VariableMapperImpl extends VariableMapper {
|
||||
private Map variables = new HashMap();
|
||||
private Map<String, ValueExpression> variables = new HashMap<String, ValueExpression>();
|
||||
|
||||
public ValueExpression resolveVariable(String name) {
|
||||
return (ValueExpression) variables.get(name);
|
||||
return variables.get(name);
|
||||
}
|
||||
|
||||
public ValueExpression setVariable(String name, ValueExpression value) {
|
||||
return (ValueExpression) variables.put(name, value);
|
||||
return variables.put(name, value);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,18 +33,18 @@ import org.springframework.binding.collection.MapAdaptable;
|
||||
*/
|
||||
public class MapAdaptableELResolver extends ELResolver {
|
||||
|
||||
public Class getCommonPropertyType(ELContext context, Object base) {
|
||||
public Class<?> getCommonPropertyType(ELContext context, Object base) {
|
||||
if (base instanceof MapAdaptable) {
|
||||
return Object.class;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator getFeatureDescriptors(ELContext context, Object base) {
|
||||
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getType(ELContext context, Object base, Object property) throws NullPointerException,
|
||||
public Class<?> getType(ELContext context, Object base, Object property) throws NullPointerException,
|
||||
PropertyNotFoundException, ELException {
|
||||
if (context == null) {
|
||||
throw new NullPointerException("The ELContext is null.");
|
||||
@@ -102,8 +103,9 @@ public class MapAdaptableELResolver extends ELResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private Map adapt(Object base) {
|
||||
MapAdaptable adaptable = (MapAdaptable) base;
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<Object, Object> adapt(Object base) {
|
||||
MapAdaptable<Object, Object> adaptable = (MapAdaptable<Object, Object>) base;
|
||||
return adaptable.asMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.binding.expression.ognl;
|
||||
import java.lang.reflect.Member;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import ognl.NoSuchPropertyException;
|
||||
@@ -46,9 +45,9 @@ class OgnlExpression implements Expression {
|
||||
|
||||
private Object expression;
|
||||
|
||||
private Map variableExpressions;
|
||||
private Map<String, Expression> variableExpressions;
|
||||
|
||||
private Class expectedResultType;
|
||||
private Class<?> expectedResultType;
|
||||
|
||||
private String expressionString;
|
||||
|
||||
@@ -57,7 +56,7 @@ class OgnlExpression implements Expression {
|
||||
/**
|
||||
* Creates a new OGNL expression.
|
||||
*/
|
||||
public OgnlExpression(Object expression, Map variableExpressions, Class expectedResultType,
|
||||
public OgnlExpression(Object expression, Map<String, Expression> variableExpressions, Class<?> expectedResultType,
|
||||
String expressionString, ConversionService conversionService) {
|
||||
this.expression = expression;
|
||||
this.variableExpressions = variableExpressions;
|
||||
@@ -78,6 +77,7 @@ class OgnlExpression implements Expression {
|
||||
return expressionString.hashCode();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object getValue(Object context) throws EvaluationException {
|
||||
try {
|
||||
Map evaluationContext = Ognl.addDefaultContext(context, getVariables(context));
|
||||
@@ -96,6 +96,7 @@ class OgnlExpression implements Expression {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void setValue(Object context, Object value) {
|
||||
try {
|
||||
Map evaluationContext = Ognl.addDefaultContext(context, getVariables(context));
|
||||
@@ -114,7 +115,7 @@ class OgnlExpression implements Expression {
|
||||
}
|
||||
}
|
||||
|
||||
public Class getValueType(Object context) {
|
||||
public Class<?> getValueType(Object context) {
|
||||
try {
|
||||
// OGNL has no native way to get this information
|
||||
return new BeanWrapperImpl(context).getPropertyType(expressionString);
|
||||
@@ -148,6 +149,7 @@ class OgnlExpression implements Expression {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private TypeConverter createTypeConverter() {
|
||||
return new TypeConverter() {
|
||||
public Object convertValue(Map context, Object target, Member member, String propertyName, Object value,
|
||||
@@ -161,14 +163,13 @@ class OgnlExpression implements Expression {
|
||||
};
|
||||
}
|
||||
|
||||
private Map getVariables(Object context) {
|
||||
private Map<String, Object> getVariables(Object context) {
|
||||
if (variableExpressions == null) {
|
||||
return Collections.EMPTY_MAP;
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map variables = new HashMap(variableExpressions.size(), 1);
|
||||
for (Iterator it = variableExpressions.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry var = (Map.Entry) it.next();
|
||||
Expression valueExpression = (Expression) var.getValue();
|
||||
Map<String, Object> variables = new HashMap<String, Object>(variableExpressions.size(), 1);
|
||||
for (Map.Entry<String, Expression> var : variableExpressions.entrySet()) {
|
||||
Expression valueExpression = var.getValue();
|
||||
variables.put(var.getKey(), valueExpression.getValue(context));
|
||||
}
|
||||
return variables;
|
||||
|
||||
@@ -57,15 +57,15 @@ public class OgnlExpressionParser extends AbstractExpressionParser {
|
||||
* @param clazz the class that contains properties needing access
|
||||
* @param propertyAccessor the property access strategy
|
||||
*/
|
||||
public void addPropertyAccessor(Class clazz, PropertyAccessor propertyAccessor) {
|
||||
public void addPropertyAccessor(Class<?> clazz, PropertyAccessor propertyAccessor) {
|
||||
OgnlRuntime.setPropertyAccessor(clazz, propertyAccessor);
|
||||
}
|
||||
|
||||
protected Expression doParseExpression(String expressionString, ParserContext context) throws ParserException {
|
||||
try {
|
||||
return new OgnlExpression(Ognl.parseExpression(expressionString), parseVariableExpressions(context
|
||||
.getExpressionVariables()), context.getExpectedEvaluationResultType(), expressionString,
|
||||
conversionService);
|
||||
return new OgnlExpression(Ognl.parseExpression(expressionString),
|
||||
parseVariableExpressions(context.getExpressionVariables()),
|
||||
context.getExpectedEvaluationResultType(), expressionString, conversionService);
|
||||
} catch (OgnlException e) {
|
||||
throw new ParserException(expressionString, e);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.binding.expression.spel;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -48,7 +47,7 @@ public class SpringELExpression implements Expression {
|
||||
|
||||
private Class<?> expectedType;
|
||||
|
||||
private Map expressionVariables;
|
||||
private Map<String, Expression> expressionVariables;
|
||||
|
||||
private ConversionService conversionService;
|
||||
|
||||
@@ -65,8 +64,9 @@ public class SpringELExpression implements Expression {
|
||||
* @param conversionService the Spring ConversionService instance to use for type conversion
|
||||
* @param propertyAccessors propertyAccessors for Spring EL to use when evaluating expressions
|
||||
*/
|
||||
public SpringELExpression(org.springframework.expression.Expression expression, Map expressionVariables,
|
||||
Class expectedType, ConversionService conversionService, List<PropertyAccessor> propertyAccessors) {
|
||||
public SpringELExpression(org.springframework.expression.Expression expression,
|
||||
Map<String, Expression> expressionVariables, Class<?> expectedType, ConversionService conversionService,
|
||||
List<PropertyAccessor> propertyAccessors) {
|
||||
Assert.notNull(expression, "The SpelExpression is required for evaluation");
|
||||
this.expression = expression;
|
||||
this.expressionVariables = expressionVariables;
|
||||
@@ -95,7 +95,7 @@ public class SpringELExpression implements Expression {
|
||||
}
|
||||
}
|
||||
|
||||
public Class getValueType(Object rootObject) throws EvaluationException {
|
||||
public Class<?> getValueType(Object rootObject) throws EvaluationException {
|
||||
try {
|
||||
return expression.getValueType(newEvaluationContext(rootObject));
|
||||
} catch (SpelEvaluationException e) {
|
||||
@@ -150,9 +150,8 @@ public class SpringELExpression implements Expression {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, Object> variableValues = new HashMap<String, Object>(expressionVariables.size());
|
||||
for (Iterator iterator = expressionVariables.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry var = (Map.Entry) iterator.next();
|
||||
variableValues.put((String) var.getKey(), ((Expression) var.getValue()).getValue(rootObject));
|
||||
for (Map.Entry<String, Expression> var : expressionVariables.entrySet()) {
|
||||
variableValues.put(var.getKey(), var.getValue().getValue(rootObject));
|
||||
}
|
||||
return variableValues;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,8 @@ public class SpringELExpressionParser implements ExpressionParser {
|
||||
public Expression parseExpression(String expressionString, ParserContext parserContext) throws ParserException {
|
||||
Assert.hasText(expressionString, "The expression string to parse is required and must not be empty");
|
||||
parserContext = (parserContext == null) ? NullParserContext.INSTANCE : parserContext;
|
||||
Map spelExpressionVariables = parseSpelExpressionVariables(parserContext.getExpressionVariables());
|
||||
Map<String, Expression> spelExpressionVariables = parseSpelExpressionVariables(parserContext
|
||||
.getExpressionVariables());
|
||||
return new SpringELExpression(parseSpelExpression(expressionString, parserContext), spelExpressionVariables,
|
||||
parserContext.getExpectedEvaluationResultType(), conversionService.getDelegateConversionService(),
|
||||
propertyAccessors);
|
||||
@@ -93,13 +94,12 @@ public class SpringELExpressionParser implements ExpressionParser {
|
||||
* @param expressionVariables an array of ExpressionVariable instances.
|
||||
* @return a Map or null if the input array is empty.
|
||||
*/
|
||||
private Map parseSpelExpressionVariables(ExpressionVariable[] expressionVariables) {
|
||||
private Map<String, Expression> parseSpelExpressionVariables(ExpressionVariable[] expressionVariables) {
|
||||
if (expressionVariables == null || expressionVariables.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Map spelExpressionVariables = new HashMap(expressionVariables.length);
|
||||
for (int i = 0; i < expressionVariables.length; i++) {
|
||||
ExpressionVariable var = expressionVariables[i];
|
||||
Map<String, Expression> spelExpressionVariables = new HashMap<String, Expression>(expressionVariables.length);
|
||||
for (ExpressionVariable var : expressionVariables) {
|
||||
spelExpressionVariables.put(var.getName(),
|
||||
parseExpression(var.getValueExpression(), var.getParserContext()));
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
|
||||
* @throws ParserException when the expressions cannot be parsed
|
||||
*/
|
||||
private Expression[] parseExpressions(String expressionString, ParserContext context) throws ParserException {
|
||||
List expressions = new LinkedList();
|
||||
List<Expression> expressions = new LinkedList<Expression>();
|
||||
int startIdx = 0;
|
||||
while (startIdx < expressionString.length()) {
|
||||
int prefixIndex = expressionString.indexOf(getExpressionPrefix(), startIdx);
|
||||
@@ -218,16 +218,15 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
|
||||
startIdx = expressionString.length();
|
||||
}
|
||||
}
|
||||
return (Expression[]) expressions.toArray(new Expression[expressions.size()]);
|
||||
return expressions.toArray(new Expression[expressions.size()]);
|
||||
}
|
||||
|
||||
protected Map parseVariableExpressions(ExpressionVariable[] variables) throws ParserException {
|
||||
protected Map<String, Expression> parseVariableExpressions(ExpressionVariable[] variables) throws ParserException {
|
||||
if (variables == null || variables.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Map variableExpressions = new HashMap(variables.length, 1);
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
ExpressionVariable var = variables[i];
|
||||
Map<String, Expression> variableExpressions = new HashMap<String, Expression>(variables.length, 1);
|
||||
for (ExpressionVariable var : variables) {
|
||||
variableExpressions.put(var.getName(), parseExpression(var.getValueExpression(), var.getParserContext()));
|
||||
}
|
||||
return variableExpressions;
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class AbstractGetValueExpression implements Expression {
|
||||
throw new UnsupportedOperationException("Setting this expression's value is not supported");
|
||||
}
|
||||
|
||||
public Class getValueType(Object context) {
|
||||
public Class<?> getValueType(Object context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ public class CollectionAddingExpression implements Expression {
|
||||
return collectionExpression.getValue(context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setValue(Object context, Object value) throws EvaluationException {
|
||||
Object result = getValue(context);
|
||||
if (result == null) {
|
||||
@@ -57,11 +58,11 @@ public class CollectionAddingExpression implements Expression {
|
||||
Assert.isInstanceOf(Collection.class, result, "Not a collection: ");
|
||||
if (value != null) {
|
||||
// add the value to the collection
|
||||
((Collection) result).add(value);
|
||||
((Collection<Object>) result).add(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Class getValueType(Object context) {
|
||||
public Class<?> getValueType(Object context) {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ public class CompositeStringExpression implements Expression {
|
||||
|
||||
public Object getValue(Object context) throws EvaluationException {
|
||||
StringBuffer buffer = new StringBuffer(128);
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
buffer.append(expressions[i].getValue(context));
|
||||
for (Expression expression : expressions) {
|
||||
buffer.append(expression.getValue(context));
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class CompositeStringExpression implements Expression {
|
||||
throw new UnsupportedOperationException("Cannot set a composite string expression value");
|
||||
}
|
||||
|
||||
public Class getValueType(Object context) {
|
||||
public Class<?> getValueType(Object context) {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ import org.springframework.binding.expression.ParserContext;
|
||||
*/
|
||||
public class FluentParserContext implements ParserContext {
|
||||
|
||||
private Class evaluationContextType;
|
||||
private Class<?> evaluationContextType;
|
||||
|
||||
private Class evaluationResultType;
|
||||
private Class<?> evaluationResultType;
|
||||
|
||||
private List expressionVariables;
|
||||
private List<ExpressionVariable> expressionVariables;
|
||||
|
||||
private boolean template;
|
||||
|
||||
@@ -48,16 +48,16 @@ public class FluentParserContext implements ParserContext {
|
||||
init();
|
||||
}
|
||||
|
||||
public Class getEvaluationContextType() {
|
||||
public Class<?> getEvaluationContextType() {
|
||||
return evaluationContextType;
|
||||
}
|
||||
|
||||
public Class getExpectedEvaluationResultType() {
|
||||
public Class<?> getExpectedEvaluationResultType() {
|
||||
return evaluationResultType;
|
||||
}
|
||||
|
||||
public ExpressionVariable[] getExpressionVariables() {
|
||||
return (ExpressionVariable[]) expressionVariables.toArray(new ExpressionVariable[expressionVariables.size()]);
|
||||
return expressionVariables.toArray(new ExpressionVariable[expressionVariables.size()]);
|
||||
}
|
||||
|
||||
public boolean isTemplate() {
|
||||
@@ -69,7 +69,7 @@ public class FluentParserContext implements ParserContext {
|
||||
* @param contextType the type of context object the parsed expression will evaluate in
|
||||
* @return this
|
||||
*/
|
||||
public FluentParserContext evaluate(Class contextType) {
|
||||
public FluentParserContext evaluate(Class<?> contextType) {
|
||||
evaluationContextType = contextType;
|
||||
return this;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class FluentParserContext implements ParserContext {
|
||||
* @param resultType the type of result object the parsed expression should return when evaluated
|
||||
* @return this
|
||||
*/
|
||||
public FluentParserContext expectResult(Class resultType) {
|
||||
public FluentParserContext expectResult(Class<?> resultType) {
|
||||
evaluationResultType = resultType;
|
||||
return this;
|
||||
}
|
||||
@@ -114,6 +114,6 @@ public class FluentParserContext implements ParserContext {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
expressionVariables = new ArrayList();
|
||||
expressionVariables = new ArrayList<ExpressionVariable>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class LiteralExpression implements Expression {
|
||||
+ "If so, should the expression string be enclosed in eval delimiters?");
|
||||
}
|
||||
|
||||
public Class getValueType(Object context) {
|
||||
public Class<?> getValueType(Object context) {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,11 +33,11 @@ public final class NullParserContext implements ParserContext {
|
||||
private NullParserContext() {
|
||||
}
|
||||
|
||||
public Class getEvaluationContextType() {
|
||||
public Class<?> getEvaluationContextType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getExpectedEvaluationResultType() {
|
||||
public Class<?> getExpectedEvaluationResultType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class StaticExpression implements Expression {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Class getValueType(Object context) {
|
||||
public Class<?> getValueType(Object context) {
|
||||
return value.getClass();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public interface MappingResults {
|
||||
/**
|
||||
* A list of all the mapping results between the source and target.
|
||||
*/
|
||||
public List getAllResults();
|
||||
public List<MappingResult> getAllResults();
|
||||
|
||||
/**
|
||||
* Whether some results were errors. Returns true if mapping errors occurred.
|
||||
@@ -47,12 +47,12 @@ public interface MappingResults {
|
||||
/**
|
||||
* A list of all error results that occurred.
|
||||
*/
|
||||
public List getErrorResults();
|
||||
public List<MappingResult> getErrorResults();
|
||||
|
||||
/**
|
||||
* Get all results that meet the given result criteria.
|
||||
* @param criteria the mapping result criteria
|
||||
*/
|
||||
public List getResults(MappingResultsCriteria criteria);
|
||||
public List<MappingResult> getResults(MappingResultsCriteria criteria);
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class DefaultMapper implements Mapper {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(DefaultMapper.class);
|
||||
|
||||
private List mappings = new ArrayList();
|
||||
private List<DefaultMapping> mappings = new ArrayList<DefaultMapping>();
|
||||
|
||||
/**
|
||||
* Add a mapping to this mapper.
|
||||
@@ -53,7 +53,7 @@ public class DefaultMapper implements Mapper {
|
||||
* @return the list of mappings
|
||||
*/
|
||||
public Mapping[] getMappings() {
|
||||
return (Mapping[]) mappings.toArray(new Mapping[mappings.size()]);
|
||||
return mappings.toArray(new Mapping[mappings.size()]);
|
||||
}
|
||||
|
||||
public MappingResults map(Object source, Object target) {
|
||||
@@ -62,9 +62,9 @@ public class DefaultMapper implements Mapper {
|
||||
+ target.getClass().getName() + "]");
|
||||
}
|
||||
DefaultMappingContext context = new DefaultMappingContext(source, target);
|
||||
Iterator it = mappings.iterator();
|
||||
Iterator<DefaultMapping> it = mappings.iterator();
|
||||
while (it.hasNext()) {
|
||||
DefaultMapping mapping = (DefaultMapping) it.next();
|
||||
DefaultMapping mapping = it.next();
|
||||
mapping.map(context);
|
||||
}
|
||||
MappingResults results = context.getMappingResults();
|
||||
|
||||
@@ -45,12 +45,12 @@ public class DefaultMappingContext {
|
||||
|
||||
private Mapping currentMapping;
|
||||
|
||||
private List mappingResults;
|
||||
private List<MappingResult> mappingResults;
|
||||
|
||||
public DefaultMappingContext(Object source, Object target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.mappingResults = new ArrayList();
|
||||
this.mappingResults = new ArrayList<MappingResult>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DefaultMappingResults implements MappingResults {
|
||||
|
||||
private Object target;
|
||||
|
||||
private List mappingResults;
|
||||
private List<MappingResult> mappingResults;
|
||||
|
||||
/**
|
||||
* Creates a new mapping results object.
|
||||
@@ -42,7 +42,7 @@ public class DefaultMappingResults implements MappingResults {
|
||||
* @param target the target
|
||||
* @param mappingResults the actual results produced by {@link DefaultMapper}
|
||||
*/
|
||||
public DefaultMappingResults(Object source, Object target, List mappingResults) {
|
||||
public DefaultMappingResults(Object source, Object target, List<MappingResult> mappingResults) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.mappingResults = mappingResults;
|
||||
@@ -56,14 +56,14 @@ public class DefaultMappingResults implements MappingResults {
|
||||
return target;
|
||||
}
|
||||
|
||||
public List getAllResults() {
|
||||
public List<MappingResult> getAllResults() {
|
||||
return Collections.unmodifiableList(mappingResults);
|
||||
}
|
||||
|
||||
public boolean hasErrorResults() {
|
||||
Iterator it = mappingResults.iterator();
|
||||
Iterator<MappingResult> it = mappingResults.iterator();
|
||||
while (it.hasNext()) {
|
||||
MappingResult result = (MappingResult) it.next();
|
||||
MappingResult result = it.next();
|
||||
if (result.isError()) {
|
||||
return true;
|
||||
}
|
||||
@@ -71,11 +71,11 @@ public class DefaultMappingResults implements MappingResults {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List getErrorResults() {
|
||||
List errorResults = new ArrayList();
|
||||
Iterator it = mappingResults.iterator();
|
||||
public List<MappingResult> getErrorResults() {
|
||||
List<MappingResult> errorResults = new ArrayList<MappingResult>();
|
||||
Iterator<MappingResult> it = mappingResults.iterator();
|
||||
while (it.hasNext()) {
|
||||
MappingResult result = (MappingResult) it.next();
|
||||
MappingResult result = it.next();
|
||||
if (result.isError()) {
|
||||
errorResults.add(result);
|
||||
}
|
||||
@@ -83,11 +83,11 @@ public class DefaultMappingResults implements MappingResults {
|
||||
return Collections.unmodifiableList(errorResults);
|
||||
}
|
||||
|
||||
public List getResults(MappingResultsCriteria criteria) {
|
||||
List results = new ArrayList();
|
||||
Iterator it = mappingResults.iterator();
|
||||
public List<MappingResult> getResults(MappingResultsCriteria criteria) {
|
||||
List<MappingResult> results = new ArrayList<MappingResult>();
|
||||
Iterator<MappingResult> it = mappingResults.iterator();
|
||||
while (it.hasNext()) {
|
||||
MappingResult result = (MappingResult) it.next();
|
||||
MappingResult result = it.next();
|
||||
if (criteria.test(result)) {
|
||||
results.add(result);
|
||||
}
|
||||
|
||||
@@ -44,9 +44,10 @@ public class DefaultMessageContext implements StateManageableMessageContext {
|
||||
|
||||
private MessageSource messageSource;
|
||||
|
||||
private Map sourceMessages = new CachingMapDecorator(new LinkedHashMap()) {
|
||||
protected Object create(Object source) {
|
||||
return new ArrayList();
|
||||
private Map<Object, List<Message>> sourceMessages = new CachingMapDecorator<Object, List<Message>>(
|
||||
new LinkedHashMap<Object, List<Message>>()) {
|
||||
protected List<Message> create(Object source) {
|
||||
return new ArrayList<Message>();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,39 +74,37 @@ public class DefaultMessageContext implements StateManageableMessageContext {
|
||||
// implementing message context
|
||||
|
||||
public Message[] getAllMessages() {
|
||||
List messages = new ArrayList();
|
||||
for (Iterator it = sourceMessages.values().iterator(); it.hasNext();) {
|
||||
messages.addAll((List) it.next());
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
for (List<Message> list : sourceMessages.values()) {
|
||||
messages.addAll(list);
|
||||
}
|
||||
return (Message[]) messages.toArray(new Message[messages.size()]);
|
||||
return messages.toArray(new Message[messages.size()]);
|
||||
}
|
||||
|
||||
public Message[] getMessagesBySource(Object source) {
|
||||
List messages = (List) sourceMessages.get(source);
|
||||
return (Message[]) messages.toArray(new Message[messages.size()]);
|
||||
List<Message> messages = sourceMessages.get(source);
|
||||
return messages.toArray(new Message[messages.size()]);
|
||||
}
|
||||
|
||||
public Message[] getMessagesByCriteria(MessageCriteria criteria) {
|
||||
List messages = new ArrayList();
|
||||
Iterator it = sourceMessages.values().iterator();
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
Iterator<List<Message>> it = sourceMessages.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
List sourceMessages = (List) it.next();
|
||||
for (Iterator it2 = sourceMessages.iterator(); it2.hasNext();) {
|
||||
Message message = (Message) it2.next();
|
||||
List<Message> sourceMessages = it.next();
|
||||
for (Message message : sourceMessages) {
|
||||
if (criteria.test(message)) {
|
||||
messages.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (Message[]) messages.toArray(new Message[messages.size()]);
|
||||
return messages.toArray(new Message[messages.size()]);
|
||||
}
|
||||
|
||||
public boolean hasErrorMessages() {
|
||||
Iterator it = sourceMessages.values().iterator();
|
||||
Iterator<List<Message>> it = sourceMessages.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
List sourceMessages = (List) it.next();
|
||||
for (Iterator it2 = sourceMessages.iterator(); it2.hasNext();) {
|
||||
Message message = (Message) it2.next();
|
||||
List<Message> sourceMessages = it.next();
|
||||
for (Message message : sourceMessages) {
|
||||
if (message.getSeverity() == Severity.ERROR) {
|
||||
return true;
|
||||
}
|
||||
@@ -120,7 +119,7 @@ public class DefaultMessageContext implements StateManageableMessageContext {
|
||||
logger.debug("Resolving message using " + messageResolver);
|
||||
}
|
||||
Message message = messageResolver.resolveMessage(messageSource, currentLocale);
|
||||
List messages = (List) sourceMessages.get(message.getSource());
|
||||
List<Message> messages = sourceMessages.get(message.getSource());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Adding resolved message " + message);
|
||||
}
|
||||
@@ -134,11 +133,12 @@ public class DefaultMessageContext implements StateManageableMessageContext {
|
||||
// implementing state manageable message context
|
||||
|
||||
public Serializable createMessagesMemento() {
|
||||
return new LinkedHashMap(sourceMessages);
|
||||
return new LinkedHashMap<Object, List<Message>>(sourceMessages);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void restoreMessages(Serializable messagesMemento) {
|
||||
sourceMessages.putAll((Map) messagesMemento);
|
||||
sourceMessages.putAll((Map<Object, List<Message>>) messagesMemento);
|
||||
}
|
||||
|
||||
public void setMessageSource(MessageSource messageSource) {
|
||||
|
||||
@@ -44,11 +44,11 @@ public class MessageBuilder {
|
||||
|
||||
private Object source;
|
||||
|
||||
private Set codes = new LinkedHashSet();
|
||||
private Set<String> codes = new LinkedHashSet<String>();
|
||||
|
||||
private Severity severity;
|
||||
|
||||
private List args = new ArrayList();
|
||||
private List<Object> args = new ArrayList<Object>();
|
||||
|
||||
private String defaultText;
|
||||
|
||||
@@ -173,8 +173,8 @@ public class MessageBuilder {
|
||||
if (args == null) {
|
||||
return this;
|
||||
}
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
this.args.add(new ResolvableArgument(args[i]));
|
||||
for (Object arg : args) {
|
||||
this.args.add(new ResolvableArgument(arg));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ public class MessageBuilder {
|
||||
throw new IllegalArgumentException(
|
||||
"A message code or the message text is required to build this message resolver");
|
||||
}
|
||||
String[] codesArray = (String[]) codes.toArray(new String[codes.size()]);
|
||||
String[] codesArray = codes.toArray(new String[codes.size()]);
|
||||
Object[] argsArray = args.toArray(new Object[args.size()]);
|
||||
return new DefaultMessageResolver(source, codesArray, severity, argsArray, defaultText);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class MessageContextErrors extends AbstractErrors {
|
||||
|
||||
public void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage) {
|
||||
field = fixedField(field);
|
||||
Class fieldType;
|
||||
Class<?> fieldType;
|
||||
if (StringUtils.hasLength(field) && (expressionParser != null)) {
|
||||
FluentParserContext parserContext = new FluentParserContext().evaluate(boundObject.getClass());
|
||||
fieldType = expressionParser.parseExpression(field, parserContext).getValueType(boundObject);
|
||||
@@ -100,9 +100,9 @@ public class MessageContextErrors extends AbstractErrors {
|
||||
}
|
||||
|
||||
public void addAllErrors(Errors errors) {
|
||||
Iterator it = errors.getAllErrors().iterator();
|
||||
Iterator<ObjectError> it = errors.getAllErrors().iterator();
|
||||
while (it.hasNext()) {
|
||||
ObjectError error = (ObjectError) it.next();
|
||||
ObjectError error = it.next();
|
||||
MessageBuilder builder = new MessageBuilder().error().codes(error.getCodes()).args(error.getArguments())
|
||||
.defaultText(error.getDefaultMessage());
|
||||
if (error instanceof FieldError) {
|
||||
@@ -117,27 +117,25 @@ public class MessageContextErrors extends AbstractErrors {
|
||||
return objectName;
|
||||
}
|
||||
|
||||
public List getGlobalErrors() {
|
||||
public List<ObjectError> getGlobalErrors() {
|
||||
Message[] messages = messageContext.getMessagesByCriteria(GLOBAL_ERROR);
|
||||
if (messages.length == 0) {
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List errors = new ArrayList(messages.length);
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
Message message = messages[i];
|
||||
List<ObjectError> errors = new ArrayList<ObjectError>(messages.length);
|
||||
for (Message message : messages) {
|
||||
errors.add(new ObjectError(objectName, message.getText()));
|
||||
}
|
||||
return Collections.unmodifiableList(errors);
|
||||
}
|
||||
|
||||
public List getFieldErrors() {
|
||||
public List<FieldError> getFieldErrors() {
|
||||
Message[] messages = messageContext.getMessagesByCriteria(FIELD_ERROR);
|
||||
if (messages.length == 0) {
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List errors = new ArrayList(messages.length);
|
||||
for (int i = 0; i < messages.length; i++) {
|
||||
Message message = messages[i];
|
||||
List<FieldError> errors = new ArrayList<FieldError>(messages.length);
|
||||
for (Message message : messages) {
|
||||
errors.add(new FieldError(objectName, (String) message.getSource(), message.getText()));
|
||||
}
|
||||
return Collections.unmodifiableList(errors);
|
||||
@@ -147,9 +145,9 @@ public class MessageContextErrors extends AbstractErrors {
|
||||
field = fixedField(field);
|
||||
// requires boundObject and expressionParser to be set to work
|
||||
if (mappingResults != null) {
|
||||
List results = mappingResults.getResults(new PropertyErrorMappingResult(field));
|
||||
List<MappingResult> results = mappingResults.getResults(new PropertyErrorMappingResult(field));
|
||||
if (!results.isEmpty()) {
|
||||
MappingResult fieldError = (MappingResult) results.get(0);
|
||||
MappingResult fieldError = results.get(0);
|
||||
return fieldError.getOriginalValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Locale;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
||||
/**
|
||||
* A factory for a Message. Allows a Message to be internationalized and to be resolved from a
|
||||
* {@link MessageSource message resource bundle}.
|
||||
* A factory for a Message. Allows a Message to be internationalized and to be resolved from a {@link MessageSource
|
||||
* message resource bundle}.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @see Message
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.binding.method;
|
||||
|
||||
|
||||
/**
|
||||
* Thrown when a method key could not be resolved to an invokable java Method on a Class.
|
||||
*
|
||||
|
||||
@@ -44,9 +44,9 @@ public class MethodInvoker {
|
||||
/**
|
||||
* A cache of invoked bean methods, keyed weakly.
|
||||
*/
|
||||
private CachingMapDecorator methodCache = new CachingMapDecorator(true) {
|
||||
public Object create(Object key) {
|
||||
return ((MethodKey) key).getMethod();
|
||||
private CachingMapDecorator<MethodKey, Method> methodCache = new CachingMapDecorator<MethodKey, Method>(true) {
|
||||
public Method create(MethodKey key) {
|
||||
return key.getMethod();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,7 +74,7 @@ public class MethodInvoker {
|
||||
Object argument = parameter.evaluateArgument(argumentSource);
|
||||
arguments[i] = applyTypeConversion(argument, parameter.getType());
|
||||
}
|
||||
Class[] parameterTypes = parameters.getTypesArray();
|
||||
Class<?>[] parameterTypes = parameters.getTypesArray();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (parameterTypes[i] == null) {
|
||||
Object argument = arguments[i];
|
||||
@@ -85,7 +85,7 @@ public class MethodInvoker {
|
||||
}
|
||||
MethodKey key = new MethodKey(bean.getClass(), signature.getMethodName(), parameterTypes);
|
||||
try {
|
||||
Method method = (Method) methodCache.get(key);
|
||||
Method method = methodCache.get(key);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Invoking method with signature [" + key + "] with arguments "
|
||||
+ StylerUtils.style(arguments) + " on bean [" + bean + "]");
|
||||
@@ -110,7 +110,7 @@ public class MethodInvoker {
|
||||
* @param targetType the target type for the conversion
|
||||
* @return the converted result
|
||||
*/
|
||||
protected Object applyTypeConversion(Object value, Class targetType) {
|
||||
protected Object applyTypeConversion(Object value, Class<?> targetType) {
|
||||
if (value == null || targetType == null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MethodKey implements Serializable {
|
||||
/**
|
||||
* The class the method is a member of.
|
||||
*/
|
||||
private Class declaredType;
|
||||
private Class<?> declaredType;
|
||||
|
||||
/**
|
||||
* The method name.
|
||||
@@ -45,7 +45,7 @@ public class MethodKey implements Serializable {
|
||||
* The method's actual parameter types. Could contain null values if the user did not specify a parameter type for
|
||||
* the corresponding parameter
|
||||
*/
|
||||
private Class[] parameterTypes;
|
||||
private Class<?>[] parameterTypes;
|
||||
|
||||
/**
|
||||
* A cached handle to the resolved method (may be null).
|
||||
@@ -58,7 +58,7 @@ public class MethodKey implements Serializable {
|
||||
* @param methodName the method name
|
||||
* @param parameterTypes the method's parameter types, or <code>null</code> if the method has no parameters
|
||||
*/
|
||||
public MethodKey(Class declaredType, String methodName, Class[] parameterTypes) {
|
||||
public MethodKey(Class<?> declaredType, String methodName, Class<?>[] parameterTypes) {
|
||||
Assert.notNull(declaredType, "The method's declared type is required");
|
||||
Assert.notNull(methodName, "The method name is required");
|
||||
this.declaredType = declaredType;
|
||||
@@ -69,7 +69,7 @@ public class MethodKey implements Serializable {
|
||||
/**
|
||||
* Return the class the method is a member of.
|
||||
*/
|
||||
public Class getDeclaredType() {
|
||||
public Class<?> getDeclaredType() {
|
||||
return declaredType;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class MethodKey implements Serializable {
|
||||
* Returns the method parameter types. Could contain null values if no type was specified for the corresponding
|
||||
* parameter.
|
||||
*/
|
||||
public Class[] getParameterTypes() {
|
||||
public Class<?>[] getParameterTypes() {
|
||||
return parameterTypes;
|
||||
}
|
||||
|
||||
@@ -121,17 +121,17 @@ public class MethodKey implements Serializable {
|
||||
*/
|
||||
protected Method findMethodConsiderAssignableParameterTypes() {
|
||||
Method[] candidateMethods = getDeclaredType().getMethods();
|
||||
for (int i = 0; i < candidateMethods.length; i++) {
|
||||
if (candidateMethods[i].getName().equals(methodName)) {
|
||||
for (Method candidateMethod : candidateMethods) {
|
||||
if (candidateMethod.getName().equals(methodName)) {
|
||||
// Check if the method has the correct number of parameters.
|
||||
Class[] candidateParameterTypes = candidateMethods[i].getParameterTypes();
|
||||
Class<?>[] candidateParameterTypes = candidateMethod.getParameterTypes();
|
||||
if (candidateParameterTypes.length == parameterTypes.length) {
|
||||
int numberOfCorrectArguments = 0;
|
||||
for (int j = 0; j < candidateParameterTypes.length; j++) {
|
||||
// Check if the candidate type is assignable to the sig
|
||||
// parameter type.
|
||||
Class candidateType = candidateParameterTypes[j];
|
||||
Class parameterType = parameterTypes[j];
|
||||
Class<?> candidateType = candidateParameterTypes[j];
|
||||
Class<?> parameterType = parameterTypes[j];
|
||||
if (parameterType != null) {
|
||||
if (isAssignable(candidateType, parameterType)) {
|
||||
numberOfCorrectArguments++;
|
||||
@@ -142,7 +142,7 @@ public class MethodKey implements Serializable {
|
||||
}
|
||||
}
|
||||
if (numberOfCorrectArguments == parameterTypes.length) {
|
||||
return candidateMethods[i];
|
||||
return candidateMethod;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public class MethodKey implements Serializable {
|
||||
&& parameterTypesEqual(other.parameterTypes);
|
||||
}
|
||||
|
||||
private boolean parameterTypesEqual(Class[] other) {
|
||||
private boolean parameterTypesEqual(Class<?>[] other) {
|
||||
if (parameterTypes == other) {
|
||||
return true;
|
||||
}
|
||||
@@ -183,10 +183,9 @@ public class MethodKey implements Serializable {
|
||||
return 0;
|
||||
}
|
||||
int hash = 0;
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
Class parameterType = parameterTypes[i];
|
||||
for (Class<?> parameterType : parameterTypes) {
|
||||
if (parameterType != null) {
|
||||
hash += parameterTypes[i].hashCode();
|
||||
hash += parameterType.hashCode();
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
@@ -225,24 +224,23 @@ public class MethodKey implements Serializable {
|
||||
* @param valueType the value type that should be assigned to the target type
|
||||
* @return if the target type is assignable from the value type
|
||||
*/
|
||||
private static boolean isAssignable(Class targetType, Class valueType) {
|
||||
return (targetType.isAssignableFrom(valueType) || targetType.equals(primitiveWrapperTypeMap.get(valueType)));
|
||||
private static boolean isAssignable(Class<?> targetType, Class<?> valueType) {
|
||||
return (targetType.isAssignableFrom(valueType) || targetType.equals(PRIMITIVE_WRAPPER_TYPE_MAP.get(valueType)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Map with primitive wrapper type as key and corresponding primitive type as value, for example: Integer.class ->
|
||||
* int.class.
|
||||
*/
|
||||
private static final Map primitiveWrapperTypeMap = new HashMap(8);
|
||||
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_TYPE_MAP = new HashMap<Class<?>, Class<?>>(8);
|
||||
static {
|
||||
primitiveWrapperTypeMap.put(Boolean.class, boolean.class);
|
||||
primitiveWrapperTypeMap.put(Byte.class, byte.class);
|
||||
primitiveWrapperTypeMap.put(Character.class, char.class);
|
||||
primitiveWrapperTypeMap.put(Double.class, double.class);
|
||||
primitiveWrapperTypeMap.put(Float.class, float.class);
|
||||
primitiveWrapperTypeMap.put(Integer.class, int.class);
|
||||
primitiveWrapperTypeMap.put(Long.class, long.class);
|
||||
primitiveWrapperTypeMap.put(Short.class, short.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Boolean.class, boolean.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Byte.class, byte.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Character.class, char.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Double.class, double.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Float.class, float.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Integer.class, int.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Long.class, long.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Short.class, short.class);
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A specification for a method consisting of the methodName and an optional set of named arguments. This class provides
|
||||
* the ability to resolve a method with parameters and evaluate its argument values as part of a
|
||||
* {@link MethodInvoker method invoker attempt}.
|
||||
* the ability to resolve a method with parameters and evaluate its argument values as part of a {@link MethodInvoker
|
||||
* method invoker attempt}.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Jeremy Grelle
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Parameter {
|
||||
/**
|
||||
* The class of the parameter, e.g "springbank.AccountNumber".
|
||||
*/
|
||||
private Class type;
|
||||
private Class<?> type;
|
||||
|
||||
/**
|
||||
* The name of the parameter as an evaluatable expression, e.g "accountNumber".
|
||||
@@ -43,7 +43,7 @@ public class Parameter {
|
||||
* @param type the parameter type, may be null
|
||||
* @param name the name the method argument expression (required)
|
||||
*/
|
||||
public Parameter(Class type, Expression name) {
|
||||
public Parameter(Class<?> type, Expression name) {
|
||||
Assert.notNull(name, "The parameter name expression is required");
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
@@ -52,7 +52,7 @@ public class Parameter {
|
||||
/**
|
||||
* Returns the parameter type. Could be null if no parameter type was specified.
|
||||
*/
|
||||
public Class getType() {
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
/**
|
||||
* An ordered list of method parameters.
|
||||
*
|
||||
* @author Keith
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class Parameters {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Parameters {
|
||||
/**
|
||||
* The list.
|
||||
*/
|
||||
private List parameters;
|
||||
private List<Parameter> parameters;
|
||||
|
||||
/**
|
||||
* Create a parameter list of the default size (3 elements).
|
||||
@@ -49,7 +49,7 @@ public class Parameters {
|
||||
* @param size the size
|
||||
*/
|
||||
public Parameters(int size) {
|
||||
this.parameters = new ArrayList(size);
|
||||
this.parameters = new ArrayList<Parameter>(size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ public class Parameters {
|
||||
* @param parameter the single parameter
|
||||
*/
|
||||
public Parameters(Parameter parameter) {
|
||||
this.parameters = new ArrayList(1);
|
||||
this.parameters = new ArrayList<Parameter>(1);
|
||||
add(parameter);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Parameters {
|
||||
* @param parameters the parameters
|
||||
*/
|
||||
public Parameters(Parameter[] parameters) {
|
||||
this.parameters = new ArrayList(parameters.length);
|
||||
this.parameters = new ArrayList<Parameter>(parameters.length);
|
||||
addAll(parameters);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class Parameters {
|
||||
* Return a parameter iterator.
|
||||
* @return the iterator
|
||||
*/
|
||||
public Iterator iterator() {
|
||||
public Iterator<Parameter> iterator() {
|
||||
return parameters.iterator();
|
||||
}
|
||||
|
||||
@@ -99,11 +99,10 @@ public class Parameters {
|
||||
* parameters did not specify a parameter type.
|
||||
* @return the types
|
||||
*/
|
||||
public Class[] getTypesArray() {
|
||||
public Class<?>[] getTypesArray() {
|
||||
int i = 0;
|
||||
Class[] types = new Class[parameters.size()];
|
||||
for (Iterator it = parameters.iterator(); it.hasNext();) {
|
||||
Parameter param = (Parameter) it.next();
|
||||
Class<?>[] types = new Class[parameters.size()];
|
||||
for (Parameter param : parameters) {
|
||||
types[i] = param.getType();
|
||||
i++;
|
||||
}
|
||||
@@ -125,7 +124,7 @@ public class Parameters {
|
||||
* @throws IndexOutOfBoundsException if the provided index is out of bounds
|
||||
*/
|
||||
public Parameter getParameter(int index) throws IndexOutOfBoundsException {
|
||||
return (Parameter) parameters.get(index);
|
||||
return parameters.get(index);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
@@ -30,7 +30,7 @@ import junit.framework.TestCase;
|
||||
public class CompositeIteratorTests extends TestCase {
|
||||
|
||||
public void testNoIterators() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
CompositeIterator<Object> it = new CompositeIterator<Object>();
|
||||
assertFalse(it.hasNext());
|
||||
try {
|
||||
it.next();
|
||||
@@ -41,7 +41,7 @@ public class CompositeIteratorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSingleIterator() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
CompositeIterator<String> it = new CompositeIterator<String>();
|
||||
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
|
||||
for (int i = 0; i < 2; i++) {
|
||||
assertTrue(it.hasNext());
|
||||
@@ -57,7 +57,7 @@ public class CompositeIteratorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testMultipleIterators() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
CompositeIterator<String> it = new CompositeIterator<String>();
|
||||
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
|
||||
it.add(Arrays.asList(new String[] { "2" }).iterator());
|
||||
it.add(Arrays.asList(new String[] { "3", "4" }).iterator());
|
||||
@@ -75,8 +75,8 @@ public class CompositeIteratorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testInUse() {
|
||||
List list = Arrays.asList(new String[] { "0", "1" });
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
List<String> list = Arrays.asList(new String[] { "0", "1" });
|
||||
CompositeIterator<String> it = new CompositeIterator<String>();
|
||||
it.add(list.iterator());
|
||||
it.hasNext();
|
||||
try {
|
||||
@@ -85,7 +85,7 @@ public class CompositeIteratorTests extends TestCase {
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
it = new CompositeIterator();
|
||||
it = new CompositeIterator<String>();
|
||||
it.add(list.iterator());
|
||||
it.next();
|
||||
try {
|
||||
@@ -97,9 +97,9 @@ public class CompositeIteratorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testDuplicateIterators() {
|
||||
List list = Arrays.asList(new String[] { "0", "1" });
|
||||
Iterator iterator = list.iterator();
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
List<String> list = Arrays.asList(new String[] { "0", "1" });
|
||||
Iterator<String> iterator = list.iterator();
|
||||
CompositeIterator<String> it = new CompositeIterator<String>();
|
||||
it.add(iterator);
|
||||
it.add(list.iterator());
|
||||
try {
|
||||
|
||||
@@ -6,14 +6,14 @@ import java.util.Map;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MapAccessorTests extends TestCase {
|
||||
private MapAccessor accessor;
|
||||
private MapAccessor<String, Object> accessor;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Map map = new HashMap();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("string", "hello");
|
||||
map.put("integer", new Integer(9));
|
||||
map.put("null", null);
|
||||
this.accessor = new MapAccessor(map);
|
||||
this.accessor = new MapAccessor<String, Object>(map);
|
||||
}
|
||||
|
||||
public void testAccessNullAttribute() {
|
||||
|
||||
@@ -27,7 +27,8 @@ import junit.framework.TestCase;
|
||||
*/
|
||||
public class SharedMapDecoratorTests extends TestCase {
|
||||
|
||||
private SharedMapDecorator map = new SharedMapDecorator(new HashMap());
|
||||
private SharedMapDecorator<String, String> map = new SharedMapDecorator<String, String>(
|
||||
new HashMap<String, String>());
|
||||
|
||||
public void testGetPutRemove() {
|
||||
assertTrue(map.size() == 0);
|
||||
@@ -47,7 +48,7 @@ public class SharedMapDecoratorTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testPutAll() {
|
||||
Map all = new HashMap();
|
||||
Map<String, String> all = new HashMap<String, String>();
|
||||
all.put("foo", "bar");
|
||||
all.put("bar", "baz");
|
||||
map.putAll(all);
|
||||
@@ -57,21 +58,21 @@ public class SharedMapDecoratorTests extends TestCase {
|
||||
public void testEntrySet() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
Set entrySet = map.entrySet();
|
||||
Set<Map.Entry<String, String>> entrySet = map.entrySet();
|
||||
assertTrue(entrySet.size() == 2);
|
||||
}
|
||||
|
||||
public void testKeySet() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
Set keySet = map.keySet();
|
||||
Set<String> keySet = map.keySet();
|
||||
assertTrue(keySet.size() == 2);
|
||||
}
|
||||
|
||||
public void testValues() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
Collection values = map.values();
|
||||
Collection<String> values = map.values();
|
||||
assertTrue(values.size() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@ import junit.framework.TestCase;
|
||||
*/
|
||||
public class StringKeyedMapAdapterTests extends TestCase {
|
||||
|
||||
private Map contents = new HashMap();
|
||||
private Map<String, String> contents = new HashMap<String, String>();
|
||||
|
||||
private StringKeyedMapAdapter map = new StringKeyedMapAdapter() {
|
||||
private StringKeyedMapAdapter<String> map = new StringKeyedMapAdapter<String>() {
|
||||
|
||||
protected Object getAttribute(String key) {
|
||||
protected String getAttribute(String key) {
|
||||
return contents.get(key);
|
||||
}
|
||||
|
||||
protected Iterator getAttributeNames() {
|
||||
protected Iterator<String> getAttributeNames() {
|
||||
return contents.keySet().iterator();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
contents.remove(key);
|
||||
}
|
||||
|
||||
protected void setAttribute(String key, Object value) {
|
||||
protected void setAttribute(String key, String value) {
|
||||
contents.put(key, value);
|
||||
}
|
||||
};
|
||||
@@ -67,7 +67,7 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testPutAll() {
|
||||
Map all = new HashMap();
|
||||
Map<String, String> all = new HashMap<String, String>();
|
||||
all.put("foo", "bar");
|
||||
all.put("bar", "baz");
|
||||
map.putAll(all);
|
||||
@@ -77,21 +77,21 @@ public class StringKeyedMapAdapterTests extends TestCase {
|
||||
public void testEntrySet() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
Set entrySet = map.entrySet();
|
||||
Set<Map.Entry<String, String>> entrySet = map.entrySet();
|
||||
assertTrue(entrySet.size() == 2);
|
||||
}
|
||||
|
||||
public void testKeySet() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
Set keySet = map.keySet();
|
||||
Set<String> keySet = map.keySet();
|
||||
assertTrue(keySet.size() == 2);
|
||||
}
|
||||
|
||||
public void testValues() {
|
||||
map.put("foo", "bar");
|
||||
map.put("bar", "baz");
|
||||
Collection values = map.values();
|
||||
Collection<String> values = map.values();
|
||||
assertTrue(values.size() == 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +45,12 @@ import org.springframework.binding.format.DefaultNumberFormatFactory;
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DefaultConversionServiceTests extends TestCase {
|
||||
|
||||
public void testConvertCompatibleTypes() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
List lst = new ArrayList();
|
||||
List<Object> lst = new ArrayList<Object>();
|
||||
assertSame(lst, service.getConversionExecutor(ArrayList.class, List.class).execute(lst));
|
||||
}
|
||||
|
||||
@@ -205,15 +206,17 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterArrayToList() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", String[].class, List.class);
|
||||
List list = (List) executor.execute(new String[] { "princy1", "princy2" });
|
||||
assertEquals("princy1", ((Principal) list.get(0)).getName());
|
||||
assertEquals("princy2", ((Principal) list.get(1)).getName());
|
||||
List<Principal> list = (List<Principal>) executor.execute(new String[] { "princy1", "princy2" });
|
||||
assertEquals("princy1", (list.get(0)).getName());
|
||||
assertEquals("princy2", (list.get(1)).getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterArrayToListReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -228,7 +231,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
return "princy2";
|
||||
}
|
||||
};
|
||||
List p = (List) executor.execute(new Principal[] { princy1, princy2 });
|
||||
List<String> p = (List<String>) executor.execute(new Principal[] { princy1, princy2 });
|
||||
assertEquals("princy1", p.get(0));
|
||||
assertEquals("princy2", p.get(1));
|
||||
}
|
||||
@@ -248,7 +251,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", List.class, Principal[].class);
|
||||
List princyList = new ArrayList();
|
||||
List<String> princyList = new ArrayList<String>();
|
||||
princyList.add("princy1");
|
||||
princyList.add("princy2");
|
||||
Principal[] p = (Principal[]) executor.execute(princyList);
|
||||
@@ -270,7 +273,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
return "princy2";
|
||||
}
|
||||
};
|
||||
List princyList = new ArrayList();
|
||||
List<Principal> princyList = new ArrayList<Principal>();
|
||||
princyList.add(princy1);
|
||||
princyList.add(princy2);
|
||||
String[] p = (String[]) executor.execute(princyList);
|
||||
@@ -321,21 +324,23 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterObjectToList() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", String.class, List.class);
|
||||
List list = (List) executor.execute("princy1");
|
||||
assertEquals("princy1", ((Principal) list.get(0)).getName());
|
||||
List<Principal> list = (List<Principal>) executor.execute("princy1");
|
||||
assertEquals("princy1", list.get(0).getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterCsvStringToList() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new PrincipalCsvStringToListConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", String.class, List.class);
|
||||
List list = (List) executor.execute("princy1,princy2");
|
||||
assertEquals("princy1", ((Principal) list.get(0)).getName());
|
||||
assertEquals("princy2", ((Principal) list.get(1)).getName());
|
||||
List<Principal> list = (List<Principal>) executor.execute("princy1,princy2");
|
||||
assertEquals("princy1", list.get(0).getName());
|
||||
assertEquals("princy2", list.get(1).getName());
|
||||
}
|
||||
|
||||
public void testRegisterCustomConverterObjectToListBogus() {
|
||||
@@ -350,6 +355,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterObjectToListReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -359,22 +365,24 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
return "princy1";
|
||||
}
|
||||
};
|
||||
List list = (List) executor.execute(princy1);
|
||||
List<String> list = (List<String>) executor.execute(princy1);
|
||||
assertEquals("princy1", list.get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterListToList() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", List.class, List.class);
|
||||
List princyList = new ArrayList();
|
||||
List<String> princyList = new ArrayList<String>();
|
||||
princyList.add("princy1");
|
||||
princyList.add("princy2");
|
||||
List list = (List) executor.execute(princyList);
|
||||
assertEquals("princy1", ((Principal) list.get(0)).getName());
|
||||
assertEquals("princy2", ((Principal) list.get(1)).getName());
|
||||
List<Principal> list = (List<Principal>) executor.execute(princyList);
|
||||
assertEquals("princy1", list.get(0).getName());
|
||||
assertEquals("princy2", list.get(1).getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRegisterCustomConverterListToListReverse() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
@@ -389,10 +397,10 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
return "princy2";
|
||||
}
|
||||
};
|
||||
List princyList = new ArrayList();
|
||||
List<Principal> princyList = new ArrayList<Principal>();
|
||||
princyList.add(princy1);
|
||||
princyList.add(princy2);
|
||||
List list = (List) executor.execute(princyList);
|
||||
List<String> list = (List<String>) executor.execute(princyList);
|
||||
assertEquals("princy1", list.get(0));
|
||||
assertEquals("princy2", list.get(1));
|
||||
}
|
||||
@@ -401,8 +409,8 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", List.class, List.class);
|
||||
List princyList = new ArrayList();
|
||||
princyList.add(new Integer(1));
|
||||
List<Integer> princyList = new ArrayList<Integer>();
|
||||
princyList.add(1);
|
||||
try {
|
||||
executor.execute(princyList);
|
||||
fail("Should have failed");
|
||||
@@ -436,10 +444,11 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals(3, result[2]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testArrayToListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String[].class, List.class);
|
||||
List result = (List) executor.execute(new String[] { "1", "2", "3" });
|
||||
List<String> result = (List<String>) executor.execute(new String[] { "1", "2", "3" });
|
||||
assertEquals("1", result.get(0));
|
||||
assertEquals("2", result.get(1));
|
||||
assertEquals("3", result.get(2));
|
||||
@@ -448,7 +457,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
public void testListToArrayConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(Collection.class, String[].class);
|
||||
List list = new ArrayList();
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
@@ -458,14 +467,15 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", result[2]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSetToListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(Set.class, List.class);
|
||||
Set set = new LinkedHashSet();
|
||||
Set<String> set = new LinkedHashSet<String>();
|
||||
set.add("1");
|
||||
set.add("2");
|
||||
set.add("3");
|
||||
List result = (List) executor.execute(set);
|
||||
List<String> result = (List<String>) executor.execute(set);
|
||||
assertEquals("1", result.get(0));
|
||||
assertEquals("2", result.get(1));
|
||||
assertEquals("3", result.get(2));
|
||||
@@ -474,7 +484,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
public void testListToArrayConversionWithComponentConversion() {
|
||||
try {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(Collection.class, Integer[].class);
|
||||
service.getConversionExecutor(Collection.class, Integer[].class);
|
||||
|
||||
// This test case is no longer supported:
|
||||
// https://jira.springframework.org/browse/SPR-7496
|
||||
@@ -493,10 +503,11 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testArrayToLinkedListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String[].class, LinkedList.class);
|
||||
LinkedList result = (LinkedList) executor.execute(new String[] { "1", "2", "3" });
|
||||
LinkedList<String> result = (LinkedList<String>) executor.execute(new String[] { "1", "2", "3" });
|
||||
assertEquals("1", result.get(0));
|
||||
assertEquals("2", result.get(1));
|
||||
assertEquals("3", result.get(2));
|
||||
@@ -521,10 +532,11 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
assertEquals("3", result[2]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testStringToListConversion() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
ConversionExecutor executor = service.getConversionExecutor(String.class, List.class);
|
||||
List result = (List) executor.execute("1,2,3");
|
||||
List<String> result = (List<String>) executor.execute("1,2,3");
|
||||
assertEquals(3, result.size());
|
||||
assertEquals("1", result.get(0));
|
||||
assertEquals("2", result.get(1));
|
||||
@@ -541,7 +553,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
|
||||
private static class CustomConverter implements Converter {
|
||||
|
||||
public Object convertSourceToTargetClass(final Object source, Class targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(final Object source, Class<?> targetClass) throws Exception {
|
||||
return new Principal() {
|
||||
public String getName() {
|
||||
return (String) source;
|
||||
@@ -549,33 +561,33 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
};
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return Principal.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class CustomTwoWayConverter extends CustomConverter implements TwoWayConverter {
|
||||
public Object convertTargetToSourceClass(Object target, Class sourceClass) throws Exception {
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception {
|
||||
return ((Principal) target).getName();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Trimmer implements Converter {
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
return ((String) source).trim();
|
||||
}
|
||||
|
||||
public Class getSourceClass() {
|
||||
public Class<?> getSourceClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public Class getTargetClass() {
|
||||
public Class<?> getTargetClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@@ -587,8 +599,8 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
super(List.class);
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class targetClass) throws Exception {
|
||||
List principals = new ArrayList();
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
List<Principal> principals = new ArrayList<Principal>();
|
||||
StringTokenizer tokenizer = new StringTokenizer(string, ",");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
final String name = tokenizer.nextToken();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.el.ELContext;
|
||||
@@ -84,8 +85,8 @@ public class ELExpressionParserTests extends TestCase {
|
||||
public void testParseBeanEvalExpressionInvalidELVariable() {
|
||||
try {
|
||||
String expressionString = "bogus";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext()
|
||||
.evaluate(TestBean.class));
|
||||
Expression exp = parser.parseExpression(expressionString,
|
||||
new FluentParserContext().evaluate(TestBean.class));
|
||||
exp.getValue(new TestBean());
|
||||
fail("Should have failed");
|
||||
} catch (EvaluationException e) {
|
||||
@@ -108,8 +109,8 @@ public class ELExpressionParserTests extends TestCase {
|
||||
|
||||
public void testParseTemplateExpressionWithVariables() {
|
||||
String expressionString = "#{value}#{max}";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().template().variable(
|
||||
new ExpressionVariable("max", "maximum")));
|
||||
Expression exp = parser.parseExpression(expressionString,
|
||||
new FluentParserContext().template().variable(new ExpressionVariable("max", "maximum")));
|
||||
TestBean target = new TestBean();
|
||||
assertEquals("foo2", exp.getValue(target));
|
||||
}
|
||||
@@ -123,9 +124,11 @@ public class ELExpressionParserTests extends TestCase {
|
||||
|
||||
public void testTemplateNestedVariables() {
|
||||
String expressionString = "#{value}#{max}";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().template().variable(
|
||||
new ExpressionVariable("max", "#{maximum}#{var}", new FluentParserContext().template().variable(
|
||||
new ExpressionVariable("var", "'bar'")))));
|
||||
Expression exp = parser.parseExpression(
|
||||
expressionString,
|
||||
new FluentParserContext().template().variable(
|
||||
new ExpressionVariable("max", "#{maximum}#{var}", new FluentParserContext().template()
|
||||
.variable(new ExpressionVariable("var", "'bar'")))));
|
||||
TestBean target = new TestBean();
|
||||
assertEquals("foo2bar", exp.getValue(target));
|
||||
}
|
||||
@@ -159,8 +162,8 @@ public class ELExpressionParserTests extends TestCase {
|
||||
|
||||
public void testGetValueCoersionError() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext()
|
||||
.expectResult(TestBean.class));
|
||||
Expression exp = parser.parseExpression(expressionString,
|
||||
new FluentParserContext().expectResult(TestBean.class));
|
||||
TestBean context = new TestBean();
|
||||
try {
|
||||
exp.getValue(context);
|
||||
@@ -201,15 +204,15 @@ public class ELExpressionParserTests extends TestCase {
|
||||
return new ELContext() {
|
||||
public ELResolver getELResolver() {
|
||||
return new ELResolver() {
|
||||
public Class getCommonPropertyType(ELContext arg0, Object arg1) {
|
||||
public Class<?> getCommonPropertyType(ELContext arg0, Object arg1) {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
public Iterator getFeatureDescriptors(ELContext arg0, Object arg1) {
|
||||
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getType(ELContext arg0, Object arg1, Object arg2) {
|
||||
public Class<?> getType(ELContext arg0, Object arg1, Object arg2) {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@ public class MapAdaptableELResolverTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testGetType() {
|
||||
Class type = context.getELResolver().getType(context, new TestMapAdaptable(), "bar");
|
||||
Class<?> type = context.getELResolver().getType(context, new TestMapAdaptable(), "bar");
|
||||
assertTrue(context.isPropertyResolved());
|
||||
assertEquals(String.class, type);
|
||||
}
|
||||
|
||||
public void testGetType_UnknownProperty() {
|
||||
Class type = context.getELResolver().getType(context, new TestMapAdaptable(), "foo");
|
||||
Class<?> type = context.getELResolver().getType(context, new TestMapAdaptable(), "foo");
|
||||
assertTrue(context.isPropertyResolved());
|
||||
assertEquals(null, type);
|
||||
}
|
||||
@@ -42,27 +42,27 @@ public class MapAdaptableELResolverTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSetValue() {
|
||||
MapAdaptable testMap = new TestMapAdaptable();
|
||||
MapAdaptable<String, String> testMap = new TestMapAdaptable();
|
||||
context.getELResolver().setValue(context, testMap, "foo", "foo");
|
||||
assertTrue(context.isPropertyResolved());
|
||||
assertEquals("foo", testMap.asMap().get("foo"));
|
||||
}
|
||||
|
||||
public void testSetValue_OverWrite() {
|
||||
MapAdaptable testMap = new TestMapAdaptable();
|
||||
MapAdaptable<String, String> testMap = new TestMapAdaptable();
|
||||
context.getELResolver().setValue(context, testMap, "bar", "foo");
|
||||
assertTrue(context.isPropertyResolved());
|
||||
assertEquals("foo", testMap.asMap().get("bar"));
|
||||
}
|
||||
|
||||
private class TestMapAdaptable implements MapAdaptable {
|
||||
private Map map = new HashMap();
|
||||
private class TestMapAdaptable implements MapAdaptable<String, String> {
|
||||
private Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
public TestMapAdaptable() {
|
||||
map.put("bar", "bar");
|
||||
}
|
||||
|
||||
public Map asMap() {
|
||||
public Map<String, String> asMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TestBean {
|
||||
private String value = "foo";
|
||||
private int maximum = 2;
|
||||
private TestBean bean;
|
||||
private List list = new ArrayList();
|
||||
private List<String> list = new ArrayList<String>();
|
||||
|
||||
public TestBean() {
|
||||
initList();
|
||||
@@ -65,7 +65,7 @@ public class TestBean {
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
public List getList() {
|
||||
public List<String> getList() {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -127,9 +127,7 @@ public class OgnlExpressionParserTests extends TestCase {
|
||||
|
||||
// maps
|
||||
parser.parseExpression("#{ 'foo' : 'foo value', 'bar' : 'bar value' }", null);
|
||||
parser
|
||||
.parseExpression("${#{ 'foo' : 'foo value', 'bar' : 'bar value' }}", new FluentParserContext()
|
||||
.template());
|
||||
parser.parseExpression("${#{ 'foo' : 'foo value', 'bar' : 'bar value' }}", new FluentParserContext().template());
|
||||
parser.parseExpression("#@java.util.LinkedHashMap@{ 'foo' : 'foo value', 'bar' : 'bar value' }", null);
|
||||
parser.parseExpression("${#@java.util.LinkedHashMap@{ 'foo' : 'foo value', 'bar' : 'bar value' }}",
|
||||
new FluentParserContext().template());
|
||||
@@ -141,8 +139,8 @@ public class OgnlExpressionParserTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testVariables() {
|
||||
Expression exp = parser.parseExpression("#var", new FluentParserContext().variable(new ExpressionVariable(
|
||||
"var", "flag")));
|
||||
Expression exp = parser.parseExpression("#var",
|
||||
new FluentParserContext().variable(new ExpressionVariable("var", "flag")));
|
||||
assertEquals(false, ((Boolean) exp.getValue(bean)).booleanValue());
|
||||
}
|
||||
|
||||
@@ -186,8 +184,8 @@ public class OgnlExpressionParserTests extends TestCase {
|
||||
|
||||
public void testGetValueCoersionError() {
|
||||
String expressionString = "number";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext()
|
||||
.expectResult(TestBean.class));
|
||||
Expression exp = parser.parseExpression(expressionString,
|
||||
new FluentParserContext().expectResult(TestBean.class));
|
||||
TestBean context = new TestBean();
|
||||
try {
|
||||
exp.getValue(context);
|
||||
|
||||
@@ -27,7 +27,7 @@ public class TestBean {
|
||||
|
||||
private Date date;
|
||||
|
||||
private List list = new ArrayList();
|
||||
private List<Object> list = new ArrayList<Object>();
|
||||
|
||||
public boolean isFlag() {
|
||||
return flag;
|
||||
@@ -45,11 +45,11 @@ public class TestBean {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public List getList() {
|
||||
public List<Object> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List list) {
|
||||
public void setList(List<Object> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
TestBean context = new TestBean();
|
||||
Class clazz = exp.getValueType(context);
|
||||
Class<?> clazz = exp.getValueType(context);
|
||||
assertTrue(int.class.equals(clazz) || Integer.class.equals(clazz));
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
TypeDescriptor.valueOf(String.class));
|
||||
}
|
||||
|
||||
public Class[] getSpecificTargetClasses() {
|
||||
public Class<?>[] getSpecificTargetClasses() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DefaultMapperTests extends TestCase {
|
||||
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("beep", null), parser.parseExpression(
|
||||
"beep", null));
|
||||
mapper.addMapping(mapping1);
|
||||
Map bean1 = new HashMap();
|
||||
Map<String, String> bean1 = new HashMap<String, String>();
|
||||
bean1.put("beep", "en");
|
||||
TestBean2 bean2 = new TestBean2();
|
||||
MappingResults results = mapper.map(bean1, bean2);
|
||||
@@ -61,11 +61,11 @@ public class DefaultMapperTests extends TestCase {
|
||||
DefaultMapping mapping1 = new DefaultMapping(parser.parseExpression("boop", null), parser.parseExpression(
|
||||
"boop", null));
|
||||
mapper.addMapping(mapping1);
|
||||
Map bean1 = new HashMap();
|
||||
Map<String, String> bean1 = new HashMap<String, String>();
|
||||
bean1.put("boop", "bogus");
|
||||
TestBean2 bean2 = new TestBean2();
|
||||
MappingResults results = mapper.map(bean1, bean2);
|
||||
assertEquals("typeMismatch", ((MappingResult) results.getErrorResults().get(0)).getCode());
|
||||
assertEquals("typeMismatch", results.getErrorResults().get(0).getCode());
|
||||
}
|
||||
|
||||
public static class TestBean {
|
||||
|
||||
@@ -45,8 +45,8 @@ public class DefaultMessageContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testResolveMessageWithArgs() {
|
||||
context.addMessage(new MessageBuilder().error().source(this).code("argmessage").arg("Keith").defaultText(
|
||||
"Hello world fallback!").build());
|
||||
context.addMessage(new MessageBuilder().error().source(this).code("argmessage").arg("Keith")
|
||||
.defaultText("Hello world fallback!").build());
|
||||
Message[] messages = context.getAllMessages();
|
||||
assertEquals(1, messages.length);
|
||||
assertEquals("Hello world Keith!", messages[0].getText());
|
||||
|
||||
@@ -80,7 +80,7 @@ public class MessageContextErrorsTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testAddAllErrors() {
|
||||
MapBindingResult result = new MapBindingResult(new HashMap(), "object");
|
||||
MapBindingResult result = new MapBindingResult(new HashMap<Object, Object>(), "object");
|
||||
result.reject("bar", new Object[] { "boop" }, null);
|
||||
result.rejectValue("field", "bar", new Object[] { "boop" }, null);
|
||||
errors.addAllErrors(result);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
assertEquals(Boolean.TRUE, methodInvoker.invoke(method, new TestObject(), null));
|
||||
}
|
||||
|
||||
private static class TestObject {
|
||||
static class TestObject {
|
||||
|
||||
public void test() {
|
||||
throw new IllegalArgumentException("just testing");
|
||||
@@ -82,7 +82,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static class Bean {
|
||||
static class Bean {
|
||||
String value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MethodKeyTests extends TestCase {
|
||||
new MethodKey(File.class, "listFiles", new Class[] { null });
|
||||
}
|
||||
|
||||
private static final Method safeGetMethod(Class type, String name, Class[] argTypes) {
|
||||
private static final Method safeGetMethod(Class<?> type, String name, Class<?>[] argTypes) {
|
||||
try {
|
||||
return type.getMethod(name, argTypes);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#Fri May 14 17:56:46 BST 2010
|
||||
#Sat Jan 28 13:20:21 PST 2012
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
|
||||
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
|
||||
@@ -19,6 +19,8 @@ org.eclipse.jdt.core.compiler.doc.comment.support=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deadCode=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||
@@ -26,11 +28,13 @@ org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
|
||||
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
@@ -42,6 +46,7 @@ org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
|
||||
@@ -49,7 +54,9 @@ org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
@@ -57,12 +64,20 @@ org.eclipse.jdt.core.compiler.problem.nullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
|
||||
@@ -70,14 +85,19 @@ org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
|
||||
@@ -65,8 +65,8 @@ public class FacesFlowBuilderServicesBeanDefinitionParser extends AbstractSingle
|
||||
parserContext.pushContainingComponent(componentDefinition);
|
||||
|
||||
parseConversionService(element, parserContext, definitionBuilder);
|
||||
parseExpressionParser(element, parserContext, definitionBuilder, parseEnableManagedBeans(element,
|
||||
definitionBuilder));
|
||||
parseExpressionParser(element, parserContext, definitionBuilder,
|
||||
parseEnableManagedBeans(element, definitionBuilder));
|
||||
parseViewFactoryCreator(element, parserContext, definitionBuilder);
|
||||
parseDevelopment(element, definitionBuilder);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user