From 2e8bfb85cc5ca1bbb3850adb74c0a0db4787dc75 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Mon, 30 Jun 2008 05:17:40 +0000 Subject: [PATCH] test --- .../registry/DefaultFormatterRegistry.java | 67 ------------- .../registry/GenericFormatterRegistry.java | 97 ------------------- .../binding/format/registry/package.html | 7 -- 3 files changed, 171 deletions(-) delete mode 100644 spring-binding/src/main/java/org/springframework/binding/format/registry/DefaultFormatterRegistry.java delete mode 100644 spring-binding/src/main/java/org/springframework/binding/format/registry/GenericFormatterRegistry.java delete mode 100644 spring-binding/src/main/java/org/springframework/binding/format/registry/package.html diff --git a/spring-binding/src/main/java/org/springframework/binding/format/registry/DefaultFormatterRegistry.java b/spring-binding/src/main/java/org/springframework/binding/format/registry/DefaultFormatterRegistry.java deleted file mode 100644 index 3da13f07..00000000 --- a/spring-binding/src/main/java/org/springframework/binding/format/registry/DefaultFormatterRegistry.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2004-2008 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.binding.format.registry; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.springframework.binding.convert.service.DefaultConversionService; -import org.springframework.binding.format.FormatterRegistry; -import org.springframework.binding.format.formatters.BooleanFormatter; -import org.springframework.binding.format.formatters.DateFormatter; -import org.springframework.binding.format.formatters.IntegerFormatter; -import org.springframework.binding.format.formatters.NumberFormatter; - -public class DefaultFormatterRegistry extends GenericFormatterRegistry { - - /** - * A singleton shared instance. Should never be modified. - */ - private static DefaultFormatterRegistry SHARED_INSTANCE; - - /** - * Creates a new formatter registry. - */ - public DefaultFormatterRegistry() { - registerDefaultFormatters(); - } - - /** - * Registers the default formatters. Subclasses may override. - */ - protected void registerDefaultFormatters() { - registerFormatter(new IntegerFormatter(Integer.class)); - registerFormatter(new IntegerFormatter(BigInteger.class)); - registerFormatter(new IntegerFormatter(Long.class)); - registerFormatter(new IntegerFormatter(Short.class)); - registerFormatter(new NumberFormatter(Float.class)); - registerFormatter(new NumberFormatter(Double.class)); - registerFormatter(new NumberFormatter(BigDecimal.class)); - registerFormatter(new NumberFormatter(Byte.class)); - registerFormatter(new BooleanFormatter()); - registerFormatter(new DateFormatter()); - } - - /** - * Returns the shared {@link DefaultConversionService} instance. - */ - public synchronized static FormatterRegistry getSharedInstance() { - if (SHARED_INSTANCE == null) { - SHARED_INSTANCE = new DefaultFormatterRegistry(); - } - return SHARED_INSTANCE; - } -} diff --git a/spring-binding/src/main/java/org/springframework/binding/format/registry/GenericFormatterRegistry.java b/spring-binding/src/main/java/org/springframework/binding/format/registry/GenericFormatterRegistry.java deleted file mode 100644 index a4f0c589..00000000 --- a/spring-binding/src/main/java/org/springframework/binding/format/registry/GenericFormatterRegistry.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2004-2008 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.binding.format.registry; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.binding.format.Formatter; -import org.springframework.binding.format.FormatterRegistry; -import org.springframework.util.Assert; - -/** - * A general-purpose {@link FormatterRegistry} implementation allows formatters to be registered programatically. - * - * @see #registerFormatter(Formatter) - * @see #registerFormatter(String, Formatter) - * - * @author Keith Donald - */ -public class GenericFormatterRegistry implements FormatterRegistry { - - private Map formattersById = new HashMap(); - - private Map formattersByClass = new HashMap(); - - public Formatter getFormatter(Class clazz) { - Assert.notNull(clazz, "The formatted class argument is required"); - clazz = convertToWrapperClassIfNecessary(clazz); - return (Formatter) formattersByClass.get(clazz); - } - - public Formatter getFormatter(Class clazz, String id) { - Assert.notNull(clazz, "The formatted class argument is required"); - Assert.hasText(id, "The id of the custom formatter is required"); - Formatter formatter = (Formatter) formattersById.get(id); - if (formatter != null && !formatter.getObjectType().equals(clazz)) { - throw new IllegalArgumentException( - "Provided class argument does not match registered Formatter objectType [" + clazz.getName() - + "]; unable to return custom Formatter instance " + formatter); - } - return formatter; - } - - // impl - - public void registerFormatter(Formatter formatter) { - Assert.notNull(formatter, "The formatter to register is required"); - formattersByClass.put(formatter.getObjectType(), formatter); - } - - public void registerFormatter(String id, Formatter formatter) { - Assert.hasText(id, "The id of the custom formatter is required"); - Assert.notNull(formatter, "The formatter to register is required"); - formattersById.put(id, formatter); - } - - // helpers - - private Class convertToWrapperClassIfNecessary(Class targetType) { - if (targetType.isPrimitive()) { - if (targetType.equals(int.class)) { - return Integer.class; - } else if (targetType.equals(short.class)) { - return Short.class; - } else if (targetType.equals(long.class)) { - return Long.class; - } else if (targetType.equals(float.class)) { - return Float.class; - } else if (targetType.equals(double.class)) { - return Double.class; - } else if (targetType.equals(byte.class)) { - return Byte.class; - } else if (targetType.equals(boolean.class)) { - return Boolean.class; - } else if (targetType.equals(char.class)) { - return Character.class; - } else { - throw new IllegalStateException("Should never happen - primitive type is not a primitive?"); - } - } else { - return targetType; - } - } -} \ No newline at end of file diff --git a/spring-binding/src/main/java/org/springframework/binding/format/registry/package.html b/spring-binding/src/main/java/org/springframework/binding/format/registry/package.html deleted file mode 100644 index dca00809..00000000 --- a/spring-binding/src/main/java/org/springframework/binding/format/registry/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - -

-A system for registering Formatters for lookup by UI artifacts. -

- - \ No newline at end of file