Browse Source

naming improvements since design review

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1419 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Keith Donald 17 years ago
parent
commit
1535d67b3c
  1. 14
      org.springframework.context/src/main/java/org/springframework/ui/binding/Binder.java
  2. 2
      org.springframework.context/src/main/java/org/springframework/ui/binding/BindingConfiguration.java
  3. 4
      org.springframework.context/src/main/java/org/springframework/ui/binding/FormatterRegistry.java
  4. 1
      org.springframework.context/src/main/java/org/springframework/ui/binding/UserValues.java
  5. 20
      org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java
  6. 4
      org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java
  7. 2
      org.springframework.context/src/main/java/org/springframework/ui/lifecycle/WebBindAndValidateLifecycle.java
  8. 1
      org.springframework.context/src/main/java/org/springframework/ui/message/MessageResolverBuilder.java
  9. 20
      org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java
  10. 4
      org.springframework.context/src/test/java/org/springframework/ui/binding/support/WebBinderTests.java
  11. 6
      org.springframework.context/src/test/java/org/springframework/ui/lifecycle/WebBindAndValidateLifecycleTests.java
  12. 2
      org.springframework.oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java

14
org.springframework.context/src/main/java/org/springframework/ui/binding/Binder.java

@ -25,7 +25,7 @@ import org.springframework.ui.format.Formatter; @@ -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 { @@ -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 { @@ -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.

2
org.springframework.context/src/main/java/org/springframework/ui/binding/BindingConfiguration.java

@ -22,7 +22,7 @@ import org.springframework.ui.format.Formatter; @@ -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 {

4
org.springframework.context/src/main/java/org/springframework/ui/binding/FormatterRegistry.java

@ -26,10 +26,10 @@ public interface FormatterRegistry { @@ -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.

1
org.springframework.context/src/main/java/org/springframework/ui/binding/UserValues.java

@ -22,6 +22,7 @@ import java.util.List; @@ -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)

20
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java

@ -67,7 +67,7 @@ import org.springframework.util.Assert; @@ -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 { @@ -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;
}

4
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java

@ -32,7 +32,7 @@ import org.springframework.ui.format.Formatter; @@ -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 { @@ -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 {

2
org.springframework.context/src/main/java/org/springframework/ui/lifecycle/WebBindAndValidateLifecycle.java

@ -109,7 +109,7 @@ public class WebBindAndValidateLifecycle { @@ -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

1
org.springframework.context/src/main/java/org/springframework/ui/message/MessageResolverBuilder.java

@ -43,6 +43,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; @@ -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)

20
org.springframework.context/src/test/java/org/springframework/ui/binding/support/GenericBinderTests.java

@ -91,34 +91,34 @@ public class GenericBinderTests { @@ -91,34 +91,34 @@ public class GenericBinderTests {
@Test
public void bindSingleValuePropertyFormatter() throws ParseException {
binder.add(new BindingConfiguration("date", new DateFormatter()));
binder.configureBinding(new BindingConfiguration("date", new DateFormatter()));
binder.bind(UserValues.single("date", "2009-06-01"));
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
}
@Test
public void bindSingleValuePropertyFormatterParseException() {
binder.add(new BindingConfiguration("date", new DateFormatter()));
binder.configureBinding(new BindingConfiguration("date", new DateFormatter()));
binder.bind(UserValues.single("date", "bogus"));
}
@Test
public void bindSingleValueWithFormatterRegistedByType() throws ParseException {
binder.add(new DateFormatter(), Date.class);
binder.registerFormatter(Date.class, new DateFormatter());
binder.bind(UserValues.single("date", "2009-06-01"));
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
}
@Test
public void bindSingleValueWithFormatterRegisteredByAnnotation() throws ParseException {
binder.add(new CurrencyFormatter(), CurrencyFormat.class);
binder.registerFormatter(CurrencyFormat.class, new CurrencyFormatter());
binder.bind(UserValues.single("currency", "$23.56"));
assertEquals(new BigDecimal("23.56"), bean.getCurrency());
}
@Test
public void bindSingleValueWithnAnnotationFormatterFactoryRegistered() throws ParseException {
binder.add(new CurrencyAnnotationFormatterFactory());
binder.registerFormatterFactory(new CurrencyAnnotationFormatterFactory());
binder.bind(UserValues.single("currency", "$23.56"));
assertEquals(new BigDecimal("23.56"), bean.getCurrency());
}
@ -160,7 +160,7 @@ public class GenericBinderTests { @@ -160,7 +160,7 @@ public class GenericBinderTests {
binder.setStrict(true);
Binding b = binder.getBinding("integer");
assertNull(b);
binder.add(new BindingConfiguration("integer", null));
binder.configureBinding(new BindingConfiguration("integer", null));
b = binder.getBinding("integer");
assertFalse(b.isCollection());
assertEquals("0", b.getValue());
@ -172,7 +172,7 @@ public class GenericBinderTests { @@ -172,7 +172,7 @@ public class GenericBinderTests {
@Test
public void bindStrictNoMappingBindings() {
binder.setStrict(true);
binder.add(new BindingConfiguration("integer", null));
binder.configureBinding(new BindingConfiguration("integer", null));
UserValues values = new UserValues();
values.add("integer", "3");
values.add("foo", "BAR");
@ -190,7 +190,7 @@ public class GenericBinderTests { @@ -190,7 +190,7 @@ public class GenericBinderTests {
@Test
public void getBindingCustomFormatter() {
binder.add(new BindingConfiguration("currency", new CurrencyFormatter()));
binder.configureBinding(new BindingConfiguration("currency", new CurrencyFormatter()));
Binding b = binder.getBinding("currency");
assertFalse(b.isCollection());
assertEquals("", b.getValue());
@ -201,7 +201,7 @@ public class GenericBinderTests { @@ -201,7 +201,7 @@ public class GenericBinderTests {
@Test
public void getBindingCustomFormatterRequiringTypeCoersion() {
// IntegerFormatter formats Longs, so conversion from Integer -> Long is performed
binder.add(new BindingConfiguration("integer", new IntegerFormatter()));
binder.configureBinding(new BindingConfiguration("integer", new IntegerFormatter()));
Binding b = binder.getBinding("integer");
b.setValue("2,300");
assertEquals("2,300", b.getValue());
@ -270,7 +270,7 @@ public class GenericBinderTests { @@ -270,7 +270,7 @@ public class GenericBinderTests {
@Test
public void formatPossibleValue() {
binder.add(new BindingConfiguration("currency", new CurrencyFormatter()));
binder.configureBinding(new BindingConfiguration("currency", new CurrencyFormatter()));
Binding b = binder.getBinding("currency");
assertEquals("$5.00", b.format(new BigDecimal("5")));
}

4
org.springframework.context/src/test/java/org/springframework/ui/binding/support/WebBinderTests.java

@ -40,8 +40,8 @@ public class WebBinderTests { @@ -40,8 +40,8 @@ public class WebBinderTests {
@Test
public void bindUserValuesCreatedFromUserMap() throws ParseException {
binder.add(new CurrencyFormatter(), CurrencyFormat.class);
binder.add(new BindingConfiguration("date", new DateFormatter()));
binder.registerFormatter(CurrencyFormat.class, new CurrencyFormatter());
binder.configureBinding(new BindingConfiguration("date", new DateFormatter()));
Map<String, String> userMap = new LinkedHashMap<String, String>();
userMap.put("string", "test");
userMap.put("_integer", "doesn't matter");

6
org.springframework.context/src/test/java/org/springframework/ui/lifecycle/WebBindAndValidateLifecycleTests.java

@ -59,7 +59,7 @@ public class WebBindAndValidateLifecycleTests { @@ -59,7 +59,7 @@ public class WebBindAndValidateLifecycleTests {
public void testExecuteLifecycleInvalidFormatBindingErrors() {
Map<String, Object> userMap = new HashMap<String, Object>();
GenericFormatterRegistry registry = new GenericFormatterRegistry();
registry.add(new IntegerFormatter(), Integer.class);
registry.add(Integer.class, new IntegerFormatter());
lifecycle.setFormatterRegistry(registry);
userMap.put("string", "test");
userMap.put("integer", "bogus");
@ -76,7 +76,7 @@ public class WebBindAndValidateLifecycleTests { @@ -76,7 +76,7 @@ public class WebBindAndValidateLifecycleTests {
lifecycle = new WebBindAndValidateLifecycle(model, alertContext);
Map<String, Object> userMap = new HashMap<String, Object>();
GenericFormatterRegistry registry = new GenericFormatterRegistry();
registry.add(new IntegerFormatter(), Integer.class);
registry.add(Integer.class, new IntegerFormatter());
lifecycle.setFormatterRegistry(registry);
userMap.put("editable", "foo");
lifecycle.execute(userMap);
@ -90,7 +90,7 @@ public class WebBindAndValidateLifecycleTests { @@ -90,7 +90,7 @@ public class WebBindAndValidateLifecycleTests {
lifecycle = new WebBindAndValidateLifecycle(model, alertContext);
Map<String, Object> userMap = new HashMap<String, Object>();
GenericFormatterRegistry registry = new GenericFormatterRegistry();
registry.add(new IntegerFormatter(), Integer.class);
registry.add(Integer.class, new IntegerFormatter());
lifecycle.setFormatterRegistry(registry);
userMap.put("editable", "foo");
userMap.put("nonEditable", "whatev");

2
org.springframework.oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java

@ -66,7 +66,7 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests { @@ -66,7 +66,7 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests {
FlightType flight = new FlightType();
flight.setNumber(42L);
flights = new Flights();
flights.getFlight().add(flight);
flights.getFlight().configureBinding(flight);
return flights;
}

Loading…
Cancel
Save