diff --git a/spring-binding/src/main/java/org/springframework/binding/collection/CompositeIterator.java b/spring-binding/src/main/java/org/springframework/binding/collection/CompositeIterator.java index 8c9e3a33..ad2009c5 100644 --- a/spring-binding/src/main/java/org/springframework/binding/collection/CompositeIterator.java +++ b/spring-binding/src/main/java/org/springframework/binding/collection/CompositeIterator.java @@ -23,16 +23,15 @@ import java.util.NoSuchElementException; import org.springframework.util.Assert; /** - * Iterator that combines multiple other iterators. This is a simple implementation - * that just maintains a list of iterators which are invoked in sequence untill - * all iterators are exhausted. + * Iterator that combines multiple other iterators. This is a simple implementation that just maintains a list of + * iterators which are invoked in sequence untill all iterators are exhausted. * * @author Erwin Vervaet */ public class CompositeIterator implements Iterator { private List iterators = new LinkedList(); - + private boolean inUse = false; /** @@ -40,7 +39,7 @@ public class CompositeIterator implements Iterator { */ public CompositeIterator() { } - + /** * Add given iterator to this composite. */ @@ -54,8 +53,8 @@ public class CompositeIterator implements Iterator { public boolean hasNext() { inUse = true; - for (Iterator it = iterators.iterator(); it.hasNext(); ) { - if (((Iterator)it.next()).hasNext()) { + for (Iterator it = iterators.iterator(); it.hasNext();) { + if (((Iterator) it.next()).hasNext()) { return true; } } @@ -64,8 +63,8 @@ public class CompositeIterator implements Iterator { public Object next() { inUse = true; - for (Iterator it = iterators.iterator(); it.hasNext(); ) { - Iterator iterator = (Iterator)it.next(); + for (Iterator it = iterators.iterator(); it.hasNext();) { + Iterator iterator = (Iterator) it.next(); if (iterator.hasNext()) { return iterator.next(); } @@ -75,5 +74,5 @@ public class CompositeIterator implements Iterator { public void remove() { throw new UnsupportedOperationException("Remove is not supported"); - } + } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/collection/MapAccessor.java b/spring-binding/src/main/java/org/springframework/binding/collection/MapAccessor.java index de09a400..419712c3 100644 --- a/spring-binding/src/main/java/org/springframework/binding/collection/MapAccessor.java +++ b/spring-binding/src/main/java/org/springframework/binding/collection/MapAccessor.java @@ -21,8 +21,8 @@ import java.util.Map; import org.springframework.util.Assert; /** - * A simple, generic decorator for getting attributes out of a map. May be - * instantiated directly or used as a base class as a convenience. + * A simple, generic decorator for getting attributes out of a map. May be instantiated directly or used as a base class + * as a convenience. * * @author Keith Donald */ @@ -43,14 +43,13 @@ public class MapAccessor implements MapAdaptable { } // implementing MapAdaptable - + public Map asMap() { return map; } /** - * Returns a value in the map, returning the defaultValue if no value was - * found. + * Returns a value in the map, returning the defaultValue if no value was found. * @param key the key * @param defaultValue the default * @return the attribute value @@ -63,27 +62,24 @@ public class MapAccessor implements MapAdaptable { } /** - * Returns a value in the map, asserting it is of the required type if - * present and returning null if not found. + * Returns a value in the map, asserting it is of the required type if present and returning null if + * not found. * @param key the key * @param requiredType the required type * @return the value - * @throws IllegalArgumentException if the key is present but the value is - * not of the required type + * @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 { return get(key, requiredType, null); } /** - * Returns a value in the map of the specified type, returning the - * defaultValue if no value is found. + * Returns a value in the map of the specified type, returning the defaultValue if no value is found. * @param key the key * @param requiredType the required type * @param defaultValue the default * @return the attribute value - * @throws IllegalArgumentException if the key is present but the value is - * not of the required type + * @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) { if (!map.containsKey(key)) { @@ -93,8 +89,7 @@ public class MapAccessor implements MapAdaptable { } /** - * Returns a value in the map, throwing an exception if the attribute is not - * present and of the correct type. + * Returns a value in the map, throwing an exception if the attribute is not present and of the correct type. * @param key the key * @return the value */ @@ -104,8 +99,7 @@ public class MapAccessor implements MapAdaptable { } /** - * Returns an value in the map, asserting it is present and of the required - * type. + * Returns an value in the map, asserting it is present and of the required type. * @param key the key * @param requiredType the required type * @return the value @@ -116,217 +110,195 @@ public class MapAccessor implements MapAdaptable { } /** - * Returns a string value in the map, returning null if no - * value was found. + * Returns a string value in the map, returning null if no value was found. * @param key the key * @return the string value - * @throws IllegalArgumentException if the key is present but the value is - * not a string + * @throws IllegalArgumentException if the key is present but the value is not a string */ public String getString(Object key) throws IllegalArgumentException { return getString(key, null); } /** - * Returns a string value in the map, returning the defaultValue if no value - * was found. + * Returns a string value in the map, returning the defaultValue if no value was found. * @param key the key * @param defaultValue the default * @return the string value - * @throws IllegalArgumentException if the key is present but the value is - * not a string + * @throws IllegalArgumentException if the key is present but the value is not a string */ public String getString(Object key, String defaultValue) throws IllegalArgumentException { if (!map.containsKey(key)) { return defaultValue; } - return (String)assertKeyValueOfType(key, String.class); + return (String) assertKeyValueOfType(key, String.class); } /** - * Returns a string value in the map, throwing an exception if the attribute - * is not present and of the correct type. + * Returns a string value in the map, throwing an exception if the attribute is not present and of the correct type. * @param key the key * @return the string value - * @throws IllegalArgumentException if the key is not present or present but - * the value is not a string + * @throws IllegalArgumentException if the key is not present or present but the value is not a string */ public String getRequiredString(Object key) throws IllegalArgumentException { assertContainsKey(key); - return (String)assertKeyValueOfType(key, String.class); + return (String) assertKeyValueOfType(key, String.class); } /** - * Returns a collection value in the map, returning null if - * no value was found. + * Returns a collection value in the map, returning null if no value was found. * @param key the key * @return the collection value - * @throws IllegalArgumentException if the key is present but the value is - * not a collection + * @throws IllegalArgumentException if the key is present but the value is not a collection */ public Collection getCollection(Object key) throws IllegalArgumentException { if (!map.containsKey(key)) { return null; } - return (Collection)assertKeyValueOfType(key, Collection.class); + return (Collection) assertKeyValueOfType(key, Collection.class); } /** - * Returns a collection value in the map, asserting it is of the required - * type if present and returning null if not found. + * Returns a collection value in the map, asserting it is of the required type if present and returning + * null if not found. * @param key the key * @return the collection value - * @throws IllegalArgumentException if the key is present but the value is - * not a collection + * @throws IllegalArgumentException if the key is present but the value is not a collection */ public Collection getCollection(Object key, Class requiredType) throws IllegalArgumentException { if (!map.containsKey(key)) { return null; } assertAssignableTo(Collection.class, requiredType); - return (Collection)assertKeyValueOfType(key, requiredType); + return (Collection) assertKeyValueOfType(key, requiredType); } /** - * Returns a collection value in the map, throwing an exception if not - * found. + * Returns a collection value in the map, throwing an exception if not found. * @param key the key * @return the collection value - * @throws IllegalArgumentException if the key is not present or present but - * the value is not a collection + * @throws IllegalArgumentException if the key is not present or present but the value is not a collection */ public Collection getRequiredCollection(Object key) throws IllegalArgumentException { assertContainsKey(key); - return (Collection)assertKeyValueOfType(key, Collection.class); + return (Collection) assertKeyValueOfType(key, Collection.class); } /** - * Returns a collection value in the map, asserting it is of the required - * type if present and throwing an exception if not found. + * Returns a collection value in the map, asserting it is of the required type if present and throwing an exception + * if not found. * @param key the key * @return the collection value - * @throws IllegalArgumentException if the key is not present or present but - * the value is not a collection of the required type + * @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 { assertContainsKey(key); assertAssignableTo(Collection.class, requiredType); - return (Collection)assertKeyValueOfType(key, requiredType); + return (Collection) assertKeyValueOfType(key, requiredType); } /** - * Returns a array value in the map, asserting it is of the required type if - * present and returning null if not found. + * Returns a array value in the map, asserting it is of the required type if present and returning null + * if not found. * @param key the key * @return the array value - * @throws IllegalArgumentException if the key is present but the value is - * not an array of the required type + * @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 { assertAssignableTo(Object[].class, requiredType); if (!map.containsKey(key)) { return null; } - return (Object[])assertKeyValueOfType(key, requiredType); + return (Object[]) assertKeyValueOfType(key, requiredType); } /** - * Returns an array value in the map, asserting it is of the required type - * if present and throwing an exception if not found. + * Returns an array value in the map, asserting it is of the required type if present and throwing an exception if + * not found. * @param key the key * @return the array value - * @throws IllegalArgumentException if the key is not present or present but - * the value is not a array of the required type + * @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 { assertContainsKey(key); assertAssignableTo(Object[].class, requiredType); - return (Object[])assertKeyValueOfType(key, requiredType); + return (Object[]) assertKeyValueOfType(key, requiredType); } /** - * Returns a number value in the map that is of the specified type, - * returning null if no value was found. + * Returns a number value in the map that is of the specified type, returning null if no value was + * found. * @param key the key * @param requiredType the required number type * @return the numbervalue - * @throws IllegalArgumentException if the key is present but the value is - * not a number of the required type + * @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 { return getNumber(key, requiredType, null); } /** - * Returns a number attribute value in the map of the specified type, - * returning the defaultValue if no value was found. + * Returns a number attribute value in the map of the specified type, returning the defaultValue if no value was + * found. * @param key the attribute name * @return the number value * @param defaultValue the default - * @throws IllegalArgumentException if the key is present but the value is - * not a number of the required type + * @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 { if (!map.containsKey(key)) { return defaultValue; } assertAssignableTo(Number.class, requiredType); - return (Number)assertKeyValueOfType(key, requiredType); + return (Number) assertKeyValueOfType(key, requiredType); } /** - * Returns a number value in the map, throwing an exception if the attribute - * is not present and of the correct type. + * Returns a number value in the map, throwing an exception if the attribute is not present and of the correct type. * @param key the key * @return the number value - * @throws IllegalArgumentException if the key is not present or present but - * the value is not a number of the required type + * @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 { assertContainsKey(key); - return (Number)assertKeyValueOfType(key, requiredType); + return (Number) assertKeyValueOfType(key, requiredType); } /** - * Returns an integer value in the map, returning null if no - * value was found. + * Returns an integer value in the map, returning null if no value was found. * @param key the key * @return the integer value - * @throws IllegalArgumentException if the key is present but the value is - * not an integer + * @throws IllegalArgumentException if the key is present but the value is not an integer */ public Integer getInteger(Object key) throws IllegalArgumentException { return getInteger(key, null); } /** - * Returns an integer value in the map, returning the defaultValue if no - * value was found. + * Returns an integer value in the map, returning the defaultValue if no value was found. * @param key the key * @param defaultValue the default * @return the integer value - * @throws IllegalArgumentException if the key is present but the value is - * not an integer + * @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 (Integer) getNumber(key, Integer.class, defaultValue); } /** - * Returns an integer value in the map, throwing an exception if the value - * is not present and of the correct type. + * Returns an integer value in the map, throwing an exception if the value is not present and of the correct type. * @param key the attribute name * @return the integer attribute value - * @throws IllegalArgumentException if the key is not present or present but - * the value is not an integer + * @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 (Integer) getRequiredNumber(key, Integer.class); } /** - * Returns a long value in the map, returning null if no - * value was found. + * Returns a long value in the map, returning null if no value was found. * @param key the key * @return the long value * @throws IllegalArgumentException if the key is present but not a long @@ -336,69 +308,59 @@ public class MapAccessor implements MapAdaptable { } /** - * Returns a long value in the map, returning the defaultValue if no value - * was found. + * Returns a long value in the map, returning the defaultValue if no value was found. * @param key the key * @param defaultValue the default * @return the long attribute value - * @throws IllegalArgumentException if the key is present but the value is - * not a long + * @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 (Long) getNumber(key, Long.class, defaultValue); } /** - * Returns a long value in the map, throwing an exception if the value is - * not present and of the correct type. + * Returns a long value in the map, throwing an exception if the value is not present and of the correct type. * @param key the key * @return the long attribute value - * @throws IllegalArgumentException if the key is not present or present but - * the value is not a long + * @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 (Long) getRequiredNumber(key, Long.class); } /** - * Returns a boolean value in the map, returning null if no - * value was found. + * Returns a boolean value in the map, returning null if no value was found. * @param key the key * @return the boolean value - * @throws IllegalArgumentException if the key is present but the value is - * not a boolean + * @throws IllegalArgumentException if the key is present but the value is not a boolean */ public Boolean getBoolean(Object key) throws IllegalArgumentException { return getBoolean(key, null); } /** - * Returns a boolean value in the map, returning the defaultValue if no - * value was found. + * Returns a boolean value in the map, returning the defaultValue if no value was found. * @param key the key * @param defaultValue the default * @return the boolean value - * @throws IllegalArgumentException if the key is present but the value is - * not a boolean + * @throws IllegalArgumentException if the key is present but the value is not a boolean */ public Boolean getBoolean(Object key, Boolean defaultValue) throws IllegalArgumentException { if (!map.containsKey(key)) { return defaultValue; } - return (Boolean)assertKeyValueOfType(key, Boolean.class); + return (Boolean) assertKeyValueOfType(key, Boolean.class); } /** - * Returns a boolean value in the map, throwing an exception if the value is - * not present and of the correct type. + * Returns a boolean value in the map, throwing an exception if the value is not present and of the correct type. * @param key the attribute * @return the boolean value - * @throws IllegalArgumentException if the key is not present or present but - * the value is not a boolean + * @throws IllegalArgumentException if the key is not present or present but the value is not a boolean */ public Boolean getRequiredBoolean(Object key) throws IllegalArgumentException { assertContainsKey(key); - return (Boolean)assertKeyValueOfType(key, Boolean.class); + return (Boolean) assertKeyValueOfType(key, Boolean.class); } /** @@ -414,8 +376,7 @@ public class MapAccessor implements MapAdaptable { } /** - * Indicates if the attribute is present in the attribute map and of the - * required type. + * Indicates if the attribute is present in the attribute map and of the required type. * @param key the attribute name * @return true if present and of the required type, false if not present. */ @@ -423,8 +384,7 @@ public class MapAccessor implements MapAdaptable { if (map.containsKey(key)) { assertKeyValueOfType(key, requiredType); return true; - } - else { + } else { return false; } } diff --git a/spring-binding/src/main/java/org/springframework/binding/collection/MapAdaptable.java b/spring-binding/src/main/java/org/springframework/binding/collection/MapAdaptable.java index ce3e7ef5..0f83697c 100644 --- a/spring-binding/src/main/java/org/springframework/binding/collection/MapAdaptable.java +++ b/spring-binding/src/main/java/org/springframework/binding/collection/MapAdaptable.java @@ -25,11 +25,11 @@ import java.util.Map; public interface MapAdaptable { /** - * Returns this object's contents as a {@link Map}. The returned map may or - * may not be modifiable depending on this implementation. + * Returns this object's contents as a {@link Map}. The returned map may or may not be modifiable depending on this + * implementation. *

- * Warning: this operation may be called frequently; if so care should be - * taken so that the map contents (if calculated) be cached as appropriate. + * Warning: this operation may be called frequently; if so care should be taken so that the map contents (if + * calculated) be cached as appropriate. * @return the object's contents as a map */ public Map asMap(); diff --git a/spring-binding/src/main/java/org/springframework/binding/collection/SharedMap.java b/spring-binding/src/main/java/org/springframework/binding/collection/SharedMap.java index fb1379a1..8652fe8a 100644 --- a/spring-binding/src/main/java/org/springframework/binding/collection/SharedMap.java +++ b/spring-binding/src/main/java/org/springframework/binding/collection/SharedMap.java @@ -18,20 +18,18 @@ package org.springframework.binding.collection; import java.util.Map; /** - * A simple subinterface of {@link Map} that exposes a mutex that - * application code can synchronize on. + * A simple subinterface of {@link Map} that exposes a mutex that application code can synchronize on. *

- * Expected to be implemented by Maps that are backed by shared objects that - * require synchronization between multiple threads. An example would be the - * HTTP session map. + * Expected to be implemented by Maps that are backed by shared objects that require synchronization between multiple + * threads. An example would be the HTTP session map. * * @author Keith Donald */ public interface SharedMap extends Map { /** - * Returns the shared mutex that may be synchronized on using a - * synchronized block. The returned mutex is guaranteed to be non-null. + * Returns the shared mutex that may be synchronized on using a synchronized block. The returned mutex is guaranteed + * to be non-null. * * Example usage: * diff --git a/spring-binding/src/main/java/org/springframework/binding/collection/SharedMapDecorator.java b/spring-binding/src/main/java/org/springframework/binding/collection/SharedMapDecorator.java index 3d7910af..f2033af4 100644 --- a/spring-binding/src/main/java/org/springframework/binding/collection/SharedMapDecorator.java +++ b/spring-binding/src/main/java/org/springframework/binding/collection/SharedMapDecorator.java @@ -23,9 +23,8 @@ import java.util.Set; import org.springframework.core.style.ToStringCreator; /** - * A map decorator that implements SharedMap. By default, simply - * returns the map itself as the mutex. Subclasses may override to return a - * different mutex object. + * A map decorator that implements SharedMap. By default, simply returns the map itself as the mutex. + * Subclasses may override to return a different mutex object. * * @author Keith Donald */ @@ -43,7 +42,7 @@ public class SharedMapDecorator implements SharedMap, Serializable { public SharedMapDecorator(Map map) { this.map = map; } - + // implementing Map public void clear() { @@ -93,7 +92,7 @@ public class SharedMapDecorator implements SharedMap, Serializable { public Collection values() { return map.values(); } - + // implementing SharedMap public Object getMutex() { diff --git a/spring-binding/src/main/java/org/springframework/binding/collection/StringKeyedMapAdapter.java b/spring-binding/src/main/java/org/springframework/binding/collection/StringKeyedMapAdapter.java index be49017a..d571ad0d 100644 --- a/spring-binding/src/main/java/org/springframework/binding/collection/StringKeyedMapAdapter.java +++ b/spring-binding/src/main/java/org/springframework/binding/collection/StringKeyedMapAdapter.java @@ -22,24 +22,24 @@ import java.util.NoSuchElementException; import java.util.Set; /** - * Base class for map adapters whose keys are String values. Concrete - * classes need only implement the abstract hook methods defined by this class. + * Base class for map adapters whose keys are String values. Concrete classes need only implement the abstract hook + * methods defined by this class. * * @author Keith Donald */ public abstract class StringKeyedMapAdapter implements Map { - + private Set keySet; private Collection values; private Set entrySet; - + // implementing Map public void clear() { for (Iterator it = getAttributeNames(); it.hasNext();) { - removeAttribute((String)it.next()); + removeAttribute((String) it.next()); } } @@ -52,7 +52,7 @@ public abstract class StringKeyedMapAdapter implements Map { return false; } for (Iterator it = getAttributeNames(); it.hasNext();) { - Object aValue = getAttribute((String)it.next()); + Object aValue = getAttribute((String) it.next()); if (value.equals(aValue)) { return true; } @@ -85,7 +85,7 @@ public abstract class StringKeyedMapAdapter implements Map { public void putAll(Map map) { for (Iterator it = map.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry)it.next(); + Entry entry = (Entry) it.next(); setAttribute(entry.getKey().toString(), entry.getValue()); } } @@ -109,40 +109,38 @@ public abstract class StringKeyedMapAdapter implements Map { public Collection values() { return (values != null) ? values : (values = new Values()); } - + // hook methods /** - * Hook method that needs to be implemented by concrete subclasses. - * Gets a value associated with a key. + * Hook method that needs to be implemented by concrete subclasses. Gets a value associated with a key. * @param key the key to lookup * @return the associated value, or null if none */ protected abstract Object getAttribute(String key); /** - * Hook method that needs to be implemented by concrete subclasses. - * Puts a key-value pair in the map, overwriting any possible earlier - * value associated with the same key. + * Hook method that needs to be implemented by concrete subclasses. Puts a key-value pair in the map, overwriting + * any possible earlier value associated with the same key. * @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); /** - * Hook method that needs to be implemented by concrete subclasses. - * Removes a key and its associated value from the map. + * Hook method that needs to be implemented by concrete subclasses. Removes a key and its associated value from the + * map. * @param key the key to remove */ protected abstract void removeAttribute(String key); /** - * Hook method that needs to be implemented by concrete subclasses. - * Returns an enumeration listing all keys known to the map. + * Hook method that needs to be implemented by concrete subclasses. Returns an enumeration listing all keys known to + * the map. * @return the key enumeration */ protected abstract Iterator getAttributeNames(); - + // internal helper classes private abstract class AbstractSet extends java.util.AbstractSet { @@ -233,7 +231,7 @@ public abstract class StringKeyedMapAdapter implements Map { if (!(o instanceof Entry)) { return false; } - Entry entry = (Entry)o; + Entry entry = (Entry) o; Object key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null) { @@ -246,13 +244,13 @@ public abstract class StringKeyedMapAdapter implements Map { if (!(o instanceof Entry)) { return false; } - Entry entry = (Entry)o; + Entry entry = (Entry) o; Object key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null || !value.equals(StringKeyedMapAdapter.this.get(key))) { return false; } - return StringKeyedMapAdapter.this.remove(((Entry)o).getKey()) != null; + return StringKeyedMapAdapter.this.remove(((Entry) o).getKey()) != null; } } diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/ConversionContext.java b/spring-binding/src/main/java/org/springframework/binding/convert/ConversionContext.java index 684c6d51..9396f7fc 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/ConversionContext.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/ConversionContext.java @@ -18,13 +18,10 @@ package org.springframework.binding.convert; /** * A context object with two main responsibities: *

    - *
  1. Exposing information to a converter to influence - * a type conversion attempt. - *
  2. Providing operations for recording progress or - * errors during the type conversion process. + *
  3. Exposing information to a converter to influence a type conversion attempt. + *
  4. Providing operations for recording progress or errors during the type conversion process. *
- * Empty for now; subclasses may define their own custom context behavior - * accessible by a converter with a downcast. + * Empty for now; subclasses may define their own custom context behavior accessible by a converter with a downcast. * * @author Keith Donald */ diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/ConversionException.java b/spring-binding/src/main/java/org/springframework/binding/convert/ConversionException.java index 054742f0..5814cc56 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/ConversionException.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/ConversionException.java @@ -23,15 +23,14 @@ import org.springframework.core.NestedRuntimeException; * @author Keith Donald */ public class ConversionException extends NestedRuntimeException { - + /** * The source type we tried to convert from */ private Class sourceClass; /** - * The value we tried to convert. - * Transient because we cannot guarantee that the value is Serializable. + * The value we tried to convert. Transient because we cannot guarantee that the value is Serializable. */ private transient Object value; @@ -77,7 +76,7 @@ public class ConversionException extends NestedRuntimeException { this.value = value; this.targetClass = targetClass; } - + /** * Creates a new conversion exception. * @param sourceClass the source type @@ -90,7 +89,7 @@ public class ConversionException extends NestedRuntimeException { this.value = null; // not available this.targetClass = targetClass; } - + /** * Creates a new conversion exception. * @param sourceClass the source type @@ -102,7 +101,7 @@ public class ConversionException extends NestedRuntimeException { this.value = null; // not available this.targetClass = null; // not available } - + /** * Creates a new conversion exception. * @param sourceClass the source type @@ -116,7 +115,7 @@ public class ConversionException extends NestedRuntimeException { this.value = value; this.targetClass = targetClass; } - + /** * Returns the source type. */ diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/ConversionExecutor.java b/spring-binding/src/main/java/org/springframework/binding/convert/ConversionExecutor.java index a6041b4d..4c717390 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/ConversionExecutor.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/ConversionExecutor.java @@ -19,11 +19,11 @@ import org.springframework.core.style.ToStringCreator; import org.springframework.util.Assert; /** - * A command object that is parameterized with the information necessary to - * perform a conversion of a source input to a target output. + * A command object that is parameterized with the information necessary to perform a conversion of a source input to a + * target output. *

- * Specifically, encapsulates knowledge about how to convert source objects to a - * specific target type using a specific converter. + * Specifically, encapsulates knowledge about how to convert source objects to a specific target type using a specific + * converter. * * @author Keith Donald */ @@ -74,7 +74,7 @@ public class ConversionExecutor { public Class getTargetClass() { return targetClass; } - + /** * Returns the converter that will perform the conversion. * @return the converter @@ -94,8 +94,7 @@ public class ConversionExecutor { /** * Execute the conversion for the provided source object. * @param source the source object to convert - * @param context the conversion context, useful for influencing the - * behavior of the converter + * @param context the conversion context, useful for influencing the behavior of the converter */ public Object execute(Object source, ConversionContext context) throws ConversionException { if (getTargetClass().isInstance(source)) { @@ -103,8 +102,8 @@ public class ConversionExecutor { return source; } if (source != null && !getSourceClass().isInstance(source)) { - throw new ConversionException(getSourceClass(), source, getTargetClass(), - "Source object '" + source + "' is expected to be an instance of " + getSourceClass()); + throw new ConversionException(getSourceClass(), source, getTargetClass(), "Source object '" + source + + "' is expected to be an instance of " + getSourceClass()); } return converter.convert(source, targetClass, context); } @@ -113,7 +112,7 @@ public class ConversionExecutor { if (!(o instanceof ConversionExecutor)) { return false; } - ConversionExecutor other = (ConversionExecutor)o; + ConversionExecutor other = (ConversionExecutor) o; return sourceClass.equals(other.sourceClass) && targetClass.equals(other.targetClass); } diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/ConversionService.java b/spring-binding/src/main/java/org/springframework/binding/convert/ConversionService.java index 3a1973fd..f435233a 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/ConversionService.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/ConversionService.java @@ -16,52 +16,44 @@ 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. + * 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. * * @author Keith Donald */ public interface ConversionService { /** - * Return a conversion executor command object capable of converting source - * objects of the specified sourceClass to instances of the - * targetClass. + * Return a conversion executor command object capable of converting source objects of the specified + * sourceClass to instances of the targetClass. *

- * The returned ConversionExecutor is thread-safe and may safely be cached - * for use in client code. + * The returned ConversionExecutor is thread-safe and may safely be cached for use in client code. * @param sourceClass the source class to convert from * @param targetClass the target class to convert to * @return the executor that can execute instance conversion, never null - * @throws ConversionException an exception occured retrieving a converter - * for the source-to-target pair + * @throws ConversionException an exception occured retrieving a converter for the source-to-target pair */ - public ConversionExecutor getConversionExecutor(Class sourceClass, Class targetClass) - throws ConversionException; + public ConversionExecutor getConversionExecutor(Class sourceClass, Class targetClass) throws ConversionException; /** - * Return a conversion executor command object capable of converting source - * objects of the specified sourceClass to target objects of - * the type associated with the specified alias. + * Return a conversion executor command object capable of converting source objects of the specified + * sourceClass to target objects of the type associated with the specified alias. * @param sourceClass the sourceClass * @param targetAlias the target alias * @return the conversion executor, or null if the alias cannot be found - * @throws ConversionException an exception occured retrieving a converter - * for the source-to-target pair + * @throws ConversionException an exception occured retrieving a converter for the source-to-target pair */ public ConversionExecutor getConversionExecutorByTargetAlias(Class sourceClass, String targetAlias) throws ConversionException; /** - * Return all conversion executors capable of converting source objects of - * the the specified sourceClass. + * Return all conversion executors capable of converting source objects of the the specified + * sourceClass. * @param sourceClass the source class to convert from * @return the matching conversion executors * @throws ConversionException an exception occured retrieving the converters */ - public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass) - throws ConversionException; + public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass) throws ConversionException; /** * Return the class with the specified alias. diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/Converter.java b/spring-binding/src/main/java/org/springframework/binding/convert/Converter.java index 8ce04ca1..f1cb60e4 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/Converter.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/Converter.java @@ -16,8 +16,8 @@ package org.springframework.binding.convert; /** - * A type converter converts objects from one type to another. They may support - * conversion of multiple source types to multiple target types. + * A type converter converts objects from one type to another. They may support conversion of multiple source types to + * multiple target types. *

* Implementations of this interface are thread-safe. * @@ -38,14 +38,11 @@ public interface Converter { public Class[] getTargetClasses(); /** - * Convert the provided source object argument to an instance of the - * specified target class. - * @param source the source object to convert, its class must be one of the - * supported sourceClasses - * @param targetClass the target class to convert the source to, must be one - * of the supported targetClasses - * @param context an optional conversion context that may be used to - * influence the conversion process + * Convert the provided source object argument to an instance of the specified target class. + * @param source the source object to convert, its class must be one of the supported sourceClasses + * @param targetClass the target class to convert the source to, must be one of the supported + * targetClasses + * @param context an optional conversion context that may be used to influence the conversion process * @return the converted object, an instance of the target type * @throws ConversionException an exception occured during the conversion */ diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/AbstractConverter.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/AbstractConverter.java index eaa1db19..974845a2 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/AbstractConverter.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/AbstractConverter.java @@ -27,42 +27,36 @@ import org.springframework.binding.convert.Converter; public abstract class AbstractConverter implements Converter { /** - * Convenience convert method that converts the provided source to the first - * target object supported by this converter. Useful when a converter only - * supports conversion to a single target. + * Convenience convert method that converts the provided source to the first target object supported by this + * converter. Useful when a converter only supports conversion to a single target. * @param source the source to convert * @return the converted object - * @throws ConversionException an exception occured converting the source - * value + * @throws ConversionException an exception occured converting the source value */ public Object convert(Object source) throws ConversionException { return convert(source, getTargetClasses()[0], null); } /** - * Convenience convert method that converts the provided source to the - * target class specified with an empty conversion context. + * Convenience convert method that converts the provided source to the target class specified with an empty + * conversion context. * @param source the source to convert - * @param targetClass the target class to convert the source to, must be one - * of the supported targetClasses + * @param targetClass the target class to convert the source to, must be one of the supported + * targetClasses * @return the converted object - * @throws ConversionException an exception occured converting the source - * value + * @throws ConversionException an exception occured converting the source value */ public Object convert(Object source, Class targetClass) throws ConversionException { return convert(source, targetClass, null); } /** - * Convenience convert method that converts the provided source to the first - * target object supported by this converter. Useful when a converter only - * supports conversion to a single target. + * Convenience convert method that converts the provided source to the first target object supported by this + * converter. Useful when a converter only supports conversion to a single target. * @param source the source to convert - * @param context the conversion context, useful for influencing the - * behavior of the converter + * @param context the conversion context, useful for influencing the behavior of the converter * @return the converted object - * @throws ConversionException an exception occured converting the source - * value + * @throws ConversionException an exception occured converting the source value */ public Object convert(Object source, ConversionContext context) throws ConversionException { return convert(source, getTargetClasses()[0], context); @@ -71,11 +65,9 @@ public abstract class AbstractConverter implements Converter { public Object convert(Object source, Class targetClass, ConversionContext context) throws ConversionException { try { return doConvert(source, targetClass, context); - } - catch (ConversionException e) { + } catch (ConversionException e) { throw e; - } - catch (Throwable e) { + } catch (Throwable e) { // wrap in a ConversionException if (targetClass == null) { targetClass = getTargetClasses()[0]; @@ -85,15 +77,12 @@ public abstract class AbstractConverter implements Converter { } /** - * Template method subclasses should override to actually perform the type - * conversion. + * Template method subclasses should override to actually perform the type conversion. * @param source the source to convert from * @param targetClass the target type to convert to - * @param context an optional conversion context that may be used to - * influence the conversion process, could be null + * @param context an optional conversion context that may be used to influence the conversion process, could be null * @return the converted source value - * @throws Exception an exception occured, will be wrapped in a conversion - * exception if necessary + * @throws Exception an exception occured, will be wrapped in a conversion exception if necessary */ protected abstract Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception; diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/AbstractFormattingConverter.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/AbstractFormattingConverter.java index 40618875..e2acfcac 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/AbstractFormattingConverter.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/AbstractFormattingConverter.java @@ -18,9 +18,8 @@ package org.springframework.binding.convert.support; import org.springframework.binding.format.FormatterFactory; /** - * A converter that delegates to a formatter to perform the conversion. - * Formatters are typically not thread safe, so we use a FormatterFactory that - * is expected to provide us with thread-safe instances as necessary. + * A converter that delegates to a formatter to perform the conversion. Formatters are typically not thread safe, so we + * use a FormatterFactory that is expected to provide us with thread-safe instances as necessary. * * @author Keith Donald */ diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/CompositeConversionService.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/CompositeConversionService.java index a5192ef9..d44e5023 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/CompositeConversionService.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/CompositeConversionService.java @@ -25,16 +25,15 @@ import org.springframework.binding.convert.ConversionService; import org.springframework.util.Assert; /** - * A conversion service that delegates to an ordered chain of other conversion - * services. The first correct reply received from a conversion service in - * the chain is returned to the caller. + * A conversion service that delegates to an ordered chain of other conversion services. The first correct reply + * received from a conversion service in the chain is returned to the caller. * * @author Erwin Vervaet */ public class CompositeConversionService implements ConversionService { - + private ConversionService[] chain; - + /** * Create a new composite conversion service. * @param conversionServices the conversion services in the chain @@ -43,28 +42,24 @@ public class CompositeConversionService implements ConversionService { Assert.notNull(conversionServices, "The conversion services chain is required"); this.chain = conversionServices; } - + /** - * Returns the conversion services in the chain managed by this - * composite conversion service. + * Returns the conversion services in the chain managed by this composite conversion service. */ public ConversionService[] getConversionServices() { return chain; } - public ConversionExecutor getConversionExecutor(Class sourceClass, Class targetClass) - throws ConversionException { + public ConversionExecutor getConversionExecutor(Class sourceClass, Class targetClass) throws ConversionException { for (int i = 0; i < chain.length; i++) { try { return chain[i].getConversionExecutor(sourceClass, targetClass); - } - catch (ConversionException e) { + } catch (ConversionException e) { // ignore and try the next conversion service in the chain } } - throw new ConversionException(sourceClass, targetClass, - "No converter registered to convert from sourceClass '" + sourceClass + - "' to target class '" + targetClass + "'"); + throw new ConversionException(sourceClass, targetClass, "No converter registered to convert from sourceClass '" + + sourceClass + "' to target class '" + targetClass + "'"); } public ConversionExecutor getConversionExecutorByTargetAlias(Class sourceClass, String targetAlias) @@ -76,29 +71,25 @@ public class CompositeConversionService implements ConversionService { if (res != null) { return res; } - } - catch (ConversionException e) { + } catch (ConversionException e) { exceptionThrown = true; } } if (exceptionThrown) { - throw new ConversionException(sourceClass, - "No converter registered to convert from sourceClass '" + sourceClass + - "' to aliased target type '" + targetAlias + "'"); - } - else { + throw new ConversionException(sourceClass, "No converter registered to convert from sourceClass '" + + sourceClass + "' to aliased target type '" + targetAlias + "'"); + } else { // alias was not recognized by any conversion service in the chain return null; } } - public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass) - throws ConversionException { + public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass) throws ConversionException { Set executors = new HashSet(); for (int i = 0; i < chain.length; i++) { executors.addAll(Arrays.asList(chain[i].getConversionExecutorsForSource(sourceClass))); } - return (ConversionExecutor[])executors.toArray(new ConversionExecutor[executors.size()]); + return (ConversionExecutor[]) executors.toArray(new ConversionExecutor[executors.size()]); } public Class getClassByAlias(String alias) throws ConversionException { @@ -108,8 +99,7 @@ public class CompositeConversionService implements ConversionService { if (res != null) { return res; } - } - catch (ConversionException e) { + } catch (ConversionException e) { // ignore and try the next conversion service in the chain } } diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/ConversionServiceAware.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/ConversionServiceAware.java index 0ccc87ac..5c5f1686 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/ConversionServiceAware.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/ConversionServiceAware.java @@ -18,16 +18,14 @@ package org.springframework.binding.convert.support; import org.springframework.binding.convert.ConversionService; /** - * Marker interface that denotes an object has a dependency on a conversion - * service that is expected to be fulfilled. + * Marker interface that denotes an object has a dependency on a conversion service that is expected to be fulfilled. * * @author Keith Donald */ public interface ConversionServiceAware { /** - * Set the conversion service this object should be made aware of (as it - * presumably depends on it). + * Set the conversion service this object should be made aware of (as it presumably depends on it). * * @param conversionService the conversion service */ diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/ConversionServiceAwareConverter.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/ConversionServiceAwareConverter.java index 4f095cdd..1c5bc8b4 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/ConversionServiceAwareConverter.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/ConversionServiceAwareConverter.java @@ -20,8 +20,7 @@ import org.springframework.binding.convert.ConversionService; import org.springframework.binding.expression.Expression; /** - * Base class for converters that use other converters to convert things, thus - * they are conversion-service aware. + * Base class for converters that use other converters to convert things, thus they are conversion-service aware. * * @author Keith Donald */ @@ -33,8 +32,8 @@ public abstract class ConversionServiceAwareConverter extends AbstractConverter private ConversionService conversionService; /** - * Default constructor, expectes to conversion service to be injected - * using {@link #setConversionService(ConversionService)}. + * Default constructor, expectes to conversion service to be injected using + * {@link #setConversionService(ConversionService)}. */ protected ConversionServiceAwareConverter() { } @@ -61,8 +60,7 @@ public abstract class ConversionServiceAwareConverter extends AbstractConverter } /** - * Returns a conversion executor capable of converting string objects to the - * specified target class. + * Returns a conversion executor capable of converting string objects to the specified target class. * @param targetClass the target class * @return the conversion executor, never null */ @@ -71,19 +69,17 @@ public abstract class ConversionServiceAwareConverter extends AbstractConverter } /** - * Returns a conversion executor capable of converting string objects to the - * target class aliased by the provided alias. + * Returns a conversion executor capable of converting string objects to the target class aliased by the provided + * alias. * @param targetAlias the target class alias, e.g "long" or "float" - * @return the conversion executor, or null if no suitable - * converter exists for alias + * @return the conversion executor, or null if no suitable converter exists for alias */ protected ConversionExecutor fromStringToAliased(String targetAlias) { return getConversionService().getConversionExecutorByTargetAlias(String.class, targetAlias); } /** - * Returns a conversion executor capable of converting objects from one - * class to another. + * Returns a conversion executor capable of converting objects from one class to another. * @param sourceClass the source class to convert from * @param targetClass the target class to convert to * @return the conversion executor, never null @@ -93,12 +89,12 @@ public abstract class ConversionServiceAwareConverter extends AbstractConverter } /** - * Helper that parsers the given expression string into an expression, using - * the installed String->Expression converter. + * Helper that parsers the given expression string into an expression, using the installed String->Expression + * converter. * @param expressionString the expression string to parse * @return the parsed, evaluatable expression */ protected Expression parseExpression(String expressionString) { - return (Expression)fromStringTo(Expression.class).execute(expressionString); + return (Expression) fromStringTo(Expression.class).execute(expressionString); } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/ConverterPropertyEditorAdapter.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/ConverterPropertyEditorAdapter.java index dcf95faf..27ed638d 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/ConverterPropertyEditorAdapter.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/ConverterPropertyEditorAdapter.java @@ -23,9 +23,8 @@ import org.springframework.util.Assert; /** * Adapts a Converter to the PropertyEditor interface. *

- * Note: with a converter, only forward conversion from-string-to-value is - * supported. Value-to-string conversion is not supported. If you need this - * capability, use a Formatter with a FormatterPropertyEditor adapter. + * Note: with a converter, only forward conversion from-string-to-value is supported. Value-to-string conversion is not + * supported. If you need this capability, use a Formatter with a FormatterPropertyEditor adapter. * * @see org.springframework.binding.format.Formatter * @see org.springframework.binding.format.support.FormatterPropertyEditor diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/CustomConverterConfigurer.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/CustomConverterConfigurer.java index 9bf14643..e5e2af11 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/CustomConverterConfigurer.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/CustomConverterConfigurer.java @@ -24,12 +24,10 @@ import org.springframework.binding.convert.ConversionService; import org.springframework.util.Assert; /** - * Registers all 'from string' converters known to a conversion service with - * a Spring bean factory. + * Registers all 'from string' converters known to a conversion service with a Spring bean factory. *

- * Acts as bean factory post processor, registering property editor adapters for - * each supported conversion with a java.lang.String sourceClass. - * This makes for very convenient use with the Spring container. + * Acts as bean factory post processor, registering property editor adapters for each supported conversion with a + * java.lang.String sourceClass. This makes for very convenient use with the Spring container. * * @author Keith Donald */ diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/DefaultConversionService.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/DefaultConversionService.java index e198e9fd..8b995fde 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/DefaultConversionService.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/DefaultConversionService.java @@ -22,17 +22,15 @@ import org.springframework.binding.format.support.SimpleFormatterFactory; import org.springframework.core.enums.LabeledEnum; /** - * Default, local implementation of a conversion service. Will automatically - * register from string converters for a number of standard Java - * types like Class, Number, Boolean and so on. + * Default, local implementation of a conversion service. Will automatically register from string converters for + * a number of standard Java types like Class, Number, Boolean and so on. * * @author Keith Donald */ public class DefaultConversionService extends GenericConversionService { /** - * Creates a new default conversion service, installing the default - * converters. + * Creates a new default conversion service, installing the default converters. */ public DefaultConversionService() { addDefaultConverters(); @@ -46,7 +44,7 @@ public class DefaultConversionService extends GenericConversionService { addConverter(new TextToNumber(new SimpleFormatterFactory())); addConverter(new TextToBoolean()); addConverter(new TextToLabeledEnum()); - + // we're not using addDefaultAlias here for efficiency reasons addAlias("string", String.class); addAlias("short", Short.class); diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/GenericConversionService.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/GenericConversionService.java index f4299f8a..61aea74b 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/GenericConversionService.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/GenericConversionService.java @@ -33,24 +33,21 @@ import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; /** - * Base implementation of a conversion service. Initially empty, e.g. no converters - * are registered by default. + * Base implementation of a conversion service. Initially empty, e.g. no converters are registered by default. * * @author Keith Donald */ public class GenericConversionService implements ConversionService { /** - * An indexed map of converters. Each entry key is a source class that can - * be converted from, and each entry value is a map of target classes that - * can be convertered to, ultimately mapping to a specific converter that - * can perform the source->target conversion. + * An indexed map of converters. Each entry key is a source class that can be converted from, and each entry value + * is a map of target classes that can be convertered to, ultimately mapping to a specific converter that can + * perform the source->target conversion. */ private Map sourceClassConverters = new HashMap(); /** - * A map of string aliases to convertible classes. Allows lookup of - * converters by alias. + * A map of string aliases to convertible classes. Allows lookup of converters by alias. */ private Map aliasMap = new HashMap(); @@ -74,16 +71,15 @@ public class GenericConversionService implements ConversionService { } /** - * Add given converter to this conversion service. If the converter is - * {@link ConversionServiceAware}, it will get the conversion service - * injected. + * Add given converter to this conversion service. If the converter is {@link ConversionServiceAware}, it will get + * the conversion service injected. */ public void addConverter(Converter converter) { Class[] sourceClasses = converter.getSourceClasses(); Class[] targetClasses = converter.getTargetClasses(); for (int i = 0; i < sourceClasses.length; i++) { Class sourceClass = sourceClasses[i]; - Map sourceMap = (Map)sourceClassConverters.get(sourceClass); + Map sourceMap = (Map) sourceClassConverters.get(sourceClass); if (sourceMap == null) { sourceMap = new HashMap(); sourceClassConverters.put(sourceClass, sourceMap); @@ -94,14 +90,13 @@ public class GenericConversionService implements ConversionService { } } if (converter instanceof ConversionServiceAware) { - ((ConversionServiceAware)converter).setConversionService(this); + ((ConversionServiceAware) converter).setConversionService(this); } } /** - * Add all given converters. If the converters are - * {@link ConversionServiceAware}, they will get the conversion service - * injected. + * Add all given converters. If the converters are {@link ConversionServiceAware}, they will get the conversion + * service injected. */ public void addConverters(Converter[] converters) { for (int i = 0; i < converters.length; i++) { @@ -110,9 +105,8 @@ public class GenericConversionService implements ConversionService { } /** - * Add given converter with an alias to the conversion service. If the - * converter is {@link ConversionServiceAware}, it will get the conversion - * service injected. + * Add given converter with an alias to the conversion service. If the converter is {@link ConversionServiceAware}, + * it will get the conversion service injected. */ public void addConverter(Converter converter, String alias) { aliasMap.put(alias, converter); @@ -127,8 +121,8 @@ public class GenericConversionService implements ConversionService { } /** - * Generate a conventions based alias for given target type. For instance, - * "java.lang.Boolean" will get the "boolean" alias. + * Generate a conventions based alias for given target type. For instance, "java.lang.Boolean" will get the + * "boolean" alias. */ public void addDefaultAlias(Class targetType) { addAlias(StringUtils.uncapitalize(ClassUtils.getShortName(targetType)), targetType); @@ -148,16 +142,14 @@ public class GenericConversionService implements ConversionService { if (converter != null) { // we found a converter return new ConversionExecutor(sourceClass, targetClass, converter); - } - else { + } else { if (parent != null) { // try the parent return parent.getConversionExecutor(sourceClass, targetClass); - } - else { + } else { throw new ConversionException(sourceClass, targetClass, - "No converter registered to convert from sourceClass '" + sourceClass + - "' to target class '" + targetClass + "'"); + "No converter registered to convert from sourceClass '" + sourceClass + "' to target class '" + + targetClass + "'"); } } } @@ -172,18 +164,15 @@ public class GenericConversionService implements ConversionService { if (parent != null) { // try the parent return parent.getConversionExecutorByTargetAlias(sourceClass, alias); - } - else { + } else { // not aliased return null; } - } - else if (targetType instanceof Class) { - return getConversionExecutor(sourceClass, (Class)targetType); - } - else { + } else if (targetType instanceof Class) { + return getConversionExecutor(sourceClass, (Class) targetType); + } else { Assert.isInstanceOf(Converter.class, targetType, "Not a converter: "); - Converter conv = (Converter)targetType; + Converter conv = (Converter) targetType; return new ConversionExecutor(sourceClass, Object.class, conv); } } @@ -195,23 +184,22 @@ public class GenericConversionService implements ConversionService { if (parent != null) { // use the parent return parent.getConversionExecutorsForSource(sourceClass); - } - else { + } else { // no converters for source class return new ConversionExecutor[0]; } - } - else { + } else { Set executors = new HashSet(); if (parent != null) { executors.addAll(Arrays.asList(parent.getConversionExecutorsForSource(sourceClass))); } Iterator it = sourceTargetConverters.entrySet().iterator(); while (it.hasNext()) { - Map.Entry entry = (Map.Entry)it.next(); - executors.add(new ConversionExecutor(sourceClass, (Class)entry.getKey(), (Converter)entry.getValue())); + Map.Entry entry = (Map.Entry) it.next(); + executors + .add(new ConversionExecutor(sourceClass, (Class) entry.getKey(), (Converter) entry.getValue())); } - return (ConversionExecutor[])executors.toArray(new ConversionExecutor[executors.size()]); + return (ConversionExecutor[]) executors.toArray(new ConversionExecutor[executors.size()]); } } @@ -220,28 +208,26 @@ public class GenericConversionService implements ConversionService { Object clazz = aliasMap.get(alias); if (clazz != null) { Assert.isInstanceOf(Class.class, clazz, "Not a Class alias '" + alias + "': "); - return (Class)clazz; - } - else { + return (Class) clazz; + } else { if (parent != null) { - // try parent service - return parent.getClassByAlias(alias); - } - else { + // try parent service + return parent.getClassByAlias(alias); + } else { // alias does not index a class, return null return null; } } } - + // internal helpers private Map findConvertersForSource(Class sourceClass) { LinkedList classQueue = new LinkedList(); classQueue.addFirst(sourceClass); while (!classQueue.isEmpty()) { - sourceClass = (Class)classQueue.removeLast(); - Map sourceTargetConverters = (Map)sourceClassConverters.get(sourceClass); + sourceClass = (Class) classQueue.removeLast(); + Map sourceTargetConverters = (Map) sourceClassConverters.get(sourceClass); if (sourceTargetConverters != null && !sourceTargetConverters.isEmpty()) { return sourceTargetConverters; } @@ -261,8 +247,8 @@ public class GenericConversionService implements ConversionService { LinkedList classQueue = new LinkedList(); classQueue.addFirst(targetClass); while (!classQueue.isEmpty()) { - targetClass = (Class)classQueue.removeLast(); - Converter converter = (Converter)sourceTargetConverters.get(targetClass); + targetClass = (Class) classQueue.removeLast(); + Converter converter = (Converter) sourceTargetConverters.get(targetClass); if (converter != null) { return converter; } @@ -277,13 +263,12 @@ public class GenericConversionService implements ConversionService { } return null; } - + // subclassing support /** - * Returns an indexed map of converters. Each entry key is a source class that - * can be converted from, and each entry value is a map of target classes that - * can be convertered to, ultimately mapping to a specific converter that can + * Returns an indexed map of converters. Each entry key is a source class that can be converted from, and each entry + * value is a map of target classes that can be convertered to, ultimately mapping to a specific converter that can * perform the source->target conversion. */ protected Map getSourceClassConverters() { @@ -291,8 +276,8 @@ public class GenericConversionService implements ConversionService { } /** - * Returns a map of known aliases. Each entry key is a String alias and the - * associated value is either a target class or a converter. + * Returns a map of known aliases. Each entry key is a String alias and the associated value is either a target + * class or a converter. */ protected Map getAliasMap() { return aliasMap; diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToBoolean.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToBoolean.java index 0c2d5b9e..459cd1e1 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToBoolean.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToBoolean.java @@ -19,8 +19,7 @@ import org.springframework.binding.convert.ConversionContext; import org.springframework.util.StringUtils; /** - * Converts a textual representation of a boolean object to a Boolean - * instance. + * Converts a textual representation of a boolean object to a Boolean instance. * * @author Keith Donald */ @@ -54,8 +53,8 @@ public class TextToBoolean extends AbstractConverter { } /** - * Create a text to boolean converter. Take given special string representations - * of true and false into account. + * Create a text to boolean converter. Take given special string representations of true and false into + * account. * @param trueString special true string to consider * @param falseString special false string to consider */ @@ -73,27 +72,22 @@ public class TextToBoolean extends AbstractConverter { } protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { - String text = (String)source; + String text = (String) source; if (!StringUtils.hasText(text)) { return null; - } - else if (this.trueString != null && text.equalsIgnoreCase(this.trueString)) { + } else if (this.trueString != null && text.equalsIgnoreCase(this.trueString)) { return Boolean.TRUE; - } - else if (this.falseString != null && text.equalsIgnoreCase(this.falseString)) { + } else if (this.falseString != null && text.equalsIgnoreCase(this.falseString)) { return Boolean.FALSE; - } - else if (this.trueString == null + } else if (this.trueString == null && (text.equalsIgnoreCase(VALUE_TRUE) || text.equalsIgnoreCase(VALUE_ON) || text.equalsIgnoreCase(VALUE_YES) || text.equals(VALUE_1))) { return Boolean.TRUE; - } - else if (this.falseString == null + } else if (this.falseString == null && (text.equalsIgnoreCase(VALUE_FALSE) || text.equalsIgnoreCase(VALUE_OFF) || text.equalsIgnoreCase(VALUE_NO) || text.equals(VALUE_0))) { return Boolean.FALSE; - } - else { + } else { throw new IllegalArgumentException("Invalid boolean value [" + text + "]"); } } diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToClass.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToClass.java index ad0e7e89..6576c2e8 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToClass.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToClass.java @@ -21,8 +21,7 @@ import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; /** - * Converts a textual representation of a class object to a Class - * instance. + * Converts a textual representation of a class object to a Class instance. * * @author Keith Donald */ @@ -41,19 +40,17 @@ public class TextToClass extends ConversionServiceAwareConverter { } protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { - String text = (String)source; + String text = (String) source; if (StringUtils.hasText(text)) { String classNameOrAlias = text.trim(); if (classNameOrAlias.startsWith(CLASS_PREFIX)) { return ClassUtils.forName(text.substring(CLASS_PREFIX.length())); - } - else if (classNameOrAlias.startsWith(ALIAS_PREFIX)) { + } else if (classNameOrAlias.startsWith(ALIAS_PREFIX)) { String alias = text.substring(ALIAS_PREFIX.length()); Class clazz = getConversionService().getClassByAlias(alias); Assert.notNull(clazz, "No class found associated with type alias '" + alias + "'"); return clazz; - } - else { + } else { // try first an aliased based lookup if (getConversionService() != null) { Class aliasedClass = getConversionService().getClassByAlias(classNameOrAlias); @@ -64,8 +61,7 @@ public class TextToClass extends ConversionServiceAwareConverter { // treat as a class name return ClassUtils.forName(classNameOrAlias); } - } - else { + } else { return null; } } diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToExpression.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToExpression.java index c632d1ad..311d3d36 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToExpression.java @@ -62,11 +62,10 @@ public class TextToExpression extends AbstractConverter { } protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { - String expressionString = (String)source; + String expressionString = (String) source; if (getExpressionParser().isDelimitedExpression(expressionString)) { - return getExpressionParser().parseExpression((String)source); - } - else { + return getExpressionParser().parseExpression((String) source); + } else { return new StaticExpression(expressionString); } } diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToLabeledEnum.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToLabeledEnum.java index 441f86ad..cebaaef3 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToLabeledEnum.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToLabeledEnum.java @@ -20,8 +20,7 @@ import org.springframework.binding.format.support.LabeledEnumFormatter; import org.springframework.core.enums.LabeledEnum; /** - * Converter that converts textual representations of enum - * instances to a specific instance of LabeledEnum. + * Converter that converts textual representations of enum instances to a specific instance of LabeledEnum. * * @author Keith Donald */ @@ -38,6 +37,6 @@ public class TextToLabeledEnum extends AbstractConverter { } protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { - return labeledEnumFormatter.parseValue((String)source, targetClass); + return labeledEnumFormatter.parseValue((String) source, targetClass); } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToNumber.java b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToNumber.java index 050a06eb..9f67a642 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToNumber.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/support/TextToNumber.java @@ -23,8 +23,8 @@ import org.springframework.binding.format.FormatterFactory; import org.springframework.binding.format.support.SimpleFormatterFactory; /** - * Converts textual representations of numbers to a Number - * specialization. Delegates to a synchronized formatter to parse text strings. + * Converts textual representations of numbers to a Number specialization. Delegates to a synchronized + * formatter to parse text strings. * * @author Keith Donald */ @@ -55,6 +55,6 @@ public class TextToNumber extends AbstractFormattingConverter { } protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { - return getFormatterFactory().getNumberFormatter(targetClass).parseValue((String)source, targetClass); + return getFormatterFactory().getNumberFormatter(targetClass).parseValue((String) source, targetClass); } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationAttempt.java b/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationAttempt.java index d011e73d..f2a50bc3 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationAttempt.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationAttempt.java @@ -77,7 +77,6 @@ public class EvaluationAttempt { } protected ToStringCreator createToString(ToStringCreator creator) { - return creator.append("expression", expression).append("target", target).append("context", - context); + return creator.append("expression", expression).append("target", target).append("context", context); } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationContext.java b/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationContext.java index dcd2c972..26231287 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationContext.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationContext.java @@ -20,10 +20,8 @@ import java.util.Map; /** * A context object with two main responsibities: *

    - *
  1. Exposing information to an expression to influence - * an evaluation attempt. - *
  2. Providing operations for recording progress or - * errors during the expression evaluation process. + *
  3. Exposing information to an expression to influence an evaluation attempt. + *
  4. Providing operations for recording progress or errors during the expression evaluation process. *
* * @author Keith Donald diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationException.java b/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationException.java index e28e1160..bde5e58b 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationException.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/EvaluationException.java @@ -25,8 +25,7 @@ import org.springframework.core.NestedRuntimeException; public class EvaluationException extends NestedRuntimeException { /** - * The evaluation attempt that failed. - * Transient because an EvaluationAttempt is not serializable. + * The evaluation attempt that failed. Transient because an EvaluationAttempt is not serializable. */ private transient EvaluationAttempt evaluationAttempt; diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/Expression.java b/spring-binding/src/main/java/org/springframework/binding/expression/Expression.java index b944f12b..62c00e8c 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/Expression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/Expression.java @@ -16,17 +16,16 @@ package org.springframework.binding.expression; /** - * Evaluates a single parsed expression on the provided input object in the - * specified context. This provides a common abstraction for expression - * evaluation independent of any language like OGNL or Spring's BeanWrapper. + * Evaluates a single parsed expression on the provided input object in the specified context. This provides a common + * abstraction for expression evaluation independent of any language like OGNL or Spring's BeanWrapper. * * @author Keith Donald */ public interface Expression { /** - * Evaluate the expression encapsulated by this evaluator against the - * provided target object and return the result of the evaluation. + * Evaluate the expression encapsulated by this evaluator against the provided target object and return the result + * of the evaluation. * @param target the target of the expression * @param context the expression evaluation context * @return the evaluation result diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/ExpressionParser.java b/spring-binding/src/main/java/org/springframework/binding/expression/ExpressionParser.java index bd088930..8692af31 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/ExpressionParser.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/ExpressionParser.java @@ -16,24 +16,23 @@ package org.springframework.binding.expression; /** - * Parses expression strings, returing a configured evaluator instance capable - * of performing parsed expression evaluation in a thread safe way. + * Parses expression strings, returing a configured evaluator instance capable of performing parsed expression + * evaluation in a thread safe way. * * @author Keith Donald */ public interface ExpressionParser { /** - * Is this expression string delimited in a manner that indicates it is a - * parseable expression? For example "${expression}". + * Is this expression string delimited in a manner that indicates it is a parseable expression? For example + * "${expression}". * @param expressionString the proposed expression string * @return true if yes, false if not */ public boolean isDelimitedExpression(String expressionString); /** - * Parse the provided expression string, returning an evaluator capable of - * evaluating it against input. + * Parse the provided expression string, returning an evaluator capable of evaluating it against input. * @param expressionString the parseable expression string * @return the evaluator for the parsed expression * @throws ParserException an exception occured during parsing @@ -41,13 +40,12 @@ public interface ExpressionParser { public Expression parseExpression(String expressionString) throws ParserException; /** - * Parse the provided settable expression string, returning an evaluator - * capable of evaluating its value as well as setting its value. + * Parse the provided settable expression string, returning an evaluator capable of evaluating its value as well as + * setting its value. * @param expressionString the parseable expression string * @return the evaluator for the parsed expression * @throws ParserException an exception occured during parsing - * @throws UnsupportedOperationException this parser does not support - * settable expressions + * @throws UnsupportedOperationException this parser does not support settable expressions */ public SettableExpression parseSettableExpression(String expressionString) throws ParserException, UnsupportedOperationException; diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/SetValueAttempt.java b/spring-binding/src/main/java/org/springframework/binding/expression/SetValueAttempt.java index 242f4f46..e4b2b9cd 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/SetValueAttempt.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/SetValueAttempt.java @@ -25,7 +25,7 @@ import org.springframework.core.style.ToStringCreator; public class SetValueAttempt extends EvaluationAttempt { /** - * The new value. + * The new value. */ private Object value; diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/SettableExpression.java b/spring-binding/src/main/java/org/springframework/binding/expression/SettableExpression.java index 48ba4ea3..e5949084 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/SettableExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/SettableExpression.java @@ -16,16 +16,14 @@ package org.springframework.binding.expression; /** - * An evaluator that is capable of setting a value on a target object at the - * path defined by this expression. + * An evaluator that is capable of setting a value on a target object at the path defined by this expression. * * @author Keith Donald */ public interface SettableExpression extends Expression { /** - * Evaluate this expression against the target object to set its value to - * the value provided. + * Evaluate this expression against the target object to set its value to the value provided. * @param target the target object * @param value the new value to be set * @param context the evaluation context diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELContextFactory.java b/spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELContextFactory.java index 745c2c66..76f95d30 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELContextFactory.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELContextFactory.java @@ -12,43 +12,43 @@ import javax.el.VariableMapper; */ public class DefaultELContextFactory implements ELContextFactory { - /** - * Configures and returns a simple EL context to use to parse EL expressions. - * @return The configured simple ELContext instance. - */ - public ELContext getParseContext() { - return new SimpleELContext(); - } - - /** - * Configures and returns a simple EL context to use to evaluate EL expressions on the given base target object. - * @return The configured simple ELContext instance. - */ - public ELContext getEvaluationContext(Object target) { - return new SimpleELContext(target); - } - - private static class SimpleELContext extends ELContext { - private DefaultELResolver resolver = new DefaultELResolver(); - - public SimpleELContext() { - + /** + * Configures and returns a simple EL context to use to parse EL expressions. + * @return The configured simple ELContext instance. + */ + public ELContext getParseContext() { + return new SimpleELContext(); } - public SimpleELContext(Object target) { - this.resolver.setTarget(target); + /** + * Configures and returns a simple EL context to use to evaluate EL expressions on the given base target object. + * @return The configured simple ELContext instance. + */ + public ELContext getEvaluationContext(Object target) { + return new SimpleELContext(target); } - public ELResolver getELResolver() { - return resolver; - } + private static class SimpleELContext extends ELContext { + private DefaultELResolver resolver = new DefaultELResolver(); - public FunctionMapper getFunctionMapper() { - return null; - } + public SimpleELContext() { - public VariableMapper getVariableMapper() { - return null; + } + + public SimpleELContext(Object target) { + this.resolver.setTarget(target); + } + + public ELResolver getELResolver() { + return resolver; + } + + public FunctionMapper getFunctionMapper() { + return null; + } + + public VariableMapper getVariableMapper() { + return null; + } } - } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELResolver.java b/spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELResolver.java index 212bf4c4..b30945ec 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELResolver.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELResolver.java @@ -24,56 +24,56 @@ import org.springframework.util.Assert; */ public class DefaultELResolver extends CompositeELResolver { - private Object target; + private Object target; - public DefaultELResolver() { - configureResolvers(); - } - - public Class getType(ELContext context, Object base, Object property) { - return super.getType(context, adaptIfNecessary(base), property); - } - - public Object getValue(ELContext context, Object base, Object property) { - Assert.notNull(target, "The DefaultELResolver must have a target base property set."); - if (base == null) { - return super.getValue(context, target, property); - } else { - return super.getValue(context, adaptIfNecessary(base), property); + public DefaultELResolver() { + configureResolvers(); } - } - public void setValue(ELContext context, Object base, Object property, Object val) { - Assert.notNull(target, "The DefaultELResolver must have a target base property set."); - if (base == null) { - super.setValue(context, target, property, val); - } else { - super.setValue(context, adaptIfNecessary(base), property, val); + public Class getType(ELContext context, Object base, Object property) { + return super.getType(context, adaptIfNecessary(base), property); } - } - public Object getTarget() { - return target; - } - - public void setTarget(Object target) { - this.target = adaptIfNecessary(target); - } - - private Object adaptIfNecessary(Object base) { - if (base instanceof MapAdaptable) { - return ((MapAdaptable) base).asMap(); - } else { - return base; + public Object getValue(ELContext context, Object base, Object property) { + Assert.notNull(target, "The DefaultELResolver must have a target base property set."); + if (base == null) { + return super.getValue(context, target, property); + } else { + return super.getValue(context, adaptIfNecessary(base), property); + } } - } - private void configureResolvers() { - add(new ArrayELResolver()); - add(new ListELResolver()); - add(new MapELResolver()); - add(new ResourceBundleELResolver()); - add(new BeanELResolver()); - } + public void setValue(ELContext context, Object base, Object property, Object val) { + Assert.notNull(target, "The DefaultELResolver must have a target base property set."); + if (base == null) { + super.setValue(context, target, property, val); + } else { + super.setValue(context, adaptIfNecessary(base), property, val); + } + } + + public Object getTarget() { + return target; + } + + public void setTarget(Object target) { + this.target = adaptIfNecessary(target); + } + + private Object adaptIfNecessary(Object base) { + if (base instanceof MapAdaptable) { + return ((MapAdaptable) base).asMap(); + } else { + return base; + } + } + + private void configureResolvers() { + add(new ArrayELResolver()); + add(new ListELResolver()); + add(new MapELResolver()); + add(new ResourceBundleELResolver()); + add(new BeanELResolver()); + } } diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/el/ELContextFactory.java b/spring-binding/src/main/java/org/springframework/binding/expression/el/ELContextFactory.java index 3a731621..3abfa434 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/el/ELContextFactory.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/el/ELContextFactory.java @@ -10,19 +10,19 @@ import javax.el.ELResolver; */ public interface ELContextFactory { - /** - * Configures and returns an {@link ELContext} to be used in parsing EL expressions. - * @return ELContext The configured ELContext instance for parsing expressions. - */ - public ELContext getParseContext(); + /** + * Configures and returns an {@link ELContext} to be used in parsing EL expressions. + * @return ELContext The configured ELContext instance for parsing expressions. + */ + public ELContext getParseContext(); - /** - * Configures and returns an {@link ELContext} to be used in evaluating EL expressions on the given base target - * object. In certain environments the target will be null and the base object of the expression is expected to be - * resolved via the ELContext's {@link ELResolver} chain. - * @param target The base object for the expression evaluation. - * @return ELContext The configured ELContext instance for evaluating expressions. - */ - public ELContext getEvaluationContext(Object target); + /** + * Configures and returns an {@link ELContext} to be used in evaluating EL expressions on the given base target + * object. In certain environments the target will be null and the base object of the expression is expected to be + * resolved via the ELContext's {@link ELResolver} chain. + * @param target The base object for the expression evaluation. + * @return ELContext The configured ELContext instance for evaluating expressions. + */ + public ELContext getEvaluationContext(Object target); } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpression.java b/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpression.java index e24555d6..7f9d7c7f 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpression.java @@ -16,67 +16,67 @@ import org.springframework.binding.expression.SettableExpression; */ public class ELExpression implements SettableExpression { - private ELContextFactory factory; + private ELContextFactory factory; - private ValueExpression expression; + private ValueExpression expression; - public ELExpression(ELContextFactory factory, ValueExpression expression) { - this.factory = factory; - this.expression = expression; - } - - public void evaluateToSet(Object target, Object value, EvaluationContext context) throws EvaluationException { - ELContext ctx = getELContext(target); - try { - expression.setValue(ctx, value); - } catch (ELException ex) { - throw new EvaluationException(new EvaluationAttempt(this, target, context), ex); + public ELExpression(ELContextFactory factory, ValueExpression expression) { + this.factory = factory; + this.expression = expression; } - } - public Object evaluate(Object target, EvaluationContext context) throws EvaluationException { - ELContext ctx = getELContext(target); - try { - return expression.getValue(ctx); - } catch (ELException ex) { - throw new EvaluationException(new EvaluationAttempt(this, target, context), ex); + public void evaluateToSet(Object target, Object value, EvaluationContext context) throws EvaluationException { + ELContext ctx = getELContext(target); + try { + expression.setValue(ctx, value); + } catch (ELException ex) { + throw new EvaluationException(new EvaluationAttempt(this, target, context), ex); + } } - } - protected Class getType(Object target, EvaluationContext context) throws EvaluationException { - ELContext ctx = getELContext(target); - try { - return expression.getType(ctx); - } catch (ELException ex) { - throw new EvaluationException(new EvaluationAttempt(this, target, context), ex); + public Object evaluate(Object target, EvaluationContext context) throws EvaluationException { + ELContext ctx = getELContext(target); + try { + return expression.getValue(ctx); + } catch (ELException ex) { + throw new EvaluationException(new EvaluationAttempt(this, target, context), ex); + } } - } - /** - * Retrieves an {@link ELContext} instance, configured with a DefaultELResolver if no other resolvers have been - * configured. - * - * @return {@link ELContext} The thread-bound {@link ELContext} instance. - */ - protected ELContext getELContext(Object target) { - ELContext ctx = factory.getEvaluationContext(target); - return ctx; - } - - public int hashCode() { - return expression.hashCode(); - } - - public boolean equals(Object o) { - if (!(o instanceof ELExpression)) { - return false; + protected Class getType(Object target, EvaluationContext context) throws EvaluationException { + ELContext ctx = getELContext(target); + try { + return expression.getType(ctx); + } catch (ELException ex) { + throw new EvaluationException(new EvaluationAttempt(this, target, context), ex); + } } - ELExpression other = (ELExpression) o; - return expression.equals(other.expression); - } - public String toString() { - return expression.getExpressionString(); - } + /** + * Retrieves an {@link ELContext} instance, configured with a DefaultELResolver if no other resolvers have been + * configured. + * + * @return {@link ELContext} The thread-bound {@link ELContext} instance. + */ + protected ELContext getELContext(Object target) { + ELContext ctx = factory.getEvaluationContext(target); + return ctx; + } + + public int hashCode() { + return expression.hashCode(); + } + + public boolean equals(Object o) { + if (!(o instanceof ELExpression)) { + return false; + } + ELExpression other = (ELExpression) o; + return expression.equals(other.expression); + } + + public String toString() { + return expression.getExpressionString(); + } } diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpressionParser.java b/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpressionParser.java index b267e163..2cc12f88 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpressionParser.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpressionParser.java @@ -15,110 +15,110 @@ import org.springframework.binding.expression.SettableExpression; */ public class ELExpressionParser implements ExpressionParser { - /** - * The expression prefix for deferred EL expressions. - */ - private static final String DEFERRED_EL_EXPRESSION_PREFIX = "#{"; + /** + * The expression prefix for deferred EL expressions. + */ + private static final String DEFERRED_EL_EXPRESSION_PREFIX = "#{"; - /** - * The expression suffix for deferred EL expressions. - */ - private static final String DEFERRED_EL_EXPRESSION_SUFFIX = "}"; + /** + * The expression suffix for deferred EL expressions. + */ + private static final String DEFERRED_EL_EXPRESSION_SUFFIX = "}"; - /** - * The marked expression delimiter prefix. - */ - private String expressionPrefix = DEFERRED_EL_EXPRESSION_PREFIX; + /** + * The marked expression delimiter prefix. + */ + private String expressionPrefix = DEFERRED_EL_EXPRESSION_PREFIX; - /** - * The marked expression delimiter suffix. - */ - private String expressionSuffix = DEFERRED_EL_EXPRESSION_SUFFIX; + /** + * The marked expression delimiter suffix. + */ + private String expressionSuffix = DEFERRED_EL_EXPRESSION_SUFFIX; - /** - * The {@link ELContextFactory} for retrieving a configured ELContext. - */ - private ELContextFactory contextFactory; + /** + * The {@link ELContextFactory} for retrieving a configured ELContext. + */ + private ELContextFactory contextFactory; - /** - * The ExpressionFactory for constructing EL expressions - */ - private ExpressionFactory expressionFactory; + /** + * The ExpressionFactory for constructing EL expressions + */ + private ExpressionFactory expressionFactory; - /** - * Creates a new EL expression parser for standalone usage. - */ - public ELExpressionParser(ExpressionFactory expressionFactory) { - this.expressionFactory = expressionFactory; - this.contextFactory = new DefaultELContextFactory(); - } - - /** - * Creates a new EL expression parser with a custom context factory for a specific environment. - * - * @param contextFactory the context factory - */ - public ELExpressionParser(ExpressionFactory expressionFactory, ELContextFactory contextFactory) { - this.expressionFactory = expressionFactory; - this.contextFactory = contextFactory; - } - - /** - * Check whether or not given criteria are expressed as an expression. - */ - public boolean isDelimitedExpression(String expressionString) { - int prefixIndex = expressionString.indexOf(expressionPrefix); - if (prefixIndex == -1) { - return false; + /** + * Creates a new EL expression parser for standalone usage. + */ + public ELExpressionParser(ExpressionFactory expressionFactory) { + this.expressionFactory = expressionFactory; + this.contextFactory = new DefaultELContextFactory(); } - int suffixIndex = expressionString.indexOf(expressionSuffix, prefixIndex); - if (suffixIndex == -1) { - return false; - } else { - if (suffixIndex == prefixIndex + expressionPrefix.length()) { - return false; - } else { - return true; - } - } - } - public final Expression parseExpression(String expressionString) throws ParserException { - if (!isDelimitedExpression(expressionString)) { - expressionString = expressionPrefix + expressionString + expressionSuffix; + /** + * Creates a new EL expression parser with a custom context factory for a specific environment. + * + * @param contextFactory the context factory + */ + public ELExpressionParser(ExpressionFactory expressionFactory, ELContextFactory contextFactory) { + this.expressionFactory = expressionFactory; + this.contextFactory = contextFactory; } - return doParseExpression(expressionString); - } - public final SettableExpression parseSettableExpression(String expressionString) throws ParserException, - UnsupportedOperationException { - if (!isDelimitedExpression(expressionString)) { - expressionString = expressionPrefix + expressionString + expressionSuffix; + /** + * Check whether or not given criteria are expressed as an expression. + */ + public boolean isDelimitedExpression(String expressionString) { + int prefixIndex = expressionString.indexOf(expressionPrefix); + if (prefixIndex == -1) { + return false; + } + int suffixIndex = expressionString.indexOf(expressionSuffix, prefixIndex); + if (suffixIndex == -1) { + return false; + } else { + if (suffixIndex == prefixIndex + expressionPrefix.length()) { + return false; + } else { + return true; + } + } } - return doParseSettableExpression(expressionString); - } - /** - * Parses the expression string into an EL value expression. - * @param expressionString - * @throws ParserException - */ - protected Expression doParseExpression(String expressionString) throws ParserException { - return doParseSettableExpression(expressionString); - } - - /** - * Parses the expression string into an EL value expression. - * @param expressionString - * @throws ParserException - */ - protected SettableExpression doParseSettableExpression(String expressionString) throws ParserException { - ELContext ctx = contextFactory.getParseContext(); - try { - return new ELExpression(contextFactory, expressionFactory.createValueExpression(ctx, expressionString, - Object.class)); - } catch (ELException ex) { - throw new ParserException(expressionString, ex); + public final Expression parseExpression(String expressionString) throws ParserException { + if (!isDelimitedExpression(expressionString)) { + expressionString = expressionPrefix + expressionString + expressionSuffix; + } + return doParseExpression(expressionString); + } + + public final SettableExpression parseSettableExpression(String expressionString) throws ParserException, + UnsupportedOperationException { + if (!isDelimitedExpression(expressionString)) { + expressionString = expressionPrefix + expressionString + expressionSuffix; + } + return doParseSettableExpression(expressionString); + } + + /** + * Parses the expression string into an EL value expression. + * @param expressionString + * @throws ParserException + */ + protected Expression doParseExpression(String expressionString) throws ParserException { + return doParseSettableExpression(expressionString); + } + + /** + * Parses the expression string into an EL value expression. + * @param expressionString + * @throws ParserException + */ + protected SettableExpression doParseSettableExpression(String expressionString) throws ParserException { + ELContext ctx = contextFactory.getParseContext(); + try { + return new ELExpression(contextFactory, expressionFactory.createValueExpression(ctx, expressionString, + Object.class)); + } catch (ELException ex) { + throw new ParserException(expressionString, ex); + } } - } } diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/ognl/OgnlExpression.java b/spring-binding/src/main/java/org/springframework/binding/expression/ognl/OgnlExpression.java index 86105f26..d3c0198d 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/ognl/OgnlExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/ognl/OgnlExpression.java @@ -31,9 +31,8 @@ import org.springframework.util.Assert; /** * Evaluates a parsed Ognl expression. *

- * IMPLEMENTATION NOTE: Ognl 2.6.7 expression objects do not respect equality - * properly, so the equality operations defined within this class do not - * function properly. + * IMPLEMENTATION NOTE: Ognl 2.6.7 expression objects do not respect equality properly, so the equality operations + * defined within this class do not function properly. * * @author Keith Donald */ @@ -71,14 +70,12 @@ class OgnlExpression implements SettableExpression { Map contextAttributes = (context != null ? context.getAttributes() : Collections.EMPTY_MAP); try { return Ognl.getValue(expression, contextAttributes, target); - } - catch (OgnlException e) { + } catch (OgnlException e) { if (e.getReason() != null && e.getReason() != e) { // unwrap the OgnlException since the actual exception is wrapped inside it // and there is not generic (getCause) way to get to it later on throw new EvaluationException(new EvaluationAttempt(this, target, context), e.getReason()); - } - else { + } else { throw new EvaluationException(new EvaluationAttempt(this, target, context), e); } } @@ -89,8 +86,7 @@ class OgnlExpression implements SettableExpression { Map contextAttributes = (context != null ? context.getAttributes() : Collections.EMPTY_MAP); try { Ognl.setValue(expression, contextAttributes, target, value); - } - catch (OgnlException e) { + } catch (OgnlException e) { throw new EvaluationException(new SetValueAttempt(this, target, value, context), e); } } diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/ognl/OgnlExpressionParser.java b/spring-binding/src/main/java/org/springframework/binding/expression/ognl/OgnlExpressionParser.java index 5b21dfe6..195e08e5 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/ognl/OgnlExpressionParser.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/ognl/OgnlExpressionParser.java @@ -39,8 +39,7 @@ public class OgnlExpressionParser extends AbstractExpressionParser { public SettableExpression doParseSettableExpression(String expressionString) throws ParserException { try { return new OgnlExpression(Ognl.parseExpression(expressionString)); - } - catch (OgnlException e) { + } catch (OgnlException e) { throw new ParserException(expressionString, e); } } diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/support/AbstractExpressionParser.java b/spring-binding/src/main/java/org/springframework/binding/expression/support/AbstractExpressionParser.java index a5a21bb3..e2cddb83 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/support/AbstractExpressionParser.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/support/AbstractExpressionParser.java @@ -91,12 +91,10 @@ public abstract class AbstractExpressionParser implements ExpressionParser { int suffixIndex = expressionString.indexOf(getExpressionSuffix(), prefixIndex); if (suffixIndex == -1) { return false; - } - else { + } else { if (suffixIndex == prefixIndex + getExpressionPrefix().length()) { return false; - } - else { + } else { return true; } } @@ -106,30 +104,27 @@ public abstract class AbstractExpressionParser implements ExpressionParser { Expression[] expressions = parseExpressions(expressionString); if (expressions.length == 1) { return expressions[0]; - } - else { + } else { return new CompositeStringExpression(expressions); } } - public final SettableExpression parseSettableExpression(String expressionString) - throws ParserException, UnsupportedOperationException { + public final SettableExpression parseSettableExpression(String expressionString) throws ParserException, + UnsupportedOperationException { expressionString = expressionString.trim(); // a settable expression should just be a single expression if (expressionString.startsWith(getExpressionPrefix()) && expressionString.endsWith(getExpressionSuffix())) { - expressionString = expressionString.substring(getExpressionPrefix().length(), - expressionString.length() - getExpressionSuffix().length()); + expressionString = expressionString.substring(getExpressionPrefix().length(), expressionString.length() + - getExpressionSuffix().length()); } return doParseSettableExpression(expressionString); } /** - * Helper that parses given expression string using the configured parser. - * The expression string can contain any number of expressions all contained - * in "${...}" markers. For instance: "foo${expr0}bar${expr1}". The static - * pieces of text will also be returned as Expressions that just return that - * static piece of text. As a result, evaluating all returned expressions - * and concatenating the results produces the complete evaluated string. + * Helper that parses given expression string using the configured parser. The expression string can contain any + * number of expressions all contained in "${...}" markers. For instance: "foo${expr0}bar${expr1}". The static + * pieces of text will also be returned as Expressions that just return that static piece of text. As a result, + * evaluating all returned expressions and concatenating the results produces the complete evaluated string. * @param expressionString the expression string * @return the parsed expressions * @throws ParserException when the expressions cannot be parsed @@ -146,74 +141,64 @@ public abstract class AbstractExpressionParser implements ExpressionParser { expressions.add(new StaticExpression(expressionString.substring(startIdx, prefixIndex))); startIdx = prefixIndex; } - int nextPrefixIndex = expressionString.indexOf(getExpressionPrefix(), - prefixIndex + getExpressionPrefix().length()); + int nextPrefixIndex = expressionString.indexOf(getExpressionPrefix(), prefixIndex + + getExpressionPrefix().length()); int suffixIndex; - if (nextPrefixIndex == -1) { + if (nextPrefixIndex == -1) { // this is the last expression in the expression string - suffixIndex = expressionString.lastIndexOf(getExpressionSuffix()); - } - else { + suffixIndex = expressionString.lastIndexOf(getExpressionSuffix()); + } else { // another expression exists after this one in the expression string - suffixIndex = expressionString.lastIndexOf(getExpressionSuffix(), nextPrefixIndex); - } + suffixIndex = expressionString.lastIndexOf(getExpressionSuffix(), nextPrefixIndex); + } if (suffixIndex < (prefixIndex + getExpressionPrefix().length())) { throw new ParserException(expressionString, "No ending suffix '" + getExpressionSuffix() + "' for expression starting at character " + prefixIndex + ": " + expressionString.substring(prefixIndex), null); - } - else if (suffixIndex == prefixIndex + getExpressionPrefix().length()) { + } else if (suffixIndex == prefixIndex + getExpressionPrefix().length()) { throw new ParserException(expressionString, "No expression defined within delimiter '" - + getExpressionPrefix() + getExpressionSuffix() + "' at character " + prefixIndex, - null); - } - else { + + getExpressionPrefix() + getExpressionSuffix() + "' at character " + prefixIndex, null); + } else { String expr = expressionString.substring(prefixIndex + getExpressionPrefix().length(), suffixIndex); expressions.add(doParseExpression(expr)); startIdx = suffixIndex + 1; } - } - else { + } else { if (startIdx == 0) { // treat entire string as one expression expressions.add(doParseExpression(expressionString)); - } - else { + } else { // no more ${expressions} found in string expressions.add(new StaticExpression(expressionString.substring(startIdx))); } startIdx = expressionString.length(); } } - } - else { + } else { expressions.add(new StaticExpression(expressionString)); } return (Expression[]) expressions.toArray(new Expression[expressions.size()]); } - + // template methods /** - * Template method for parsing a filtered expression string. Subclasses should - * override. + * Template method for parsing a filtered expression string. Subclasses should override. * @param expressionString the expression string * @return the parsed expression * @throws ParserException an exception occured during parsing */ protected abstract Expression doParseExpression(String expressionString) throws ParserException; - + /** - * Template method for parsing a filtered settable expression string. Subclasses - * should override. + * Template method for parsing a filtered settable expression string. Subclasses should override. * @param expressionString the expression string * @return the parsed expression * @throws ParserException an exception occured during parsing - * @throws UnsupportedOperationException this parser does not support - * settable expressions + * @throws UnsupportedOperationException this parser does not support settable expressions */ - protected abstract SettableExpression doParseSettableExpression(String expressionString) - throws ParserException, UnsupportedOperationException; + protected abstract SettableExpression doParseSettableExpression(String expressionString) throws ParserException, + UnsupportedOperationException; } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/support/BeanWrapperExpression.java b/spring-binding/src/main/java/org/springframework/binding/expression/support/BeanWrapperExpression.java index 170be0c3..1e67ed4c 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/support/BeanWrapperExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/support/BeanWrapperExpression.java @@ -48,15 +48,14 @@ class BeanWrapperExpression implements SettableExpression { if (!(o instanceof BeanWrapperExpression)) { return false; } - BeanWrapperExpression other = (BeanWrapperExpression)o; + BeanWrapperExpression other = (BeanWrapperExpression) o; return expression.equals(other.expression); } public Object evaluate(Object target, EvaluationContext context) throws EvaluationException { try { return new BeanWrapperImpl(target).getPropertyValue(expression); - } - catch (BeansException e) { + } catch (BeansException e) { throw new EvaluationException(new EvaluationAttempt(this, target, context), e); } } @@ -65,8 +64,7 @@ class BeanWrapperExpression implements SettableExpression { try { Assert.notNull(target, "The target object to evaluate is required"); new BeanWrapperImpl(target).setPropertyValue(expression, value); - } - catch (BeansException e) { + } catch (BeansException e) { throw new EvaluationException(new SetValueAttempt(this, target, value, context), e); } } diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/support/BeanWrapperExpressionParser.java b/spring-binding/src/main/java/org/springframework/binding/expression/support/BeanWrapperExpressionParser.java index abea91ff..bd4f6b96 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/support/BeanWrapperExpressionParser.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/support/BeanWrapperExpressionParser.java @@ -25,7 +25,7 @@ import org.springframework.binding.expression.SettableExpression; * @author Keith Donald */ public class BeanWrapperExpressionParser extends AbstractExpressionParser { - + protected Expression doParseExpression(String expressionString) throws ParserException { return doParseSettableExpression(expressionString); } diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/support/CollectionAddingExpression.java b/spring-binding/src/main/java/org/springframework/binding/expression/support/CollectionAddingExpression.java index 82d206f1..e18136a6 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/support/CollectionAddingExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/support/CollectionAddingExpression.java @@ -27,7 +27,7 @@ import org.springframework.util.Assert; /** * A settable expression that adds non-null values to a collection. - * + * * @author Keith Donald */ public class CollectionAddingExpression implements SettableExpression { @@ -52,13 +52,13 @@ public class CollectionAddingExpression implements SettableExpression { public void evaluateToSet(Object target, Object value, EvaluationContext context) throws EvaluationException { Object result = evaluate(target, context); if (result == null) { - throw new EvaluationException(new SetValueAttempt(this, target, value, null), - new IllegalArgumentException("The collection expression evaluated to a [null] reference")); + throw new EvaluationException(new SetValueAttempt(this, target, value, null), new IllegalArgumentException( + "The collection expression evaluated to a [null] reference")); } Assert.isInstanceOf(Collection.class, result, "Not a collection: "); if (value != null) { // add the value to the collection - ((Collection)result).add(value); + ((Collection) result).add(value); } } diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/support/CompositeStringExpression.java b/spring-binding/src/main/java/org/springframework/binding/expression/support/CompositeStringExpression.java index 3070894c..89ce2581 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/support/CompositeStringExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/support/CompositeStringExpression.java @@ -34,8 +34,8 @@ public class CompositeStringExpression implements Expression { /** * Creates a new composite string expression. - * @param expressions the ordered set of expressions that when evaluated - * will have their results stringed together to build the composite string + * @param expressions the ordered set of expressions that when evaluated will have their results stringed together + * to build the composite string */ public CompositeStringExpression(Expression[] expressions) { this.expressions = expressions; diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/support/StaticExpression.java b/spring-binding/src/main/java/org/springframework/binding/expression/support/StaticExpression.java index dec94e9e..7ed9bdf9 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/support/StaticExpression.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/support/StaticExpression.java @@ -21,8 +21,7 @@ import org.springframework.binding.expression.Expression; import org.springframework.util.ObjectUtils; /** - * A simple expression evaluator that just returns a fixed result on each - * evaluation. + * A simple expression evaluator that just returns a fixed result on each evaluation. * * @author Keith Donald */ @@ -44,8 +43,7 @@ public class StaticExpression implements Expression { public int hashCode() { if (value == null) { return 0; - } - else { + } else { return value.hashCode(); } } @@ -54,7 +52,7 @@ public class StaticExpression implements Expression { if (!(o instanceof StaticExpression)) { return false; } - StaticExpression other = (StaticExpression)o; + StaticExpression other = (StaticExpression) o; return ObjectUtils.nullSafeEquals(value, other.value); } diff --git a/spring-binding/src/main/java/org/springframework/binding/format/Formatter.java b/spring-binding/src/main/java/org/springframework/binding/format/Formatter.java index e3db0db6..b77fa088 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/Formatter.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/Formatter.java @@ -16,8 +16,7 @@ package org.springframework.binding.format; /** - * A lightweight interface for formatting a value and parsing a value from its - * formatted form. + * A lightweight interface for formatting a value and parsing a value from its formatted form. * * @author Keith Donald */ @@ -32,8 +31,7 @@ public interface Formatter { public String formatValue(Object value) throws IllegalArgumentException; /** - * Parse the formatted string representation of a value, restoring the - * value. + * Parse the formatted string representation of a value, restoring the value. * @param formattedString the formatted string representation * @param targetClass the target class to convert the formatted value to * @return the parsed value diff --git a/spring-binding/src/main/java/org/springframework/binding/format/FormatterFactory.java b/spring-binding/src/main/java/org/springframework/binding/format/FormatterFactory.java index 7a2cb209..76618e8c 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/FormatterFactory.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/FormatterFactory.java @@ -18,9 +18,8 @@ package org.springframework.binding.format; /** * Source for shared and commonly used Formatters. *

- * Formatters are typically not thread safe as Format objects - * aren't thread safe: so implementations of this service should take care to - * synchronize them as neccessary. + * Formatters are typically not thread safe as Format objects aren't thread safe: so implementations of + * this service should take care to synchronize them as neccessary. * * @see java.text.Format * diff --git a/spring-binding/src/main/java/org/springframework/binding/format/InvalidFormatException.java b/spring-binding/src/main/java/org/springframework/binding/format/InvalidFormatException.java index e6c61b11..23643ade 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/InvalidFormatException.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/InvalidFormatException.java @@ -44,7 +44,8 @@ public class InvalidFormatException extends NestedRuntimeException { * @param cause the underlying cause of this exception */ public InvalidFormatException(String invalidValue, String expectedFormat, Throwable cause) { - super("Invalid format for value '" + invalidValue + "'; the expected format was '" + expectedFormat + "'", cause); + super("Invalid format for value '" + invalidValue + "'; the expected format was '" + expectedFormat + "'", + cause); this.invalidValue = invalidValue; this.expectedFormat = expectedFormat; } diff --git a/spring-binding/src/main/java/org/springframework/binding/format/support/AbstractFormatter.java b/spring-binding/src/main/java/org/springframework/binding/format/support/AbstractFormatter.java index df4327b8..cc0294e1 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/support/AbstractFormatter.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/support/AbstractFormatter.java @@ -62,18 +62,16 @@ public abstract class AbstractFormatter implements Formatter { Assert.isTrue(!isEmpty(value), "Object to format cannot be empty"); return doFormatValue(value); } - + /** - * Template method subclasses should override to encapsulate formatting - * logic. + * Template method subclasses should override to encapsulate formatting logic. * @param value the value to format * @return the formatted string representation */ protected abstract String doFormatValue(Object value); /** - * Returns the formatted form of an empty value. Default implementation - * just returns the empty string. + * Returns the formatted form of an empty value. Default implementation just returns the empty string. */ protected String getEmptyFormattedValue() { return ""; @@ -85,8 +83,7 @@ public abstract class AbstractFormatter implements Formatter { return getEmptyValue(); } return doParseValue(formattedString, targetClass); - } - catch (ParseException ex) { + } catch (ParseException ex) { throw new InvalidFormatException(formattedString, getExpectedFormat(targetClass), ex); } } @@ -102,16 +99,15 @@ public abstract class AbstractFormatter implements Formatter { ParseException; /** - * Returns the empty value (resulting from parsing an empty input string). - * This default implementation just returns null. + * Returns the empty value (resulting from parsing an empty input string). This default implementation just returns + * null. */ protected Object getEmptyValue() { return null; } /** - * Returns the expected string format for the given target class. - * The default implementation just returns null. + * Returns the expected string format for the given target class. The default implementation just returns null. */ protected String getExpectedFormat(Class targetClass) { return null; @@ -123,11 +119,9 @@ public abstract class AbstractFormatter implements Formatter { protected boolean isEmpty(Object o) { if (o == null) { return true; - } - else if (o instanceof String) { - return !StringUtils.hasText((String)o); - } - else { + } else if (o instanceof String) { + return !StringUtils.hasText((String) o); + } else { return false; } } diff --git a/spring-binding/src/main/java/org/springframework/binding/format/support/AbstractFormatterFactory.java b/spring-binding/src/main/java/org/springframework/binding/format/support/AbstractFormatterFactory.java index 23a585d9..165e35fa 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/support/AbstractFormatterFactory.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/support/AbstractFormatterFactory.java @@ -24,8 +24,8 @@ import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.SimpleLocaleContext; /** - * Base class for formatter factories. Manages the locale used by the produced - * formatters using Spring's {@link org.springframework.context.i18n.LocaleContext} system. + * Base class for formatter factories. Manages the locale used by the produced formatters using Spring's + * {@link org.springframework.context.i18n.LocaleContext} system. * * @author Keith Donald */ @@ -38,8 +38,7 @@ public abstract class AbstractFormatterFactory implements FormatterFactory { private Style defaultTimeStyle = Style.MEDIUM; /** - * Sets the locale context used. Defaults to a {@link SimpleLocaleContext} holding - * the system default locale. + * Sets the locale context used. Defaults to a {@link SimpleLocaleContext} holding the system default locale. */ public void setLocaleContext(LocaleContext localeContext) { this.localeContext = localeContext; diff --git a/spring-binding/src/main/java/org/springframework/binding/format/support/DateFormatter.java b/spring-binding/src/main/java/org/springframework/binding/format/support/DateFormatter.java index f094beca..7c938a38 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/support/DateFormatter.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/support/DateFormatter.java @@ -31,8 +31,7 @@ public class DateFormatter extends AbstractFormatter { private DateFormat dateFormat; /** - * Constructs a date formatter that will delegate to the specified date - * format. + * Constructs a date formatter that will delegate to the specified date format. * @param dateFormat the date format to use */ public DateFormatter(DateFormat dateFormat) { @@ -40,8 +39,7 @@ public class DateFormatter extends AbstractFormatter { } /** - * Constructs a date formatter that will delegate to the specified date - * format. + * Constructs a date formatter that will delegate to the specified date format. * @param dateFormat the date format to use * @param allowEmpty should this formatter allow empty input arguments? */ @@ -52,7 +50,7 @@ public class DateFormatter extends AbstractFormatter { // convert from date to string protected String doFormatValue(Object date) { - return dateFormat.format((Date)date); + return dateFormat.format((Date) date); } // convert back from string to date @@ -64,6 +62,6 @@ public class DateFormatter extends AbstractFormatter { * Convenience method to parse a date. */ public Date parseDate(String formattedString) throws InvalidFormatException { - return (Date)parseValue(formattedString, Date.class); + return (Date) parseValue(formattedString, Date.class); } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/format/support/LabeledEnumFormatter.java b/spring-binding/src/main/java/org/springframework/binding/format/support/LabeledEnumFormatter.java index a2f1cb45..c148226c 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/support/LabeledEnumFormatter.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/support/LabeledEnumFormatter.java @@ -53,7 +53,7 @@ public class LabeledEnumFormatter extends AbstractFormatter { } protected String doFormatValue(Object value) { - LabeledEnum labeledEnum = (LabeledEnum)value; + LabeledEnum labeledEnum = (LabeledEnum) value; return labeledEnum.getLabel(); } @@ -71,6 +71,6 @@ public class LabeledEnumFormatter extends AbstractFormatter { * Convenience method to parse a LabeledEnum. */ public LabeledEnum parseLabeledEnum(String formattedString, Class enumClass) throws InvalidFormatException { - return (LabeledEnum)parseValue(formattedString, enumClass); + return (LabeledEnum) parseValue(formattedString, enumClass); } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/format/support/NumberFormatter.java b/spring-binding/src/main/java/org/springframework/binding/format/support/NumberFormatter.java index 59a110eb..d1d78565 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/support/NumberFormatter.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/support/NumberFormatter.java @@ -23,18 +23,17 @@ import org.springframework.binding.format.InvalidFormatException; import org.springframework.util.NumberUtils; /** - * Converts from various Number specializations to - * String and back. + * Converts from various Number specializations to String and back. * * @author Keith Donald */ public class NumberFormatter extends AbstractFormatter { private NumberFormat numberFormat; - + /** - * Default constructor. The formatter will use "toString" when formatting - * a value and "valueOf" when parsing a value. + * Default constructor. The formatter will use "toString" when formatting a value and "valueOf" when parsing a + * value. */ public NumberFormatter() { } @@ -61,8 +60,7 @@ public class NumberFormatter extends AbstractFormatter { if (this.numberFormat != null) { // use NumberFormat for rendering value return this.numberFormat.format(number); - } - else { + } else { // use toString method for rendering value return number.toString(); } @@ -78,38 +76,38 @@ public class NumberFormatter extends AbstractFormatter { return NumberUtils.parseNumber(text, targetClass); } } - + // convenience methods public Byte parseByte(String formattedString) throws InvalidFormatException { - return (Byte)parseValue(formattedString, Byte.class); + return (Byte) parseValue(formattedString, Byte.class); } public Short parseShort(String formattedString) throws InvalidFormatException { - return (Short)parseValue(formattedString, Short.class); + return (Short) parseValue(formattedString, Short.class); } public Integer parseInteger(String formattedString) throws InvalidFormatException { - return (Integer)parseValue(formattedString, Integer.class); + return (Integer) parseValue(formattedString, Integer.class); } public Long parseLong(String formattedString) throws InvalidFormatException { - return (Long)parseValue(formattedString, Long.class); + return (Long) parseValue(formattedString, Long.class); } public Float parseFloat(String formattedString) throws InvalidFormatException { - return (Float)parseValue(formattedString, Float.class); + return (Float) parseValue(formattedString, Float.class); } public Double parseDouble(String formattedString) throws InvalidFormatException { - return (Double)parseValue(formattedString, Double.class); + return (Double) parseValue(formattedString, Double.class); } public BigInteger parseBigInteger(String formattedString) throws InvalidFormatException { - return (BigInteger)parseValue(formattedString, BigInteger.class); + return (BigInteger) parseValue(formattedString, BigInteger.class); } - + public BigDecimal parseBigDecimal(String formattedString) throws InvalidFormatException { - return (BigDecimal)parseValue(formattedString, BigDecimal.class); + return (BigDecimal) parseValue(formattedString, BigDecimal.class); } } \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/AttributeMapper.java b/spring-binding/src/main/java/org/springframework/binding/mapping/AttributeMapper.java index cba73828..89af6730 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/AttributeMapper.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/AttributeMapper.java @@ -18,9 +18,8 @@ package org.springframework.binding.mapping; /** * A lightweight service interface for mapping between two attribute sources. *

- * Implementations of this interface are expected to encapsulate the mapping - * configuration information as well as the logic to act on it to perform - * mapping between a given source and target attribute source. + * Implementations of this interface are expected to encapsulate the mapping configuration information as well as the + * logic to act on it to perform mapping between a given source and target attribute source. * * @author Keith Donald */ diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/DefaultAttributeMapper.java b/spring-binding/src/main/java/org/springframework/binding/mapping/DefaultAttributeMapper.java index b054036a..5de07f65 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/DefaultAttributeMapper.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/DefaultAttributeMapper.java @@ -23,8 +23,7 @@ import java.util.List; import org.springframework.core.style.ToStringCreator; /** - * Generic attributes mapper implementation that allows mappings to be - * configured programatically. + * Generic attributes mapper implementation that allows mappings to be configured programatically. * * @author Erwin Vervaet * @author Keith Donald @@ -49,7 +48,7 @@ public class DefaultAttributeMapper implements AttributeMapper { /** * Add a set of mappings. - * @param mappings the mappings + * @param mappings the mappings */ public void addMappings(AttributeMapper[] mappings) { if (mappings == null) { @@ -63,14 +62,14 @@ public class DefaultAttributeMapper implements AttributeMapper { * @return the list of mappings */ public AttributeMapper[] getMappings() { - return (AttributeMapper[])mappings.toArray(new AttributeMapper[mappings.size()]); + return (AttributeMapper[]) mappings.toArray(new AttributeMapper[mappings.size()]); } public void map(Object source, Object target, MappingContext context) { if (mappings != null) { Iterator it = mappings.iterator(); while (it.hasNext()) { - AttributeMapper mapping = (AttributeMapper)it.next(); + AttributeMapper mapping = (AttributeMapper) it.next(); mapping.map(source, target, context); } } diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/Mapping.java b/spring-binding/src/main/java/org/springframework/binding/mapping/Mapping.java index 13926ace..c58db23b 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/Mapping.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/Mapping.java @@ -24,10 +24,8 @@ import org.springframework.core.style.ToStringCreator; import org.springframework.util.Assert; /** - * A single mapping definition, encapulating the information neccessary to map - * the result of evaluating an expression on a source object to a property on a - * target object, optionally applying a type conversion during the mapping - * process. + * A single mapping definition, encapulating the information neccessary to map the result of evaluating an expression on + * a source object to a property on a target object, optionally applying a type conversion during the mapping process. * * @author Keith Donald */ @@ -51,8 +49,7 @@ public class Mapping implements AttributeMapper { private final ConversionExecutor typeConverter; /** - * Whether or not this is a required mapping; if true, the source expression - * must return a non-null value. + * Whether or not this is a required mapping; if true, the source expression must return a non-null value. */ private boolean required; @@ -62,8 +59,7 @@ public class Mapping implements AttributeMapper { * @param targetExpression the target expression * @param typeConverter a type converter */ - public Mapping(Expression sourceExpression, SettableExpression targetExpression, - ConversionExecutor typeConverter) { + public Mapping(Expression sourceExpression, SettableExpression targetExpression, ConversionExecutor typeConverter) { this(sourceExpression, targetExpression, typeConverter, false); } @@ -85,9 +81,8 @@ public class Mapping implements AttributeMapper { } /** - * Map the sourceAttribute in to the - * targetAttribute target map, performing type conversion if - * necessary. + * Map the sourceAttribute in to the targetAttribute target map, performing type + * conversion if necessary. * @param source The source data structure * @param target The target data structure */ @@ -99,8 +94,7 @@ public class Mapping implements AttributeMapper { throw new RequiredMappingException("This mapping is required; evaluation of expression '" + sourceExpression + "' against source of type [" + source.getClass() + "] must return a non-null value"); - } - else { + } else { // source expression returned no value, simply abort mapping return; } @@ -121,9 +115,8 @@ public class Mapping implements AttributeMapper { if (!(o instanceof Mapping)) { return false; } - Mapping other = (Mapping)o; - return sourceExpression.equals(other.sourceExpression) - && targetExpression.equals(other.targetExpression); + Mapping other = (Mapping) o; + return sourceExpression.equals(other.sourceExpression) && targetExpression.equals(other.targetExpression); } public int hashCode() { diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/MappingBuilder.java b/spring-binding/src/main/java/org/springframework/binding/mapping/MappingBuilder.java index a7cd3f8b..6d836956 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/MappingBuilder.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/MappingBuilder.java @@ -25,8 +25,8 @@ import org.springframework.binding.expression.support.CollectionAddingExpression import org.springframework.util.Assert; /** - * A stateful builder that builds {@link Mapping} objects. Designed for - * convenience to build mappings in a clear, readable manner. + * A stateful builder that builds {@link Mapping} objects. Designed for convenience to build mappings in a clear, + * readable manner. *

* Example usage: * @@ -35,8 +35,8 @@ import org.springframework.util.Assert; * Mapping result = mapping.source("foo").target("bar").from(String.class).to(Long.class).value(); * * - * Calling the {@link #value()} result method clears out this builder's state so - * it can be reused to build another mapping. + * Calling the {@link #value()} result method clears out this builder's state so it can be reused to build another + * mapping. * * @author Keith Donald * @author Erwin Vervaet @@ -77,10 +77,9 @@ public class MappingBuilder { * Whether or not the built mapping is a required mapping. */ private boolean required; - + /** - * Creates a mapping builder that uses the expression parser to parse - * attribute mapping expressions. + * Creates a mapping builder that uses the expression parser to parse attribute mapping expressions. * @param expressionParser the expression parser */ public MappingBuilder(ExpressionParser expressionParser) { @@ -89,9 +88,8 @@ public class MappingBuilder { } /** - * Sets the conversion service that will convert the object returned by - * evaluating the source expression to the {@link #to(Class)} type if - * necessary. + * Sets the conversion service that will convert the object returned by evaluating the source expression to the + * {@link #to(Class)} type if necessary. * @param conversionService the conversion service */ public void setConversionService(ConversionService conversionService) { @@ -114,7 +112,7 @@ public class MappingBuilder { * @return this, to support call-chaining */ public MappingBuilder target(String expressionString) { - targetExpression = (SettableExpression)expressionParser.parseExpression(expressionString); + targetExpression = (SettableExpression) expressionParser.parseExpression(expressionString); return this; } @@ -124,15 +122,13 @@ public class MappingBuilder { * @return this, to support call-chaining */ public MappingBuilder targetCollection(String expressionString) { - targetExpression = new CollectionAddingExpression( - expressionParser.parseSettableExpression(expressionString)); + targetExpression = new CollectionAddingExpression(expressionParser.parseSettableExpression(expressionString)); return this; } /** - * Sets the expected type of the object returned by evaluating the source - * expression. Used in conjunction with {@link #to(Class)} to perform a type - * conversion during the mapping process. + * Sets the expected type of the object returned by evaluating the source expression. Used in conjunction with + * {@link #to(Class)} to perform a type conversion during the mapping process. * @param sourceType the source type * @return this, to support call-chaining */ @@ -159,17 +155,16 @@ public class MappingBuilder { this.required = true; return this; } - + /** - * The logical GoF builder getResult method, returning a fully constructed - * Mapping from the configured pieces. Once called, the state of this - * builder is nulled out to support building a new mapping object again. + * The logical GoF builder getResult method, returning a fully constructed Mapping from the configured pieces. Once + * called, the state of this builder is nulled out to support building a new mapping object again. * @return the mapping result */ public Mapping value() { Assert.notNull(sourceExpression, "The source expression must be set at a minimum"); if (targetExpression == null) { - targetExpression = (SettableExpression)sourceExpression; + targetExpression = (SettableExpression) sourceExpression; } ConversionExecutor typeConverter = null; if (sourceType != null) { @@ -179,14 +174,13 @@ public class MappingBuilder { Mapping result; if (required) { result = new RequiredMapping(sourceExpression, targetExpression, typeConverter); - } - else { + } else { result = new Mapping(sourceExpression, targetExpression, typeConverter); } reset(); return result; } - + /** * Reset this mapping builder. */ diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/MappingContext.java b/spring-binding/src/main/java/org/springframework/binding/mapping/MappingContext.java index 3595fb97..73aa66c9 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/MappingContext.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/MappingContext.java @@ -18,13 +18,10 @@ package org.springframework.binding.mapping; /** * A context object with two main responsibities: *

    - *
  1. Exposing information to a mapper to influence - * a mapping attempt. - *
  2. Providing operations for recording progress or - * errors during the mapping process. + *
  3. Exposing information to a mapper to influence a mapping attempt. + *
  4. Providing operations for recording progress or errors during the mapping process. *
- * Empty for now; subclasses may define their own custom context behavior - * accessible by a mapper with a downcast. + * Empty for now; subclasses may define their own custom context behavior accessible by a mapper with a downcast. * * @author Keith Donald */ diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/RequiredMapping.java b/spring-binding/src/main/java/org/springframework/binding/mapping/RequiredMapping.java index b2291e56..0e659319 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/RequiredMapping.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/RequiredMapping.java @@ -25,7 +25,7 @@ import org.springframework.binding.expression.SettableExpression; * @author Keith Donald */ public class RequiredMapping extends Mapping { - + /** * Creates a required mapping. * @param sourceExpression the source mapping expression diff --git a/spring-binding/src/main/java/org/springframework/binding/mapping/RequiredMappingException.java b/spring-binding/src/main/java/org/springframework/binding/mapping/RequiredMappingException.java index 4c2c09c8..1cba4ce0 100644 --- a/spring-binding/src/main/java/org/springframework/binding/mapping/RequiredMappingException.java +++ b/spring-binding/src/main/java/org/springframework/binding/mapping/RequiredMappingException.java @@ -21,7 +21,7 @@ package org.springframework.binding.mapping; * @author Keith Donald */ public class RequiredMappingException extends IllegalStateException { - + /** * Create a new required mapping exception. * @param message a descriptive message diff --git a/spring-binding/src/main/java/org/springframework/binding/method/InvalidMethodKeyException.java b/spring-binding/src/main/java/org/springframework/binding/method/InvalidMethodKeyException.java index f8690ea8..42b8672b 100644 --- a/spring-binding/src/main/java/org/springframework/binding/method/InvalidMethodKeyException.java +++ b/spring-binding/src/main/java/org/springframework/binding/method/InvalidMethodKeyException.java @@ -18,8 +18,7 @@ package org.springframework.binding.method; import org.springframework.core.NestedRuntimeException; /** - * Thrown when a method key could not be resolved to an invokable java Method on - * a Class. + * Thrown when a method key could not be resolved to an invokable java Method on a Class. * * @author Keith Donald */ @@ -29,7 +28,7 @@ public class InvalidMethodKeyException extends NestedRuntimeException { * The method key that could not be resolved. */ private MethodKey methodKey; - + /** * Creates an exception signaling an invalid method signature. * @param methodKey the class method key diff --git a/spring-binding/src/main/java/org/springframework/binding/method/MethodInvocationException.java b/spring-binding/src/main/java/org/springframework/binding/method/MethodInvocationException.java index 764bf189..5a8640cd 100644 --- a/spring-binding/src/main/java/org/springframework/binding/method/MethodInvocationException.java +++ b/spring-binding/src/main/java/org/springframework/binding/method/MethodInvocationException.java @@ -28,20 +28,17 @@ import org.springframework.core.style.StylerUtils; public class MethodInvocationException extends NestedRuntimeException { /** - * The method signature. - * Transient because a MethodSignature is not Serializable. + * The method signature. Transient because a MethodSignature is not Serializable. */ private transient MethodSignature methodSignature; /** - * The method invocation argument values. - * Transient because we cannot guarantee that the arguments are Serializable. + * The method invocation argument values. Transient because we cannot guarantee that the arguments are Serializable. */ private transient Object[] arguments; /** - * Signals that the method with the specified signature could not be invoked - * with the provided arguments. + * Signals that the method with the specified signature could not be invoked with the provided arguments. * @param methodSignature the method signature * @param arguments the arguments * @param cause the root cause @@ -73,7 +70,7 @@ public class MethodInvocationException extends NestedRuntimeException { public Throwable getTargetException() { Throwable targetException = getCause(); while (targetException instanceof InvocationTargetException) { - targetException = ((InvocationTargetException)targetException).getTargetException(); + targetException = ((InvocationTargetException) targetException).getTargetException(); } return targetException; } diff --git a/spring-binding/src/main/java/org/springframework/binding/method/MethodInvoker.java b/spring-binding/src/main/java/org/springframework/binding/method/MethodInvoker.java index 44832a6a..28e30520 100644 --- a/spring-binding/src/main/java/org/springframework/binding/method/MethodInvoker.java +++ b/spring-binding/src/main/java/org/springframework/binding/method/MethodInvoker.java @@ -26,9 +26,8 @@ import org.springframework.core.style.StylerUtils; import org.springframework.util.CachingMapDecorator; /** - * A helper for invoking typed methods on abritrary objects, with support for - * argument value type conversion from values retrieved from a argument - * attribute source. + * A helper for invoking typed methods on abritrary objects, with support for argument value type conversion from values + * retrieved from a argument attribute source. * * @author Keith Donald */ @@ -37,8 +36,7 @@ public class MethodInvoker { private static final Log logger = LogFactory.getLog(MethodInvoker.class); /** - * Conversion service for converting arguments to the neccessary type if - * required. + * Conversion service for converting arguments to the neccessary type if required. */ private ConversionService conversionService = new DefaultConversionService(); @@ -59,10 +57,8 @@ public class MethodInvoker { } /** - * Invoke the method on the bean provided. Argument values are pulled from - * the provided argument source. - * @param signature the definition of the method to invoke, including the - * method name and the method argument types + * Invoke the method on the bean provided. Argument values are pulled from the provided argument source. + * @param signature the definition of the method to invoke, including the method name and the method argument types * @param bean the bean to invoke * @param argumentSource the source for method arguments * @return the invoked method's return value @@ -99,11 +95,9 @@ public class MethodInvoker { logger.debug("Invoked method with signature [" + key + "] returned value [" + returnValue + "]"); } return returnValue; - } - catch (InvocationTargetException e) { + } catch (InvocationTargetException e) { throw new MethodInvocationException(signature, arguments, e.getTargetException()); - } - catch (Exception e) { + } catch (Exception e) { throw new MethodInvocationException(signature, arguments, e); } } diff --git a/spring-binding/src/main/java/org/springframework/binding/method/MethodKey.java b/spring-binding/src/main/java/org/springframework/binding/method/MethodKey.java index 29f6049e..b842f74a 100644 --- a/spring-binding/src/main/java/org/springframework/binding/method/MethodKey.java +++ b/spring-binding/src/main/java/org/springframework/binding/method/MethodKey.java @@ -42,9 +42,8 @@ public class MethodKey implements Serializable { private String methodName; /** - * The method's actual parameter types. Could contain null values - * if the user did not specify a parameter type for the corresponding - * parameter + * 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; @@ -57,8 +56,7 @@ public class MethodKey implements Serializable { * Create a new method key. * @param declaredType the class the method is a member of * @param methodName the method name - * @param parameterTypes the method's parameter types, or null - * if the method has no parameters + * @param parameterTypes the method's parameter types, or null if the method has no parameters */ public MethodKey(Class declaredType, String methodName, Class[] parameterTypes) { Assert.notNull(declaredType, "The method's declared type is required"); @@ -83,8 +81,8 @@ public class MethodKey implements Serializable { } /** - * Returns the method parameter types. Could contain null values - * if no type was specified for the corresponding parameter. + * Returns the method parameter types. Could contain null values if no type was specified for the corresponding + * parameter. */ public Class[] getParameterTypes() { return parameterTypes; @@ -108,13 +106,11 @@ public class MethodKey implements Serializable { protected Method resolveMethod() throws InvalidMethodKeyException { try { return declaredType.getMethod(methodName, parameterTypes); - } - catch (NoSuchMethodException e) { + } catch (NoSuchMethodException e) { Method method = findMethodConsiderAssignableParameterTypes(); if (method != null) { return method; - } - else { + } else { throw new InvalidMethodKeyException(this, e); } } @@ -140,8 +136,7 @@ public class MethodKey implements Serializable { if (isAssignable(candidateType, parameterType)) { numberOfCorrectArguments++; } - } - else { + } else { // just match on a null param type (effectively 'any') numberOfCorrectArguments++; } @@ -202,16 +197,14 @@ public class MethodKey implements Serializable { } /** - * Convenience method that returns the parameter types describing the - * signature of the method as a string. + * Convenience method that returns the parameter types describing the signature of the method as a string. */ private String parameterTypesString() { StringBuffer parameterTypesString = new StringBuffer(); for (int i = 0; i < parameterTypes.length; i++) { if (parameterTypes[i] == null) { parameterTypesString.append(""); - } - else { + } else { parameterTypesString.append(ClassUtils.getShortName(parameterTypes[i])); } if (i < parameterTypes.length - 1) { @@ -224,13 +217,12 @@ public class MethodKey implements Serializable { // internal helpers /** - * Determine if the given target type is assignable from the given value - * type, assuming setting by reflection. Considers primitive wrapper classes - * as assignable to the corresponding primitive types.

NOTE: Pulled from - * ClassUtils in Spring 2.0 for 1.2.8 compatability. + * Determine if the given target type is assignable from the given value type, assuming setting by reflection. + * Considers primitive wrapper classes as assignable to the corresponding primitive types. + *

+ * NOTE: Pulled from ClassUtils in Spring 2.0 for 1.2.8 compatability. * @param targetType the target type - * @param valueType the value type that should be assigned to the target - * type + * @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) { @@ -238,8 +230,8 @@ public class MethodKey implements Serializable { } /** - * Map with primitive wrapper type as key and corresponding primitive type - * as value, for example: Integer.class -> int.class. + * 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); diff --git a/spring-binding/src/main/java/org/springframework/binding/method/MethodSignature.java b/spring-binding/src/main/java/org/springframework/binding/method/MethodSignature.java index cade750e..3daeafdc 100644 --- a/spring-binding/src/main/java/org/springframework/binding/method/MethodSignature.java +++ b/spring-binding/src/main/java/org/springframework/binding/method/MethodSignature.java @@ -19,9 +19,8 @@ import org.springframework.core.style.ToStringCreator; 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 + * 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}. * * @author Keith Donald diff --git a/spring-binding/src/main/java/org/springframework/binding/method/Parameter.java b/spring-binding/src/main/java/org/springframework/binding/method/Parameter.java index e6f65798..45888eef 100644 --- a/spring-binding/src/main/java/org/springframework/binding/method/Parameter.java +++ b/spring-binding/src/main/java/org/springframework/binding/method/Parameter.java @@ -22,8 +22,7 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** - * A named method parameter. Each parameter has an identifying name and is of a - * specified type (class). + * A named method parameter. Each parameter has an identifying name and is of a specified type (class). * * @author Keith Donald */ @@ -35,14 +34,13 @@ public class Parameter { private Class type; /** - * The name of the parameter as an evaluatable expression, e.g - * "accountNumber". + * The name of the parameter as an evaluatable expression, e.g "accountNumber". */ private Expression name; /** - * Create a new named parameter definition. Named parameters are capable of resolving - * parameter values (arguments) from argument sources. + * Create a new named parameter definition. Named parameters are capable of resolving parameter values (arguments) + * from argument sources. * @param type the parameter type, may be null * @param name the name the method argument expression (required) */ @@ -53,8 +51,7 @@ public class Parameter { } /** - * Returns the parameter type. Could be null if no parameter type - * was specified. + * Returns the parameter type. Could be null if no parameter type was specified. */ public Class getType() { return type; @@ -68,8 +65,7 @@ public class Parameter { } /** - * Evaluate this method parameter against the provided argument source, - * returning a single method argument value. + * Evaluate this method parameter against the provided argument source, returning a single method argument value. * @param argumentSource the meyhod argument source * @param context the evaluation context * @return the method argument value diff --git a/spring-binding/src/main/java/org/springframework/binding/method/Parameters.java b/spring-binding/src/main/java/org/springframework/binding/method/Parameters.java index f900efd5..54bcca30 100644 --- a/spring-binding/src/main/java/org/springframework/binding/method/Parameters.java +++ b/spring-binding/src/main/java/org/springframework/binding/method/Parameters.java @@ -95,16 +95,15 @@ public class Parameters { } /** - * Get an array containing each parameter type. The resulting array - * could contain null values if the corresponding parameters did - * not specify a parameter type. + * Get an array containing each parameter type. The resulting array could contain null values if the corresponding + * parameters did not specify a parameter type. * @return the types */ public Class[] getTypesArray() { int i = 0; Class[] types = new Class[parameters.size()]; for (Iterator it = parameters.iterator(); it.hasNext();) { - Parameter param = (Parameter)it.next(); + Parameter param = (Parameter) it.next(); types[i] = param.getType(); i++; } @@ -126,14 +125,14 @@ 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 (Parameter) parameters.get(index); } public boolean equals(Object obj) { if (!(obj instanceof Parameters)) { return false; } - Parameters other = (Parameters)obj; + Parameters other = (Parameters) obj; return parameters.equals(other.parameters); } diff --git a/spring-binding/src/main/java/org/springframework/binding/method/TextToMethodSignature.java b/spring-binding/src/main/java/org/springframework/binding/method/TextToMethodSignature.java index b015918e..2cf85125 100644 --- a/spring-binding/src/main/java/org/springframework/binding/method/TextToMethodSignature.java +++ b/spring-binding/src/main/java/org/springframework/binding/method/TextToMethodSignature.java @@ -25,20 +25,17 @@ import org.springframework.binding.convert.support.ConversionServiceAwareConvert import org.springframework.binding.expression.Expression; /** - * Converter that takes an encoded string representation and produces a - * corresponding MethodSignature object. + * Converter that takes an encoded string representation and produces a corresponding MethodSignature + * object. *

* This converter supports the following encoded forms: *

* * @see MethodSignature @@ -71,14 +68,13 @@ public class TextToMethodSignature extends ConversionServiceAwareConverter { } protected Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception { - String encodedMethodSignature = (String)source; + String encodedMethodSignature = (String) source; encodedMethodSignature = encodedMethodSignature.trim(); int openParan = encodedMethodSignature.indexOf('('); if (openParan == -1) { // form "foo" return new MethodSignature(encodedMethodSignature); - } - else { + } else { // form "foo(...)" String methodName = encodedMethodSignature.substring(0, openParan); int closeParan = encodedMethodSignature.lastIndexOf(')'); @@ -94,13 +90,12 @@ public class TextToMethodSignature extends ConversionServiceAwareConverter { String param = paramArray[i].trim(); int space = param.indexOf(' '); int expr = param.indexOf('{'); - if (space == -1 || (expr != -1 && space > expr)) { + if (space == -1 || (expr != -1 && space > expr)) { // "name" or "${name}" params.add(new Parameter(null, parseExpression(param))); - } - else { + } else { // "type name" or "type ${name}" - Class type = (Class)fromStringTo(Class.class).execute(param.substring(0, space).trim()); + Class type = (Class) fromStringTo(Class.class).execute(param.substring(0, space).trim()); Expression name = parseExpression(param.substring(space + 1).trim()); params.add(new Parameter(type, name)); } @@ -108,31 +103,31 @@ public class TextToMethodSignature extends ConversionServiceAwareConverter { return new MethodSignature(methodName, params); } } - + /** * Split given parameter string into individual parameter definitions. */ private String[] splitParameters(String encodedMethodSignature, String parameters) { List res = new LinkedList(); - + int paramStart = 0; int blockNestingCount = 0; for (int i = 0; i < parameters.length(); i++) { switch (parameters.charAt(i)) { - case '{': - blockNestingCount++; - break; - case '}': - blockNestingCount--; - break; - case ',': - if (blockNestingCount == 0) { - // only take comma delimiter into account when not inside - // a block - res.add(parameters.substring(paramStart, i)); - paramStart = i + 1; - } - break; + case '{': + blockNestingCount++; + break; + case '}': + blockNestingCount--; + break; + case ',': + if (blockNestingCount == 0) { + // only take comma delimiter into account when not inside + // a block + res.add(parameters.substring(paramStart, i)); + paramStart = i + 1; + } + break; } } if (blockNestingCount != 0) { @@ -142,7 +137,7 @@ public class TextToMethodSignature extends ConversionServiceAwareConverter { if (paramStart < parameters.length()) { res.add(parameters.substring(paramStart)); } - - return (String[])res.toArray(new String[res.size()]); + + return (String[]) res.toArray(new String[res.size()]); } } \ No newline at end of file diff --git a/spring-binding/src/test/java/org/springframework/binding/collection/CompositeIteratorTests.java b/spring-binding/src/test/java/org/springframework/binding/collection/CompositeIteratorTests.java index cc730dc5..cc87e6eb 100644 --- a/spring-binding/src/test/java/org/springframework/binding/collection/CompositeIteratorTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/collection/CompositeIteratorTests.java @@ -28,19 +28,18 @@ import junit.framework.TestCase; * @author Erwin Vervaet */ public class CompositeIteratorTests extends TestCase { - + public void testNoIterators() { CompositeIterator it = new CompositeIterator(); assertFalse(it.hasNext()); try { it.next(); fail(); - } - catch (NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } } - + public void testSingleIterator() { CompositeIterator it = new CompositeIterator(); it.add(Arrays.asList(new String[] { "0", "1" }).iterator()); @@ -52,12 +51,11 @@ public class CompositeIteratorTests extends TestCase { try { it.next(); fail(); - } - catch (NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } } - + public void testMultipleIterators() { CompositeIterator it = new CompositeIterator(); it.add(Arrays.asList(new String[] { "0", "1" }).iterator()); @@ -71,12 +69,11 @@ public class CompositeIteratorTests extends TestCase { try { it.next(); fail(); - } - catch (NoSuchElementException e) { + } catch (NoSuchElementException e) { // expected } } - + public void testInUse() { List list = Arrays.asList(new String[] { "0", "1" }); CompositeIterator it = new CompositeIterator(); @@ -85,8 +82,7 @@ public class CompositeIteratorTests extends TestCase { try { it.add(list.iterator()); fail(); - } - catch (IllegalStateException e) { + } catch (IllegalStateException e) { // expected } it = new CompositeIterator(); @@ -95,12 +91,11 @@ public class CompositeIteratorTests extends TestCase { try { it.add(list.iterator()); fail(); - } - catch (IllegalStateException e) { + } catch (IllegalStateException e) { // expected } } - + public void testDuplicateIterators() { List list = Arrays.asList(new String[] { "0", "1" }); Iterator iterator = list.iterator(); @@ -110,8 +105,7 @@ public class CompositeIteratorTests extends TestCase { try { it.add(iterator); fail(); - } - catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { // expected } } diff --git a/spring-binding/src/test/java/org/springframework/binding/convert/ConversionExecutorTests.java b/spring-binding/src/test/java/org/springframework/binding/convert/ConversionExecutorTests.java index f6bfc89f..6d5e5fe4 100644 --- a/spring-binding/src/test/java/org/springframework/binding/convert/ConversionExecutorTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/convert/ConversionExecutorTests.java @@ -25,42 +25,41 @@ import org.springframework.binding.convert.support.AbstractConverter; * Test case for {@link ConversionExecutor}. */ public class ConversionExecutorTests extends TestCase { - + private ConversionExecutor conversionExecutor; - + protected void setUp() throws Exception { conversionExecutor = new ConversionExecutor(String.class, Date.class, new TestTextToDate()); } - + public void testTypeConversion() { assertTrue(conversionExecutor.execute("10-10-2008").getClass().equals(Date.class)); } - + public void testAssignmentCompatibleTypeConversion() { java.sql.Date date = new java.sql.Date(123L); assertSame(date, conversionExecutor.execute(date)); } - + public void testConvertNull() { assertNull(conversionExecutor.execute(null)); } - + public void testIllegalType() { try { conversionExecutor.execute(new StringBuffer()); fail(); - } - catch (ConversionException e) { + } catch (ConversionException e) { // expected } } private class TestTextToDate extends AbstractConverter { - + public Class[] getSourceClasses() { return new Class[] { String.class }; } - + public Class[] getTargetClasses() { return new Class[] { Date.class }; } diff --git a/spring-binding/src/test/java/org/springframework/binding/convert/support/CompositeConversionServiceTests.java b/spring-binding/src/test/java/org/springframework/binding/convert/support/CompositeConversionServiceTests.java index 74c514ea..12b8cd64 100644 --- a/spring-binding/src/test/java/org/springframework/binding/convert/support/CompositeConversionServiceTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/convert/support/CompositeConversionServiceTests.java @@ -25,13 +25,13 @@ import org.springframework.binding.convert.ConversionService; /** * Test case for the {@link CompositeConversionService}. - * + * * @author Erwin Vervaet */ public class CompositeConversionServiceTests extends TestCase { - + private CompositeConversionService service; - + protected void setUp() throws Exception { GenericConversionService first = new GenericConversionService(); first.addConverter(new TextToClass()); @@ -52,24 +52,21 @@ public class CompositeConversionServiceTests extends TestCase { try { service.getConversionExecutor(String.class, Date.class); fail(); - } - catch (ConversionException e) { + } catch (ConversionException e) { // expected } } - + public void testGetConversionExecutorByTargetAlias() { assertNotNull(service.getConversionExecutorByTargetAlias(String.class, "boolean")); assertEquals(Boolean.TRUE, service.getConversionExecutorByTargetAlias(String.class, "boolean").execute("ja")); assertNotNull(service.getConversionExecutorByTargetAlias(String.class, "integer")); assertNull(service.getConversionExecutorByTargetAlias(String.class, "class")); } - + public void testGetConversionExecutorsForSource() { - assertEquals( - new TextToClass().getTargetClasses().length + - new TextToBoolean().getTargetClasses().length + - new TextToNumber().getTargetClasses().length, + assertEquals(new TextToClass().getTargetClasses().length + new TextToBoolean().getTargetClasses().length + + new TextToNumber().getTargetClasses().length, service.getConversionExecutorsForSource(String.class).length); assertEquals(0, service.getConversionExecutorsForSource(Date.class).length); ConversionExecutor[] fromStringConversionExecutors = service.getConversionExecutorsForSource(String.class); @@ -81,7 +78,7 @@ public class CompositeConversionServiceTests extends TestCase { } assertEquals(Boolean.TRUE, booleanConversionExecutor.execute("ja")); } - + public void testGetClassByAlias() { assertEquals(Boolean.class, service.getClassByAlias("boolean")); assertEquals(Integer.class, service.getClassByAlias("integer")); diff --git a/spring-binding/src/test/java/org/springframework/binding/convert/support/DefaultConversionServiceTests.java b/spring-binding/src/test/java/org/springframework/binding/convert/support/DefaultConversionServiceTests.java index d74da8bf..e07b2876 100644 --- a/spring-binding/src/test/java/org/springframework/binding/convert/support/DefaultConversionServiceTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/convert/support/DefaultConversionServiceTests.java @@ -32,7 +32,7 @@ import org.springframework.core.enums.ShortCodedLabeledEnum; * @author Keith Donald */ public class DefaultConversionServiceTests extends TestCase { - + public void testConvertCompatibleTypes() { DefaultConversionService service = new DefaultConversionService(); service.addAlias("list", List.class); @@ -40,36 +40,34 @@ public class DefaultConversionServiceTests extends TestCase { List lst = new ArrayList(); assertSame(lst, service.getConversionExecutor(ArrayList.class, List.class).execute(lst)); assertSame(lst, service.getConversionExecutorByTargetAlias(ArrayList.class, "list").execute(lst)); - + try { service.getConversionExecutor(List.class, ArrayList.class); fail(); - } - catch (ConversionException e) { + } catch (ConversionException e) { // expected } } - + public void testOverrideConverter() { Converter customConverter = new TextToBoolean("ja", "nee"); - + DefaultConversionService service = new DefaultConversionService(); - + ConversionExecutor executor = service.getConversionExecutor(String.class, Boolean.class); assertNotSame(customConverter, executor.getConverter()); try { executor.execute("ja"); fail(); - } - catch (ConversionException e) { + } catch (ConversionException e) { // expected } - + service.addConverter(customConverter); - + executor = service.getConversionExecutor(String.class, Boolean.class); assertSame(customConverter, executor.getConverter()); - assertTrue(((Boolean)executor.execute("ja")).booleanValue()); + assertTrue(((Boolean) executor.execute("ja")).booleanValue()); } public void testTargetClassNotSupported() { @@ -77,15 +75,14 @@ public class DefaultConversionServiceTests extends TestCase { try { service.getConversionExecutor(String.class, HashMap.class); fail("Should have thrown an exception"); - } - catch (ConversionException e) { + } catch (ConversionException e) { } } public void testValidConversion() { DefaultConversionService service = new DefaultConversionService(); ConversionExecutor executor = service.getConversionExecutor(String.class, Integer.class); - Integer three = (Integer)executor.execute("3"); + Integer three = (Integer) executor.execute("3"); assertEquals(3, three.intValue()); } @@ -95,15 +92,14 @@ public class DefaultConversionServiceTests extends TestCase { try { executor.execute("My Invalid Label"); fail("Should have failed"); - } - catch (ConversionException e) { + } catch (ConversionException e) { } } public void testValidLabeledEnumConversion() { DefaultConversionService service = new DefaultConversionService(); ConversionExecutor executor = service.getConversionExecutor(String.class, MyEnum.class); - MyEnum myEnum = (MyEnum)executor.execute("My Label 1"); + MyEnum myEnum = (MyEnum) executor.execute("My Label 1"); assertEquals(MyEnum.ONE, myEnum); } diff --git a/spring-binding/src/test/java/org/springframework/binding/expression/el/ELExpressionParserTests.java b/spring-binding/src/test/java/org/springframework/binding/expression/el/ELExpressionParserTests.java index a553c7c7..05aa44be 100644 --- a/spring-binding/src/test/java/org/springframework/binding/expression/el/ELExpressionParserTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/expression/el/ELExpressionParserTests.java @@ -17,86 +17,86 @@ import org.springframework.binding.expression.support.TestMethods; */ public class ELExpressionParserTests extends TestCase { - ELExpressionParser parser = new ELExpressionParser(new ExpressionFactoryImpl()); + ELExpressionParser parser = new ELExpressionParser(new ExpressionFactoryImpl()); - Map context; + Map context; - Map container; + Map container; - TestMethods target; + TestMethods target; - protected void setUp() throws Exception { - context = new HashMap(); - container = new HashMap(); - target = (TestMethods) EasyMock.createMock(TestMethods.class); - context.put("container", container); - container.put("myObject", target); - } + protected void setUp() throws Exception { + context = new HashMap(); + container = new HashMap(); + target = (TestMethods) EasyMock.createMock(TestMethods.class); + context.put("container", container); + container.put("myObject", target); + } - public void testWithIntParam() { - String expression = "#{container.myObject.doSomethingWithInt(container.param1)}"; - int param = 5; - container.put("param1", new Integer(param)); - target.doSomethingWithInt(param); - EasyMock.replay(new Object[] { target }); + public void testWithIntParam() { + String expression = "#{container.myObject.doSomethingWithInt(container.param1)}"; + int param = 5; + container.put("param1", new Integer(param)); + target.doSomethingWithInt(param); + EasyMock.replay(new Object[] { target }); - parser.parseExpression(expression).evaluate(context, null); - EasyMock.verify(new Object[] { target }); + parser.parseExpression(expression).evaluate(context, null); + EasyMock.verify(new Object[] { target }); - } + } - public void testReturnWithIntParam() { - String expected = "sucess"; - String expression = "#{container.myObject.returnStringFromInt(container.param1)}"; - int param = 5; - container.put("param1", new Integer(param)); - EasyMock.expect(target.returnStringFromInt(param)).andReturn(expected); - EasyMock.replay(new Object[] { target }); + public void testReturnWithIntParam() { + String expected = "sucess"; + String expression = "#{container.myObject.returnStringFromInt(container.param1)}"; + int param = 5; + container.put("param1", new Integer(param)); + EasyMock.expect(target.returnStringFromInt(param)).andReturn(expected); + EasyMock.replay(new Object[] { target }); - String result = (String) parser.parseExpression(expression).evaluate(context, null); - EasyMock.verify(new Object[] { target }); - assertEquals(expected, result); - } + String result = (String) parser.parseExpression(expression).evaluate(context, null); + EasyMock.verify(new Object[] { target }); + assertEquals(expected, result); + } - public void testReturnWithIntAndObject() { - String expected = "success"; - String expression = "#{container.myObject.returnStringFromIntAndObject(container.param1, container.param2)}"; - int param1 = 5; - container.put("param1", new Integer(param1)); - TestBean param2 = new TestBean(); - container.put("param2", param2); - EasyMock.expect(target.returnStringFromIntAndObject(param1, param2)).andReturn(expected); - EasyMock.replay(new Object[] { target }); + public void testReturnWithIntAndObject() { + String expected = "success"; + String expression = "#{container.myObject.returnStringFromIntAndObject(container.param1, container.param2)}"; + int param1 = 5; + container.put("param1", new Integer(param1)); + TestBean param2 = new TestBean(); + container.put("param2", param2); + EasyMock.expect(target.returnStringFromIntAndObject(param1, param2)).andReturn(expected); + EasyMock.replay(new Object[] { target }); - String result = (String) parser.parseExpression(expression).evaluate(context, null); - EasyMock.verify(new Object[] { target }); - assertEquals(expected, result); - } + String result = (String) parser.parseExpression(expression).evaluate(context, null); + EasyMock.verify(new Object[] { target }); + assertEquals(expected, result); + } - public void testEmptyMethod() { + public void testEmptyMethod() { - String expStr1 = "#{foo.bar()}"; - Expression result1 = parser.parseExpression(expStr1); - assertNotNull(result1); - assertEquals(expStr1, result1.toString()); + String expStr1 = "#{foo.bar()}"; + Expression result1 = parser.parseExpression(expStr1); + assertNotNull(result1); + assertEquals(expStr1, result1.toString()); - String expStr2 = "foo.bar()"; - Expression result2 = parser.parseExpression(expStr2); - assertNotNull(result2); - assertEquals(expStr1, result2.toString()); - } + String expStr2 = "foo.bar()"; + Expression result2 = parser.parseExpression(expStr2); + assertNotNull(result2); + assertEquals(expStr1, result2.toString()); + } - public void testMethodWithParams() { + public void testMethodWithParams() { - String expStr1 = "#{foo.bar(moe.curly, groucho.harpo)}"; - Expression result1 = parser.parseExpression(expStr1); - assertNotNull(result1); - assertEquals(expStr1, result1.toString()); + String expStr1 = "#{foo.bar(moe.curly, groucho.harpo)}"; + Expression result1 = parser.parseExpression(expStr1); + assertNotNull(result1); + assertEquals(expStr1, result1.toString()); - String expStr2 = "foo.bar(moe.curly, groucho.harpo)"; - Expression result2 = parser.parseExpression(expStr2); - assertNotNull(result2); - assertEquals(expStr1, result2.toString()); - } + String expStr2 = "foo.bar(moe.curly, groucho.harpo)"; + Expression result2 = parser.parseExpression(expStr2); + assertNotNull(result2); + assertEquals(expStr1, result2.toString()); + } } diff --git a/spring-binding/src/test/java/org/springframework/binding/expression/ognl/OgnlExpressionParserTests.java b/spring-binding/src/test/java/org/springframework/binding/expression/ognl/OgnlExpressionParserTests.java index 24667a00..92d104a5 100644 --- a/spring-binding/src/test/java/org/springframework/binding/expression/ognl/OgnlExpressionParserTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/expression/ognl/OgnlExpressionParserTests.java @@ -30,29 +30,29 @@ public class OgnlExpressionParserTests extends TestCase { private OgnlExpressionParser parser = new OgnlExpressionParser(); private TestBean bean = new TestBean(); - + public void testParseSimpleDelimited() { String exp = "${flag}"; Expression e = parser.parseExpression(exp); assertNotNull(e); - Boolean b = (Boolean)e.evaluate(bean, null); + Boolean b = (Boolean) e.evaluate(bean, null); assertFalse(b.booleanValue()); } - + public void testParseSimple() { String exp = "flag"; Expression e = parser.parseExpression(exp); assertNotNull(e); - Boolean b = (Boolean)e.evaluate(bean, null); + Boolean b = (Boolean) e.evaluate(bean, null); assertFalse(b.booleanValue()); } - + public void testParseNull() { Expression e = parser.parseExpression(null); assertNotNull(e); assertNull(e.evaluate(bean, null)); } - + public void testParseEmpty() { Expression e = parser.parseExpression(""); assertNotNull(e); @@ -63,7 +63,7 @@ public class OgnlExpressionParserTests extends TestCase { String exp = "hello ${flag} ${flag} ${flag}"; Expression e = parser.parseExpression(exp); assertNotNull(e); - String str = (String)e.evaluate(bean, null); + String str = (String) e.evaluate(bean, null); assertEquals("hello false false false", str); } @@ -72,8 +72,7 @@ public class OgnlExpressionParserTests extends TestCase { try { parser.parseExpression(exp); fail("Should've failed - not intended use"); - } - catch (ParserException e) { + } catch (ParserException e) { } } @@ -81,58 +80,54 @@ public class OgnlExpressionParserTests extends TestCase { try { parser.parseExpression("${"); fail(); - } - catch (ParserException e) { + } catch (ParserException e) { } try { String exp = "hello ${flag} ${abcd defg"; parser.parseExpression(exp); fail("Should've failed - not intended use"); - } - catch (ParserException e) { + } catch (ParserException e) { } } - + public void testSyntaxError2() { try { parser.parseExpression("${}"); fail("Should've failed - not intended use"); - } - catch (ParserException e) { + } catch (ParserException e) { } try { String exp = "hello ${flag} ${}"; parser.parseExpression(exp); fail("Should've failed - not intended use"); - } - catch (ParserException e) { + } catch (ParserException e) { } } - + public void testIsDelimitedExpression() { assertTrue(parser.isDelimitedExpression("${foo}")); assertTrue(parser.isDelimitedExpression("${foo ${foo}}")); assertTrue(parser.isDelimitedExpression("foo ${bar}")); } - + public void testIsNotDelimitedExpression() { assertFalse(parser.isDelimitedExpression("foo")); assertFalse(parser.isDelimitedExpression("foo ${")); assertFalse(parser.isDelimitedExpression("$foo}")); assertFalse(parser.isDelimitedExpression("foo ${}")); } - + public void testCollectionContructionSyntax() { // lists parser.parseExpression("name in {null, \"Untitled\"}"); parser.parseExpression("${name in {null, \"Untitled\"}}"); - + // native arrays parser.parseExpression("new int[] {1, 2, 3}"); parser.parseExpression("${new int[] {1, 2, 3}}"); - + // maps parser.parseExpression("#{ 'foo' : 'foo value', 'bar' : 'bar value' }"); parser.parseExpression("${#{ 'foo' : 'foo value', 'bar' : 'bar value' }}"); diff --git a/spring-binding/src/test/java/org/springframework/binding/expression/support/CollectionAddingExpressionTests.java b/spring-binding/src/test/java/org/springframework/binding/expression/support/CollectionAddingExpressionTests.java index e9a342fe..5cf232bd 100644 --- a/spring-binding/src/test/java/org/springframework/binding/expression/support/CollectionAddingExpressionTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/expression/support/CollectionAddingExpressionTests.java @@ -47,18 +47,17 @@ public class CollectionAddingExpressionTests extends TestCase { assertEquals("1", bean.getList().get(0)); assertEquals("2", bean.getList().get(1)); } - + public void testNotACollection() { - Expression exp = parser.parseExpression("flag"); + Expression exp = parser.parseExpression("flag"); CollectionAddingExpression colExp = new CollectionAddingExpression(exp); try { colExp.evaluateToSet(bean, "1", null); fail("not a collection"); - } - catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { } } - + public void testNoAddOnNullValue() { CollectionAddingExpression colExp = new CollectionAddingExpression(exp); colExp.evaluateToSet(bean, null, null); diff --git a/spring-binding/src/test/java/org/springframework/binding/expression/support/SimpleExpressionTests.java b/spring-binding/src/test/java/org/springframework/binding/expression/support/SimpleExpressionTests.java index 42326566..e664678b 100644 --- a/spring-binding/src/test/java/org/springframework/binding/expression/support/SimpleExpressionTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/expression/support/SimpleExpressionTests.java @@ -37,68 +37,68 @@ import junit.framework.TestSuite; */ public class SimpleExpressionTests extends TestCase { - private ExpressionParser expressionParser; - private String expressionPrefix; - private TestBean bean; + private ExpressionParser expressionParser; + private String expressionPrefix; + private TestBean bean; - public static TestSuite suite() { - TestSuite suite = new TestSuite(); - suite.addTest(new SimpleExpressionTests("testGetValue", new OgnlExpressionParser(), "$")); - suite.addTest(new SimpleExpressionTests("testSetValue", new OgnlExpressionParser(), "$")); - suite.addTest(new SimpleExpressionTests("testSyntaxError", new OgnlExpressionParser(), "$")); - suite.addTest(new SimpleExpressionTests("testGetValue", new BeanWrapperExpressionParser(), "$")); - suite.addTest(new SimpleExpressionTests("testSetValue", new BeanWrapperExpressionParser(), "$")); - suite.addTest(new SimpleExpressionTests("testSyntaxError", new BeanWrapperExpressionParser(), "$")); - suite.addTest(new SimpleExpressionTests("testGetValue", new ELExpressionParser(new ExpressionFactoryImpl()), - "#")); - suite.addTest(new SimpleExpressionTests("testSetValue", new ELExpressionParser(new ExpressionFactoryImpl()), - "#")); - suite.addTest(new SimpleExpressionTests("testSyntaxError", new ELExpressionParser(new ExpressionFactoryImpl()), - "#")); - return suite; - } - - public SimpleExpressionTests(String name, ExpressionParser expressionParser, String expressionPrefix) { - super(name); - this.expressionParser = expressionParser; - this.expressionPrefix = expressionPrefix; - } - - protected void setUp() throws Exception { - bean = new TestBean(); - bean.setFlag(true); - List list = new ArrayList(); - list.add("foo"); - list.add("bar"); - bean.setList(list); - } - - public void testGetValue() { - assertEquals(Boolean.TRUE, expressionParser.parseExpression(expressionPrefix + "{flag}").evaluate(bean, null)); - assertEquals(Boolean.TRUE, expressionParser.parseExpression("flag").evaluate(bean, null)); - assertSame(bean.getList(), expressionParser.parseExpression(expressionPrefix + "{list}").evaluate(bean, null)); - assertEquals("foo", expressionParser.parseExpression(expressionPrefix + "{list[0]}").evaluate(bean, null)); - } - - public void testSetValue() { - expressionParser.parseSettableExpression(expressionPrefix + "{flag}").evaluateToSet(bean, Boolean.FALSE, null); - assertFalse(bean.isFlag()); - expressionParser.parseSettableExpression("flag").evaluateToSet(bean, Boolean.TRUE, null); - assertTrue(bean.isFlag()); - List newList = new ArrayList(); - newList.add("boo"); - expressionParser.parseSettableExpression(expressionPrefix + "{list}").evaluateToSet(bean, newList, null); - assertSame(newList, bean.getList()); - expressionParser.parseSettableExpression(expressionPrefix + "{list[0]}").evaluateToSet(bean, "baa", null); - assertEquals("baa", bean.getList().get(0)); - } - - public void testSyntaxError() { - try { - expressionParser.parseExpression("foo(").evaluate(bean, null); - fail("should have failed"); - } catch (ParserException e) { - } catch (EvaluationException e) { + public static TestSuite suite() { + TestSuite suite = new TestSuite(); + suite.addTest(new SimpleExpressionTests("testGetValue", new OgnlExpressionParser(), "$")); + suite.addTest(new SimpleExpressionTests("testSetValue", new OgnlExpressionParser(), "$")); + suite.addTest(new SimpleExpressionTests("testSyntaxError", new OgnlExpressionParser(), "$")); + suite.addTest(new SimpleExpressionTests("testGetValue", new BeanWrapperExpressionParser(), "$")); + suite.addTest(new SimpleExpressionTests("testSetValue", new BeanWrapperExpressionParser(), "$")); + suite.addTest(new SimpleExpressionTests("testSyntaxError", new BeanWrapperExpressionParser(), "$")); + suite.addTest(new SimpleExpressionTests("testGetValue", new ELExpressionParser(new ExpressionFactoryImpl()), + "#")); + suite.addTest(new SimpleExpressionTests("testSetValue", new ELExpressionParser(new ExpressionFactoryImpl()), + "#")); + suite.addTest(new SimpleExpressionTests("testSyntaxError", new ELExpressionParser(new ExpressionFactoryImpl()), + "#")); + return suite; + } + + public SimpleExpressionTests(String name, ExpressionParser expressionParser, String expressionPrefix) { + super(name); + this.expressionParser = expressionParser; + this.expressionPrefix = expressionPrefix; + } + + protected void setUp() throws Exception { + bean = new TestBean(); + bean.setFlag(true); + List list = new ArrayList(); + list.add("foo"); + list.add("bar"); + bean.setList(list); + } + + public void testGetValue() { + assertEquals(Boolean.TRUE, expressionParser.parseExpression(expressionPrefix + "{flag}").evaluate(bean, null)); + assertEquals(Boolean.TRUE, expressionParser.parseExpression("flag").evaluate(bean, null)); + assertSame(bean.getList(), expressionParser.parseExpression(expressionPrefix + "{list}").evaluate(bean, null)); + assertEquals("foo", expressionParser.parseExpression(expressionPrefix + "{list[0]}").evaluate(bean, null)); + } + + public void testSetValue() { + expressionParser.parseSettableExpression(expressionPrefix + "{flag}").evaluateToSet(bean, Boolean.FALSE, null); + assertFalse(bean.isFlag()); + expressionParser.parseSettableExpression("flag").evaluateToSet(bean, Boolean.TRUE, null); + assertTrue(bean.isFlag()); + List newList = new ArrayList(); + newList.add("boo"); + expressionParser.parseSettableExpression(expressionPrefix + "{list}").evaluateToSet(bean, newList, null); + assertSame(newList, bean.getList()); + expressionParser.parseSettableExpression(expressionPrefix + "{list[0]}").evaluateToSet(bean, "baa", null); + assertEquals("baa", bean.getList().get(0)); + } + + public void testSyntaxError() { + try { + expressionParser.parseExpression("foo(").evaluate(bean, null); + fail("should have failed"); + } catch (ParserException e) { + } catch (EvaluationException e) { + } } - } } diff --git a/spring-binding/src/test/java/org/springframework/binding/expression/support/TestBean.java b/spring-binding/src/test/java/org/springframework/binding/expression/support/TestBean.java index c28f43cb..e8f97636 100644 --- a/spring-binding/src/test/java/org/springframework/binding/expression/support/TestBean.java +++ b/spring-binding/src/test/java/org/springframework/binding/expression/support/TestBean.java @@ -19,11 +19,11 @@ import java.util.ArrayList; import java.util.List; public class TestBean { - + private boolean flag; private List list = new ArrayList(); - + public boolean isFlag() { return flag; } @@ -35,7 +35,7 @@ public class TestBean { public List getList() { return list; } - + public void setList(List list) { this.list = list; } diff --git a/spring-binding/src/test/java/org/springframework/binding/expression/support/TestMethods.java b/spring-binding/src/test/java/org/springframework/binding/expression/support/TestMethods.java index 45f75b0f..478e6080 100644 --- a/spring-binding/src/test/java/org/springframework/binding/expression/support/TestMethods.java +++ b/spring-binding/src/test/java/org/springframework/binding/expression/support/TestMethods.java @@ -3,8 +3,8 @@ package org.springframework.binding.expression.support; public interface TestMethods { public void doSomethingWithInt(int arg); - + public String returnStringFromInt(int arg); - + public String returnStringFromIntAndObject(int arg, TestBean bean); } diff --git a/spring-binding/src/test/java/org/springframework/binding/format/support/NumberFormatterTests.java b/spring-binding/src/test/java/org/springframework/binding/format/support/NumberFormatterTests.java index 213199e7..51feb701 100644 --- a/spring-binding/src/test/java/org/springframework/binding/format/support/NumberFormatterTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/format/support/NumberFormatterTests.java @@ -29,18 +29,18 @@ import junit.framework.TestCase; * @author Erwin Vervaet */ public class NumberFormatterTests extends TestCase { - + private Locale systemDefaultLocale; - + protected void setUp() throws Exception { systemDefaultLocale = Locale.getDefault(); } - + protected void tearDown() throws Exception { // restore default Locale.setDefault(systemDefaultLocale); } - + public void testParseUsBigDecimalInUs() { Locale.setDefault(Locale.US); SimpleFormatterFactory formatterFactory = new SimpleFormatterFactory(); @@ -56,7 +56,7 @@ public class NumberFormatterTests extends TestCase { Formatter formatter = formatterFactory.getNumberFormatter(BigDecimal.class); assertEquals(new BigDecimal("123.45"), formatter.parseValue("123.45", BigDecimal.class)); } - + public void testParseGermanBigDecimalInGermany() { Locale.setDefault(Locale.GERMANY); SimpleFormatterFactory formatterFactory = new SimpleFormatterFactory(); diff --git a/spring-binding/src/test/java/org/springframework/binding/mapping/RequiredMappingTests.java b/spring-binding/src/test/java/org/springframework/binding/mapping/RequiredMappingTests.java index 243d544b..5d3cb573 100644 --- a/spring-binding/src/test/java/org/springframework/binding/mapping/RequiredMappingTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/mapping/RequiredMappingTests.java @@ -25,7 +25,7 @@ import org.springframework.binding.expression.ognl.OgnlExpressionParser; * Unit tests for the {@link org.springframework.binding.mapping.RequiredMapping}. */ public class RequiredMappingTests extends TestCase { - + public void testRequired() { MappingBuilder builder = new MappingBuilder(new OgnlExpressionParser()); Mapping mapping = builder.source("foo").target("bar").required().value(); @@ -35,7 +35,7 @@ public class RequiredMappingTests extends TestCase { mapping.map(source, target, null); assertEquals("baz", target.get("bar")); } - + public void testRequiredExceptionOnNull() { MappingBuilder builder = new MappingBuilder(new OgnlExpressionParser()); Mapping mapping = builder.source("foo").target("bar").required().value(); @@ -44,8 +44,7 @@ public class RequiredMappingTests extends TestCase { HashMap target = new HashMap(); try { mapping.map(source, target, null); - } - catch (RequiredMappingException e) { + } catch (RequiredMappingException e) { } } @@ -56,8 +55,7 @@ public class RequiredMappingTests extends TestCase { HashMap target = new HashMap(); try { mapping.map(source, target, null); - } - catch (RequiredMappingException e) { + } catch (RequiredMappingException e) { } } diff --git a/spring-binding/src/test/java/org/springframework/binding/method/MethodInvocationExceptionTests.java b/spring-binding/src/test/java/org/springframework/binding/method/MethodInvocationExceptionTests.java index 87d9c7ef..8d53dd95 100644 --- a/spring-binding/src/test/java/org/springframework/binding/method/MethodInvocationExceptionTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/method/MethodInvocationExceptionTests.java @@ -32,7 +32,7 @@ public class MethodInvocationExceptionTests extends TestCase { IllegalArgumentException iae = new IllegalArgumentException("test"); MethodInvocationException ex = testException(iae); assertSame(iae, ex.getTargetException()); - + // exception IOException ioe = new IOException("test"); ex = testException(ioe); @@ -42,15 +42,15 @@ public class MethodInvocationExceptionTests extends TestCase { InvocationTargetException ite = new InvocationTargetException(ioe); ex = testException(ite); assertSame(ioe, ex.getTargetException()); - + // deep nesting ite = new InvocationTargetException(new InvocationTargetException(ioe)); ex = testException(ite); assertSame(ioe, ex.getTargetException()); } - + // internal helpers - + private MethodInvocationException testException(Throwable cause) { return new MethodInvocationException(new MethodSignature("test"), null, cause); } diff --git a/spring-binding/src/test/java/org/springframework/binding/method/MethodInvokerTests.java b/spring-binding/src/test/java/org/springframework/binding/method/MethodInvokerTests.java index 6cfde2d0..ebb97ecd 100644 --- a/spring-binding/src/test/java/org/springframework/binding/method/MethodInvokerTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/method/MethodInvokerTests.java @@ -36,8 +36,7 @@ public class MethodInvokerTests extends TestCase { try { methodInvoker.invoke(new MethodSignature("test"), new TestObject(), null); fail(); - } - catch (MethodInvocationException e) { + } catch (MethodInvocationException e) { assertTrue(e.getTargetException() instanceof IllegalArgumentException); assertEquals("just testing", e.getTargetException().getMessage()); } @@ -47,8 +46,7 @@ public class MethodInvokerTests extends TestCase { try { methodInvoker.invoke(new MethodSignature("bogus"), new TestObject(), null); fail(); - } - catch (MethodInvocationException e) { + } catch (MethodInvocationException e) { assertTrue(e.getTargetException() instanceof InvalidMethodKeyException); } } diff --git a/spring-binding/src/test/java/org/springframework/binding/method/MethodKeyTests.java b/spring-binding/src/test/java/org/springframework/binding/method/MethodKeyTests.java index b96ae7da..a75c6e96 100644 --- a/spring-binding/src/test/java/org/springframework/binding/method/MethodKeyTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/method/MethodKeyTests.java @@ -31,7 +31,7 @@ public class MethodKeyTests extends TestCase { private static final Method LIST_FILENAME_FILTER = safeGetMethod(File.class, "list", new Class[] { FilenameFilter.class }); - + public void testGetMethodWithNoArgs() throws Exception { MethodKey key = new MethodKey(File.class, "list", new Class[0]); Method m = key.getMethod(); @@ -62,8 +62,7 @@ public class MethodKeyTests extends TestCase { private static final Method safeGetMethod(Class type, String name, Class[] argTypes) { try { return type.getMethod(name, argTypes); - } - catch (NoSuchMethodException e) { + } catch (NoSuchMethodException e) { throw new IllegalStateException("Unable to safely access a known method via reflection. " + e.getMessage()); } } diff --git a/spring-binding/src/test/java/org/springframework/binding/method/TextToMethodSignatureTests.java b/spring-binding/src/test/java/org/springframework/binding/method/TextToMethodSignatureTests.java index fbda9507..577a9c6e 100644 --- a/spring-binding/src/test/java/org/springframework/binding/method/TextToMethodSignatureTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/method/TextToMethodSignatureTests.java @@ -28,9 +28,9 @@ import org.springframework.binding.expression.ognl.OgnlExpressionParser; * @author Erwin Vervaet */ public class TextToMethodSignatureTests extends TestCase { - + private TextToMethodSignature converter; - + protected void setUp() throws Exception { DefaultConversionService conversionService = new DefaultConversionService(); conversionService.addConverter(new TextToExpression(new OgnlExpressionParser())); @@ -38,102 +38,101 @@ public class TextToMethodSignatureTests extends TestCase { } public void testParseNoArguments() { - MethodSignature signature = (MethodSignature)converter.convert("foo"); + MethodSignature signature = (MethodSignature) converter.convert("foo"); assertEquals("foo", signature.getMethodName()); assertEquals(0, signature.getParameters().size()); - - signature = (MethodSignature)converter.convert("foo()"); + + signature = (MethodSignature) converter.convert("foo()"); assertEquals("foo", signature.getMethodName()); assertEquals(0, signature.getParameters().size()); } - + public void testSingleArgument() { - MethodSignature signature = (MethodSignature)converter.convert("foo(${flowScope.bar})"); + MethodSignature signature = (MethodSignature) converter.convert("foo(${flowScope.bar})"); assertEquals("foo", signature.getMethodName()); assertEquals(1, signature.getParameters().size()); assertNull(signature.getParameters().getParameter(0).getType()); assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString()); - - signature = (MethodSignature)converter.convert("foo(${'Foo' + flowScope.bar})"); + + signature = (MethodSignature) converter.convert("foo(${'Foo' + flowScope.bar})"); assertEquals("foo", signature.getMethodName()); assertEquals(1, signature.getParameters().size()); assertEquals("\"Foo\" + flowScope.bar", signature.getParameters().getParameter(0).getName().toString()); } - + public void testSingleArgumentWithType() { - MethodSignature signature = (MethodSignature)converter.convert("foo(java.lang.String ${flowScope.bar})"); + MethodSignature signature = (MethodSignature) converter.convert("foo(java.lang.String ${flowScope.bar})"); assertEquals("foo", signature.getMethodName()); assertEquals(1, signature.getParameters().size()); assertEquals(String.class, signature.getParameters().getParameter(0).getType()); assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString()); - - signature = (MethodSignature)converter.convert("foo(long ${flowScope.bar})"); + + signature = (MethodSignature) converter.convert("foo(long ${flowScope.bar})"); assertEquals("foo", signature.getMethodName()); assertEquals(1, signature.getParameters().size()); assertEquals(Long.class, signature.getParameters().getParameter(0).getType()); assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString()); } - + public void testMultipleArguments() { - MethodSignature signature = (MethodSignature)converter.convert( - "foo(${flowScope.bar}, ${externalContext.requestParameterMap.test})"); + MethodSignature signature = (MethodSignature) converter + .convert("foo(${flowScope.bar}, ${externalContext.requestParameterMap.test})"); assertEquals("foo", signature.getMethodName()); assertEquals(2, signature.getParameters().size()); assertNull(signature.getParameters().getParameter(0).getType()); assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString()); assertNull(signature.getParameters().getParameter(1).getType()); - assertEquals("externalContext.requestParameterMap.test", signature.getParameters().getParameter(1).getName().toString()); + assertEquals("externalContext.requestParameterMap.test", signature.getParameters().getParameter(1).getName() + .toString()); } - + public void testMultipleArgumentsWithType() { - MethodSignature signature = (MethodSignature)converter.convert( - "foo(long ${flowScope.bar}, java.lang.String ${externalContext.requestParameterMap.test})"); + MethodSignature signature = (MethodSignature) converter + .convert("foo(long ${flowScope.bar}, java.lang.String ${externalContext.requestParameterMap.test})"); assertEquals("foo", signature.getMethodName()); assertEquals(2, signature.getParameters().size()); assertEquals(Long.class, signature.getParameters().getParameter(0).getType()); assertEquals("flowScope.bar", signature.getParameters().getParameter(0).getName().toString()); assertEquals(String.class, signature.getParameters().getParameter(1).getType()); - assertEquals("externalContext.requestParameterMap.test", signature.getParameters().getParameter(1).getName().toString()); + assertEquals("externalContext.requestParameterMap.test", signature.getParameters().getParameter(1).getName() + .toString()); } - + public void testCollectionConstructionSyntax() { - MethodSignature signature = (MethodSignature)converter.convert("foo({1, 2, 3})"); + MethodSignature signature = (MethodSignature) converter.convert("foo({1, 2, 3})"); assertEquals("foo", signature.getMethodName()); assertEquals(1, signature.getParameters().size()); assertNull(signature.getParameters().getParameter(0).getType()); assertEquals("{1, 2, 3}", signature.getParameters().getParameter(0).getName().toString()); } - + public void testCollectionConstructionSyntaxWithType() { - MethodSignature signature = (MethodSignature)converter.convert("foo(java.util.List {1, 2, 3})"); + MethodSignature signature = (MethodSignature) converter.convert("foo(java.util.List {1, 2, 3})"); assertEquals("foo", signature.getMethodName()); assertEquals(1, signature.getParameters().size()); assertEquals(java.util.List.class, signature.getParameters().getParameter(0).getType()); assertEquals("{1, 2, 3}", signature.getParameters().getParameter(0).getName().toString()); - - signature = (MethodSignature)converter.convert("foo(a${b,#{1:2},e}f${g,#{3:4},j}k)"); + + signature = (MethodSignature) converter.convert("foo(a${b,#{1:2},e}f${g,#{3:4},j}k)"); } - + public void testSyntaxErrors() { try { converter.convert("foo("); fail(); - } - catch (ConversionException e) { + } catch (ConversionException e) { } try { converter.convert("foo(long 1, ${bar()}"); fail(); + } catch (ConversionException e) { } - catch (ConversionException e) { - } - + try { converter.convert("foo(long 1, {1, 2)"); fail(); - } - catch (ConversionException e) { + } catch (ConversionException e) { } } }