From ab7e985d721128ab700bad230f2ba0ecd20e14d6 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Wed, 22 Jul 2009 19:55:35 +0000 Subject: [PATCH] polish --- .../springframework/ui/binding/Binding.java | 96 ++++--------------- .../ui/binding/BindingStatus.java | 33 +++++++ .../ui/binding/ValidationStatus.java | 23 +++++ .../ui/binding/binder/BindingResult.java | 2 +- .../ui/binding/binder/GenericBinder.java | 2 +- .../ui/binding/support/GenericBinding.java | 3 +- .../support/GenericBindingFactory.java | 2 +- .../binding/support/GenericBinderTests.java | 2 +- 8 files changed, 83 insertions(+), 80 deletions(-) create mode 100644 org.springframework.context/src/main/java/org/springframework/ui/binding/BindingStatus.java create mode 100644 org.springframework.context/src/main/java/org/springframework/ui/binding/ValidationStatus.java diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/Binding.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/Binding.java index 45b93d62e3a..a03625b846c 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/Binding.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/Binding.java @@ -61,6 +61,26 @@ public interface Binding { * Used to determine if the user can see the field. */ boolean isVisible(); + + /** + * The current binding status. + * Initially {@link BindingStatus#CLEAN clean}. + * Is {@link BindingStatus#DIRTY} after applying a source value to the value buffer. + * Is {@link BindingStatus#COMMITTED} after successfully committing the buffered value. + * Is {@link BindingStatus#INVALID_SOURCE_VALUE} if a source value could not be applied. + * Is {@link BindingStatus#COMMIT_FAILURE} if a buffered value could not be committed. + */ + BindingStatus getStatus(); + + /** + * An alert that communicates current status to the user. + * Returns null if {@link BindingStatus#CLEAN} and {@link ValidationStatus#NOT_VALIDATED}. + * Returns a {@link Severity#INFO} Alert with code bindSuccess when {@link BindingStatus#COMMITTED}. + * Returns a {@link Severity#ERROR} Alert with code typeMismatch when {@link BindingStatus#INVALID_SOURCE_VALUE} or {@link BindingStatus#COMMIT_FAILURE} due to a value parse / type conversion error. + * Returns a {@link Severity#FATAL} Alert with code internalError when {@link BindingStatus#COMMIT_FAILURE} due to a unexpected runtime exception. + * Returns a {@link Severity#INFO} Alert describing results of validation if {@link ValidationStatus#VALID} or {@link ValidationStatus#INVALID}. + */ + Alert getStatusAlert(); /** * Apply the source value to this binding. @@ -79,26 +99,6 @@ public interface Binding { */ Object getInvalidSourceValue(); - /** - * The current binding status. - * Initially {@link BindingStatus#CLEAN clean}. - * Is {@link BindingStatus#DIRTY} after applying a source value to the value buffer. - * Is {@link BindingStatus#COMMITTED} after successfully committing the buffered value. - * Is {@link BindingStatus#INVALID_SOURCE_VALUE} if a source value could not be applied. - * Is {@link BindingStatus#COMMIT_FAILURE} if a buffered value could not be committed. - */ - BindingStatus getStatus(); - - /** - * An alert that communicates current status to the user. - * Returns null if {@link BindingStatus#CLEAN} and {@link ValidationStatus#NOT_VALIDATED}. - * Returns a {@link Severity#INFO} Alert with code bindSuccess when {@link BindingStatus#COMMITTED}. - * Returns a {@link Severity#ERROR} Alert with code typeMismatch when {@link BindingStatus#INVALID_SOURCE_VALUE} or {@link BindingStatus#COMMIT_FAILURE} due to a value parse / type conversion error. - * Returns a {@link Severity#FATAL} Alert with code internalError when {@link BindingStatus#COMMIT_FAILURE} due to a unexpected runtime exception. - * Returns a {@link Severity#INFO} Alert describing results of validation if {@link ValidationStatus#VALID} or {@link ValidationStatus#INVALID}. - */ - Alert getStatusAlert(); - /** * Commit the buffered value to the model. * Sets to {@link BindingStatus#COMMITTED} if succeeds. @@ -119,7 +119,7 @@ public interface Binding { * @return the binding to the nested property * @throws IllegalStateException if not a bean */ - Binding getBinding(String property); + Binding getNestedBinding(String property); /** * If bound to an indexable Collection, either a {@link java.util.List} or an array. @@ -155,58 +155,4 @@ public interface Binding { * @return the formatted string */ String formatValue(Object potentialModelValue); - - /** - * Binding states. - * @author Keith Donald - */ - public enum BindingStatus { - - /** - * Initial state: No value is buffered, and there is a direct channel to the model value. - */ - CLEAN, - - /** - * An invalid source value is applied. - */ - INVALID_SOURCE_VALUE, - - /** - * The binding buffer contains a valid value that has not been committed. - */ - DIRTY, - - /** - * The buffered value has been committed. - */ - COMMITTED, - - /** - * The buffered value failed to commit. - */ - COMMIT_FAILURE - } - - /** - * Validation states. - * @author Keith Donald - */ - public enum ValidationStatus { - - /** - * Initial state: No validation has run. - */ - NOT_VALIDATED, - - /** - * Validation has succeeded. - */ - VALID, - - /** - * Validation has failed. - */ - INVALID - } } \ No newline at end of file diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingStatus.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingStatus.java new file mode 100644 index 00000000000..685ec456c65 --- /dev/null +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingStatus.java @@ -0,0 +1,33 @@ +package org.springframework.ui.binding; + +/** + * Binding states. + * @author Keith Donald + */ +public enum BindingStatus { + + /** + * Initial state: No value is buffered, and there is a direct channel to the model value. + */ + CLEAN, + + /** + * An invalid source value is applied. + */ + INVALID_SOURCE_VALUE, + + /** + * The binding buffer contains a valid value that has not been committed. + */ + DIRTY, + + /** + * The buffered value has been committed. + */ + COMMITTED, + + /** + * The buffered value failed to commit. + */ + COMMIT_FAILURE +} \ No newline at end of file diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/ValidationStatus.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/ValidationStatus.java new file mode 100644 index 00000000000..204d0adf2cb --- /dev/null +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/ValidationStatus.java @@ -0,0 +1,23 @@ +package org.springframework.ui.binding; + +/** + * Validation states. + * @author Keith Donald + */ +public enum ValidationStatus { + + /** + * Initial state: No validation has run. + */ + NOT_VALIDATED, + + /** + * Validation has succeeded. + */ + VALID, + + /** + * Validation has failed. + */ + INVALID +} \ No newline at end of file diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/BindingResult.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/BindingResult.java index caee4d62a5a..953316ca4a5 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/BindingResult.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/BindingResult.java @@ -29,7 +29,7 @@ public interface BindingResult { /** * The model property this binding result is for. - * @see Binder#getBinding(String) + * @see Binder#getNestedBinding(String) */ String getProperty(); diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/GenericBinder.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/GenericBinder.java index d196fe05762..7dfed3bf632 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/GenericBinder.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/GenericBinder.java @@ -23,7 +23,7 @@ import org.springframework.context.MessageSource; import org.springframework.core.convert.TypeConverter; import org.springframework.ui.binding.Binding; import org.springframework.ui.binding.BindingFactory; -import org.springframework.ui.binding.Binding.BindingStatus; +import org.springframework.ui.binding.BindingStatus; import org.springframework.ui.binding.support.PropertyNotFoundException; import org.springframework.util.Assert; diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinding.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinding.java index d1a6a17f7af..87944e9a1dd 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinding.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinding.java @@ -35,6 +35,7 @@ import org.springframework.core.style.StylerUtils; import org.springframework.ui.alert.Alert; import org.springframework.ui.alert.Severity; import org.springframework.ui.binding.Binding; +import org.springframework.ui.binding.BindingStatus; import org.springframework.ui.format.Formatter; import org.springframework.ui.message.MessageBuilder; import org.springframework.ui.message.ResolvableArgument; @@ -278,7 +279,7 @@ public class GenericBinding implements Binding { } } - public Binding getBinding(String property) { + public Binding getNestedBinding(String property) { return bindingContext.getBinding(property); } diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBindingFactory.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBindingFactory.java index c9a3bca8e26..bbd9ace9030 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBindingFactory.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBindingFactory.java @@ -134,7 +134,7 @@ public class GenericBindingFactory implements BindingFactory { throw new IllegalArgumentException("Attempted to index a property that is not a List or Map"); } } else { - binding = binding.getBinding(element.getValue()); + binding = binding.getNestedBinding(element.getValue()); } } return binding; diff --git a/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java b/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java index 79a7db83da6..74363f3cc0f 100644 --- a/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java +++ b/org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.style.ToStringCreator; import org.springframework.ui.binding.Binding; -import org.springframework.ui.binding.Binding.BindingStatus; +import org.springframework.ui.binding.BindingStatus; import org.springframework.ui.binding.binder.BindingResults; import org.springframework.ui.binding.binder.GenericBinder; import org.springframework.ui.binding.binder.MissingSourceValuesException;