From 2bd664f7ee54f110d5e1bbbc47e5fe974a6a192d Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Wed, 19 Aug 2009 15:02:50 +0000 Subject: [PATCH] removed framework specific annotation in favor of user-defined for now --- .../ui/format/FormatterRegistry.java | 8 ++--- .../ui/format/number/CurrencyFormat.java | 34 ------------------- .../format/GenericFormatterRegistryTests.java | 19 ++++++++--- 3 files changed, 19 insertions(+), 42 deletions(-) delete mode 100644 org.springframework.context/src/main/java/org/springframework/ui/format/number/CurrencyFormat.java diff --git a/org.springframework.context/src/main/java/org/springframework/ui/format/FormatterRegistry.java b/org.springframework.context/src/main/java/org/springframework/ui/format/FormatterRegistry.java index 0c895e9112..2ba39676a2 100644 --- a/org.springframework.context/src/main/java/org/springframework/ui/format/FormatterRegistry.java +++ b/org.springframework.context/src/main/java/org/springframework/ui/format/FormatterRegistry.java @@ -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 <T>, then delegates to targetFormatter to format the value. - * On parse, the decorator first delegates to the formatter to parse a <T>, then coerses the parsed value to objectType. + * On format, the decorator first coerses the instance of type to <T>, then delegates to targetFormatter to format the value. + * On parse, the decorator first delegates to the formatter to parse a <T>, then coerses the parsed value to type. * @param type the object type * @param targetFormatter the target formatter * @param the type of object the target formatter formats @@ -47,14 +47,14 @@ public interface FormatterRegistry { void add(Class type, Formatter 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 */ void add(AnnotationFormatterFactory factory); /** * Get the Formatter for the type descriptor. - * @return the Formatter, or null if none is registered + * @return the Formatter, or null if no suitable one is registered */ @SuppressWarnings("unchecked") Formatter getFormatter(TypeDescriptor type); diff --git a/org.springframework.context/src/main/java/org/springframework/ui/format/number/CurrencyFormat.java b/org.springframework.context/src/main/java/org/springframework/ui/format/number/CurrencyFormat.java deleted file mode 100644 index bd37362d6d..0000000000 --- a/org.springframework.context/src/main/java/org/springframework/ui/format/number/CurrencyFormat.java +++ /dev/null @@ -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 { - -} diff --git a/org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java b/org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java index 210bb37be9..ec5de930fc 100644 --- a/org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java +++ b/org.springframework.context/src/test/java/org/springframework/ui/format/GenericFormatterRegistryTests.java @@ -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 { + AnnotationFormatterFactory { private CurrencyFormatter currencyFormatter = new CurrencyFormatter(); - public Formatter getFormatter(CurrencyFormat annotation) { + public Formatter 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