naming improvements since design review
This commit is contained in:
@@ -25,7 +25,7 @@ import org.springframework.ui.format.Formatter;
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @param <M> The kind of model object this binder binds to
|
||||
* @see #add(BindingConfiguration)
|
||||
* @see #configureBinding(BindingConfiguration)
|
||||
* @see #bind(UserValues)
|
||||
*/
|
||||
public interface Binder {
|
||||
@@ -37,7 +37,7 @@ public interface Binder {
|
||||
Object getModel();
|
||||
|
||||
/**
|
||||
* Configures if this binder is <i>strict</i>; a strict binder requires all bindings to be registered explicitly using {@link #add(BindingConfiguration)}.
|
||||
* Configures if this binder is <i>strict</i>; a strict binder requires all bindings to be registered explicitly using {@link #configureBinding(BindingConfiguration)}.
|
||||
* An <i>optimistic</i> binder will implicitly create bindings as required to support {@link #bind(UserValues)} operations.
|
||||
* Default is optimistic.
|
||||
* @param strict strict binder status
|
||||
@@ -46,23 +46,23 @@ public interface Binder {
|
||||
|
||||
/**
|
||||
* Adds a new binding.
|
||||
* @param binding the binding configuration
|
||||
* @param configuration the binding configuration
|
||||
* @return the new binding created from the configuration provided
|
||||
*/
|
||||
Binding add(BindingConfiguration binding);
|
||||
Binding configureBinding(BindingConfiguration configuration);
|
||||
|
||||
/**
|
||||
* Adds a Formatter that will format property values of type <code>propertyType</coe>.
|
||||
* @param formatter the formatter
|
||||
* @param propertyType the property type
|
||||
* @param formatter the formatter
|
||||
*/
|
||||
void add(Formatter<?> formatter, Class<?> propertyType);
|
||||
void registerFormatter(Class<?> propertyType, Formatter<?> formatter);
|
||||
|
||||
/**
|
||||
* Adds a AnnotationFormatterFactory that will format values of properties annotated with a specific annotation.
|
||||
* @param factory the annotation formatter factory
|
||||
*/
|
||||
void add(AnnotationFormatterFactory<?, ?> factory);
|
||||
void registerFormatterFactory(AnnotationFormatterFactory<?, ?> factory);
|
||||
|
||||
/**
|
||||
* Returns the binding for the property.
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.ui.format.Formatter;
|
||||
* Configuration used to create a new {@link Binding} registered with a {@link GenericBinder}.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see GenericBinder#add(BindingConfiguration)
|
||||
* @see GenericBinder#configureBinding(BindingConfiguration)
|
||||
*/
|
||||
public class BindingConfiguration {
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@ public interface FormatterRegistry {
|
||||
* <p>
|
||||
* Note the Formatter's formatted object type does not have to equal the associated property type.
|
||||
* When the property type differs from the formatted object type, the caller of the Formatter is expected to coerse a property value to the type expected by the Formatter.
|
||||
* @param formatter the formatter
|
||||
* @param propertyType the type
|
||||
* @param formatter the formatter
|
||||
*/
|
||||
void add(Formatter<?> formatter, Class<?> propertyType);
|
||||
void add(Class<?> propertyType, Formatter<?> formatter);
|
||||
|
||||
/**
|
||||
* Adds a AnnotationFormatterFactory that will format values of properties annotated with a specific annotation.
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* A holder for a list of UserValues.
|
||||
* TODO just use a map here
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see Binder#bind(UserValues)
|
||||
|
||||
@@ -67,7 +67,7 @@ import org.springframework.util.Assert;
|
||||
* TODO - localization of alert messages using MessageResolver/MesageSource
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see #add(BindingConfiguration)
|
||||
* @see #configureBinding(BindingConfiguration)
|
||||
* @see #bind(UserValues)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -120,29 +120,29 @@ public class GenericBinder implements Binder {
|
||||
this.formatterRegistry = formatterRegistry;
|
||||
}
|
||||
|
||||
public Binding add(BindingConfiguration binding) {
|
||||
Binding newBinding;
|
||||
public Binding configureBinding(BindingConfiguration configuration) {
|
||||
Binding binding;
|
||||
try {
|
||||
newBinding = new BindingImpl(binding);
|
||||
binding = new BindingImpl(configuration);
|
||||
} catch (org.springframework.expression.ParseException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
bindings.put(binding.getProperty(), newBinding);
|
||||
return newBinding;
|
||||
bindings.put(configuration.getProperty(), binding);
|
||||
return binding;
|
||||
}
|
||||
|
||||
public void add(Formatter<?> formatter, Class<?> propertyType) {
|
||||
formatterRegistry.add(formatter, propertyType);
|
||||
public void registerFormatter(Class<?> propertyType, Formatter<?> formatter) {
|
||||
formatterRegistry.add(propertyType, formatter);
|
||||
}
|
||||
|
||||
public void add(AnnotationFormatterFactory<?, ?> factory) {
|
||||
public void registerFormatterFactory(AnnotationFormatterFactory<?, ?> factory) {
|
||||
formatterRegistry.add(factory);
|
||||
}
|
||||
|
||||
public Binding getBinding(String property) {
|
||||
Binding binding = bindings.get(property);
|
||||
if (binding == null && !strict) {
|
||||
return add(new BindingConfiguration(property, null));
|
||||
return configureBinding(new BindingConfiguration(property, null));
|
||||
} else {
|
||||
return binding;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.ui.format.Formatter;
|
||||
* A generic implementation of {@link FormatterRegistry} suitable for use in most binding environments.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see #add(Formatter, Class)
|
||||
* @see #add(Class, Formatter)
|
||||
* @see #add(AnnotationFormatterFactory)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -58,7 +58,7 @@ public class GenericFormatterRegistry implements FormatterRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Formatter<?> formatter, Class<?> propertyType) {
|
||||
public void add(Class<?> propertyType, Formatter<?> formatter) {
|
||||
if (propertyType.isAnnotation()) {
|
||||
annotationFormatters.put(propertyType, new SimpleAnnotationFormatterFactory(formatter));
|
||||
} else {
|
||||
|
||||
@@ -109,7 +109,7 @@ public class WebBindAndValidateLifecycle {
|
||||
Bound b = AnnotationUtils.getAnnotation(getter, Bound.class);
|
||||
if (b != null) {
|
||||
// TODO should we wire formatter here if using a format annotation - an optimization?
|
||||
binder.add(new BindingConfiguration(prop.getName(), null));
|
||||
binder.configureBinding(new BindingConfiguration(prop.getName(), null));
|
||||
}
|
||||
}
|
||||
// TODO @Bound fields
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
* invalidFormat=The #{label} must be in format #{format}.
|
||||
* mathForm.decimalField=Decimal Field
|
||||
* </pre>
|
||||
* TODO favor MessageBuilder accepting message source
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see #code(String)
|
||||
|
||||
Reference in New Issue
Block a user