since 3.0
This commit is contained in:
@@ -23,7 +23,7 @@ import org.springframework.ui.format.Formatter;
|
||||
/**
|
||||
* Binds user-entered values to properties of a model object.
|
||||
* @author Keith Donald
|
||||
*
|
||||
* @since 3.0
|
||||
* @param <M> The kind of model object this binder binds to
|
||||
* @see #add(BindingConfiguration)
|
||||
* @see #bind(UserValues)
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.ui.binding;
|
||||
/**
|
||||
* A binding between a user interface element and a model property.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface Binding {
|
||||
|
||||
|
||||
@@ -21,6 +21,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)
|
||||
*/
|
||||
public class BindingConfiguration {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.ui.binding;
|
||||
/**
|
||||
* The result of a bind operation.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see Binder#bind(UserValues)
|
||||
* @see Binding#setValue(Object)
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
/**
|
||||
* The results of a bind operation.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see Binder#bind(UserValues)
|
||||
*/
|
||||
public interface BindingResults extends Iterable<BindingResult> {
|
||||
|
||||
@@ -6,8 +6,8 @@ import org.springframework.ui.format.Formatter;
|
||||
|
||||
/**
|
||||
* A centralized registry of Formatters indexed by property types.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface FormatterRegistry {
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ package org.springframework.ui.binding;
|
||||
/**
|
||||
* Holds a user-entered value to bind to a model property.
|
||||
* @author Keith Donald
|
||||
* @see Binder#bind(List).
|
||||
* @since 3.0
|
||||
* @see Binder#bind(List)
|
||||
*/
|
||||
public class UserValue {
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -6,9 +21,9 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simpler holder for a list of UserValues.
|
||||
*
|
||||
* A holder for a list of UserValues.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see Binder#bind(UserValues)
|
||||
*/
|
||||
public class UserValues implements Iterable<UserValue> {
|
||||
|
||||
@@ -57,8 +57,9 @@ import org.springframework.ui.format.AnnotationFormatterFactory;
|
||||
import org.springframework.ui.format.Formatter;
|
||||
|
||||
/**
|
||||
* A generic {@link Binder binder} suitable for use in most binding environments.
|
||||
* A generic {@link Binder binder} suitable for use in most environments.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see #add(BindingConfiguration)
|
||||
* @see #bind(UserValues)
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,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(AnnotationFormatterFactory)
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.ui.binding.UserValues;
|
||||
* A binder designed for use in HTTP (web) environments.
|
||||
* Suited for binding user-provided HTTP query parameters to model properties.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see #setDefaultPrefix(String)
|
||||
* @see #setPresentPrefix(String)
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.lang.annotation.Annotation;
|
||||
* A factory that creates {@link Formatter formatters} to format property values on properties annotated with a particular format {@link Annotation}.
|
||||
* For example, a <code>CurrencyAnnotationFormatterFactory</code> might create a <code>Formatter</code> that formats a <code>BigDecimal</code> value set on a property annotated with <code>@CurrencyFormat</code>.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @param <A> The type of Annotation this factory uses to create Formatter instances
|
||||
* @param <T> The type of Object Formatters created by this factory format
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Locale;
|
||||
/**
|
||||
* Formats objects of type T for display.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @param <T> the type of object this formatter can format
|
||||
*/
|
||||
public interface Formatter<T> {
|
||||
|
||||
@@ -28,8 +28,9 @@ import org.springframework.ui.format.Formatter;
|
||||
/**
|
||||
* A formatter for {@link Date} types.
|
||||
* Allows the configuration of an explicit date pattern and locale.
|
||||
* @see SimpleDateFormat
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see SimpleDateFormat
|
||||
*/
|
||||
public class DateFormatter implements Formatter<Date> {
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.ui.format.Formatter;
|
||||
* Sets the scale of parsed BigDecimal values to {@link NumberFormat#getMaximumFractionDigits()}.
|
||||
* Applies {@link RoundingMode#DOWN} to parsed values.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public class CurrencyFormatter implements Formatter<BigDecimal> {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Locale;
|
||||
/**
|
||||
* Produces NumberFormat instances that format currency values.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see NumberFormat
|
||||
*/
|
||||
final class CurrencyNumberFormatFactory extends NumberFormatFactory {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.ui.format.Formatter;
|
||||
* Configures BigDecimal parsing so there is no loss in precision.
|
||||
* Allows configuration over the decimal number pattern; see {@link #DecimalFormatter(String)}.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public class DecimalFormatter implements Formatter<BigDecimal> {
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
* @author Keith Donald
|
||||
* @see NumberFormat
|
||||
* @see DecimalFormat
|
||||
* @since 3.0
|
||||
*/
|
||||
class DefaultNumberFormatFactory extends NumberFormatFactory {
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.ui.format.Formatter;
|
||||
* A Long formatter for whole integer values.
|
||||
* Delegates to {@link NumberFormat#getIntegerInstance(Locale)}.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public class IntegerFormatter implements Formatter<Long> {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Locale;
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @see NumberFormat
|
||||
* @since 3.0
|
||||
*/
|
||||
final class IntegerNumberFormatFactory extends NumberFormatFactory {
|
||||
public NumberFormat getNumberFormat(Locale locale) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Locale;
|
||||
* caching number format instances.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
abstract class NumberFormatFactory {
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.ui.format.Formatter;
|
||||
* Delegates to {@link NumberFormat#getPercentInstance(Locale)}.
|
||||
* Configures BigDecimal parsing so there is no loss in precision.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public class PercentFormatter implements Formatter<BigDecimal> {
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Locale;
|
||||
*
|
||||
* @see NumberFormat
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
final class PercentNumberFormatFactory extends NumberFormatFactory {
|
||||
public NumberFormat getNumberFormat(Locale locale) {
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.expression.PropertyAccessor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
class DefaultMessageResolver implements MessageResolver, MessageSourceResolvable {
|
||||
final class DefaultMessageResolver implements MessageResolver, MessageSourceResolvable {
|
||||
|
||||
private Severity severity;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.springframework.ui.message;
|
||||
* For example, a error message may inform a user of a web application a business rule was violated.
|
||||
* TODO - should we introduce summary/detail fields instead of just text
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface Message {
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
* mathForm.decimalField=Decimal Field
|
||||
* </pre>
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see MessageContext#add(MessageResolver, String)
|
||||
*/
|
||||
public class MessageBuilder {
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* A context for recording and retrieving messages for display in a user interface.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface MessageContext {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.ui.message;
|
||||
/**
|
||||
* Runtime exception thrown by a {@link MessageResolver} if a message resolution fails.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class MessageResolutionException extends RuntimeException {
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.context.MessageSource;
|
||||
/**
|
||||
* A factory for a localized Message.
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
* @see Message
|
||||
* @see MessageSource
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.ui.message;
|
||||
* Enum exposing supported message severities.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Jeremy Grelle
|
||||
* @since 3.0
|
||||
* @see Message
|
||||
*/
|
||||
public enum Severity {
|
||||
|
||||
@@ -15,56 +15,46 @@
|
||||
*/
|
||||
package org.springframework.ui.message.support;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.context.support.AbstractMessageSource;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.ui.message.Message;
|
||||
import org.springframework.ui.message.MessageContext;
|
||||
import org.springframework.ui.message.MessageResolver;
|
||||
import org.springframework.ui.message.Severity;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CachingMapDecorator;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Collections;
|
||||
|
||||
/**
|
||||
* The default message context implementation.
|
||||
* Uses a {@link MessageSource} to resolve messages that are added by callers.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
public class DefaultMessageContext implements MessageContext {
|
||||
|
||||
private MessageSource messageSource;
|
||||
private final MessageSource messageSource;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private Map<String, ArrayList<Message>> messagesByElement = new CachingMapDecorator<String, ArrayList<Message>>(new LinkedHashMap<String, ArrayList<Message>>()) {
|
||||
protected ArrayList<Message> create(String element) {
|
||||
private Map<String, List<Message>> messagesByElement = new CachingMapDecorator<String, List<Message>>(new LinkedHashMap<String, List<Message>>()) {
|
||||
protected List<Message> create(String element) {
|
||||
return new ArrayList<Message>();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new default message context.
|
||||
* Defaults to a message source that simply resolves default text and cannot resolve localized message codes.
|
||||
*/
|
||||
public DefaultMessageContext() {
|
||||
init(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new default message context.
|
||||
* @param messageSource the message source to resolve messages added to this context
|
||||
*/
|
||||
public DefaultMessageContext(MessageSource messageSource) {
|
||||
init(messageSource);
|
||||
Assert.notNull(messageSource, "The MessageSource is required");
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,12 +67,10 @@ public class DefaultMessageContext implements MessageContext {
|
||||
|
||||
// implementing message context
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, List<Message>> getMessages() {
|
||||
return Collections.unmodifiableMap(messagesByElement);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Message> getMessages(String element) {
|
||||
List<Message> messages = messagesByElement.get(element);
|
||||
if (messages.isEmpty()) {
|
||||
@@ -102,23 +90,6 @@ public class DefaultMessageContext implements MessageContext {
|
||||
|
||||
// internal helpers
|
||||
|
||||
private void init(MessageSource messageSource) {
|
||||
setMessageSource(messageSource);
|
||||
}
|
||||
|
||||
private void setMessageSource(MessageSource messageSource) {
|
||||
if (messageSource == null) {
|
||||
messageSource = new DefaultTextFallbackMessageSource();
|
||||
}
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
private static class DefaultTextFallbackMessageSource extends AbstractMessageSource {
|
||||
protected MessageFormat resolveCode(String code, Locale locale) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class ResolvableMessage implements Message {
|
||||
|
||||
private MessageResolver resolver;
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.ui.validation;
|
||||
|
||||
/**
|
||||
* TODO Document ValidateResults.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO Document Validator.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user