diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/ValueBuffer.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/ValueBuffer.java new file mode 100644 index 00000000000..7faefe3555a --- /dev/null +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/ValueBuffer.java @@ -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; + } +} \ No newline at end of file