This commit is contained in:
Keith Donald
2009-07-19 06:42:33 +00:00
parent 0993e9cfb9
commit 263d502f51

View File

@@ -0,0 +1,63 @@
/**
*
*/
package org.springframework.ui.binding.support;
import org.springframework.ui.binding.Binding.Model;
class ValueBuffer {
private Object value;
private boolean hasValue;
private Model model;
private boolean flushFailed;
private Exception flushException;
public ValueBuffer(Model model) {
this.model = model;
}
public boolean hasValue() {
return hasValue;
}
public Object getValue() {
if (!hasValue()) {
throw new IllegalStateException("No value in buffer");
}
return value;
}
public void setValue(Object value) {
this.value = value;
hasValue = true;
}
public void flush() {
try {
model.setValue(value);
clear();
} catch (Exception e) {
flushFailed = true;
flushException = e;
}
}
public void clear() {
value = null;
hasValue = false;
flushFailed = false;
}
public boolean flushFailed() {
return flushFailed;
}
public Exception getFlushException() {
return flushException;
}
}