From dc3fbf854a524902a767ad038ce80f01e1d99cee Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Wed, 27 Jun 2007 18:14:01 +0000 Subject: [PATCH] remove: BeanNameMapping, since it is a questionable feature and one always can use Converters which are robust under refactoring and which are features of the conversion process, not the Bean itself SVN: 707 --- .../common/annotation/BeanNameMapping.java | 41 ------------------- .../cisd/common/utilities/BeanUtils.java | 22 ---------- .../cisd/common/utilities/BeanUtilsTest.java | 20 --------- 3 files changed, 83 deletions(-) delete mode 100644 common/source/java/ch/systemsx/cisd/common/annotation/BeanNameMapping.java diff --git a/common/source/java/ch/systemsx/cisd/common/annotation/BeanNameMapping.java b/common/source/java/ch/systemsx/cisd/common/annotation/BeanNameMapping.java deleted file mode 100644 index c31459ab9c5..00000000000 --- a/common/source/java/ch/systemsx/cisd/common/annotation/BeanNameMapping.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2007 ETH Zuerich, CISD - * - * 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 ch.systemsx.cisd.common.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation that allows to override the name mapping of beans, i.e. that a setter requires a getter on the source - * bean with same name. - * - * @author Bernd Rinn - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -@Inherited -public @interface BeanNameMapping -{ - - /** - * The names to look for among the getters instead of the setter name. - */ - String[] names(); -} diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/BeanUtils.java b/common/source/java/ch/systemsx/cisd/common/utilities/BeanUtils.java index 1e91d31e6d9..820a6929bfc 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/BeanUtils.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/BeanUtils.java @@ -37,9 +37,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.lang.StringUtils; - -import ch.systemsx.cisd.common.annotation.BeanNameMapping; import ch.systemsx.cisd.common.annotation.CollectionMapping; import ch.systemsx.cisd.common.exceptions.CheckedExceptionTunnel; @@ -653,30 +650,11 @@ public final class BeanUtils private static Method getGetter(Method setter, Map<String, Method> sourceGetters, AnnotationMap annotationMap) { - final BeanNameMapping mapping = annotationMap.getAnnotation(BeanNameMapping.class); - if (mapping != null) - { - return getGetter(sourceGetters, getGetterPrefix(setter), mapping.names()); - } final String getterName = getGetterPrefix(setter) + setter.getName().substring("set".length()); final Method getter = sourceGetters.get(getterName); return getter; } - private static Method getGetter(Map<String, Method> sourceGetters, String prefix, String... attributeNames) - { - for (String attributeName : attributeNames) - { - final String getterName = prefix + StringUtils.capitalize(attributeName); - final Method getter = sourceGetters.get(getterName); - if (getter != null) - { - return getter; - } - } - return null; - } - private static String getGetterPrefix(final Method setter) { final Class<?> type = setter.getParameterTypes()[0]; diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/BeanUtilsTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/BeanUtilsTest.java index ed90cbb6ded..c2aae9cb8d5 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/BeanUtilsTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/BeanUtilsTest.java @@ -32,7 +32,6 @@ import org.apache.commons.lang.StringUtils; import org.testng.AssertJUnit; import org.testng.annotations.Test; -import ch.systemsx.cisd.common.annotation.BeanNameMapping; import ch.systemsx.cisd.common.annotation.CollectionMapping; /** @@ -957,31 +956,12 @@ public final class BeanUtilsTest return bar; } - @BeanNameMapping(names = {"bar", "foo"}) public void setBar(String bar) { this.bar = bar; } } - @Test - public void testNameMapping1() - { - final FooBean fooBean = new FooBean(); - fooBean.setFoo("foo is now bar"); - final BarBean barBean = BeanUtils.fillBean(BarBean.class, fooBean); - assertEquals(fooBean.getFoo(), barBean.getBar()); - } - - @Test - public void testNameMapping2() - { - final BarBean barBean = new BarBean(); - barBean.setBar("bar is still bar"); - final BarBean barBean2 = BeanUtils.fillBean(BarBean.class, barBean); - assertEquals(barBean.getBar(), barBean2.getBar()); - } - @Test public void testConverter() { -- GitLab