RESOLVED - BATCH-900: Retreive null values from the ExecutionContext

This commit is contained in:
robokaso
2008-11-03 19:23:29 +00:00
parent 5e7f79783a
commit aa90589ea4
2 changed files with 194 additions and 0 deletions

View File

@@ -34,6 +34,14 @@ import org.springframework.util.Assert;
*/
public class ExecutionContext implements Serializable {
/**
* Underlying {@link ConcurrentHashMap} does not accept <code>null</code>
* values, so we convert it to a private constant under the covers.
*/
private static enum Constants {
NULL
};
private volatile boolean dirty = false;
private final Map<String, Object> map;
@@ -112,6 +120,9 @@ public class ExecutionContext implements Serializable {
if (value != null) {
Assert.isInstanceOf(Serializable.class, value, "Value: [ " + value + "must be serializable.");
}
else {
value = Constants.NULL;
}
dirty = true;
map.put(key, value);
}
@@ -233,6 +244,10 @@ public class ExecutionContext implements Serializable {
Object value = map.get(key);
if (value == Constants.NULL) {
return null;
}
if (!type.isInstance(value)) {
throw new ClassCastException("Value for key=[" + key + "] is not of type: [" + type + "], it is ["
+ (value == null ? null : "(" + value.getClass() + ")" + value) + "]");