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

This commit is contained in:
Keith Donald 2009-08-19 15:02:50 +00:00
parent 704cc79cee
commit 2bd664f7ee
3 changed files with 19 additions and 42 deletions

View File

@ -38,8 +38,8 @@ public interface FormatterRegistry {
* Adds a Formatter to this registry indexed by type. * Adds a Formatter to this registry indexed by type.
* Use this add method when type differs from <T>. * Use this add method when type differs from <T>.
* Calling getFormatter(type) returns a decorator that wraps the targetFormatter. * 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 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 objectType. * 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 type the object type
* @param targetFormatter the target formatter * @param targetFormatter the target formatter
* @param <T> the type of object the target formatter formats * @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); <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 * @param factory the annotation formatter factory
*/ */
<A extends Annotation, T> void add(AnnotationFormatterFactory<A, T> factory); <A extends Annotation, T> void add(AnnotationFormatterFactory<A, T> factory);
/** /**
* Get the Formatter for the type descriptor. * 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") @SuppressWarnings("unchecked")
Formatter getFormatter(TypeDescriptor type); Formatter getFormatter(TypeDescriptor type);

View File

@ -1,34 +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.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 {
}

View File

@ -3,6 +3,11 @@ package org.springframework.ui.format;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; 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.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.ParseException; import java.text.ParseException;
@ -12,7 +17,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.style.ToStringCreator; 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.CurrencyFormatter;
import org.springframework.ui.format.number.IntegerFormatter; import org.springframework.ui.format.number.IntegerFormatter;
@ -73,7 +77,7 @@ public class GenericFormatterRegistryTests {
registry.add(Integer.class, new AddressFormatter()); registry.add(Integer.class, new AddressFormatter());
} }
@CurrencyFormat @Currency
public BigDecimal currencyField; public BigDecimal currencyField;
private static TypeDescriptor typeDescriptor(Class<?> clazz) { private static TypeDescriptor typeDescriptor(Class<?> clazz) {
@ -81,11 +85,11 @@ public class GenericFormatterRegistryTests {
} }
public static class CurrencyAnnotationFormatterFactory implements public static class CurrencyAnnotationFormatterFactory implements
AnnotationFormatterFactory<CurrencyFormat, BigDecimal> { AnnotationFormatterFactory<Currency, BigDecimal> {
private CurrencyFormatter currencyFormatter = new CurrencyFormatter(); private CurrencyFormatter currencyFormatter = new CurrencyFormatter();
public Formatter<BigDecimal> getFormatter(CurrencyFormat annotation) { public Formatter<BigDecimal> getFormatter(Currency annotation) {
return currencyFormatter; return currencyFormatter;
} }
} }
@ -162,4 +166,11 @@ public class GenericFormatterRegistryTests {
} }
@Target( { ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Currency {
}
} }