From a74422ed65f6f518584c03ee4b73205f33ec0df2 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Thu, 23 Jul 2009 13:55:39 +0000 Subject: [PATCH] polish --- .../ui/binding/BindingFactory.java | 1 + .../ui/binding/BindingFactoryLocator.java | 1 + .../ui/binding/BindingStatus.java | 1 + .../ui/binding/ValidationStatus.java | 1 + .../binder/ArrayListBindingResults.java | 1 - .../ui/binding/binder/BinderExecutor.java | 1 + .../ui/binding/binder/BindingResult.java | 4 +- .../binder/MissingSourceValuesException.java | 2 +- .../ui/binding/support/BindingContext.java | 7 +- .../ui/binding/support/BindingRule.java | 35 ---------- .../ui/binding/support/DefaultFormatter.java | 44 ------------- .../ui/binding/support/FormatterRegistry.java | 7 +- .../ui/binding/support/GenericBinding.java | 2 +- .../support/GenericBindingFactory.java | 6 +- .../GenericCollectionPropertyType.java | 64 ------------------- .../support/GenericFormatterRegistry.java | 26 ++++---- .../ui/binding/support/ValueBuffer.java | 1 - .../ui/binding/support/ValueModel.java | 15 +++++ .../binding/support/GenericBinderTests.java | 4 +- 19 files changed, 50 insertions(+), 173 deletions(-) delete mode 100644 org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingRule.java delete mode 100644 org.springframework.context/src/main/java/org/springframework/ui/binding/support/DefaultFormatter.java delete mode 100644 org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericCollectionPropertyType.java diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingFactory.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingFactory.java index 5f739c3fbe2..8aceee3750b 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingFactory.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingFactory.java @@ -18,6 +18,7 @@ package org.springframework.ui.binding; /** * A factory for model property bindings. * @author Keith Donald + * @since 3.0 */ public interface BindingFactory { diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingFactoryLocator.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingFactoryLocator.java index e880b6b66c4..b671c60e2e8 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingFactoryLocator.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/BindingFactoryLocator.java @@ -19,6 +19,7 @@ package org.springframework.ui.binding; * A locator for BindingFactories indexed by their models. * Makes it easy for clients to lookup BindingFactories for models the need to bind to. * @author Keith Donald + * @since 3.0 */ public interface BindingFactoryLocator { 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 index 42da4289265..1cb6600353d 100644 --- 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 @@ -18,6 +18,7 @@ package org.springframework.ui.binding; /** * Binding states. * @author Keith Donald + * @since 3.0 */ public enum BindingStatus { 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 index 7ba52b6fc32..ac60413c0b3 100644 --- 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 @@ -18,6 +18,7 @@ package org.springframework.ui.binding; /** * Validation states. * @author Keith Donald + * @since 3.0 */ public enum ValidationStatus { diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/ArrayListBindingResults.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/ArrayListBindingResults.java index e9835cacde3..a6a215f4841 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/ArrayListBindingResults.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/ArrayListBindingResults.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; - class ArrayListBindingResults implements BindingResults { private List results; diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/BinderExecutor.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/BinderExecutor.java index c8308dad945..568bec6dd6f 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/BinderExecutor.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/BinderExecutor.java @@ -21,6 +21,7 @@ import org.springframework.ui.binding.config.BindingRuleConfiguration; * A SPI interface that lets you configure a model binder, then execute it. * Hides details about the source of binder source values. * @author Keith Donald + * @since 3.0 * @param the type of model to bind to */ public interface BinderExecutor { 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 953316ca4a5..ae64628bc52 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 @@ -16,14 +16,12 @@ package org.springframework.ui.binding.binder; import org.springframework.ui.alert.Alert; -import org.springframework.ui.binding.Binding; /** * The result of a bind operation. * @author Keith Donald * @since 3.0 - * @see Binder#bind(Map) - * @see Binding#setValue(Object) + * @see Binder#bind(java.util.Map) */ public interface BindingResult { diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/MissingSourceValuesException.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/MissingSourceValuesException.java index 9ba6db0084a..6f528fa03be 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/MissingSourceValuesException.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/binder/MissingSourceValuesException.java @@ -23,7 +23,7 @@ import java.util.Map; * Indicates a client configuration error. * @author Keith Donald * @since 3.0 - * @see Binder#bind(Map) + * @see Binder#bind(java.util.Map) */ @SuppressWarnings("serial") public class MissingSourceValuesException extends RuntimeException { diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingContext.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingContext.java index bea8ace5a37..246c0c9d12c 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingContext.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingContext.java @@ -21,6 +21,11 @@ import org.springframework.ui.binding.Binding; import org.springframework.ui.binding.config.Condition; import org.springframework.ui.format.Formatter; +/** + * A context that allows a Binding to query its BindingRule. + * @author Keith Donald + * @since 3.0 + */ public interface BindingContext { MessageSource getMessageSource(); @@ -33,7 +38,7 @@ public interface BindingContext { Condition getVisibleCondition(); - Binding getBinding(String property); + Binding getNestedBinding(String property); @SuppressWarnings("unchecked") Formatter getFormatter(); diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingRule.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingRule.java deleted file mode 100644 index 86cd9d3cab3..00000000000 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingRule.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2004-2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ui.binding.support; - -import org.springframework.ui.binding.config.Condition; -import org.springframework.ui.format.Formatter; - -public interface BindingRule { - - Formatter getFormatter(); - - Formatter getKeyFormatter(); - - Formatter getElementFormatter(); - - Condition getEditableCondition(); - - Condition getEnabledCondition(); - - Condition getVisibleCondition(); - -} \ No newline at end of file diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/DefaultFormatter.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/DefaultFormatter.java deleted file mode 100644 index 948a16f3e55..00000000000 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/DefaultFormatter.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2004-2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ui.binding.support; - -import java.text.ParseException; -import java.util.Locale; - -import org.springframework.ui.format.Formatter; - -@SuppressWarnings("unchecked") -// TODO should this delegate to type converter... -class DefaultFormatter implements Formatter { - - public static final Formatter INSTANCE = new DefaultFormatter(); - - public String format(Object object, Locale locale) { - if (object == null) { - return ""; - } else { - return object.toString(); - } - } - - public Object parse(String formatted, Locale locale) throws ParseException { - if (formatted == "") { - return null; - } else { - return formatted; - } - } -} \ No newline at end of file diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/FormatterRegistry.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/FormatterRegistry.java index ad5440c9280..a0afdafc93a 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/FormatterRegistry.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/FormatterRegistry.java @@ -22,7 +22,6 @@ import org.springframework.ui.format.Formatter; /** * A centralized registry of Formatters indexed by property types. - * TODO - consider moving to ui.format * TODO - consider a general add(Formatter) method for simplicity * @author Keith Donald * @since 3.0 @@ -51,11 +50,11 @@ public interface FormatterRegistry { void add(Class propertyType, Formatter formatter); /** - * Adds a Formatter that will format the values of properties of the provided type. - * @param propertyType the type + * Adds a Formatter that will format the values of collection properties of the provided type. + * @param type the type * @param formatter the formatter */ - void add(GenericCollectionPropertyType propertyType, Formatter formatter); + void add(CollectionTypeDescriptor type, Formatter formatter); /** * Adds a AnnotationFormatterFactory that will format values of properties annotated with a specific annotation. 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 41fbed97dc3..80ba735029b 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 @@ -288,7 +288,7 @@ public class GenericBinding implements Binding { } public Binding getNestedBinding(String property) { - return bindingContext.getBinding(property); + return bindingContext.getNestedBinding(property); } public boolean isList() { 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 8f7cb22232b..4ea4add0796 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 @@ -226,7 +226,7 @@ public class GenericBindingFactory implements BindingFactory { return visibleCondition; } - public Binding getBinding(String property) { + public Binding getNestedBinding(String property) { createValueIfNecessary(); return getBindingRule(property, binding.getValueType()).getBinding(binding.getValue()); } @@ -444,7 +444,7 @@ public class GenericBindingFactory implements BindingFactory { return listBindingContext.getTypeConverter(); } - public Binding getBinding(String property) { + public Binding getNestedBinding(String property) { Object model = ((List) listBindingContext.binding.getValue()).get(index); Class elementType = listBindingContext.getElementType(); if (elementType == null) { @@ -523,7 +523,7 @@ public class GenericBindingFactory implements BindingFactory { } @SuppressWarnings("unchecked") - public Binding getBinding(String property) { + public Binding getNestedBinding(String property) { Object model = ((Map) mapBindingContext.binding.getValue()).get(key); Class elementType = mapBindingContext.getElementType(); if (elementType == null) { diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericCollectionPropertyType.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericCollectionPropertyType.java deleted file mode 100644 index 0bc7f964b7a..00000000000 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericCollectionPropertyType.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2004-2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ui.binding.support; - -/** - * Specifies the element type of a generic collection type. - * @author Keith Donald - * @since 3.0 - */ -public class GenericCollectionPropertyType { - - private Class collectionType; - - private Class elementType; - - /** - * Creates a new generic collection property type - * @param collectionType the collection type - * @param elementType the element type - */ - public GenericCollectionPropertyType(Class collectionType, Class elementType) { - this.collectionType = collectionType; - this.elementType = elementType; - } - - /** - * The collection type. - */ - public Class getCollectionType() { - return collectionType; - } - - /** - * The element type. - */ - public Class getElementType() { - return elementType; - } - - public boolean equals(Object o) { - if (!(o instanceof GenericCollectionPropertyType)) { - return false; - } - GenericCollectionPropertyType type = (GenericCollectionPropertyType) o; - return collectionType.equals(type.collectionType) && elementType.equals(type.elementType); - } - - public int hashCode() { - return collectionType.hashCode() + elementType.hashCode(); - } -} \ No newline at end of file diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java index a56ce13aa65..05240760c92 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericFormatterRegistry.java @@ -55,16 +55,16 @@ public class GenericFormatterRegistry implements FormatterRegistry { private Map typeFormatters = new ConcurrentHashMap(); - private Map collectionTypeFormatters = new ConcurrentHashMap(); + private Map collectionTypeFormatters = new ConcurrentHashMap(); private Map annotationFormatters = new HashMap(); private TypeConverter typeConverter = new DefaultTypeConverter(); - + public void setTypeConverter(TypeConverter typeConverter) { this.typeConverter = typeConverter; } - + public Formatter getFormatter(PropertyDescriptor property) { Assert.notNull(property, "The PropertyDescriptor is required"); TypeDescriptor propertyType = new TypeDescriptor(new MethodParameter(property.getReadMethod(), -1)); @@ -78,8 +78,8 @@ public class GenericFormatterRegistry implements FormatterRegistry { Formatter formatter = null; Class type; if (propertyType.isCollection() || propertyType.isArray()) { - GenericCollectionPropertyType collectionType = new GenericCollectionPropertyType(propertyType.getType(), - propertyType.getElementType()); + CollectionTypeDescriptor collectionType = new CollectionTypeDescriptor(propertyType.getType(), propertyType + .getElementType()); formatter = collectionTypeFormatters.get(collectionType); if (formatter != null) { return formatter; @@ -126,7 +126,7 @@ public class GenericFormatterRegistry implements FormatterRegistry { } } - public void add(GenericCollectionPropertyType propertyType, Formatter formatter) { + public void add(CollectionTypeDescriptor propertyType, Formatter formatter) { collectionTypeFormatters.put(propertyType, formatter); } @@ -183,16 +183,16 @@ public class GenericFormatterRegistry implements FormatterRegistry { private static class DefaultFormatter implements Formatter { public static final Formatter DEFAULT_INSTANCE = new DefaultFormatter(null, null); - + private Class objectType; - + private TypeConverter typeConverter; - + public DefaultFormatter(Class objectType, TypeConverter typeConverter) { this.objectType = objectType; this.typeConverter = typeConverter; } - + public String format(Object object, Locale locale) { if (object == null) { return ""; @@ -221,14 +221,14 @@ public class GenericFormatterRegistry implements FormatterRegistry { } } } - + private static class DefaultCollectionFormatter implements Formatter { - private GenericCollectionPropertyType collectionType; + private CollectionTypeDescriptor collectionType; private Formatter elementFormatter; - public DefaultCollectionFormatter(GenericCollectionPropertyType collectionType, + public DefaultCollectionFormatter(CollectionTypeDescriptor collectionType, GenericFormatterRegistry formatterRegistry) { this.collectionType = collectionType; this.elementFormatter = collectionType.getElementType() != null ? formatterRegistry 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 index 06c58abc68c..ff246749a72 100644 --- 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 @@ -15,7 +15,6 @@ */ package org.springframework.ui.binding.support; - class ValueBuffer { private Object value; diff --git a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/ValueModel.java b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/ValueModel.java index a4b6f474d27..11af9ae3e96 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/binding/support/ValueModel.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/binding/support/ValueModel.java @@ -1,3 +1,18 @@ +/* + * Copyright 2004-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ui.binding.support; import org.springframework.core.convert.TypeDescriptor; 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 a047379cbfc..f0abf806af5 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 @@ -262,7 +262,7 @@ public class GenericBinderTests { @Test public void bindToListSingleString() { GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry(); - formatterRegistry.add(new GenericCollectionPropertyType(List.class, Address.class), new AddressListFormatter()); + formatterRegistry.add(new CollectionTypeDescriptor(List.class, Address.class), new AddressListFormatter()); bindingFactory.setFormatterRegistry(formatterRegistry); Map values = new LinkedHashMap(); values @@ -309,7 +309,7 @@ public class GenericBinderTests { @Test public void getListAsSingleString() { GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry(); - formatterRegistry.add(new GenericCollectionPropertyType(List.class, Address.class), new AddressListFormatter()); + formatterRegistry.add(new CollectionTypeDescriptor(List.class, Address.class), new AddressListFormatter()); bindingFactory.setFormatterRegistry(formatterRegistry); Address address1 = new Address(); address1.setStreet("s1");