javado polish

This commit is contained in:
Keith Donald 2009-06-08 04:09:31 +00:00
parent 68631eb80d
commit b8b84f4f39
4 changed files with 64 additions and 2 deletions

View File

@ -1,7 +1,36 @@
/*
* 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; package org.springframework.ui.format;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
/**
* A factory that creates Formatters to format property values on properties annotated with a particular format {@link Annotation}.
* For example, a <code>CurrencyAnnotationFormatterFactory</code> might create a {@link Formatter} that formats a <code>BigDecimal</code> value set on a property annotated with <code>@CurrencyFormat</code>.
* @author Keith Donald
* @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
*/
public interface AnnotationFormatterFactory<A extends Annotation, T> { public interface AnnotationFormatterFactory<A extends Annotation, T> {
/**
* Get the Formatter that will format the value of the property annotated with the provided annotation.
* The annotation instance can contain properties that may be used to configure the Formatter that is returned.
* @param annotation the annotation instance
* @return the Formatter to use to format values of properties annotated with the annotation.
*/
Formatter<T> getFormatter(A annotation); Formatter<T> getFormatter(A annotation);
} }

View File

@ -35,7 +35,6 @@ public interface Formatter<T> {
/** /**
* Parse an object from its formatted representation. * Parse an object from its formatted representation.
* TODO - remove dependency on java.text by replacing ParseException?
* @param formatted a formatted representation * @param formatted a formatted representation
* @param locale the user's locale * @param locale the user's locale
* @return the parsed object * @return the parsed object

View File

@ -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.format.number; package org.springframework.ui.format.number;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -5,6 +20,10 @@ import java.math.BigDecimal;
import org.springframework.ui.format.AnnotationFormatterFactory; import org.springframework.ui.format.AnnotationFormatterFactory;
import org.springframework.ui.format.Formatter; import org.springframework.ui.format.Formatter;
/**
* Returns a CurrencyFormatter for properties annotated with the {@link CurrencyFormat} annotation.
* @author Keith Donald
*/
public class CurrencyAnnotationFormatterFactory implements AnnotationFormatterFactory<CurrencyFormat, BigDecimal> { public class CurrencyAnnotationFormatterFactory implements AnnotationFormatterFactory<CurrencyFormat, BigDecimal> {
public Formatter<BigDecimal> getFormatter(CurrencyFormat annotation) { public Formatter<BigDecimal> getFormatter(CurrencyFormat annotation) {
return new CurrencyFormatter(); return new CurrencyFormatter();

View File

@ -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.format.number; package org.springframework.ui.format.number;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
@ -7,7 +22,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* A annotation to apply to a BigDecimal property to have property values formatted as currency using a {@link CurrencyFormatter}. * A annotation to apply to a BigDecimal property to have its value formatted as currency amount using a {@link CurrencyFormatter}.
* @author Keith Donald * @author Keith Donald
*/ */
@Target( { ElementType.METHOD, ElementType.FIELD }) @Target( { ElementType.METHOD, ElementType.FIELD })