提交 2bd664f7 编写于 作者: K Keith Donald

removed framework specific annotation in favor of user-defined for now

上级 704cc79c
......@@ -38,8 +38,8 @@ public interface FormatterRegistry {
* Adds a Formatter to this registry indexed by type.
* Use this add method when type differs from <T>.
* Calling getFormatter(type) returns a decorator that wraps the targetFormatter.
* On format, the decorator first coerses the instance of tType to &lt;T&gt;, then delegates to <code>targetFormatter</code> to format the value.
* On parse, the decorator first delegates to the formatter to parse a &lt;T&gt;, then coerses the parsed value to objectType.
* On format, the decorator first coerses the instance of type to &lt;T&gt;, then delegates to <code>targetFormatter</code> to format the value.
* On parse, the decorator first delegates to the formatter to parse a &lt;T&gt;, then coerses the parsed value to type.
* @param type the object type
* @param targetFormatter the target formatter
* @param <T> the type of object the target formatter formats
......@@ -47,14 +47,14 @@ public interface FormatterRegistry {
<T> void add(Class<?> type, Formatter<T> targetFormatter);
/**
* Adds a AnnotationFormatterFactory that will format values of properties annotated with a specific annotation.
* Adds a AnnotationFormatterFactory that returns the Formatter for properties annotated with a specific annotation.
* @param factory the annotation formatter factory
*/
<A extends Annotation, T> void add(AnnotationFormatterFactory<A, T> factory);
/**
* Get the Formatter for the type descriptor.
* @return the Formatter, or <code>null</code> if none is registered
* @return the Formatter, or <code>null</code> if no suitable one is registered
*/
@SuppressWarnings("unchecked")
Formatter getFormatter(TypeDescriptor type);
......
/*
* 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.format.number;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* A annotation to apply to a BigDecimal property to have its value formatted as currency amount using a {@link CurrencyFormatter}.
* @author Keith Donald
* @since 3.0
*/
@Target( { ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CurrencyFormat {
}
......@@ -3,6 +3,11 @@ package org.springframework.ui.format;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParseException;
......@@ -12,7 +17,6 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.style.ToStringCreator;
import org.springframework.ui.format.number.CurrencyFormat;
import org.springframework.ui.format.number.CurrencyFormatter;
import org.springframework.ui.format.number.IntegerFormatter;
......@@ -73,7 +77,7 @@ public class GenericFormatterRegistryTests {
registry.add(Integer.class, new AddressFormatter());
}
@CurrencyFormat
@Currency
public BigDecimal currencyField;
private static TypeDescriptor typeDescriptor(Class<?> clazz) {
......@@ -81,11 +85,11 @@ public class GenericFormatterRegistryTests {
}
public static class CurrencyAnnotationFormatterFactory implements
AnnotationFormatterFactory<CurrencyFormat, BigDecimal> {
AnnotationFormatterFactory<Currency, BigDecimal> {
private CurrencyFormatter currencyFormatter = new CurrencyFormatter();
public Formatter<BigDecimal> getFormatter(CurrencyFormat annotation) {
public Formatter<BigDecimal> getFormatter(Currency annotation) {
return currencyFormatter;
}
}
......@@ -161,5 +165,12 @@ public class GenericFormatterRegistryTests {
}
}
@Target( { ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Currency {
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册